From 1a758613b652e70c834eb8485dc6f5daf0ddc816 Mon Sep 17 00:00:00 2001 From: Kyle Smith Date: Fri, 17 Nov 2023 10:17:02 -0500 Subject: [PATCH] Resolve target definition variables during p2 repository assembly --- .../projects/target.variables/env/pom.xml | 1 + .../target.variables/env/site/category.xml | 3 ++ .../target.variables/env/site/pom.xml | 26 +++++++++++++++++ .../projects/target.variables/sysprop/pom.xml | 1 + .../sysprop/site/category.xml | 3 ++ .../target.variables/sysprop/site/pom.xml | 26 +++++++++++++++++ .../targetplatform/targetplatform.target | 1 - .../target/TargetVariableResolutionTest.java | 28 +++++++++++++++++++ .../p2/repository/AssembleRepositoryMojo.java | 8 ++++-- 9 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 tycho-its/projects/target.variables/env/site/category.xml create mode 100644 tycho-its/projects/target.variables/env/site/pom.xml create mode 100644 tycho-its/projects/target.variables/sysprop/site/category.xml create mode 100644 tycho-its/projects/target.variables/sysprop/site/pom.xml diff --git a/tycho-its/projects/target.variables/env/pom.xml b/tycho-its/projects/target.variables/env/pom.xml index e1c0165ccb..cb5a88de02 100644 --- a/tycho-its/projects/target.variables/env/pom.xml +++ b/tycho-its/projects/target.variables/env/pom.xml @@ -54,6 +54,7 @@ targetplatform project + site diff --git a/tycho-its/projects/target.variables/env/site/category.xml b/tycho-its/projects/target.variables/env/site/category.xml new file mode 100644 index 0000000000..a38da4c9dc --- /dev/null +++ b/tycho-its/projects/target.variables/env/site/category.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/tycho-its/projects/target.variables/env/site/pom.xml b/tycho-its/projects/target.variables/env/site/pom.xml new file mode 100644 index 0000000000..010c945ebc --- /dev/null +++ b/tycho-its/projects/target.variables/env/site/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + site + eclipse-repository + + tycho-its-project.variables.env + aggregator + 1.0.0 + + + + + + org.eclipse.tycho + tycho-p2-repository-plugin + ${tycho-version} + + true + + + + + \ No newline at end of file diff --git a/tycho-its/projects/target.variables/sysprop/pom.xml b/tycho-its/projects/target.variables/sysprop/pom.xml index d06f2b79d5..b761a34c35 100644 --- a/tycho-its/projects/target.variables/sysprop/pom.xml +++ b/tycho-its/projects/target.variables/sysprop/pom.xml @@ -54,6 +54,7 @@ targetplatform project + site diff --git a/tycho-its/projects/target.variables/sysprop/site/category.xml b/tycho-its/projects/target.variables/sysprop/site/category.xml new file mode 100644 index 0000000000..a38da4c9dc --- /dev/null +++ b/tycho-its/projects/target.variables/sysprop/site/category.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/tycho-its/projects/target.variables/sysprop/site/pom.xml b/tycho-its/projects/target.variables/sysprop/site/pom.xml new file mode 100644 index 0000000000..c778e1ea93 --- /dev/null +++ b/tycho-its/projects/target.variables/sysprop/site/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + site + eclipse-repository + + tycho-its-project.variables.sysprop + aggregator + 1.0.0 + + + + + + org.eclipse.tycho + tycho-p2-repository-plugin + ${tycho-version} + + true + + + + + \ No newline at end of file diff --git a/tycho-its/projects/target.variables/sysprop/targetplatform/targetplatform.target b/tycho-its/projects/target.variables/sysprop/targetplatform/targetplatform.target index c802356861..7a6e58cb09 100644 --- a/tycho-its/projects/target.variables/sysprop/targetplatform/targetplatform.target +++ b/tycho-its/projects/target.variables/sysprop/targetplatform/targetplatform.target @@ -4,7 +4,6 @@ - diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetVariableResolutionTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetVariableResolutionTest.java index 2fa42955c1..47e94d826a 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetVariableResolutionTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetVariableResolutionTest.java @@ -12,11 +12,21 @@ *******************************************************************************/ package org.eclipse.tycho.test.target; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.junit.Assert.assertEquals; + +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Arrays; +import java.util.List; import org.apache.maven.it.Verifier; +import org.eclipse.equinox.p2.repository.IRepository; import org.eclipse.tycho.test.AbstractTychoIntegrationTest; import org.eclipse.tycho.test.util.HttpServer; +import org.eclipse.tycho.test.util.P2RepositoryTool; +import org.eclipse.tycho.test.util.P2RepositoryTool.RepositoryReference; import org.eclipse.tycho.test.util.ResourceUtil; import org.junit.After; import org.junit.Before; @@ -48,6 +58,7 @@ public void repositoryUrlCanContainEnvVarVariable() throws Exception { verifier.executeGoals(Arrays.asList("package")); verifier.verifyErrorFreeLog(); verifier.verifyTextInLog("validate-target-platform"); + verifyResolution(verifier); } @Test @@ -57,5 +68,22 @@ public void repositoryUrlCanContainSystemPropertyVariable() throws Exception { verifier.executeGoals(Arrays.asList("package")); verifier.verifyErrorFreeLog(); verifier.verifyTextInLog("validate-target-platform"); + verifyResolution(verifier); + } + + /** + * Verify that the update site has the target platform variables resolved + * correctly. + */ + private void verifyResolution(Verifier verifier) throws Exception { + final Path sitePath = Paths.get(verifier.getBasedir(), "site"); + P2RepositoryTool p2Repo = P2RepositoryTool.forEclipseRepositoryModule(sitePath.toFile()); + List allRepositoryReferences = p2Repo.getAllRepositoryReferences(); + // artifact + metadata + assertEquals(2, allRepositoryReferences.size()); + final String REPO = baseurl + "/repo"; + assertThat(allRepositoryReferences, + containsInAnyOrder(new RepositoryReference(REPO, IRepository.TYPE_ARTIFACT, IRepository.ENABLED), + new RepositoryReference(REPO, IRepository.TYPE_METADATA, IRepository.ENABLED))); } } diff --git a/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/AssembleRepositoryMojo.java b/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/AssembleRepositoryMojo.java index e4b45a21fa..c30aa20485 100644 --- a/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/AssembleRepositoryMojo.java +++ b/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/AssembleRepositoryMojo.java @@ -44,6 +44,7 @@ import org.eclipse.tycho.p2.tools.RepositoryReference; import org.eclipse.tycho.p2.tools.RepositoryReferences; import org.eclipse.tycho.p2.tools.mirroring.facade.MirrorApplicationService; +import org.eclipse.tycho.p2resolver.TargetDefinitionVariableResolver; import org.eclipse.tycho.p2tools.RepositoryReferenceTool; import org.eclipse.tycho.targetplatform.TargetDefinition.InstallableUnitLocation; @@ -307,6 +308,9 @@ public static class RepositoryReferenceFilter { @Component MirrorApplicationService mirrorApp; + @Component + private TargetDefinitionVariableResolver varResolver; + @Component(role = TychoProject.class, hint = PackagingType.TYPE_ECLIPSE_REPOSITORY) private EclipseRepositoryProject eclipseRepositoryProject; @@ -349,8 +353,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { .flatMap(tpFile -> tpFile.getLocations().stream()) .filter(InstallableUnitLocation.class::isInstance).map(InstallableUnitLocation.class::cast) .flatMap(iu -> iu.getRepositories().stream()) - .filter(iuRepo -> autoReferencesFilter.test(iuRepo.getLocation())) - .map(iuRepo -> new RepositoryReference(null, iuRepo.getLocation(), true)) + .map(iuRepo -> varResolver.resolve(iuRepo.getLocation())).filter(autoReferencesFilter) + .map(location -> new RepositoryReference(null, location, true)) .forEach(autoRepositoryRefeferences::add); } DestinationRepositoryDescriptor destinationRepoDescriptor = new DestinationRepositoryDescriptor(