summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMickael Istria2012-11-30 10:34:43 (EST)
committer Tobias Oberlies2012-12-03 11:09:49 (EST)
commitd1588e852ecf1fecaf755cac5604e326e3032cfb (patch)
treeb52af1339d9f650422ad5f0d7be7825e117f17a2
parent055055ba9dcc7ef950246918070cf2b0bd20bc3c (diff)
downloadorg.eclipse.tycho.extras-d1588e852ecf1fecaf755cac5604e326e3032cfb.zip
org.eclipse.tycho.extras-d1588e852ecf1fecaf755cac5604e326e3032cfb.tar.gz
org.eclipse.tycho.extras-d1588e852ecf1fecaf755cac5604e326e3032cfb.tar.bz2
374349 Copy feature attributes to source featurerefs/changes/99/6199/9
- Copy attributes label, description, provider, copyright, license (and corresponding URLs) from the binary to the source feature. When using an internationalized feature, the source feature values are then all taken from sourceFeatureTemplate/feature.properties, and you have full control over the attributes in the source feature. - Verify that used internationalization keys exist in sourceFeatureTemplate/feature.properties. - Added tests. Bug: 374349 Change-Id: I42c4a3ce75fc998b181c5d38f0c3ea0347e8cbf2
-rw-r--r--tycho-source-feature-plugin/pom.xml24
-rw-r--r--tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/build.properties2
-rw-r--r--tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/feature.properties1
-rw-r--r--tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/feature.xml5
-rw-r--r--tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/sourceTemplateFeature/feature.properties1
-rw-r--r--tycho-source-feature-plugin/src/it/basic/verify.groovy24
-rw-r--r--tycho-source-feature-plugin/src/main/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureMojo.java137
-rw-r--r--tycho-source-feature-plugin/src/test/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureSkeletonTest.java83
-rw-r--r--tycho-source-feature-plugin/src/test/resources/featureWithLabelInProperties.xml7
-rw-r--r--tycho-source-feature-plugin/src/test/resources/labelInProperties.properties1
10 files changed, 225 insertions, 60 deletions
diff --git a/tycho-source-feature-plugin/pom.xml b/tycho-source-feature-plugin/pom.xml
index 4deeb0e..eb4e586 100644
--- a/tycho-source-feature-plugin/pom.xml
+++ b/tycho-source-feature-plugin/pom.xml
@@ -36,20 +36,23 @@
<artifactId>tycho-packaging-plugin</artifactId>
<version>${tycho-version}</version>
</dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-testing</groupId>
+ <artifactId>maven-plugin-testing-harness</artifactId>
+ <scope>test</scope>
+ <version>2.0</version>
+ </dependency>
</dependencies>
<build>
<plugins>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
-
- <plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>1.5.5</version>
@@ -78,4 +81,5 @@
</build>
</profile>
</profiles>
-</project> \ No newline at end of file
+
+</project>
diff --git a/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/build.properties b/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/build.properties
index 64f93a9..9e015b6 100644
--- a/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/build.properties
+++ b/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/build.properties
@@ -1 +1 @@
-bin.includes = feature.xml
+bin.includes = feature.xml, feature.properties
diff --git a/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/feature.properties b/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/feature.properties
new file mode 100644
index 0000000..b92a627
--- /dev/null
+++ b/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/feature.properties
@@ -0,0 +1 @@
+label=A Feature
diff --git a/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/feature.xml b/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/feature.xml
index fbfd3ad..78a45f7 100644
--- a/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/feature.xml
+++ b/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/feature.xml
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="sourcefeature.feature"
- label="sourcefeature.feature"
- version="1.0.0.qualifier">
+ label="%label"
+ version="1.0.0.qualifier"
+ provider-name="Eclipse.org">
<includes
id="sourcefeature.feature.indirect"
diff --git a/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/sourceTemplateFeature/feature.properties b/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/sourceTemplateFeature/feature.properties
index e69de29..2e86237 100644
--- a/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/sourceTemplateFeature/feature.properties
+++ b/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/sourceTemplateFeature/feature.properties
@@ -0,0 +1 @@
+label=A Source Feature
diff --git a/tycho-source-feature-plugin/src/it/basic/verify.groovy b/tycho-source-feature-plugin/src/it/basic/verify.groovy
index 8717e26..b926d0f 100644
--- a/tycho-source-feature-plugin/src/it/basic/verify.groovy
+++ b/tycho-source-feature-plugin/src/it/basic/verify.groovy
@@ -1,22 +1,24 @@
+import java.util.regex.Pattern;
+import java.util.zip.ZipFile;
import java.io.*;
+import junit.framework.Assert;
+
File feature = new File(basedir, "sourcefeature.repository/target/repository/features/sourcefeature.feature.source_1.0.0.123abc.jar");
-if (!feature.canRead()) {
- throw new Exception("Missing expected file "+feature);
-}
+Assert.assertTrue("Missing expected file "+feature, feature.canRead());
-// TODO actually look inside the feature jar to check if template files were included
+ZipFile featureZip = new ZipFile(feature);
+Assert.assertNotNull("Content of sourceTemplateFeature not included", featureZip.entries().find {it.name.equals("feature.properties")})
+// Test Bug 374349
+def featureXml = new XmlParser().parseText(featureZip.getInputStream(featureZip.getEntry("feature.xml")).text);
+Assert.assertEquals("Wrong label - bug 374349", "%label", featureXml.@label);
-feature = new File(basedir, "sourcefeature.repository/target/repository/features/sourcefeature.feature.indirect.source_1.0.0.123abc.jar");
-if (!feature.canRead()) {
- throw new Exception("Missing expected file "+feature);
-}
+File indirectFeature = new File(basedir, "sourcefeature.repository/target/repository/features/sourcefeature.feature.indirect.source_1.0.0.123abc.jar");
+Assert.assertTrue("Missing expected file "+indirectFeature, indirectFeature.canRead())
File bundle = new File(basedir, "sourcefeature.repository/target/repository/plugins/sourcefeature.bundle.source_1.0.0.123abc.jar");
-if (!bundle.canRead()) {
- throw new Exception("Missing expected file "+bundle);
-}
+Assert.assertTrue("Missing expected file "+bundle, bundle.canRead());
return true;
diff --git a/tycho-source-feature-plugin/src/main/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureMojo.java b/tycho-source-feature-plugin/src/main/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureMojo.java
index 80d8f21..5ecdabe 100644
--- a/tycho-source-feature-plugin/src/main/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureMojo.java
+++ b/tycho-source-feature-plugin/src/main/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureMojo.java
@@ -11,11 +11,13 @@
package org.eclipse.tycho.extras.sourcefeature;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import org.apache.maven.archiver.MavenArchiveConfiguration;
@@ -30,11 +32,12 @@ import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.archiver.util.DefaultFileSet;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.util.IOUtil;
import org.eclipse.sisu.equinox.EquinoxServiceFactory;
import org.eclipse.tycho.ArtifactKey;
import org.eclipse.tycho.artifacts.TargetPlatform;
-import org.eclipse.tycho.core.TychoProject;
import org.eclipse.tycho.core.osgitools.DebugUtils;
+import org.eclipse.tycho.core.utils.TychoProjectUtils;
import org.eclipse.tycho.model.Feature;
import org.eclipse.tycho.model.FeatureRef;
import org.eclipse.tycho.model.PluginRef;
@@ -110,11 +113,6 @@ public class SourceFeatureMojo extends AbstractMojo {
*/
private MavenProjectHelper projectHelper;
- /**
- * @component role="org.eclipse.tycho.core.TychoProject"
- */
- private Map<String, TychoProject> projectTypes;
-
/** @component */
private EquinoxServiceFactory equinox;
@@ -130,33 +128,23 @@ public class SourceFeatureMojo extends AbstractMojo {
File outputJarFile = getOutputJarFile();
- TychoProject tychoProject = projectTypes.get(project.getPackaging());
-
- if (tychoProject == null) {
- throw new MojoExecutionException("Is not a supported tycho project " + project);
- }
-
- MavenArchiver archiver = new MavenArchiver();
- archiver.setArchiver(jarArchiver);
- archiver.setOutputFile(outputJarFile);
-
try {
- File sourceFeatireDir = getSourcesFeatureDir(project);
- File featureXml = new File(sourceFeatireDir, Feature.FEATURE_XML);
-
- TargetPlatform targetPlatform = tychoProject.getTargetPlatform(project);
+ File sourceFeatureDir = getSourcesFeatureDir(project);
+ File featureXml = new File(sourceFeatureDir, Feature.FEATURE_XML);
+ Feature feature = Feature.read(new File(this.project.getBuild().getDirectory(), "feature.xml"));
- final Feature sourceFeature = getSourceFeature(project, targetPlatform);
+ final Feature sourceFeature = createSourceFeatureSkeleton(feature, readSourceFeatureProperties());
+ fillReferences(sourceFeature, feature, TychoProjectUtils.getTargetPlatform(project));
Feature.write(sourceFeature, featureXml);
- DefaultFileSet mainFileSet = new DefaultFileSet();
- mainFileSet.setDirectory(template);
-
- archiver.getArchiver().addFileSet(mainFileSet);
-
+ MavenArchiver archiver = new MavenArchiver();
+ archiver.setArchiver(jarArchiver);
+ archiver.setOutputFile(outputJarFile);
+ DefaultFileSet templateFileSet = new DefaultFileSet();
+ templateFileSet.setDirectory(template);
+ archiver.getArchiver().addFileSet(templateFileSet);
archiver.getArchiver().addFile(featureXml, Feature.FEATURE_XML);
-
archiver.createArchive(project, archive);
projectHelper.attachArtifact(project, outputJarFile, SOURCES_FEATURE_CLASSIFIER);
@@ -174,14 +162,30 @@ public class SourceFeatureMojo extends AbstractMojo {
return dir;
}
- private Feature getSourceFeature(MavenProject project, TargetPlatform targetPlatform) throws IOException,
- MojoExecutionException {
- P2ResolverFactory factory = equinox.getService(P2ResolverFactory.class);
- P2Resolver p2 = factory.createResolver(new MavenLoggerAdapter(logger, DebugUtils.isDebugEnabled(session,
- project)));
-
- Feature feature = Feature.read(new File(project.getBuild().getDirectory(), "feature.xml"));
+ private Properties readSourceFeatureProperties() throws IOException {
+ String sourceFeaturePropertiesPath = FEATURE_TEMPLATE_DIR + "/feature.properties";
+ File sourceFeaturePropertiesFile = new File(project.getBasedir(), sourceFeaturePropertiesPath);
+ Properties sourceFeatureProperties = new Properties();
+ if (sourceFeaturePropertiesFile.isFile()) {
+ FileInputStream propertiesStream = null;
+ try {
+ propertiesStream = new FileInputStream(sourceFeaturePropertiesFile);
+ sourceFeatureProperties.load(propertiesStream);
+ } finally {
+ IOUtil.close(propertiesStream);
+ }
+ } else {
+ logger.debug("No '" + sourceFeaturePropertiesPath + "' available.");
+ }
+ return sourceFeatureProperties;
+ }
+ /**
+ * This only create the new feature skeleton by setting labels and other not-structural values
+ * that don't require platform resolution.
+ */
+ Feature createSourceFeatureSkeleton(Feature feature, Properties sourceFeatureProperties)
+ throws FileNotFoundException, IOException, MojoExecutionException {
Document document = new Document();
document.setRootNode(new Element("feature"));
document.setXmlDeclaration(new XMLDeclaration("1.0", "UTF-8"));
@@ -195,6 +199,67 @@ public class SourceFeatureMojo extends AbstractMojo {
binaryRef.setVersion(feature.getVersion());
sourceFeature.addFeatureRef(binaryRef);
+ if (feature.getLabel() != null) {
+ sourceFeature.setLabel(validateValue(feature.getLabel(), sourceFeatureProperties));
+ }
+ if (feature.getProvider() != null) {
+ sourceFeature.setProvider(validateValue(feature.getProvider(), sourceFeatureProperties));
+ }
+ if (feature.getDescription() != null) {
+ sourceFeature.setDescription(validateValue(feature.getDescription(), sourceFeatureProperties));
+ }
+ if (feature.getDescriptionURL() != null) {
+ sourceFeature.setDescriptionURL(validateValue(feature.getDescriptionURL(), sourceFeatureProperties));
+ }
+ if (feature.getCopyright() != null) {
+ sourceFeature.setCopyright(validateValue(feature.getCopyright(), sourceFeatureProperties));
+ }
+ if (feature.getCopyrightURL() != null) {
+ sourceFeature.setCopyrightURL(validateValue(feature.getCopyrightURL(), sourceFeatureProperties));
+ }
+ if (feature.getLicense() != null) {
+ sourceFeature.setLicense(validateValue(feature.getLicense(), sourceFeatureProperties));
+ }
+ if (feature.getLicenseURL() != null) {
+ sourceFeature.setLicenseURL(validateValue(feature.getLicenseURL(), sourceFeatureProperties));
+ }
+ return sourceFeature;
+ }
+
+ /**
+ * Returns the value for a field. In case the value is a reference to feature.properties, verify
+ * that the entry exist in the feature.properties file for source
+ *
+ * @param fieldValue
+ * @param sourceFeatureProperties
+ * @return
+ */
+ private static String validateValue(String fieldValue, Properties sourceFeatureProperties)
+ throws MojoExecutionException {
+ if (fieldValue.charAt(0) == '%') {
+ String key = fieldValue.substring(1);
+ if (!sourceFeatureProperties.containsKey(key)) {
+ throw new MojoExecutionException("Source feature depends on '" + FEATURE_TEMPLATE_DIR
+ + "/feature.properties', entry '" + key + "'. However, this key could not be found");
+ }
+ }
+ return fieldValue;
+ }
+
+ /**
+ * Added all references to sourceFeature, as deduced by feature and resolved by targetPlatform
+ *
+ * @param sourceFeature
+ * @param feature
+ * @param targetPlatform
+ * @throws MojoExecutionException
+ */
+ private void fillReferences(Feature sourceFeature, Feature feature, TargetPlatform targetPlatform)
+ throws MojoExecutionException {
+ P2ResolverFactory factory = this.equinox.getService(P2ResolverFactory.class);
+ P2Resolver p2 = factory.createResolver(new MavenLoggerAdapter(this.logger, DebugUtils.isDebugEnabled(
+ this.session, this.project)));
+
List<PluginRef> missingSourcePlugins = new ArrayList<PluginRef>();
List<FeatureRef> missingSourceFeatures = new ArrayList<FeatureRef>();
List<PluginRef> missingExtraPlugins = new ArrayList<PluginRef>();
@@ -270,7 +335,6 @@ public class SourceFeatureMojo extends AbstractMojo {
throw new MojoExecutionException(sb.toString());
}
- return sourceFeature;
}
protected String toStrictVersionRange(String version) {
@@ -352,4 +416,5 @@ public class SourceFeatureMojo extends AbstractMojo {
}
return attr;
}
+
}
diff --git a/tycho-source-feature-plugin/src/test/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureSkeletonTest.java b/tycho-source-feature-plugin/src/test/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureSkeletonTest.java
new file mode 100644
index 0000000..8f25151
--- /dev/null
+++ b/tycho-source-feature-plugin/src/test/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureSkeletonTest.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tycho.extras.sourcefeature;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.apache.maven.plugin.testing.SilentLog;
+import org.codehaus.plexus.util.IOUtil;
+import org.eclipse.tycho.model.Feature;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SourceFeatureSkeletonTest extends AbstractMojoTestCase {
+
+ @Before
+ @Override
+ public void setUp() {
+ // Do nothing, we don't use lookup
+ }
+
+ @Test
+ public void testFeatureWithLabelInProperties_OK() throws Exception {
+ SourceFeatureMojo mojo = new SourceFeatureMojo();
+ setVariableValueToObject(mojo, "logger", new SilentLog());
+ InputStream featureStream = null;
+ Feature originalFeature = null;
+ try {
+ featureStream = getClass().getResourceAsStream("/featureWithLabelInProperties.xml");
+ originalFeature = Feature.read(featureStream);
+ } finally {
+ IOUtil.close(featureStream);
+ }
+ Assert.assertEquals("%label", originalFeature.getLabel());
+ Properties sourceFeatureProperties = new Properties();
+ InputStream propertiesStream = null;
+ try {
+ propertiesStream = getClass().getResourceAsStream("/labelInProperties.properties");
+ sourceFeatureProperties.load(propertiesStream);
+ } finally {
+ IOUtil.close(propertiesStream);
+ }
+
+ Feature sourceFeature = mojo.createSourceFeatureSkeleton(originalFeature, sourceFeatureProperties);
+ Assert.assertEquals("%label", sourceFeature.getLabel());
+ }
+
+ @Test
+ public void testFeatureWithLabelInProperties_KO() throws Exception {
+ SourceFeatureMojo mojo = new SourceFeatureMojo();
+ setVariableValueToObject(mojo, "logger", new SilentLog());
+ InputStream featureStream = null;
+ Feature originalFeature = null;
+ try {
+ featureStream = getClass().getResourceAsStream("/featureWithLabelInProperties.xml");
+ originalFeature = Feature.read(featureStream);
+ } finally {
+ IOUtil.close(featureStream);
+ }
+ Assert.assertEquals("%label", originalFeature.getLabel());
+ Properties sourceFeatureProperties = new Properties();
+ // Don't load properties
+
+ try {
+ Feature sourceFeature = mojo.createSourceFeatureSkeleton(originalFeature, sourceFeatureProperties);
+ fail("Expected Exception for label not found");
+ } catch (MojoExecutionException ex) {
+ // Success
+ }
+ }
+
+}
diff --git a/tycho-source-feature-plugin/src/test/resources/featureWithLabelInProperties.xml b/tycho-source-feature-plugin/src/test/resources/featureWithLabelInProperties.xml
new file mode 100644
index 0000000..350b48e
--- /dev/null
+++ b/tycho-source-feature-plugin/src/test/resources/featureWithLabelInProperties.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<feature
+ id="sourcefeature.feature.labelInProperties"
+ label="%label"
+ version="1.0.0.qualifier"
+ provider-name="Eclipse.org">
+</feature>
diff --git a/tycho-source-feature-plugin/src/test/resources/labelInProperties.properties b/tycho-source-feature-plugin/src/test/resources/labelInProperties.properties
new file mode 100644
index 0000000..41ea21f
--- /dev/null
+++ b/tycho-source-feature-plugin/src/test/resources/labelInProperties.properties
@@ -0,0 +1 @@
+label=My feature.properties works in source feature \ No newline at end of file