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] Minimal reproducer test-case for #3824 | Use the updated p2 metadata once the project is packed #3928

Merged
merged 2 commits into from
Jun 8, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public class InstallableUnitGenerator {

private static final String KEY_UNITS = "InstallableUnitGenerator.units";

private static final String KEY_ARTIFACT_FILE = "InstallableUnitGenerator.artifactFile";

@Requirement
private IProvisioningAgent provisioningAgent;

Expand Down Expand Up @@ -165,28 +167,37 @@ public Collection<IInstallableUnit> getInstallableUnits(MavenProject project, Ma
Objects.requireNonNull(session);
log.debug("Computing installable units for " + project + ", force update = " + forceUpdate);
synchronized (project) {
if (!forceUpdate) {
Object contextValue = project.getContextValue(KEY_UNITS);
if (contextValue instanceof Collection<?>) {
Collection<IInstallableUnit> collection = (Collection<IInstallableUnit>) contextValue;
if (isCompatible(collection)) {
log.debug("Using cached value for " + project);
return collection;
} else {
log.debug("Cannot use cached value for " + project
+ " because of incompatible classloaders, update is forced");
}
}
}
File basedir = project.getBasedir();
if (basedir == null || !basedir.isDirectory()) {
log.warn("No valid basedir for " + project + " found");
return Collections.emptyList();
}
File projectArtifact = getProjectArtifact(project);
if (!forceUpdate) {
// first check if the packed state might has changed...
if (Objects.equals(project.getContextValue(KEY_ARTIFACT_FILE), projectArtifact)) {
Object contextValue = project.getContextValue(KEY_UNITS);
if (contextValue instanceof Collection<?>) {
// now check if we are classlaoder compatible...
Collection<IInstallableUnit> collection = (Collection<IInstallableUnit>) contextValue;
if (isCompatible(collection)) {
log.debug("Using cached value for " + project);
return collection;
} else {
log.debug("Cannot use cached value for " + project
+ " because of incompatible classloaders, update is forced");
}
}
} else {
log.info("Cannot use cached value for " + project
+ " because project artifact has changed, update is forced");
}
}
String packaging = project.getPackaging();
String version = project.getVersion();
String artifactId = project.getArtifactId();
List<IPublisherAction> actions = getPublisherActions(packaging, basedir, version, artifactId);
List<IPublisherAction> actions = getPublisherActions(packaging, basedir, projectArtifact, version,
artifactId);
Collection<IInstallableUnit> publishedUnits = publisher.publishMetadata(actions);
for (InstallableUnitProvider unitProvider : getProvider(project, session)) {
log.debug("Asking " + unitProvider + " for additional units for " + project);
Expand All @@ -207,24 +218,38 @@ public Collection<IInstallableUnit> getInstallableUnits(MavenProject project, Ma
log.debug("Cannot generate any InstallableUnit for packaging type '" + packaging + "' for " + project);
}
project.setContextValue(KEY_UNITS, result);
project.setContextValue(KEY_ARTIFACT_FILE, projectArtifact);
return result;

}
}

private List<IPublisherAction> getPublisherActions(String packaging, File basedir, String version,
String artifactId) throws CoreException {
private static File getProjectArtifact(MavenProject project) {
Artifact artifact = project.getArtifact();
if (artifact != null) {
File file = artifact.getFile();
if (file != null && file.exists()) {
return file;
}
}
return null;
}

private List<IPublisherAction> getPublisherActions(String packaging, File basedir, File projectArtifact,
String version, String artifactId) throws CoreException {
List<IPublisherAction> actions = new ArrayList<>();
switch (packaging) {
case PackagingType.TYPE_ECLIPSE_TEST_PLUGIN:
case PackagingType.TYPE_ECLIPSE_PLUGIN: {
actions.add(new BundlesAction(new File[] { basedir }));
File bundleFile = Objects.requireNonNullElse(projectArtifact, basedir);
actions.add(new BundlesAction(new File[] { bundleFile }));
break;
}
case PackagingType.TYPE_ECLIPSE_FEATURE: {
FeatureParser parser = new FeatureParser();
Feature feature = parser.parse(basedir);
feature.setLocation(basedir.getAbsolutePath());
File featureFile = Objects.requireNonNullElse(projectArtifact, basedir);
Feature feature = parser.parse(featureFile);
feature.setLocation(featureFile.getAbsolutePath());
FeatureDependenciesAction action = new FeatureDependenciesAction(feature);
actions.add(action);
break;
Expand Down Expand Up @@ -353,32 +378,31 @@ public synchronized Collection<IInstallableUnit> getUnits(Artifact artifact) {
if (PackagingType.TYPE_ECLIPSE_PLUGIN.equals(type)
|| PackagingType.TYPE_ECLIPSE_TEST_PLUGIN.equals(type) || "bundle".equals(type)) {
List<IPublisherAction> actions = getPublisherActions(PackagingType.TYPE_ECLIPSE_PLUGIN, file,
artifact.getVersion(), artifact.getArtifactId());
file, artifact.getVersion(), artifact.getArtifactId());
return units = publisher.publishMetadata(actions);
} else if (PackagingType.TYPE_ECLIPSE_FEATURE.equals(type)) {
List<IPublisherAction> actions = getPublisherActions(PackagingType.TYPE_ECLIPSE_FEATURE, file,
artifact.getVersion(), artifact.getArtifactId());
file, artifact.getVersion(), artifact.getArtifactId());
return units = publisher.publishMetadata(actions);
} else {
boolean isBundle = false;
boolean isFeature = false;
try (JarFile jarFile = new JarFile(file)) {
Manifest manifest = jarFile.getManifest();
isBundle = manifest != null
&& manifest.getMainAttributes()
.getValue(Constants.BUNDLE_SYMBOLICNAME) != null;
&& manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME) != null;
isFeature = jarFile.getEntry("feature.xml") != null;
} catch (IOException e) {
// can't determine the type then...
}
if (isBundle) {
List<IPublisherAction> actions = getPublisherActions(PackagingType.TYPE_ECLIPSE_PLUGIN,
file, artifact.getVersion(), artifact.getArtifactId());
file, file, artifact.getVersion(), artifact.getArtifactId());
return units = publisher.publishMetadata(actions);
}
if (isFeature) {
List<IPublisherAction> actions = getPublisherActions(PackagingType.TYPE_ECLIPSE_FEATURE,
file, artifact.getVersion(), artifact.getArtifactId());
file, file, artifact.getVersion(), artifact.getArtifactId());
return units = publisher.publishMetadata(actions);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ public final int hashCode() {
return Objects.hash(getArtifactId(), getGroupId(), getVersion());
}

@Override
public String toString() {
return "ReactorProjectIdentities [GroupId=" + getGroupId() + ", ArtifactId=" + getArtifactId() + ", Version="
+ getVersion() + ", Basedir=" + getBasedir() + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,7 @@ public Map<String, IP2Artifact> generateMetadata(MavenProject project, boolean g
PublisherOptions options = new PublisherOptions();
options.setGenerateDownloadStats(generateDownloadStatsProperty);
options.setGenerateChecksums(generateChecksums);
Map<String, IP2Artifact> generatedMetadata = generateMetadata(artifacts, options, targetDir);
return generatedMetadata;
return generateMetadata(artifacts, options, targetDir);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,9 @@ private Map<IInstallableUnit, ReactorProjectIdentities> getPreliminaryReactorPro
Map<IInstallableUnit, Set<File>> duplicateReactorUIs = new HashMap<>();

for (ReactorProject project : reactorProjects) {
Set<IInstallableUnit> projectIUs = project.getDependencyMetadata(DependencyMetadataType.INITIAL);

if (projectIUs == null) {
Set<IInstallableUnit> projectIUs = getPreliminaryReactorProjectUIs(project);
if (projectIUs == null || projectIUs.isEmpty()) {
continue;
}
for (IInstallableUnit iu : projectIUs) {
Expand All @@ -589,6 +589,19 @@ private Map<IInstallableUnit, ReactorProjectIdentities> getPreliminaryReactorPro
return reactorUIs;
}

private Set<IInstallableUnit> getPreliminaryReactorProjectUIs(ReactorProject project) {
String packaging = project.getPackaging();
if (PackagingType.TYPE_ECLIPSE_PLUGIN.equals(packaging) || PackagingType.TYPE_ECLIPSE_FEATURE.equals(packaging)
|| PackagingType.TYPE_ECLIPSE_TEST_PLUGIN.equals(packaging)) {
File artifact = project.getArtifact();
if (artifact != null && artifact.isFile()) {
//the project was already build, use the seed units as they include anything maybe updated by p2-metadata mojo
return project.getDependencyMetadata(DependencyMetadataType.SEED);
}
}
return project.getDependencyMetadata(DependencyMetadataType.INITIAL);
}

private void applyFilters(TargetPlatformFilterEvaluator filter, Collection<IInstallableUnit> collectionToModify,
Set<IInstallableUnit> reactorProjectUIs, ExecutionEnvironmentResolutionHints eeResolutionHints,
Set<IInstallableUnit> shadowedIus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,20 @@
<artifactId>org.eclipse.swt.gtk.linux.x86</artifactId>
<version>3.102.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<configuration>
<dependency-resolution>
<optionalDependencies>ignore</optionalDependencies>
<profileProperties>
<org.eclipse.swt.buildtime>true</org.eclipse.swt.buildtime>
</profileProperties>
</dependency-resolution>
</configuration>
</plugin>
</plugins>
</build>
</project>
8 changes: 8 additions & 0 deletions tycho-its/projects/tycho-ds-dependency/.mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-build</artifactId>
<version>${tycho-version}</version>
</extension>
</extensions>
1 change: 1 addition & 0 deletions tycho-its/projects/tycho-ds-dependency/.mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Dtycho.localArtifacts=ignore
7 changes: 7 additions & 0 deletions tycho-its/projects/tycho-ds-dependency/plugin.a/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: plugin.a
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-17
Import-Package: org.osgi.service.event;version="[1.4.0,2.0.0)"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package foo.bar;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.event.EventHandler;
import org.osgi.service.event.Event;

@Component(service = EventHandler.class)
public class MyComponent implements EventHandler {
@Override
public void handleEvent(Event event) {
}
}
7 changes: 7 additions & 0 deletions tycho-its/projects/tycho-ds-dependency/plugin.b/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: plugin.b
Bundle-Version: 1.0.0.qualifier
Require-Bundle: plugin.a;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin.includes = META-INF/,\
.
51 changes: 51 additions & 0 deletions tycho-its/projects/tycho-ds-dependency/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>foo</groupId>
<artifactId>foo</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
<module>plugin.a</module>
<module>plugin.b</module>
</modules>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</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-ds-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<dsVersion>1.4</dsVersion>
<enabled>true</enabled>
</configuration>
</plugin>

</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -91,6 +92,15 @@ private void verifyDs(Verifier verifier) throws VerificationException {
assertFalse(new File(generated, "tycho.ds.TestComponent2.xml").isFile());
}

@Test
public void testTransitiveDSComponents() throws Exception {
Verifier verifier = getVerifier("tycho-ds-dependency", true, true);
verifier.executeGoals(List.of("clean", "verify"));
verifier.verifyErrorFreeLog();
Path generated = Path.of(verifier.getBasedir(), "plugin.a/target/classes/OSGI-INF");
assertTrue(Files.isRegularFile(generated.resolve("foo.bar.MyComponent.xml")));
}

@Test
public void testOSGiAnnotations() throws Exception {
Verifier verifier = getVerifier("compiler.annotations", false, true);
Expand Down
Loading