Skip to content

Commit

Permalink
Add support for including a JRE in the product
Browse files Browse the repository at this point in the history
PDE recently added a new flag for the product to mark it to include a
jre eclipse-pde/eclipse.pde#1075 but this
currently has no effect in Tycho.

This now adds support for automatically include a JustJ JRE if the
option is selected.
  • Loading branch information
laeubi committed May 5, 2024
1 parent 8ef98a0 commit f657f27
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 24 deletions.
7 changes: 7 additions & 0 deletions demo/justj/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Tycho JustJ Demo Projects
===================

Sample projects demonstrating how to use Tycho with JustJ.

* `product`: Shows how to manually include JustJ in a product using a dedicated feature
* `automaticInstall`: Shows how to use automatic install with the `includeJRE` option in the product
66 changes: 66 additions & 0 deletions demo/justj/automaticInstall/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.tycho.demo</groupId>
<artifactId>product-with-justj</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>eclipse-repository</packaging>
<properties>
<tycho-version>5.0.0-SNAPSHOT</tycho-version>
<target-platform>https://download.eclipse.org/releases/2024-03/</target-platform>
</properties>
<repositories>
<repository>
<id>platform</id>
<url>${target-platform}</url>
<layout>p2</layout>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-director-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>materialize-products</id>
<goals>
<goal>materialize-products</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- as we are only interested in the product in this demo we disable the assemly and archiving of the repository -->
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>default-assemble-repository</id>
<goals>
<goal>assemble-repository</goal>
</goals>
<phase>none</phase>
</execution>
<execution>
<id>default-archive-repository</id>
<goals>
<goal>archive-repository</goal>
</goals>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
10 changes: 10 additions & 0 deletions demo/justj/automaticInstall/product-with-features.product
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?>

<product name="A product with justj" uid="product-with-justj-features" id="org.eclipse.platform.ide" application="org.eclipse.ui.ide.workbench" version="0.0.1" type="features" includeLaunchers="true" includeJRE="true" autoIncludeRequirements="true">

<features>
<feature id="org.eclipse.e4.rcp" installMode="root"/>
</features>

</product>
45 changes: 41 additions & 4 deletions demo/justj/product/pom.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<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 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.tycho.demo</groupId>
<artifactId>product-with-justj</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>eclipse-repository</packaging>
<properties>
<tycho-version>2.7.3</tycho-version>
<target-platform>https://download.eclipse.org/releases/2022-06/</target-platform>
<tycho-version>5.0.0-SNAPSHOT</tycho-version>
<target-platform>https://download.eclipse.org/releases/2024-03/</target-platform>
</properties>
<repositories>
<repository>
Expand All @@ -35,11 +36,47 @@
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<!-- Prevents Tycho from injecting some mock a.jre units for system packages and EE capabilities;
<!-- Prevents Tycho from injecting some mock a.jre units for
system packages and EE capabilities;
while we expect justj units to provide them -->
<executionEnvironment>none</executionEnvironment>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-director-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>materialize-products</id>
<goals>
<goal>materialize-products</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- as we are only interested in the product in this demo we disable the assemly and archiving of the repository -->
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>default-assemble-repository</id>
<goals>
<goal>assemble-repository</goal>
</goals>
<phase>none</phase>
</execution>
<execution>
<id>default-archive-repository</id>
<goals>
<goal>archive-repository</goal>
</goals>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
12 changes: 11 additions & 1 deletion demo/justj/product/product-with-features.product
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?>

<product name="A product with justj" uid="product-with-justj-features" version="0.0.1" useFeatures="true" includeLaunchers="true">
<product name="A product with justj" uid="product-with-justj-features" version="0.0.1" type="features" includeLaunchers="true" autoIncludeRequirements="true">

<configIni use="default">
</configIni>
Expand All @@ -11,11 +11,21 @@
</vmArgsMac>
</launcherArgs>

<launcher>
<win useIco="false">
<bmp/>
</win>
</launcher>

<vm>
</vm>

<plugins>
</plugins>

<features>
<feature id="org.eclipse.justj.openjdk.hotspot.jre.full"/>
<feature id="org.eclipse.e4.rcp" installMode="root"/>
</features>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@
import org.eclipse.equinox.internal.p2.publisher.eclipse.IProductDescriptor;
import org.eclipse.equinox.internal.p2.publisher.eclipse.ProductFile;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IRequirement;
import org.eclipse.equinox.p2.metadata.IVersionedId;
import org.eclipse.equinox.p2.metadata.MetadataFactory;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.publisher.AdviceFileAdvice;
import org.eclipse.equinox.p2.publisher.IPublisherAction;
import org.eclipse.equinox.p2.publisher.IPublisherAdvice;
import org.eclipse.equinox.p2.publisher.actions.RootIUAction;
import org.eclipse.equinox.p2.publisher.eclipse.ProductAction;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
Expand Down Expand Up @@ -68,16 +73,34 @@ public PublishProductToolImpl(PublisherActionRunner publisherRunner, PublishingR
}

@Override
public List<DependencySeed> publishProduct(File productFile, File launcherBinaries, String flavor)
throws IllegalArgumentException {
public List<DependencySeed> publishProduct(File productFile, File launcherBinaries, String flavor,
boolean includeJRE) throws IllegalArgumentException {

IProductDescriptor originalProduct = loadProductFile(productFile);
ExpandedProduct expandedProduct = new ExpandedProduct(originalProduct, buildQualifier, targetPlatform,
interpolator, logger);

IPublisherAdvice[] advice = getProductSpecificAdviceFileAdvice(productFile, expandedProduct);

ProductAction action = new ProductAction(null, expandedProduct, flavor, launcherBinaries);
ProductAction action = new ProductAction(null, expandedProduct, flavor, launcherBinaries) {
@Override
protected IPublisherAction createRootIUAction() {
if (includeJRE) {
return new RootIUAction(id, version, name) {
@Override
protected Collection<IRequirement> createIURequirements(
Collection<? extends IVersionedId> children) {
Collection<IRequirement> requirements = new ArrayList<>(
super.createIURequirements(children));
requirements.add(MetadataFactory.createRequirement("org.eclipse.justj", "jre", null, null,
false, false));
return requirements;
}
};
}
return super.createRootIUAction();
}
};
IMetadataRepository metadataRepository = publishingRepository.getMetadataRepository();
IArtifactRepository artifactRepository = publishingRepository
.getArtifactRepositoryForWriting(new ProductBinariesWriteSession(expandedProduct.getId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public interface PublishProductTool {
* A folder that contains the native Eclipse launcher binaries
* @param flavor
* The installation flavor the product shall be published for
* @param includeJRE
* controls if a requirement of a (JustJ) JRE has to be added
* @return a handles to the published product IU
*/
List<DependencySeed> publishProduct(File productDefinition, File launcherBinaries, String flavor);
List<DependencySeed> publishProduct(File productDefinition, File launcherBinaries, String flavor,
boolean includeJRE);
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void testProductPublishingWithLaunchers() throws Exception {
File launcherBinaries = resourceFile("launchers/");

subject = initPublisher();
Collection<DependencySeed> seeds = subject.publishProduct(productDefinition, launcherBinaries, FLAVOR);
Collection<DependencySeed> seeds = subject.publishProduct(productDefinition, launcherBinaries, FLAVOR, false);

assertEquals(1, seeds.size());
DependencySeed seed = seeds.iterator().next();
Expand All @@ -132,7 +132,7 @@ public void testExpandProductVersionQualifier() {
File productDefinition = resourceFile("publishers/products/test.product");
subject = initPublisher();

IInstallableUnit unit = getUnit(subject.publishProduct(productDefinition, null, FLAVOR));
IInstallableUnit unit = getUnit(subject.publishProduct(productDefinition, null, FLAVOR, false));

assertEquals("0.1.0." + QUALIFIER, unit.getVersion().toString());
}
Expand All @@ -143,7 +143,7 @@ public void testExpandVersionsOfInclusionsWithZeros() throws Exception {
subject = initPublisher(createBundleIU("test.plugin", "0.1.0.20141230"), createBundleIU("test.plugin", "1.1.0"),
createFeatureIU("test.feature", "0.2.0.20141230"), createFeatureIU("test.feature", "1.2.0"));

IInstallableUnit unit = getUnit(subject.publishProduct(productDefinition, null, FLAVOR));
IInstallableUnit unit = getUnit(subject.publishProduct(productDefinition, null, FLAVOR, false));

assertThat(unit.getRequirements(), hasItem(strictRequirement("test.plugin", "1.1.0")));
assertThat(unit.getRequirements(), hasItem(strictRequirement("test.feature.feature.group", "1.2.0")));
Expand All @@ -155,7 +155,7 @@ public void testExpandVersionsOfInclusionsWithQualifierLiterals() throws Excepti
subject = initPublisher(createBundleIU("test.plugin", "0.1.0.20141230"), createBundleIU("test.plugin", "1.1.0"),
createFeatureIU("test.feature", "0.2.0.20141230"), createFeatureIU("test.feature", "1.2.0"));

IInstallableUnit unit = getUnit(subject.publishProduct(productDefinition, null, FLAVOR));
IInstallableUnit unit = getUnit(subject.publishProduct(productDefinition, null, FLAVOR, false));

assertThat(unit.getRequirements(), hasItem(strictRequirement("test.plugin", "0.1.0.20141230")));
assertThat(unit.getRequirements(), hasItem(strictRequirement("test.feature.feature.group", "0.2.0.20141230")));
Expand All @@ -167,7 +167,7 @@ public void testExpandVersionWithSyntaxError() throws Exception {
subject = initPublisher();

BuildFailureException e = assertThrows(BuildFailureException.class,
() -> subject.publishProduct(productDefinition, null, FLAVOR));
() -> subject.publishProduct(productDefinition, null, FLAVOR, false));
assertThat(e.getMessage(),
both(containsString("inclusionsWithVersionSyntaxError.product")).and(containsString("nonOSGi")));
}
Expand All @@ -180,7 +180,7 @@ public void testPublishingReportsAllResolutionErrorsAtOnce() throws Exception {
logVerifier.expectError(containsString("test.feature1"));
logVerifier.expectError(containsString("test.feature2"));
assertThrows(DependencyResolutionException.class,
() -> subject.publishProduct(productDefinition, null, FLAVOR));
() -> subject.publishProduct(productDefinition, null, FLAVOR, false));
}

@Test
Expand All @@ -189,7 +189,7 @@ public void testExpandVersionsIgnoresBundlesInFeatureBasedProduct() throws Excep
File productDefinition = resourceFile("publishers/products/featureProductWithLeftovers.product");
subject = initPublisher(createFeatureIU("org.eclipse.rcp", "3.3.101.R34x_v20081125"));

IInstallableUnit unit = getUnit(subject.publishProduct(productDefinition, null, FLAVOR));
IInstallableUnit unit = getUnit(subject.publishProduct(productDefinition, null, FLAVOR, false));

assertThat(unit.getRequirements(),
hasItem(strictRequirement("org.eclipse.rcp.feature.group", "3.3.101.R34x_v20081125")));
Expand All @@ -200,7 +200,7 @@ public void testExpandVersionsIgnoresFeaturesInBundleBasedProduct() throws Excep
File productDefinition = resourceFile("publishers/products/pluginProductWithLeftovers.product");
subject = initPublisher(createBundleIU("org.eclipse.core.runtime", "3.5.0.v20090525"));

IInstallableUnit unit = getUnit(subject.publishProduct(productDefinition, null, FLAVOR));
IInstallableUnit unit = getUnit(subject.publishProduct(productDefinition, null, FLAVOR, false));

assertThat(unit.getRequirements(), hasItem(strictRequirement("org.eclipse.core.runtime", "3.5.0.v20090525")));
}
Expand All @@ -214,15 +214,15 @@ public void testPublishingWithMissingFragments() throws Exception {

logVerifier.expectError(containsString("org.eclipse.core.filesystem.hpux.ppc"));
assertThrows(DependencyResolutionException.class,
() -> subject.publishProduct(productDefinition, launcherBinaries, FLAVOR));
() -> subject.publishProduct(productDefinition, launcherBinaries, FLAVOR, false));
}

@Test
public void testPublishingWithP2Inf() {
File productDefinition = resourceFile("publishers/products/p2Inf/test.product");
subject = initPublisher();

subject.publishProduct(productDefinition, null, FLAVOR);
subject.publishProduct(productDefinition, null, FLAVOR, false);

assertThat(unitsIn(outputRepository), hasItem(unitWithId("testproduct")));
IInstallableUnit unit = getUnique(unitWithId("testproduct"), unitsIn(outputRepository));
Expand All @@ -239,7 +239,7 @@ public void testPublishingWithProductSpecificP2Inf() {
File productDefinition = resourceFile("publishers/products/p2InfPerProduct/test.product");
subject = initPublisher();

IInstallableUnit unit = getUnit(subject.publishProduct(productDefinition, null, FLAVOR));
IInstallableUnit unit = getUnit(subject.publishProduct(productDefinition, null, FLAVOR, false));

assertThat(unit.getRequirements(), hasItem(strictRequirement("extra.iu", "1.2.3." + QUALIFIER)));
}
Expand All @@ -250,7 +250,7 @@ public void testPublishingWithVariableExpansion() {
subject = initPublisher(createBundleIU("org.eclipse.osgi", "3.10.1.v20140909-1633"));
when(interpolatorMock.interpolate("${unqualifiedVersion}.${buildQualifier}")).thenReturn("1.0.0.20150109");

IInstallableUnit mainUnit = getUnit(subject.publishProduct(productDefinition, null, FLAVOR));
IInstallableUnit mainUnit = getUnit(subject.publishProduct(productDefinition, null, FLAVOR, false));

String configUnitId = "tooling" + mainUnit.getId() + ".config.testws.testos.testarch";
IInstallableUnit configUnit = getUnique(unitWithId(configUnitId), unitsIn(outputRepository));
Expand All @@ -265,7 +265,7 @@ public void testPublishingWithRootFeatures() {
createFeatureIU("org.eclipse.e4.rcp", "1.0"), createFeatureIU("org.eclipse.help", "2.0.102.v20140128"),
createFeatureIU("org.eclipse.egit", "2.0"));

List<DependencySeed> seeds = subject.publishProduct(productDefinition, null, FLAVOR);
List<DependencySeed> seeds = subject.publishProduct(productDefinition, null, FLAVOR, false);
IInstallableUnit productUnit = getUnique(productUnit(), unitsIn(seeds));

assertThat(productUnit.getRequirements(),
Expand Down
9 changes: 9 additions & 0 deletions tycho-its/src/test/java/org/eclipse/tycho/test/DemoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.tycho.test;

import java.io.File;
import java.util.List;

import org.apache.maven.it.Verifier;
Expand All @@ -23,6 +24,14 @@
*/
public class DemoTest extends AbstractTychoIntegrationTest {

@Test
public void testTychoJustJDemo() throws Exception {
assertIncludesJustJ(new File(runDemo("justj", "-f", "product").getBasedir(),
"product/target/products/product-with-justj-features"));
assertIncludesJustJ(new File(runDemo("justj", "-f", "automaticInstall").getBasedir(),
"automaticInstall/target/products/product-with-justj-features"));
}

@Test
public void testSureFireDemo() throws Exception {
runDemo("testing/surefire/", "-f", "with-maven-layout");
Expand Down

0 comments on commit f657f27

Please sign in to comment.