Skip to content

Commit

Permalink
Resolve target definition variables during p2 repository assembly
Browse files Browse the repository at this point in the history
  • Loading branch information
kysmith-csg authored and laeubi committed Nov 18, 2023
1 parent 3eef484 commit 1a75861
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 3 deletions.
1 change: 1 addition & 0 deletions tycho-its/projects/target.variables/env/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<modules>
<module>targetplatform</module>
<module>project</module>
<module>site</module>
</modules>

</project>
3 changes: 3 additions & 0 deletions tycho-its/projects/target.variables/env/site/category.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<site>

</site>
26 changes: 26 additions & 0 deletions tycho-its/projects/target.variables/env/site/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>site</artifactId>
<packaging>eclipse-repository</packaging>
<parent>
<groupId>tycho-its-project.variables.env</groupId>
<artifactId>aggregator</artifactId>
<version>1.0.0</version>
</parent>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<addIUTargetRepositoryReferences>true</addIUTargetRepositoryReferences>
</configuration>
</plugin>
</plugins>
</build>
</project>
1 change: 1 addition & 0 deletions tycho-its/projects/target.variables/sysprop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<modules>
<module>targetplatform</module>
<module>project</module>
<module>site</module>
</modules>

</project>
3 changes: 3 additions & 0 deletions tycho-its/projects/target.variables/sysprop/site/category.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<site>

</site>
26 changes: 26 additions & 0 deletions tycho-its/projects/target.variables/sysprop/site/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>site</artifactId>
<packaging>eclipse-repository</packaging>
<parent>
<groupId>tycho-its-project.variables.sysprop</groupId>
<artifactId>aggregator</artifactId>
<version>1.0.0</version>
</parent>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<addIUTargetRepositoryReferences>true</addIUTargetRepositoryReferences>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="${system_property:myMirror}/repo"/>

<unit id="javax.xml" version="0.0.0"/>
</location>
</locations>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,6 +58,7 @@ public void repositoryUrlCanContainEnvVarVariable() throws Exception {
verifier.executeGoals(Arrays.asList("package"));
verifier.verifyErrorFreeLog();
verifier.verifyTextInLog("validate-target-platform");
verifyResolution(verifier);
}

@Test
Expand All @@ -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<RepositoryReference> 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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 1a75861

Please sign in to comment.