Skip to content

Commit

Permalink
TargetPlatformFactoryImpl.gatherP2InfUnits should use artifact version
Browse files Browse the repository at this point in the history
Currently the implementation hard codes the version to 1.0.0 when
parsing advice from a p2.inf.  This can result in an IAE if the version
is used in a range such as [1.0.0,$version$) where because [1.0.0,1.0.0)
is not a valid range. Instead use the reactor project's actual version.
  • Loading branch information
merks authored and laeubi committed Apr 2, 2024
1 parent 586a97b commit d9f36d2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
Expand Up @@ -122,6 +122,8 @@

public class TargetPlatformFactoryImpl implements TargetPlatformFactory {

private static final Version DEFAULT_P2_ADVICE_VERSION = Version.parseVersion("1.0.0.qualifier");

private final MavenContext mavenContext;
private final MavenLogger logger;
private final IProgressMonitor monitor;
Expand Down Expand Up @@ -304,12 +306,13 @@ private void gatherP2InfUnits(ReactorProject reactorProject, Set<IInstallableUni
if (reactorProject == null) {
return;
}

AdviceFileAdvice advice;
if (PackagingType.TYPE_ECLIPSE_PLUGIN.equals(reactorProject.getPackaging())) {
advice = new AdviceFileAdvice(reactorProject.getArtifactId(), Version.parseVersion("1.0.0"),
advice = new AdviceFileAdvice(reactorProject.getArtifactId(), getVersion(reactorProject),
new Path(reactorProject.getBasedir().getAbsolutePath()), AdviceFileAdvice.BUNDLE_ADVICE_FILE);
} else if (PackagingType.TYPE_ECLIPSE_FEATURE.equals(reactorProject.getPackaging())) {
advice = new AdviceFileAdvice(reactorProject.getArtifactId(), Version.parseVersion("1.0.0"),
advice = new AdviceFileAdvice(reactorProject.getArtifactId(), getVersion(reactorProject),
new Path(reactorProject.getBasedir().getAbsolutePath()), new Path("p2.inf"));
} else {
//not a project with advice...
Expand All @@ -325,6 +328,18 @@ private void gatherP2InfUnits(ReactorProject reactorProject, Set<IInstallableUni
}
}

private Version getVersion(ReactorProject reactorProject) {
if (projectManager == null) {
return DEFAULT_P2_ADVICE_VERSION;
}
try {
return projectManager.getArtifactKey(reactorProject).map(key -> Version.parseVersion(key.getVersion()))
.orElseGet(() -> DEFAULT_P2_ADVICE_VERSION);
} catch (IllegalArgumentException ex) {
return DEFAULT_P2_ADVICE_VERSION;
}
}

private List<MavenArtifactKey> getMissingJunitBundles(ReactorProject project, Set<IInstallableUnit> externalUIs) {
List<MavenArtifactKey> missing = new ArrayList<>();
if (projectManager != null) {
Expand Down
Expand Up @@ -2,6 +2,6 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: pvu.bundle
Bundle-SymbolicName: pvu.bundle;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Version: 2.0.0.qualifier
Bundle-Vendor: TEST
Bundle-RequiredExecutionEnvironment: JavaSE-17
12 changes: 9 additions & 3 deletions tycho-its/projects/p2Inf.virtualUnit/bundle/META-INF/p2.inf
@@ -1,11 +1,17 @@
# Create the virtual IU
units.0.id=configure.pvu.bundle
units.0.version=1.0.0
units.0.version=$version$
units.0.provides.1.namespace=org.eclipse.equinox.p2.iu
units.0.provides.1.name=configure.pvu.bundle
units.0.provides.1.version=1.0.0
units.0.provides.1.version=$version$

# Require in this bundle the created virtual IU
requires.0.namespace=org.eclipse.equinox.p2.iu
requires.0.name=configure.pvu.bundle
requires.0.range=0.0.0
requires.0.range=$version$

# Specify update advice with a version range that is invalid if $version$ expands to 1.0.0
# For this example it should expand to 2.0.0
update.id = update.pvu.bundle
update.range = [1.0.0,$version$)
update.severity = 0
2 changes: 1 addition & 1 deletion tycho-its/projects/p2Inf.virtualUnit/bundle/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>tycho-its-project.p2Inf.virtualUnit</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>pvu.bundle</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion tycho-its/projects/p2Inf.virtualUnit/pom.xml
Expand Up @@ -6,7 +6,7 @@

<groupId>tycho-its-project.p2Inf.virtualUnit</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
Expand Down

0 comments on commit d9f36d2

Please sign in to comment.