Skip to content

Commit

Permalink
Fix pom.model properties read for bundle-projects and add it-tests
Browse files Browse the repository at this point in the history
The TychoBundleMapping tried to look up the buiild.properties of a
'eclipse-plugin' project in its 'META-INF' folder instead of the project
root. This change fixes that.

+ Add extensive integration tests to ensure all pom.model attributes are
correctly read

+ Remove DefaultTychoResolver.setBuildProperties() because its
functionality is already handled by AbstractTychoMapping and it is
currently not working
  • Loading branch information
HannesWell committed Jun 29, 2022
1 parent f3fa30c commit a9eaf32
Show file tree
Hide file tree
Showing 41 changed files with 613 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
*******************************************************************************/
package org.eclipse.tycho.core.resolver;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -70,7 +67,6 @@ public class DefaultTychoResolver implements TychoResolver {
public static final String TYCHO_ENV_OSGI_WS = "tycho.env.osgi.ws";
public static final String TYCHO_ENV_OSGI_OS = "tycho.env.osgi.os";
public static final String TYCHO_ENV_OSGI_ARCH = "tycho.env.osgi.arch";
public static final String PROPERTY_PREFIX = "pom.model.property.";

@Override
public void setupProject(MavenSession session, MavenProject project, ReactorProject reactorProject) {
Expand All @@ -97,7 +93,6 @@ public void setupProject(MavenSession session, MavenProject project, ReactorProj
reactorProject.setContextValue(TychoConstants.CTX_MERGED_PROPERTIES, properties);

setTychoEnvironmentProperties(properties, project);
setBuildProperties(project);

TargetPlatformConfiguration configuration = configurationReader.getTargetPlatformConfiguration(session,
project);
Expand Down Expand Up @@ -195,29 +190,4 @@ protected void setTychoEnvironmentProperties(Properties properties, MavenProject
project.getProperties().put(TYCHO_ENV_OSGI_OS, os);
project.getProperties().put(TYCHO_ENV_OSGI_ARCH, arch);
}

protected void setBuildProperties(MavenProject project) {
File pomfile = project.getFile();
if (pomfile != null) {
File buildPropertiesFile = new File(pomfile.getParentFile(), "build.properties");
if (buildPropertiesFile.isFile() && buildPropertiesFile.length() > 0) {
Properties buildProperties = new Properties();
try {
try (FileInputStream stream = new FileInputStream(buildPropertiesFile)) {
buildProperties.load(stream);
}
Properties projectProperties = project.getProperties();
buildProperties.stringPropertyNames().forEach(key -> {
if (key.startsWith(PROPERTY_PREFIX)) {
projectProperties.setProperty(key.substring(PROPERTY_PREFIX.length()),
buildProperties.getProperty(key));
}
});
} catch (IOException e) {
logger.warn("reading build.properties from project " + project.getName() + " failed", e);
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -280,17 +280,20 @@ public Properties getEnhancementProperties(Map<String, ?> options) {
String location = PolyglotModelUtil.getLocation(options);
File file = new File(location);
try {
if (file.isDirectory()) {
return getBuildProperties(file);
} else if (file.isFile()) {
return getBuildProperties(file.getParentFile());
}
return getEnhancementProperties(file);
} catch (IOException e) {
logger.warn("reading EnhancementProperties encountered a problem and was skipped for this reason", e);
}
return null;
}

protected Properties getEnhancementProperties(File file) throws IOException {
if (file.isDirectory()) {
return getBuildProperties(file);
}
return getBuildProperties(file.getParentFile());
}

private static void setLocation(Model model, File modelSource) {
InputSource inputSource = new InputSource();
inputSource.setLocation(modelSource.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ protected void initModel(Model model, Reader artifactReader, File artifactFile)

}

@Override
protected Properties getEnhancementProperties(File file) throws IOException {
//Look up build.properties in the project's root. The passed file points to the 'META-INF' folder.
return getBuildProperties(file.getParentFile());
}

private static Plugin createBndPlugin(Model model) {
//See https://github.com/bndtools/bnd/blob/master/maven/bnd-maven-plugin/README.md#bnd-process-goal
Build build = model.getBuild();
Expand Down
7 changes: 7 additions & 0 deletions tycho-its/projects/pomless-model/.mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<extensions>
<extension>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-build</artifactId>
<version>${tycho-version}</version>
</extension>
</extensions>
2 changes: 2 additions & 0 deletions tycho-its/projects/pomless-model/.mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-Dtycho-version=3.0.0-SNAPSHOT
-Dtycho.pomless.aggregator.names=bundles,bundles-with-enhanced-parents
16 changes: 16 additions & 0 deletions tycho-its/projects/pomless-model/alternative-parent/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>foo.bar</groupId>
<artifactId>simple</artifactId>
<version>1.0.0</version>
</parent>
<groupId>foo.other</groupId>
<artifactId>another-parent</artifactId>
<packaging>pom</packaging>
<name>Alternative Parent 2 from pomXML</name>
<properties>
<custom.user.property>alternative-parent-from-pomXML</custom.user.property>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Plugin
Bundle-SymbolicName: foo.bar.bundle-5
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-11
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin.includes = META-INF/
pom.model.name = Bundle 5 pomless
# Inherit pom.model.property.custom.user.property from parent
19 changes: 19 additions & 0 deletions tycho-its/projects/pomless-model/bundles-2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>foo.bar</groupId>
<artifactId>simple</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>bundles-2</artifactId>
<version>1.1.0</version>
<packaging>pom</packaging>
<name>Aggregator 2 from pomXML</name>
<properties>
<custom.user.property>aggregator2-from-pomXML</custom.user.property>
</properties>
<modules>
<module>foo.bar.bundle-5</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pom.model.groupId = bundles-enhanced-pomless
pom.model.version = 1.2.0
pom.model.name = Aggregator 3 pomless
pom.model.property.custom.user.property = aggregator3-pomless
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Plugin
Bundle-SymbolicName: foo.bar.bundle-3
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-11
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin.includes = META-INF/
tycho.pomless.parent = ../../alternative-parent
pom.model.name = Bundle 3 pomless
# Inherit pom.model.property.custom.user.property from parent
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Plugin
Bundle-SymbolicName: foo.bar.bundle-4
Bundle-Version: 1.0.0
Automatic-Module-Name: foo.bar.plugin
Bundle-RequiredExecutionEnvironment: JavaSE-11
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
pom.model.name = Bundle 4 pomless
# Inherit pom.model.property.custom.user.property from parent
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Plugin
Bundle-SymbolicName: foo.bar.bundle-2
Bundle-Version: 1.0.0
Automatic-Module-Name: foo.bar.plugin
Bundle-RequiredExecutionEnvironment: JavaSE-11
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin.includes = META-INF/
tycho.pomless.parent = ../../alternative-parent
pom.model.name = Bundle 2 pomless
pom.model.property.custom.user.property = bundle2-pomless
16 changes: 16 additions & 0 deletions tycho-its/projects/pomless-model/bundles/foo.bar.bundle-2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>foo.bar</groupId>
<artifactId>simple</artifactId>
<version>1.0.0</version>
<relativePath>../..</relativePath>
</parent>
<artifactId>foo.bar.bundle-2</artifactId>
<packaging>eclipse-plugin</packaging>
<name>Bundle 2 from pom.xml</name>
<properties>
<custom.user.property>bundle2-from-pomXML</custom.user.property>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Plugin
Bundle-SymbolicName: foo.bar.bundle
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-11
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin.includes = META-INF/
pom.model.name = Bundle 1 pomless
pom.model.property.custom.user.property = bundle1-pomless
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin.includes = feature.xml
pom.model.name = Feature 2 pomless
pom.model.property.custom.user.property = feature2-pomless
27 changes: 27 additions & 0 deletions tycho-its/projects/pomless-model/foo.bar.feature-2/feature.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="foo.bar.feature-2"
label="Feature"
version="1.0.0">

<description url="http://www.example.com/description">
[Enter Feature Description here.]
</description>

<copyright url="http://www.example.com/copyright">
[Enter Copyright Description here.]
</copyright>

<license url="http://www.example.com/license">
[Enter License Description here.]
</license>

<plugin
id="foo.bar.plugin-2"
download-size="0"
install-size="0"
version="0.0.0"
fragment="true"
unpack="false"/>

</feature>
15 changes: 15 additions & 0 deletions tycho-its/projects/pomless-model/foo.bar.feature-2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>foo.bar</groupId>
<artifactId>simple</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>foo.bar.feature-2</artifactId>
<packaging>eclipse-feature</packaging>
<name>Feature 2 from pom.xml</name>
<properties>
<custom.user.property>feature2-from-pomXML</custom.user.property>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin.includes = feature.xml
pom.model.name = Feature 1 pomless
pom.model.property.custom.user.property = feature1-pomless
27 changes: 27 additions & 0 deletions tycho-its/projects/pomless-model/foo.bar.feature/feature.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="foo.bar.feature"
label="Feature"
version="1.0.0">

<description url="http://www.example.com/description">
[Enter Feature Description here.]
</description>

<copyright url="http://www.example.com/copyright">
[Enter Copyright Description here.]
</copyright>

<license url="http://www.example.com/license">
[Enter License Description here.]
</license>

<plugin
id="foo.bar.plugin"
download-size="0"
install-size="0"
version="0.0.0"
fragment="true"
unpack="false"/>

</feature>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Plugin
Bundle-SymbolicName: foo.bar.plugin-2
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-11
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin.includes = META-INF/
pom.model.name = Plugin 2 pomless
pom.model.property.custom.user.property = plugin2-pomless
15 changes: 15 additions & 0 deletions tycho-its/projects/pomless-model/foo.bar.plugin-2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>foo.bar</groupId>
<artifactId>simple</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>foo.bar.plugin-2</artifactId>
<packaging>eclipse-plugin</packaging>
<name>Plugin 2 from pom.xml</name>
<properties>
<custom.user.property>plugin2-from-pomXML</custom.user.property>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Plugin
Bundle-SymbolicName: foo.bar.plugin
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-11
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin.includes = META-INF/
pom.model.name = Plugin 1 pomless
pom.model.property.custom.user.property = plugin1-pomless
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pom.model.name = Product 2 pomless
pom.model.property.custom.user.property = product2-pomless
19 changes: 19 additions & 0 deletions tycho-its/projects/pomless-model/foo.bar.product-2/foo.bar.product
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?>

<product name="Product" uid="foo.bar.product-2" id="org.eclipse.platform.ide" application="org.eclipse.ui.ide.workbench" version="1.0.0" useFeatures="true" includeLaunchers="false" autoIncludeRequirements="true">

<configIni use="default">
</configIni>

<launcherArgs>
<vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts
</vmArgsMac>
</launcherArgs>

<features>
<feature id="foo.bar.feature-2"/>
</features>


</product>
Loading

0 comments on commit a9eaf32

Please sign in to comment.