diff --git a/tycho-bundles/org.eclipse.tycho.core.shared/src/main/java/org/eclipse/tycho/core/shared/MavenDependenciesResolver.java b/tycho-bundles/org.eclipse.tycho.core.shared/src/main/java/org/eclipse/tycho/core/shared/MavenDependenciesResolver.java
index 09fcac4d41..fda0c0e63e 100644
--- a/tycho-bundles/org.eclipse.tycho.core.shared/src/main/java/org/eclipse/tycho/core/shared/MavenDependenciesResolver.java
+++ b/tycho-bundles/org.eclipse.tycho.core.shared/src/main/java/org/eclipse/tycho/core/shared/MavenDependenciesResolver.java
@@ -44,7 +44,7 @@ public interface MavenDependenciesResolver {
* the packaging type, might be null
in witch case "jar" is assumed
* @param classifier
* the classifier or null
if no classifier is desired
- * @param dependencyScope
+ * @param collection
* optional dependency scope, if given it tries to resolve transitive dependencies of
* the given artifact as well
* @param additionalRepositories
@@ -53,14 +53,14 @@ public interface MavenDependenciesResolver {
* @throws DependencyResolutionException
*/
default Collection /* IArtifactFacade */> resolve(String groupId, String artifactId, String version,
- String packaging, String classifier, String dependencyScope, int depth,
+ String packaging, String classifier, Collection scopes, int depth,
Collection additionalRepositories) throws DependencyResolutionException {
- return resolve(groupId, artifactId, version, packaging, classifier, dependencyScope, depth,
- additionalRepositories, null);
+ return resolve(groupId, artifactId, version, packaging, classifier, scopes, depth, additionalRepositories,
+ null);
}
Collection /* IArtifactFacade */> resolve(String groupId, String artifactId, String version, String packaging,
- String classifier, String dependencyScope, int depth,
+ String classifier, Collection scopes, int depth,
Collection additionalRepositories,
Object/* MavenSession */ session) throws DependencyResolutionException;
diff --git a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/target/TestResolverFactory.java b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/target/TestResolverFactory.java
index 48e645288e..9f3a62bf37 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/target/TestResolverFactory.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/target/TestResolverFactory.java
@@ -67,7 +67,7 @@ public TestResolverFactory(MavenLogger logger) {
@Override
public Collection> resolve(String groupId, String artifactId, String version, String packaging,
- String classifier, String dependencyScope, int depth,
+ String classifier, Collection dependencyScopes, int depth,
Collection additionalRepositories, Object session)
throws DependencyResolutionException {
GAV gav = new GAV(groupId, artifactId, version);
diff --git a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/resolver/MavenTargetDefinitionContent.java b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/resolver/MavenTargetDefinitionContent.java
index f9e24e6a89..b93acc8953 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/resolver/MavenTargetDefinitionContent.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/resolver/MavenTargetDefinitionContent.java
@@ -109,7 +109,6 @@ public MavenTargetDefinitionContent(MavenGAVLocation location, MavenDependencies
List locationSourceBundles = new ArrayList<>();
for (MavenDependency mavenDependency : location.getRoots()) {
int depth;
- String scope = location.getIncludeDependencyScope();
DependencyDepth dependencyDepth = location.getIncludeDependencyDepth();
if (dependencyDepth == DependencyDepth.NONE
&& POM_PACKAGING_TYPE.equalsIgnoreCase(mavenDependency.getArtifactType())) {
@@ -131,8 +130,8 @@ public MavenTargetDefinitionContent(MavenGAVLocation location, MavenDependencies
try {
resolve = mavenDependenciesResolver.resolve(mavenDependency.getGroupId(),
mavenDependency.getArtifactId(), mavenDependency.getVersion(),
- mavenDependency.getArtifactType(), mavenDependency.getClassifier(), scope, depth,
- location.getRepositoryReferences());
+ mavenDependency.getArtifactType(), mavenDependency.getClassifier(),
+ location.getIncludeDependencyScopes(), depth, location.getRepositoryReferences());
} catch (DependencyResolutionException e1) {
throw new TargetDefinitionResolutionException("MavenDependency " + mavenDependency + " of location "
+ location + " could not be resolved", e1);
diff --git a/tycho-bundles/org.eclipse.tycho.p2.resolver.shared/src/main/java/org/eclipse/tycho/p2/target/facade/TargetDefinition.java b/tycho-bundles/org.eclipse.tycho.p2.resolver.shared/src/main/java/org/eclipse/tycho/p2/target/facade/TargetDefinition.java
index 2ed9404c57..ab0b240228 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.resolver.shared/src/main/java/org/eclipse/tycho/p2/target/facade/TargetDefinition.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.resolver.shared/src/main/java/org/eclipse/tycho/p2/target/facade/TargetDefinition.java
@@ -97,7 +97,7 @@ enum DependencyDepth {
NONE, DIRECT, INFINITE;
}
- String getIncludeDependencyScope();
+ Collection getIncludeDependencyScopes();
DependencyDepth getIncludeDependencyDepth();
diff --git a/tycho-bundles/org.eclipse.tycho.p2.resolver.shared/src/main/java/org/eclipse/tycho/p2/target/facade/TargetDefinitionFile.java b/tycho-bundles/org.eclipse.tycho.p2.resolver.shared/src/main/java/org/eclipse/tycho/p2/target/facade/TargetDefinitionFile.java
index ef3840440f..02ef6c027c 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.resolver.shared/src/main/java/org/eclipse/tycho/p2/target/facade/TargetDefinitionFile.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.resolver.shared/src/main/java/org/eclipse/tycho/p2/target/facade/TargetDefinitionFile.java
@@ -163,7 +163,7 @@ public String getUri() {
private static class MavenLocation implements TargetDefinition.MavenGAVLocation {
private final Set globalExcludes;
- private final String includeDependencyScope;
+ private final Collection includeDependencyScopes;
private final MissingManifestStrategy manifestStrategy;
private final boolean includeSource;
private final Collection instructions;
@@ -172,12 +172,12 @@ private static class MavenLocation implements TargetDefinition.MavenGAVLocation
private final Collection repositoryReferences;
private final Element featureTemplate;
- public MavenLocation(Collection roots, String includeDependencyScope,
+ public MavenLocation(Collection roots, Collection includeDependencyScopes,
MissingManifestStrategy manifestStrategy, Set globalExcludes, boolean includeSource,
Collection instructions, DependencyDepth dependencyDepth,
Collection repositoryReferences, Element featureTemplate) {
this.roots = roots;
- this.includeDependencyScope = includeDependencyScope;
+ this.includeDependencyScopes = includeDependencyScopes;
this.manifestStrategy = manifestStrategy;
this.globalExcludes = globalExcludes;
this.includeSource = includeSource;
@@ -187,9 +187,8 @@ public MavenLocation(Collection roots, String includeDependency
this.featureTemplate = featureTemplate == null ? null : (Element) featureTemplate.cloneNode(true);
}
- @Override
- public String getIncludeDependencyScope() {
- return includeDependencyScope;
+ public Collection getIncludeDependencyScopes() {
+ return includeDependencyScopes;
}
@Override
@@ -207,7 +206,7 @@ public String toString() {
StringBuilder builder = new StringBuilder("MavenDependencyRoots = ");
builder.append(getRoots());
builder.append(", IncludeDependencyScope = ");
- builder.append(getIncludeDependencyScope());
+ builder.append(getIncludeDependencyScopes());
builder.append(", MissingManifestStrategy = ");
builder.append(getMissingManifestStrategy());
builder.append(", IncludeSource = ");
@@ -566,9 +565,37 @@ private static MavenLocation parseMavenLocation(Element dom) {
for (Element element : getChildren(dom, "exclude")) {
globalExcludes.add(element.getTextContent());
}
+ Collection scopes = new ArrayList<>();
String scope = dom.getAttribute("includeDependencyScope");
+ if (dom.hasAttribute("includeDependencyScopes")) {
+ String scopesAttribute = dom.getAttribute("includeDependencyScopes");
+ for (String s : scopesAttribute.split(",")) {
+ scopes.add(s.strip());
+ }
+ } else {
+ //backward compat ...
+ String SCOPE_COMPILE = "compile";
+ String SCOPE_TEST = "test";
+ String SCOPE_RUNTIME = "runtime";
+ String SCOPE_PROVIDED = "provided";
+ String SCOPE_SYSTEM = "system";
+ if (scope == null || scope.isBlank() || SCOPE_COMPILE.equalsIgnoreCase(scope)) {
+ scopes.add(SCOPE_COMPILE);
+ } else if (SCOPE_PROVIDED.equalsIgnoreCase(scope)) {
+ scopes.add(SCOPE_PROVIDED);
+ scopes.add(SCOPE_COMPILE);
+ scopes.add(SCOPE_SYSTEM);
+ scopes.add(SCOPE_RUNTIME);
+ } else if (SCOPE_TEST.equalsIgnoreCase(scope)) {
+ scopes.add(SCOPE_TEST);
+ scopes.add(SCOPE_COMPILE);
+ scopes.add(SCOPE_PROVIDED);
+ scopes.add(SCOPE_SYSTEM);
+ scopes.add(SCOPE_RUNTIME);
+ }
+ }
Element featureTemplate = getChild(dom, "feature");
- return new MavenLocation(parseRoots(dom, globalExcludes), scope, parseManifestStrategy(dom), globalExcludes,
+ return new MavenLocation(parseRoots(dom, globalExcludes), scopes, parseManifestStrategy(dom), globalExcludes,
Boolean.parseBoolean(dom.getAttribute("includeSource")), parseInstructions(dom),
parseDependencyDepth(dom, scope), parseRepositoryReferences(dom), featureTemplate);
}
diff --git a/tycho-core/src/main/java/org/eclipse/tycho/osgi/configuration/MavenDependenciesResolverConfigurer.java b/tycho-core/src/main/java/org/eclipse/tycho/osgi/configuration/MavenDependenciesResolverConfigurer.java
index ae83df1e4b..81346098ef 100644
--- a/tycho-core/src/main/java/org/eclipse/tycho/osgi/configuration/MavenDependenciesResolverConfigurer.java
+++ b/tycho-core/src/main/java/org/eclipse/tycho/osgi/configuration/MavenDependenciesResolverConfigurer.java
@@ -13,10 +13,6 @@
package org.eclipse.tycho.osgi.configuration;
import static org.apache.maven.artifact.Artifact.SCOPE_COMPILE;
-import static org.apache.maven.artifact.Artifact.SCOPE_PROVIDED;
-import static org.apache.maven.artifact.Artifact.SCOPE_RUNTIME;
-import static org.apache.maven.artifact.Artifact.SCOPE_SYSTEM;
-import static org.apache.maven.artifact.Artifact.SCOPE_TEST;
import java.io.File;
import java.io.FileReader;
@@ -66,7 +62,7 @@ public class MavenDependenciesResolverConfigurer extends EquinoxLifecycleListene
@Override
public Collection> resolve(String groupId, String artifactId, String version, String packaging, String classifier,
- String dependencyScope, int depth, Collection additionalRepositories,
+ Collection scopes, int depth, Collection additionalRepositories,
Object session) throws DependencyResolutionException {
Artifact artifact;
if (classifier != null && !classifier.isEmpty()) {
@@ -87,11 +83,11 @@ public Collection> resolve(String groupId, String artifactId, String version,
public boolean include(Artifact a) {
List trail = a.getDependencyTrail();
if (logger.isDebugEnabled()) {
- logger.debug("[depth=" + trail.size() + ", scope matches =" + isValidScope(a, dependencyScope)
- + "][" + a + "][" + trail.stream().collect(Collectors.joining(" >> ")) + "]");
+ logger.debug("[depth=" + trail.size() + ", scope matches =" + isValidScope(a, scopes) + "][" + a
+ + "][" + trail.stream().collect(Collectors.joining(" >> ")) + "]");
}
if (trail.size() <= depth) {
- return isValidScope(a, dependencyScope);
+ return isValidScope(a, scopes);
}
return false;
}
@@ -117,24 +113,20 @@ public boolean include(Artifact a) {
.collect(Collectors.toList());
}
- protected boolean isValidScope(Artifact artifact, String desiredScope) {
+ protected boolean isValidScope(Artifact artifact, Collection scopes) {
String artifactScope = artifact.getScope();
if (artifactScope == null || artifactScope.isBlank()) {
return true;
}
//compile is the default scope if not specified see
// https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#dependency-scope
- if (desiredScope == null || desiredScope.isBlank() || SCOPE_COMPILE.equalsIgnoreCase(desiredScope)) {
+ if (scopes == null || scopes.isEmpty()) {
return SCOPE_COMPILE.equalsIgnoreCase(artifactScope);
}
- if (SCOPE_PROVIDED.equalsIgnoreCase(desiredScope)) {
- return SCOPE_PROVIDED.equalsIgnoreCase(artifactScope) || SCOPE_COMPILE.equalsIgnoreCase(artifactScope)
- || SCOPE_SYSTEM.equalsIgnoreCase(artifactScope) || SCOPE_RUNTIME.equalsIgnoreCase(artifactScope);
- }
- if (SCOPE_TEST.equalsIgnoreCase(desiredScope)) {
- return SCOPE_TEST.equalsIgnoreCase(artifactScope) || SCOPE_COMPILE.equalsIgnoreCase(artifactScope)
- || SCOPE_PROVIDED.equalsIgnoreCase(artifactScope) || SCOPE_SYSTEM.equalsIgnoreCase(artifactScope)
- || SCOPE_RUNTIME.equalsIgnoreCase(artifactScope);
+ for (String scope : scopes) {
+ if (artifactScope.equals(scope)) {
+ return true;
+ }
}
//invalid scope type
return false;
diff --git a/tycho-its/projects/target.maven-scopes/pom.xml b/tycho-its/projects/target.maven-scopes/pom.xml
new file mode 100644
index 0000000000..e67fe31a4d
--- /dev/null
+++ b/tycho-its/projects/target.maven-scopes/pom.xml
@@ -0,0 +1,48 @@
+
+
+
+
+ 4.0.0
+
+ org.eclipse.tycho.itests
+ issue-447-parent
+ 0.0.1-SNAPSHOT
+ pom
+
+ 2.7.0-SNAPSHOT
+
+
+
+ test.bundle
+
+
+
+
+
+ org.eclipse.tycho
+ tycho-maven-plugin
+ ${tycho-version}
+ true
+
+
+ org.eclipse.tycho
+ target-platform-configuration
+ ${tycho-version}
+
+
+ ../test.target
+
+
+
+
+
+
+
+
+
diff --git a/tycho-its/projects/target.maven-scopes/test.bundle/META-INF/MANIFEST.MF b/tycho-its/projects/target.maven-scopes/test.bundle/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..bcd40d8a72
--- /dev/null
+++ b/tycho-its/projects/target.maven-scopes/test.bundle/META-INF/MANIFEST.MF
@@ -0,0 +1,11 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Bundle
+Bundle-SymbolicName: test.bundle
+Bundle-Version: 0.0.1.qualifier
+Automatic-Module-Name: test.bundle
+Bundle-RequiredExecutionEnvironment: JavaSE-11
+Require-Bundle: net.bytebuddy.byte-buddy;bundle-version="1.12.1",
+ net.bytebuddy.byte-buddy-agent;bundle-version="1.12.1",
+ org.mockito.mockito-core;bundle-version="4.1.0",
+ org.objenesis;bundle-version="3.2.0"
diff --git a/tycho-its/projects/target.maven-scopes/test.bundle/build.properties b/tycho-its/projects/target.maven-scopes/test.bundle/build.properties
new file mode 100644
index 0000000000..34d2e4d2da
--- /dev/null
+++ b/tycho-its/projects/target.maven-scopes/test.bundle/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/tycho-its/projects/target.maven-scopes/test.bundle/pom.xml b/tycho-its/projects/target.maven-scopes/test.bundle/pom.xml
new file mode 100644
index 0000000000..d8b84f1558
--- /dev/null
+++ b/tycho-its/projects/target.maven-scopes/test.bundle/pom.xml
@@ -0,0 +1,21 @@
+
+
+
+ 4.0.0
+
+ test.bundle
+ eclipse-plugin
+
+
+ org.eclipse.tycho.itests
+ issue-447-parent
+ 0.0.1-SNAPSHOT
+
+
+
\ No newline at end of file
diff --git a/tycho-its/projects/target.maven-scopes/test.bundle/src/test/bundle/TestClass.java b/tycho-its/projects/target.maven-scopes/test.bundle/src/test/bundle/TestClass.java
new file mode 100644
index 0000000000..b2f4ba80f2
--- /dev/null
+++ b/tycho-its/projects/target.maven-scopes/test.bundle/src/test/bundle/TestClass.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2022 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 test.bundle;
+
+public class TestClass {
+ public static void main(String[] args) {
+ }
+}
diff --git a/tycho-its/projects/target.maven-scopes/test.target b/tycho-its/projects/target.maven-scopes/test.target
new file mode 100644
index 0000000000..d9e0592fde
--- /dev/null
+++ b/tycho-its/projects/target.maven-scopes/test.target
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+ org.mockito
+ mockito-core
+ 4.1.0
+ jar
+
+
+
+
+
\ No newline at end of file
diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetPlatformLocationsTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetPlatformLocationsTest.java
index fe3d73e655..3bbc8d38a1 100644
--- a/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetPlatformLocationsTest.java
+++ b/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetPlatformLocationsTest.java
@@ -39,6 +39,13 @@ public void testMavenLocation() throws Exception {
verifier.verifyErrorFreeLog();
}
+ @Test
+ public void testMavenLocationScopes() throws Exception {
+ Verifier verifier = getVerifier("target.maven-scopes", false, true);
+ verifier.executeGoal("verify");
+ verifier.verifyErrorFreeLog();
+ }
+
@Test
public void testMavenArtifactHaveMavenRepoPath() throws Exception {
Verifier verifier = getVerifier("target.maven", false, true);