Skip to content

Commit a9f0372

Browse files
committed
Add classpathDependencies option for target platform resolution
Adds a new <classpathDependencies> configuration option under <dependency-resolution> in target-platform-configuration with values require (default), optional, and ignore. This controls how jars.extra.classpath entries from build.properties are handled during resolution, fixing issues where platform-specific extra classpath entries cause resolution failures (e.g. SWT SVG fragment).
1 parent 591fba2 commit a9f0372

5 files changed

Lines changed: 81 additions & 4 deletions

File tree

target-platform-configuration/src/main/java/org/eclipse/tycho/target/DependencyResolutionConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.Properties;
1414

1515
import org.apache.maven.plugins.annotations.Parameter;
16+
import org.eclipse.tycho.ClasspathDependenciesAction;
1617
import org.eclipse.tycho.OptionalResolutionAction;
1718
import org.eclipse.tycho.core.TargetPlatformConfiguration.LocalArtifactHandling;
1819
import org.eclipse.tycho.core.resolver.DefaultTargetPlatformConfigurationReader;
@@ -27,6 +28,7 @@ public class ExtraRequirementConfiguration {
2728
}
2829

2930
public OptionalResolutionAction optionalDependencies;
31+
public ClasspathDependenciesAction classpathDependencies;
3032
public List<ExtraRequirementConfiguration> extraRequirements;
3133
public Properties profileProperties;
3234
@Parameter(property = DefaultTargetPlatformConfigurationReader.LOCAL_ARTIFACTS_PROPERTY, name = DefaultTargetPlatformConfigurationReader.LOCAL_ARTIFACTS)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 Christoph Läubrich and others.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Christoph Läubrich - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.tycho;
14+
15+
/**
16+
* Defines how extra classpath dependencies (from <code>jars.extra.classpath</code> in
17+
* build.properties) are handled during target platform resolution.
18+
*/
19+
public enum ClasspathDependenciesAction {
20+
21+
/**
22+
* Treat extra classpath dependencies as required.
23+
*/
24+
REQUIRE,
25+
26+
/**
27+
* Treat extra classpath dependencies as optional (included if available, not an error if
28+
* missing).
29+
*/
30+
OPTIONAL,
31+
32+
/**
33+
* Ignore extra classpath dependencies during resolution.
34+
*/
35+
IGNORE;
36+
}

tycho-core/src/main/java/org/eclipse/tycho/core/TargetPlatformConfiguration.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.eclipse.equinox.p2.metadata.IRequirement;
3737
import org.eclipse.tycho.ArtifactKey;
3838
import org.eclipse.tycho.ArtifactType;
39+
import org.eclipse.tycho.ClasspathDependenciesAction;
3940
import org.eclipse.tycho.DefaultArtifactKey;
4041
import org.eclipse.tycho.OptionalResolutionAction;
4142
import org.eclipse.tycho.TargetEnvironment;
@@ -123,6 +124,8 @@ public enum InjectP2MavenMetadataHandling {
123124

124125
private OptionalResolutionAction optionalAction = OptionalResolutionAction.REQUIRE;
125126

127+
private ClasspathDependenciesAction classpathDependenciesAction = ClasspathDependenciesAction.REQUIRE;
128+
126129
private final List<ArtifactKey> extraRequirements = new ArrayList<>();
127130
private final Set<String> exclusions = new HashSet<>();
128131

@@ -300,6 +303,14 @@ public void setOptionalResolutionAction(OptionalResolutionAction optionalAction)
300303
this.optionalAction = optionalAction;
301304
}
302305

306+
public ClasspathDependenciesAction getClasspathDependenciesAction() {
307+
return classpathDependenciesAction;
308+
}
309+
310+
public void setClasspathDependenciesAction(ClasspathDependenciesAction classpathDependenciesAction) {
311+
this.classpathDependenciesAction = classpathDependenciesAction;
312+
}
313+
303314
/**
304315
* Returns the properties to be used for evaluating filters during dependency resolution.
305316
*/

tycho-core/src/main/java/org/eclipse/tycho/core/resolver/AdditionalBundleRequirementsInstallableUnitProvider.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
import org.eclipse.equinox.p2.metadata.VersionRange;
3535
import org.eclipse.tycho.BuildProperties;
3636
import org.eclipse.tycho.BuildPropertiesParser;
37+
import org.eclipse.tycho.ClasspathDependenciesAction;
3738
import org.eclipse.tycho.ReactorProject;
3839
import org.eclipse.tycho.TychoConstants;
40+
import org.eclipse.tycho.core.TargetPlatformConfiguration;
3941
import org.eclipse.tycho.core.TychoProjectManager;
4042
import org.eclipse.tycho.core.osgitools.DefaultReactorProject;
4143
import org.eclipse.tycho.p2maven.tmp.BundlesAction;
@@ -80,10 +82,18 @@ public Collection<IInstallableUnit> getInstallableUnits(MavenProject project, Ma
8082
//"classic" pde project with build properties
8183
ReactorProject reactorProject = DefaultReactorProject.adapt(project);
8284
BuildProperties buildProperties = buildPropertiesParser.parse(reactorProject);
83-
Stream<IRequirement> extraClassPath = buildProperties.getJarsExtraClasspath().stream()
84-
.map(TychoConstants.PLATFORM_URL_PATTERN::matcher).filter(Matcher::matches)
85-
.map(m -> MetadataFactory.createRequirement(BundlesAction.CAPABILITY_NS_OSGI_BUNDLE, m.group(2),
86-
VersionRange.emptyRange, null, true, false));
85+
TargetPlatformConfiguration tpConfig = projectManager.getTargetPlatformConfiguration(project);
86+
ClasspathDependenciesAction classpathAction = tpConfig.getClasspathDependenciesAction();
87+
Stream<IRequirement> extraClassPath;
88+
if (classpathAction == ClasspathDependenciesAction.IGNORE) {
89+
extraClassPath = Stream.empty();
90+
} else {
91+
boolean optional = classpathAction == ClasspathDependenciesAction.OPTIONAL;
92+
extraClassPath = buildProperties.getJarsExtraClasspath().stream()
93+
.map(TychoConstants.PLATFORM_URL_PATTERN::matcher).filter(Matcher::matches)
94+
.map(m -> MetadataFactory.createRequirement(BundlesAction.CAPABILITY_NS_OSGI_BUNDLE,
95+
m.group(2), VersionRange.emptyRange, null, optional, false));
96+
}
8797
Stream<IRequirement> additionalBundles = buildProperties.getAdditionalBundles().stream()
8898
.map(bundleName -> MetadataFactory.createRequirement(BundlesAction.CAPABILITY_NS_OSGI_BUNDLE,
8999
bundleName, VersionRange.emptyRange, null, true, false));

tycho-core/src/main/java/org/eclipse/tycho/core/resolver/DefaultTargetPlatformConfigurationReader.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.codehaus.plexus.logging.Logger;
3737
import org.codehaus.plexus.util.xml.Xpp3Dom;
3838
import org.eclipse.tycho.BuildFailureException;
39+
import org.eclipse.tycho.ClasspathDependenciesAction;
3940
import org.eclipse.tycho.DefaultArtifactKey;
4041
import org.eclipse.tycho.OptionalResolutionAction;
4142
import org.eclipse.tycho.TargetEnvironment;
@@ -65,6 +66,7 @@ public class DefaultTargetPlatformConfigurationReader {
6566
public static final String REFERENCED_REPOSITORY_MODE = "referencedRepositoryMode";
6667
public static final String DEPENDENCY_RESOLUTION = "dependency-resolution";
6768
public static final String OPTIONAL_DEPENDENCIES = "optionalDependencies";
69+
public static final String CLASSPATH_DEPENDENCIES = "classpathDependencies";
6870
public static final String LOCAL_ARTIFACTS = "localArtifacts";
6971
public static final String LOCAL_ARTIFACTS_PROPERTY = "tycho.localArtifacts";
7072

@@ -217,6 +219,7 @@ protected void readDependencyResolutionConfiguration(TargetPlatformConfiguration
217219
}
218220

219221
setOptionalDependencies(result, resolverDom);
222+
setClasspathDependencies(result, resolverDom);
220223
setLocalArtifacts(result, resolverDom, mavenSession);
221224
readExtraRequirements(result, resolverDom);
222225
readProfileProperties(result, resolverDom);
@@ -263,6 +266,21 @@ private void setOptionalDependencies(TargetPlatformConfiguration result, Xpp3Dom
263266
}
264267
}
265268

269+
private void setClasspathDependencies(TargetPlatformConfiguration result, Xpp3Dom resolverDom) {
270+
String value = getStringValue(resolverDom.getChild(CLASSPATH_DEPENDENCIES));
271+
272+
if (value == null) {
273+
return;
274+
}
275+
try {
276+
result.setClasspathDependenciesAction(ClasspathDependenciesAction.valueOf(value.toUpperCase()));
277+
} catch (IllegalArgumentException e) {
278+
throw new BuildFailureException("Illegal value of <" + CLASSPATH_DEPENDENCIES
279+
+ "> dependency resolution parameter: " + value + ", allowed values are: "
280+
+ Arrays.toString(ClasspathDependenciesAction.values()));
281+
}
282+
}
283+
266284
protected void readExtraRequirements(TargetPlatformConfiguration result, Xpp3Dom resolverDom)
267285
throws BuildFailureException {
268286
Xpp3Dom requirementsDom = resolverDom.getChild("extraRequirements");

0 commit comments

Comments
 (0)