Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTorbjörn Svensson2019-10-13 17:46:07 +0000
committerMickael Istria2019-10-21 18:11:40 +0000
commit2e4ff33a4120812c2f235f6fab1b2e5b16e2e26a (patch)
tree8313bc47beb55b9bd125f3a91c090a6a8e85a923
parentfb41ebbc21cc53cf5fb8c5937c18f3722bdd0377 (diff)
downloadorg.eclipse.tycho.extras-2e4ff33a4120812c2f235f6fab1b2e5b16e2e26a.tar.gz
org.eclipse.tycho.extras-2e4ff33a4120812c2f235f6fab1b2e5b16e2e26a.tar.xz
org.eclipse.tycho.extras-2e4ff33a4120812c2f235f6fab1b2e5b16e2e26a.zip
Bug 552066 - Respect src.includes/src.excludes for source features
When building the "base" feature, the bin.includes and bin.excludes are used to populate the feature with resources based on feature developers preference. When building the "source" feature for a "base" feature, the src.includes and src.excludes properties should be used to populate the "source" feature with resources based ont he featue developers prefernce. The functions in this changeset are copied from PackageFeatureMojo.java and AbstractTychoPackagingMojo.java and then updated to use the src properties rather than the bin properties. Change-Id: I5dcf57120b559d2bb63ceac04a6c33a03b38d199 Signed-off-by: Torbjörn Svensson <azoff@svenskalinuxforeningen.se>
-rw-r--r--tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/bin-only.txt0
-rw-r--r--tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/build.properties3
-rw-r--r--tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/license.html0
-rw-r--r--tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/src-only.txt0
-rw-r--r--tycho-source-feature-plugin/src/it/basic/verify.groovy28
-rw-r--r--tycho-source-feature-plugin/src/main/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureMojo.java55
6 files changed, 78 insertions, 8 deletions
diff --git a/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/bin-only.txt b/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/bin-only.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/bin-only.txt
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 9e015b6..f60e48e 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,2 @@
-bin.includes = feature.xml, feature.properties
+bin.includes = feature.xml, feature.properties, license.html, bin-only.txt
+src.includes = license.html, src-only.txt
diff --git a/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/license.html b/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/license.html
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/license.html
diff --git a/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/src-only.txt b/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/src-only.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tycho-source-feature-plugin/src/it/basic/sourcefeature.feature/src-only.txt
diff --git a/tycho-source-feature-plugin/src/it/basic/verify.groovy b/tycho-source-feature-plugin/src/it/basic/verify.groovy
index 3674c5b..0d8cf3e 100644
--- a/tycho-source-feature-plugin/src/it/basic/verify.groovy
+++ b/tycho-source-feature-plugin/src/it/basic/verify.groovy
@@ -4,23 +4,37 @@ 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");
-Assert.assertTrue("Missing expected file "+feature, feature.canRead());
+File feature = new File(basedir, "sourcefeature.repository/target/repository/features/sourcefeature.feature_1.0.0.123abc.jar");
+Assert.assertTrue("Missing expected file " + feature, feature.canRead());
ZipFile featureZip = new ZipFile(feature);
-Assert.assertNotNull("Content of sourceTemplateFeature not included", featureZip.entries().find {it.name.equals("feature.properties")})
+Assert.assertNotNull("Missing expected file featrue.properties in " + feature, featureZip.entries().find {it.name.equals("feature.properties")})
+
+File sourceFeature = new File(basedir, "sourcefeature.repository/target/repository/features/sourcefeature.feature.source_1.0.0.123abc.jar");
+Assert.assertTrue("Missing expected file " + sourceFeature, sourceFeature.canRead());
+
+ZipFile sourceFeatureZip = new ZipFile(sourceFeature);
+Assert.assertNotNull("Content of sourceTemplateFeature not included", sourceFeatureZip.entries().find {it.name.equals("feature.properties")})
+
+// Test for bug 552066
+Assert.assertNotNull("license.html not found in " + feature, featureZip.entries().find {it.name.equals("license.html")})
+Assert.assertNotNull("bin-only.txt not found in " + feature, featureZip.entries().find {it.name.equals("bin-only.txt")})
+Assert.assertNull("src-only.txt found in " + feature, featureZip.entries().find {it.name.equals("src-only.txt")})
+Assert.assertNotNull("license.html not found in " + sourceFeature, sourceFeatureZip.entries().find {it.name.equals("license.html")})
+Assert.assertNull("bin-only.txt found in " + sourceFeature, sourceFeatureZip.entries().find {it.name.equals("bin-only.txt")})
+Assert.assertNotNull("src-only.txt not found in " + sourceFeature, sourceFeatureZip.entries().find {it.name.equals("src-only.txt")})
// Test Bug 374349
-def featureXml = new XmlParser().parseText(featureZip.getInputStream(featureZip.getEntry("feature.xml")).text);
-Assert.assertEquals("Wrong label - bug 374349", "%label", featureXml.@label);
+def sourceFeatureXml = new XmlParser().parseText(sourceFeatureZip.getInputStream(sourceFeatureZip.getEntry("feature.xml")).text);
+Assert.assertEquals("Wrong label - bug 374349", "%label", sourceFeatureXml.@label);
// Test bug 407706
-Assert.assertNull(featureXml.@plugin);
+Assert.assertNull(sourceFeatureXml.@plugin);
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())
ZipFile indirectFeatureZip = new ZipFile(indirectFeature);
-def indirectFeatureXml = new XmlParser().parseText(indirectFeatureZip.getInputStream(featureZip.getEntry("feature.xml")).text);
+def indirectFeatureXml = new XmlParser().parseText(indirectFeatureZip.getInputStream(sourceFeatureZip.getEntry("feature.xml")).text);
// Test bug 407706
Assert.assertEquals("sourcefeature.bundle", indirectFeatureXml.@plugin);
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 4525518..9c95f2d 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
@@ -16,7 +16,9 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
@@ -34,14 +36,18 @@ import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.plexus.archiver.Archiver;
+import org.codehaus.plexus.archiver.FileSet;
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.AbstractScanner;
import org.eclipse.sisu.equinox.EquinoxServiceFactory;
import org.eclipse.tycho.PackagingType;
import org.eclipse.tycho.artifacts.TargetPlatform;
import org.eclipse.tycho.core.osgitools.DebugUtils;
+import org.eclipse.tycho.core.shared.BuildProperties;
+import org.eclipse.tycho.core.shared.BuildPropertiesParser;
import org.eclipse.tycho.core.utils.TychoProjectUtils;
import org.eclipse.tycho.model.Feature;
import org.eclipse.tycho.model.FeatureRef;
@@ -158,6 +164,9 @@ public class SourceFeatureMojo extends AbstractMojo {
@Parameter
private PlexusConfiguration plugins;
+ @Parameter(defaultValue = "true")
+ protected boolean useDefaultExcludes;
+
@Parameter(property = "session", readonly = true)
private MavenSession session;
@@ -187,6 +196,9 @@ public class SourceFeatureMojo extends AbstractMojo {
private LicenseFeatureHelper licenseFeatureHelper;
@Component
+ private BuildPropertiesParser buildPropertiesParser;
+
+ @Component
private EquinoxServiceFactory equinox;
@Component
@@ -214,6 +226,10 @@ public class SourceFeatureMojo extends AbstractMojo {
templateFileSet.setExcludes(new String[] { Feature.FEATURE_XML, FEATURE_PROPERTIES });
archiver.getArchiver().addFileSet(templateFileSet);
}
+
+ BuildProperties buildProperties = buildPropertiesParser.parse(project.getBasedir());
+ archiver.getArchiver().addFileSet(getManuallyIncludedFiles(project.getBasedir(), buildProperties));
+
archiver.getArchiver().addFile(sourceFeatureXml, Feature.FEATURE_XML);
archiver.getArchiver().addFile(getMergedSourceFeaturePropertiesFile(), FEATURE_PROPERTIES);
File licenseFeature = licenseFeatureHelper
@@ -555,4 +571,43 @@ public class SourceFeatureMojo extends AbstractMojo {
return attr;
}
+ /**
+ * @return A {@link FileSet} including files as configured by the <tt>src.includes</tt> and
+ * <tt>src.excludes</tt> properties without the files that are always included
+ * automatically.
+ */
+ private FileSet getManuallyIncludedFiles(File basedir, BuildProperties buildProperties) {
+ List<String> srcExcludes = new ArrayList<>(buildProperties.getSourceExcludes());
+ srcExcludes.add(Feature.FEATURE_XML); // we'll include updated feature.xml
+ srcExcludes.add(FEATURE_PROPERTIES); // we'll include updated feature.properties
+ return getFileSet(basedir, buildProperties.getSourceIncludes(), srcExcludes);
+ }
+
+ /**
+ * @return a {@link FileSet} with the given includes and excludes and the configured default
+ * excludes. An empty list of includes leads to an empty file set.
+ */
+ protected FileSet getFileSet(File basedir, List<String> includes, List<String> excludes) {
+ DefaultFileSet fileSet = new DefaultFileSet();
+ fileSet.setDirectory(basedir);
+
+ if (includes.isEmpty()) {
+ // FileSet interprets empty list as "everything", so we need to express "nothing" in a different way
+ fileSet.setIncludes(new String[] { "" });
+ } else {
+ fileSet.setIncludes(includes.toArray(new String[includes.size()]));
+ }
+
+ Set<String> allExcludes = new LinkedHashSet<>();
+ if (excludes != null) {
+ allExcludes.addAll(excludes);
+ }
+ if (useDefaultExcludes) {
+ allExcludes.addAll(Arrays.asList(AbstractScanner.DEFAULTEXCLUDES));
+ }
+
+ fileSet.setExcludes(allExcludes.toArray(new String[allExcludes.size()]));
+
+ return fileSet;
+ }
}

Back to the top