Skip to content

Commit

Permalink
Fix eclipse-tycho#194 Support additional repositories defined in the …
Browse files Browse the repository at this point in the history
…maven-target

location

Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
  • Loading branch information
laeubi committed Jul 20, 2021
1 parent c7d99e1 commit a8a5e17
Show file tree
Hide file tree
Showing 15 changed files with 261 additions and 23 deletions.
8 changes: 6 additions & 2 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

This page describes the noteworthy improvements provided by each release of Eclipse Tycho.

### Next release...
## Next release...

### Support for new m2e-pde features

Tycho supports the new m2e-pde features regarding [multiple dependencies per target](https://github.com/eclipse-m2e/m2e-core/blob/master/RELEASE_NOTES.md#the-m2e-pde-editor-now-supports-adding-more-than-one-dependency-per-target-location) and specifying [extra repositories in the target](https://github.com/eclipse-m2e/m2e-core/blob/master/RELEASE_NOTES.md#the-m2e-pde-editor-now-supports-adding-additional-maven-repoistories-for-a-target-location).

## 2.4.0

### [Support resolving of JUnit Classpath Container](https://bugs.eclipse.org/bugs/show_bug.cgi?id=572602)
It is now possible to resolve the JDT 'JUnit Classpath Container', for this do the follwoing:
It is now possible to resolve the JDT 'JUnit Classpath Container', for this do the following:

- add the 'JUnit Classpath Container' to the classpath of your eclipse project
- make sure you check in the .classpath file
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2021 Christoph Läubrich and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.tycho.core.shared;

public interface MavenArtifactRepositoryReference {

String getId();

String getUrl();

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020 Christoph Läubrich and others.
* Copyright (c) 2020, 2021 Christoph Läubrich and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -14,6 +14,7 @@

import java.io.File;
import java.util.Collection;
import java.util.Collections;

public interface MavenDependenciesResolver {

Expand All @@ -35,8 +36,15 @@ public interface MavenDependenciesResolver {
* the given artifact as well
* @return
*/
default Collection<? /* IArtifactFacade */> resolve(String groupId, String artifactId, String version,
String packaging, String classifier, String dependencyScope) {
return resolve(groupId, artifactId, version, packaging, classifier, dependencyScope, Collections.emptyList());
}

Collection<? /* IArtifactFacade */> resolve(String groupId, String artifactId, String version, String packaging,
String classifier, String dependencyScope);
String classifier, String dependencyScope,
Collection<MavenArtifactRepositoryReference> additionalRepositories);

File getRepositoryRoot();

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public MavenTargetDefinitionContent(MavenGAVLocation location, MavenDependencies
Collection<?> resolve = mavenDependenciesResolver.resolve(mavenDependency.getGroupId(),
mavenDependency.getArtifactId(), mavenDependency.getVersion(),
mavenDependency.getArtifactType(), mavenDependency.getClassifier(),
location.getIncludeDependencyScope());
location.getIncludeDependencyScope(), location.getRepositoryReferences());

Iterator<IArtifactFacade> resolvedArtifacts = resolve.stream().filter(IArtifactFacade.class::isInstance)
.map(IArtifactFacade.class::cast).iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [Bug 568729] - Support new "Maven" Target location
* [Bug 569481] - Support for maven target location includeSource="true" attribute
* [Issue 189] - Support multiple maven-dependencies for one target location
* [Issue 194] - Support additional repositories defined in the maven-target location #
*******************************************************************************/
package org.eclipse.tycho.p2.target.facade;

Expand All @@ -21,6 +22,8 @@
import java.util.List;
import java.util.Properties;

import org.eclipse.tycho.core.shared.MavenArtifactRepositoryReference;

// TODO javadoc
public interface TargetDefinition {

Expand Down Expand Up @@ -85,6 +88,8 @@ enum MissingManifestStrategy {

Collection<MavenDependency> getRoots();

Collection<MavenArtifactRepositoryReference> getRepositoryReferences();

boolean includeSource();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* - [Bug 568729] - Support new "Maven" Target location
* - [Bug 569481] - Support for maven target location includeSource="true" attribute
* - [Issue 189] - Support multiple maven-dependencies for one target location
* - [Issue 194] - Support additional repositories defined in the maven-target location #
*******************************************************************************/
package org.eclipse.tycho.core.ee;

Expand All @@ -39,6 +40,7 @@
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

import org.eclipse.tycho.core.shared.MavenArtifactRepositoryReference;
import org.eclipse.tycho.p2.target.facade.TargetDefinition;
import org.eclipse.tycho.p2.target.facade.TargetDefinitionSyntaxException;

Expand Down Expand Up @@ -222,6 +224,31 @@ public Collection<MavenDependency> getRoots() {
return Collections.singleton(new MavenDependencyRoot(dom));
}

@Override
public Collection<MavenArtifactRepositoryReference> getRepositoryReferences() {
for (Element dependencies : dom.getChildren("repositories")) {
List<MavenArtifactRepositoryReference> list = new ArrayList<MavenArtifactRepositoryReference>();
for (Element repository : dependencies.getChildren("repository")) {
list.add(new MavenArtifactRepositoryReference() {

@Override
public String getId() {
return getTextFromChild(repository, "id",
String.valueOf(System.identityHashCode(repository)));
}

@Override
public String getUrl() {
return getTextFromChild(repository, "url", null);
}

});
}
return list;
}
return Collections.emptyList();
}

}

private static final class MavenDependencyRoot implements MavenDependency {
Expand All @@ -234,37 +261,27 @@ public MavenDependencyRoot(Element dom) {

@Override
public String getGroupId() {
return getTextFromChild("groupId", null);
return getTextFromChild(dom, "groupId", null);
}

@Override
public String getArtifactId() {
return getTextFromChild("artifactId", null);
return getTextFromChild(dom, "artifactId", null);
}

@Override
public String getVersion() {
return getTextFromChild("version", null);
return getTextFromChild(dom, "version", null);
}

@Override
public String getArtifactType() {
return getTextFromChild("type", "jar");
return getTextFromChild(dom, "type", "jar");
}

@Override
public String getClassifier() {
return getTextFromChild("classifier", "");
}

private String getTextFromChild(String childName, String defaultValue) {
for (Element element : dom.getChildren(childName)) {
return element.getNormalizedText();
}
if (defaultValue != null) {
return defaultValue;
}
throw new TargetDefinitionSyntaxException("Missing child element '" + childName + "'");
return getTextFromChild(dom, "classifier", "");
}

@Override
Expand All @@ -284,6 +301,16 @@ public String toString() {

}

private static String getTextFromChild(Element dom, String childName, String defaultValue) {
for (Element element : dom.getChildren(childName)) {
return element.getNormalizedText();
}
if (defaultValue != null) {
return defaultValue;
}
throw new TargetDefinitionSyntaxException("Missing child element '" + childName + "'");
}

public class IULocation implements TargetDefinition.InstallableUnitLocation {
private final Element dom;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020 Christoph Läubrich and others.
* Copyright (c) 2020, 2021 Christoph Läubrich and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -15,9 +15,11 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.execution.MavenSession;
Expand All @@ -29,6 +31,7 @@
import org.eclipse.sisu.equinox.embedder.EmbeddedEquinox;
import org.eclipse.sisu.equinox.embedder.EquinoxLifecycleListener;
import org.eclipse.tycho.core.maven.MavenArtifactFacade;
import org.eclipse.tycho.core.shared.MavenArtifactRepositoryReference;
import org.eclipse.tycho.core.shared.MavenDependenciesResolver;
import org.eclipse.tycho.p2.metadata.IArtifactFacade;

Expand All @@ -46,7 +49,7 @@ public class MavenDependenciesResolverConfigurer extends EquinoxLifecycleListene

@Override
public Collection<?> resolve(String groupId, String artifactId, String version, String packaging, String classifier,
String dependencyScope) {
String dependencyScope, Collection<MavenArtifactRepositoryReference> additionalRepositories) {
Artifact artifact;
if (classifier != null && !classifier.isEmpty()) {
artifact = repositorySystem.createArtifactWithClassifier(groupId, artifactId, version, packaging,
Expand All @@ -61,7 +64,13 @@ public Collection<?> resolve(String groupId, String artifactId, String version,
request.setOffline(session.isOffline());
request.setLocalRepository(session.getLocalRepository());
request.setResolveTransitively(dependencyScope != null && !dependencyScope.isEmpty());
request.setRemoteRepositories(session.getCurrentProject().getRemoteArtifactRepositories());
List<ArtifactRepository> repositories = new ArrayList<>(
session.getCurrentProject().getRemoteArtifactRepositories());
for (MavenArtifactRepositoryReference reference : additionalRepositories) {
repositories.add(
repositorySystem.createArtifactRepository(reference.getId(), reference.getUrl(), null, null, null));
}
request.setRemoteRepositories(repositories);
ArtifactResolutionResult result = repositorySystem.resolve(request);
Set<Artifact> artifacts = result.getArtifacts();
ArrayList<IArtifactFacade> list = new ArrayList<IArtifactFacade>();
Expand Down
49 changes: 49 additions & 0 deletions tycho-its/projects/target.mavenRepos/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- - Copyright (c) 2015, 2020 SAP SE and others. - All rights reserved. This
program and the accompanying materials - are made available under the terms
of the Eclipse Public License v1.0 - which accompanies this distribution,
and is available at - http://www.eclipse.org/legal/epl-v10.html - - Contributors:
- SAP SE - initial API and implementation -->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.eclipse.tycho.itests</groupId>
<artifactId>issue-194-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
<tycho-version>2.5.0-SNAPSHOT</tycho-version>
</properties>

<modules>
<module>test.bundle</module>
<module>test.feature</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<target>
<file>../test.target</file>
</target>
</configuration>
</plugin>
</plugins>
</build>



</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Bundle
Bundle-SymbolicName: test.bundle
Bundle-Version: 0.0.1.qualifier
Require-Bundle: wrapped.edu.ucar.cdm;bundle-version="5.0.0",
wrapped.edu.ucar.udunits;bundle-version="5.0.0"
Automatic-Module-Name: test.bundle
Bundle-RequiredExecutionEnvironment: JavaSE-11
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
20 changes: 20 additions & 0 deletions tycho-its/projects/target.mavenRepos/test.bundle/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2012 SAP AG All rights reserved. This program and the
accompanying materials are made available under the terms of the Eclipse
Public License v1.0 which accompanies this distribution, and is available
at http://www.eclipse.org/legal/epl-v10.html -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>test.bundle</artifactId>
<packaging>eclipse-plugin</packaging>

<parent>
<groupId>org.eclipse.tycho.itests</groupId>
<artifactId>issue-194-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin.includes = feature.xml
40 changes: 40 additions & 0 deletions tycho-its/projects/target.mavenRepos/test.feature/feature.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="test.feature"
label="Feature"
version="0.0.1.qualifier">

<description url="http://www.example.com/description">
[Enter Feature Description here.]
</description>

<copyright url="http://www.example.com/copyright">
[Enter Copyright Description here.]
</copyright>

<license url="http://www.example.com/license">
[Enter License Description here.]
</license>

<plugin
id="wrapped.edu.ucar.cdm"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="wrapped.edu.ucar.udunits"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="com.beust.jcommander"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

</feature>
Loading

0 comments on commit a8a5e17

Please sign in to comment.