Skip to content

Commit

Permalink
Add test case for invalid compilation against fragments from P2 repo
Browse files Browse the repository at this point in the history
When compiling a fragment for whose hose a fragment exists in a P2 repo
referenced by the build (even if the platform filter does not match),
the classes from that fragment are put on the classpath, such that code
in the currently compiled fragment is illegally compiled against that
fragment code.

This change adds a test case that demonstrates the behavior via a
fragment that uses code from another fragment, which is must not depend
on.

(cherry picked from commit 9464bc9)
  • Loading branch information
HeikoKlare authored and eclipse-tycho-bot committed Nov 4, 2024
1 parent 2000880 commit dddb8ab
Show file tree
Hide file tree
Showing 21 changed files with 389 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="test" path="test">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Manifest-Version: 1.0
Fragment-Host: compiler.fragments.unmatchinginp2; bundle-version="[1.0.0,1.1.0)"
Bundle-Name: %fragmentName
Bundle-Vendor: %providerName
Bundle-SymbolicName: compiler.fragments.unmatchinginp2.gtk.linux.x86; singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-ManifestVersion: 2
Bundle-Localization: fragment
Export-Package: org.eclipse.swt.graphics
Eclipse-PlatformFilter: (& (osgi.ws=gtk) (osgi.os=linux) (osgi.arch=x86))
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin.includes = .,META-INF/
source.. = src/
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.tycho.compiler.fragments.unmatchinginp2</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>compiler.fragments.unmatchinginp2.gtk.linux.x86</artifactId>
<version>1.0.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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.eclipse.swt.graphics;

public final class Image {
public static void test() {
Image2 instanceOfClassFromUnmatchingFragment = new Image2();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.eclipse.swt.graphics;

public final class ImageTest {
public static void test() {
Image2 instanceOfClassFromUnmatchingFragment = new Image2();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?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-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Manifest-Version: 1.0
Fragment-Host: compiler.fragments.unmatchinginp2;bundle-version="[1.0.0,1.1.0)"
Bundle-Name: %fragmentName
Bundle-Vendor: %providerName
Bundle-SymbolicName: compiler.fragments.unmatchinginp2.unmatching; singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-ManifestVersion: 2
Bundle-Localization: fragment
Export-Package: org.eclipse.swt.graphics
Eclipse-PlatformFilter: (& (osgi.ws=unknown) (osgi.os=unknown) (osgi.arch=unknown))
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin.includes = .,META-INF/
source.. = src/
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.tycho.compiler.fragments.unmatchinginp2</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>compiler.fragments.unmatchinginp2.unmatching</artifactId>
<version>1.0.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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.eclipse.swt.graphics;

public final class Image2 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Manifest-Version: 1.0
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-SymbolicName: compiler.fragments.unmatchinginp2;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-ManifestVersion: 2
Bundle-Localization: plugin
Eclipse-ExtensibleAPI: true
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
requires.1.namespace = org.eclipse.equinox.p2.iu
requires.1.name = org.eclipse.swt.gtk.linux.x86
requires.1.range = [$version$,$version$]
requires.1.filter = (&(osgi.os=linux)(osgi.ws=gtk)(osgi.arch=x86)(!(org.eclipse.swt.buildtime=true)))

requires.2.namespace = org.eclipse.equinox.p2.iu
requires.2.name = org.eclipse.swt.unmatching
requires.2.range = [$version$,$version$]
requires.2.filter = (&(osgi.os=unmatching)(osgi.ws=unmatching)(osgi.arch=unmatching)(!(org.eclipse.swt.buildtime=true)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin.includes = META-INF/

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.tycho.compiler.fragments.unmatchinginp2</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>compiler.fragments.unmatchinginp2</artifactId>
<version>1.0.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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.eclipse.tycho.compiler.fragments.unmatchinginp2</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>

<packaging>pom</packaging>

<modules>
<module>compiler.fragments.unmatchinginp2</module>
<module>compiler.fragments.unmatchinginp2.gtk.linux.x86</module>
<!-- This module is only for genering an unnmatching fragment to be provided via a p2 repository -->
<!-- <module>compiler.fragments.unmatchinginp2.unmatching</module> -->
</modules>

<repositories>
<repository>
<id>repo_with_fragment_not_matching_platform_filter</id>
<url>file:///${basedir}/../resources/p2withUnmatchingFragment</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>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<resolveWithExecutionEnvironmentConstraints>false</resolveWithExecutionEnvironmentConstraints>
<environments>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version='1.0' encoding='UTF-8'?>
<?artifactRepository version='1.1.0'?>
<repository name='file:////Users/heikoklare/dev/eclipse/tycho/git/tycho/tycho-its/repositories/compiler.fragments.unmatchinginp2 - artifacts' type='org.eclipse.equinox.p2.artifact.repository.simpleRepository' version='1'>
<properties size='2'>
<property name='p2.timestamp' value='1727095539506'/>
<property name='p2.compressed' value='false'/>
</properties>
<mappings size='3'>
<rule filter='(&amp; (classifier=osgi.bundle))' output='${repoUrl}/plugins/${id}_${version}.jar'/>
<rule filter='(&amp; (classifier=binary))' output='${repoUrl}/binary/${id}_${version}'/>
<rule filter='(&amp; (classifier=org.eclipse.update.feature))' output='${repoUrl}/features/${id}_${version}.jar'/>
</mappings>
<artifacts size='2'>
<artifact classifier='osgi.bundle' id='compiler.fragments.unmatchinginp2' version='1.0.0.202409231244'>
<properties size='4'>
<property name='artifact.size' value='2320'/>
<property name='download.size' value='2320'/>
<property name='download.checksum.sha-512' value='1bfb6009197a16eeb9f94c1a8cf618bcba968acfc6e709dc6dff85a01a36d105600c24cd29baa07991eecb0dde698777410461af301f8374d79441a344c57fcd'/>
<property name='download.checksum.sha-256' value='7ad2215dff3bf21d2c0179033996a027733f7c8de0c7482743b328de5cf50d05'/>
</properties>
</artifact>
<artifact classifier='osgi.bundle' id='compiler.fragments.unmatchinginp2.unmatching' version='1.0.0.202409231244'>
<properties size='4'>
<property name='artifact.size' value='3058'/>
<property name='download.size' value='3058'/>
<property name='download.checksum.sha-512' value='30773842dd10f8ddaacf098893b8e8d17cc69c33c5ec4050b2d99680421e6bcdb84a02fa182ff26d7e3903413bc76c1db63d3695ec77e458dfdcad80d07c075d'/>
<property name='download.checksum.sha-256' value='d1c23c7a36b89afbfc942b13d387f0030b6b90491417c68778d5fe6b392a81f6'/>
</properties>
</artifact>
</artifacts>
</repository>
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version='1.0' encoding='UTF-8'?>
<?metadataRepository version='1.2.0'?>
<repository name='file:////Users/heikoklare/dev/eclipse/tycho/git/tycho/tycho-its/repositories/compiler.fragments.unmatchinginp2 - metadata' type='org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository' version='1'>
<properties size='2'>
<property name='p2.timestamp' value='1727095539506'/>
<property name='p2.compressed' value='false'/>
</properties>
<units size='2'>
<unit id='compiler.fragments.unmatchinginp2' version='1.0.0.202409231244' generation='2'>
<update id='compiler.fragments.unmatchinginp2' range='[0.0.0,1.0.0.202409231244)' severity='0'/>
<properties size='3'>
<property name='org.eclipse.equinox.p2.name' value='%pluginName'/>
<property name='org.eclipse.equinox.p2.provider' value='%providerName'/>
<property name='org.eclipse.equinox.p2.bundle.localization' value='plugin'/>
</properties>
<provides size='4'>
<provided namespace='org.eclipse.equinox.p2.iu' name='compiler.fragments.unmatchinginp2' version='1.0.0.202409231244'/>
<provided namespace='osgi.bundle' name='compiler.fragments.unmatchinginp2' version='1.0.0.202409231244'/>
<provided namespace='osgi.identity' name='compiler.fragments.unmatchinginp2' version='1.0.0.202409231244'>
<properties size='1'>
<property name='type' value='osgi.bundle'/>
</properties>
</provided>
<provided namespace='org.eclipse.equinox.p2.eclipse.type' name='bundle' version='1.0.0'/>
</provides>
<requires size='4'>
<required namespace='org.eclipse.equinox.p2.iu' name='org.eclipse.swt.unmatching' range='[1.0.0.202409231244,1.0.0.202409231244]'>
<filter>
(&amp;(osgi.arch=unmatching)(osgi.os=unmatching)(osgi.ws=unmatching)(!(org.eclipse.swt.buildtime=true)))
</filter>
</required>
<required namespace='org.eclipse.equinox.p2.iu' name='org.eclipse.swt.gtk.linux.x86' range='[1.0.0.202409231244,1.0.0.202409231244]'>
<filter>
(&amp;(osgi.arch=x86)(osgi.os=linux)(osgi.ws=gtk)(!(org.eclipse.swt.buildtime=true)))
</filter>
</required>
<requiredProperties namespace='osgi.ee' match='(&amp;(osgi.ee=JavaSE)(version=1.8))'>
<description>
compiler.fragments.unmatchinginp2
</description>
</requiredProperties>
<required namespace='org.eclipse.equinox.p2.iu' name='compiler.fragments.unmatchinginp2.source' range='[1.0.0.202409231244,1.0.0.202409231244]' optional='true'>
<filter>
(org.eclipse.update.install.sources=true)
</filter>
</required>
</requires>
<artifacts size='1'>
<artifact classifier='osgi.bundle' id='compiler.fragments.unmatchinginp2' version='1.0.0.202409231244'/>
</artifacts>
<touchpoint id='org.eclipse.equinox.p2.osgi' version='1.0.0'/>
<touchpointData size='1'>
<instructions size='1'>
<instruction key='manifest'>
Bundle-SymbolicName: compiler.fragments.unmatchinginp2;singleton:=true&#xA;Bundle-Version: 1.0.0.202409231244&#xA;
</instruction>
</instructions>
</touchpointData>
</unit>
<unit id='compiler.fragments.unmatchinginp2.unmatching' version='1.0.0.202409231244' generation='2'>
<update id='compiler.fragments.unmatchinginp2.unmatching' range='[0.0.0,1.0.0.202409231244)' severity='0'/>
<properties size='3'>
<property name='org.eclipse.equinox.p2.name' value='%fragmentName'/>
<property name='org.eclipse.equinox.p2.provider' value='%providerName'/>
<property name='org.eclipse.equinox.p2.bundle.localization' value='fragment'/>
</properties>
<provides size='6'>
<provided namespace='org.eclipse.equinox.p2.iu' name='compiler.fragments.unmatchinginp2.unmatching' version='1.0.0.202409231244'/>
<provided namespace='osgi.bundle' name='compiler.fragments.unmatchinginp2.unmatching' version='1.0.0.202409231244'/>
<provided namespace='java.package' name='org.eclipse.swt.graphics' version='0.0.0'/>
<provided namespace='osgi.identity' name='compiler.fragments.unmatchinginp2.unmatching' version='1.0.0.202409231244'>
<properties size='1'>
<property name='type' value='osgi.fragment'/>
</properties>
</provided>
<provided namespace='org.eclipse.equinox.p2.eclipse.type' name='bundle' version='1.0.0'/>
<provided namespace='osgi.fragment' name='compiler.fragments.unmatchinginp2' version='1.0.0.202409231244'/>
</provides>
<requires size='3'>
<required namespace='osgi.bundle' name='compiler.fragments.unmatchinginp2' range='[1.0.0,1.1.0)'/>
<requiredProperties namespace='osgi.ee' match='(&amp;(osgi.ee=JavaSE)(version=1.8))'>
<description>
compiler.fragments.unmatchinginp2.unmatching
</description>
</requiredProperties>
<required namespace='org.eclipse.equinox.p2.iu' name='compiler.fragments.unmatchinginp2.unmatching.source' range='[1.0.0.202409231244,1.0.0.202409231244]' optional='true'>
<filter>
(org.eclipse.update.install.sources=true)
</filter>
</required>
</requires>
<filter>
(&amp;(osgi.arch=unknown)(osgi.os=unknown)(osgi.ws=unknown))
</filter>
<artifacts size='1'>
<artifact classifier='osgi.bundle' id='compiler.fragments.unmatchinginp2.unmatching' version='1.0.0.202409231244'/>
</artifacts>
<touchpoint id='org.eclipse.equinox.p2.osgi' version='1.0.0'/>
<touchpointData size='1'>
<instructions size='1'>
<instruction key='manifest'>
Bundle-SymbolicName: compiler.fragments.unmatchinginp2.unmatching; singleton:=true&#xA;Bundle-Version: 1.0.0.202409231244&#xA;Fragment-Host: compiler.fragments.unmatchinginp2;bundle-version=&quot;[1.0.0,1.1.0)&quot;&#xA;
</instruction>
</instructions>
</touchpointData>
</unit>
</units>
</repository>
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit dddb8ab

Please sign in to comment.