Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tycho-4.0.x] Support version-ranges and no-version for units in IU target locations #4365

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

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

## 4.0.10

backports:
- Support version-ranges and no-version for units in IU target locations

## 4.0.9

backports:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private static IInstallableUnit findUnits(Unit unitReference, IQueryable<IInstal

private static IQueryResult<IInstallableUnit> findUnit(Unit unitReference, IQueryable<IInstallableUnit> units)
throws TargetDefinitionSyntaxException {
Version version = parseVersion(unitReference);
VersionRange version = parseVersion(unitReference);

// the createIUQuery treats 0.0.0 version as "any version", and all other versions as exact versions
IQuery<IInstallableUnit> matchingIUQuery = QueryUtil.createIUQuery(unitReference.getId(), version);
Expand All @@ -285,12 +285,20 @@ private static IQueryResult<IInstallableUnit> findUnit(Unit unitReference, IQuer
return queryResult;
}

private static Version parseVersion(Unit unitReference) throws TargetDefinitionSyntaxException {
private static VersionRange parseVersion(Unit unitReference) throws TargetDefinitionSyntaxException {
String version = unitReference.getVersion();
try {
return Version.parseVersion(unitReference.getVersion());
if ("0.0.0".equals(version)) {
return VersionRange.emptyRange;
} else if (version.contains(",")) { // a real version range
return VersionRange.create(version);
} else { // an explicit/exact version -> create strict version range
Version v = Version.parseVersion(version);
return new VersionRange(v, true, v, true);
}
} catch (IllegalArgumentException e) {
throw new TargetDefinitionSyntaxException(NLS.bind("Cannot parse version \"{0}\" of unit \"{1}\"",
unitReference.getVersion(), unitReference.getId()), e);
throw new TargetDefinitionSyntaxException(
NLS.bind("Cannot parse version \"{0}\" of unit \"{1}\"", version, unitReference.getId()), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IVersionedId;
import org.eclipse.equinox.p2.metadata.VersionedId;
import org.eclipse.tycho.ArtifactType;
import org.eclipse.tycho.DefaultArtifactKey;
import org.eclipse.tycho.IDependencyMetadata.DependencyMetadataType;
Expand Down Expand Up @@ -298,7 +299,7 @@ public void testDuplicateReactorUnits() throws Exception {
@Ignore("This test don't work because maven provides a 'not real' local repo to the test")
public void testMavenArtifactsInTargetDefinitionResolveToMavenPath() throws Exception {
File targetDefinition = resourceFile("targetresolver/mavenDep.target");
tpConfig.getTargetDefinitions().add(TargetDefinitionFile.read(targetDefinition));
tpConfig.addTargetDefinition(TargetDefinitionFile.read(targetDefinition));
P2TargetPlatform targetPlatform = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, List.of());
File artifactLocation = targetPlatform.getArtifactLocation(
new DefaultArtifactKey(ArtifactType.TYPE_ECLIPSE_PLUGIN, "org.apache.commons.logging", "1.2.0"));
Expand All @@ -307,6 +308,17 @@ public void testMavenArtifactsInTargetDefinitionResolveToMavenPath() throws Exce
assertTrue(p2ArtifactPath.startsWith(localM2Repo));
}

@Test
public void testUnitsWithVersionRangeAndNoVersionInTargetDefinition() throws Exception {
File targetDefinition = resourceFile("targetresolver/versionRanges.target");
tpConfig.addTargetDefinition(TargetDefinitionFile.read(targetDefinition));
P2TargetPlatform tp = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, List.of());
Set<IInstallableUnit> ius = tp.getInstallableUnits();
assertThat(ius, hasItem(unitWithIdAndVersion(new VersionedId("jakarta.activation-api", "2.1.3"))));
assertThat(tp.getInstallableUnits(),
hasItem(unitWithIdAndVersion(new VersionedId("jakarta.inject.jakarta.inject-api", "1.0.5"))));
}

private static TargetDefinition plannerTargetDefinition(TestRepositories repository, IVersionedId unit) {
TargetDefinition.Location location = new TargetDefinitionResolverIncludeModeTest.PlannerLocationStub(repository,
unit);
Expand Down
11 changes: 11 additions & 0 deletions tycho-core/src/test/resources/targetresolver/versionRanges.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?>
<target name="version-ranges">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://download.eclipse.org/eclipse/updates/4.33/R-4.33-202409030240/"/>
<unit id="jakarta.activation-api" />
<unit id="jakarta.inject.jakarta.inject-api" version="[1.0,2)"/>
</location>
</locations>
</target>
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ private static IULocation parseIULocation(Element dom) {
for (Element unitDom : getChildren(dom, "unit")) {
String id = unitDom.getAttribute("id");
String version = unitDom.getAttribute("version");
if (version == null || version.isBlank()) {
version = "0.0.0";
}
units.add(new Unit(id, version));
}
final List<Repository> repositories = new ArrayList<>();
Expand Down
Loading