Permalink
Browse files

371877 Honor src.includes in OsgiSourceMojo

OsgiSourceMojo#execute() should not be skipped
with non-empty src.includes entry in build.prroperties.

Change-Id: I6fbf335f7668d44cac2b05d31c53e27b028f5ae5
  • Loading branch information...
1 parent 53f9cb1 commit c0fbaff1faeb56aa17cc3dff6b7427543d4f2b9f @jsievers jsievers committed Dec 19, 2012
@@ -65,6 +65,10 @@
<artifactId>tycho-packaging-plugin</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
</dependencies>
<build>
@@ -105,7 +105,7 @@
/**
* Whether source folders are required or not. If not required (the default), projects without
- * source folders will be silently ignored.
+ * source folders/source includes will be silently ignored.
*
* @parameter default-value="false"
* @readonly
@@ -129,7 +129,7 @@
/**
* @component
*/
- private BuildPropertiesParser buildPropertiesParser;
+ BuildPropertiesParser buildPropertiesParser;
/**
* @component
@@ -143,14 +143,13 @@
/** {@inheritDoc} */
protected List<String> getSources(MavenProject p) throws MojoExecutionException {
- return getSources(project, requireSourceRoots, buildPropertiesParser);
+ return getSources(project, requireSourceRoots, buildPropertiesParser.parse(p.getBasedir()));
}
- protected static List<String> getSources(MavenProject p, boolean requireSourceRoots,
- BuildPropertiesParser buildPropertiesParser) throws MojoExecutionException {
+ protected static List<String> getSources(MavenProject p, boolean requireSourceRoots, BuildProperties buildProperties)
+ throws MojoExecutionException {
List<String> sources = new ArrayList<String>();
- for (List<String> sourceFolderList : buildPropertiesParser.parse(p.getBasedir()).getJarToSourceFolderMap()
- .values()) {
+ for (List<String> sourceFolderList : buildProperties.getJarToSourceFolderMap().values()) {
for (String sourceFolder : sourceFolderList) {
sources.add(new File(p.getBasedir(), sourceFolder).getAbsolutePath());
}
@@ -338,12 +337,10 @@ protected static boolean isRelevantProjectImpl(MavenProject project, BuildProper
if (requireSourceRoots) {
return true;
}
- try {
- if (!getSources(project, requireSourceRoots, buildPropertiesParser).isEmpty()) {
- return true;
- }
- } catch (MojoExecutionException e) {
- // can't happen because requireSourceRoots==false
+ BuildProperties buildProperties = buildPropertiesParser.parse(project.getBasedir());
+ if (buildProperties.getJarToSourceFolderMap().size() > 0
+ || buildProperties.getSourceIncludes().size() > 0) {
+ return true;
}
}
}
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2012 SAP AG 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:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tycho.source;
+
+import static java.util.Arrays.asList;
+
+import java.io.File;
+
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginExecution;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.eclipse.tycho.core.facade.BuildPropertiesParser;
+
+public class OsgiSourceMojoTest extends PlexusTestCase {
+
+ private OsgiSourceMojo mojo;
+
+ @Override
+ protected void setUp() throws Exception {
+ BuildPropertiesParser parser = lookup(BuildPropertiesParser.class);
+ mojo = new OsgiSourceMojo();
+ mojo.buildPropertiesParser = parser;
+ }
+
+ public void testIsRelevantProjectPackagingType() throws Exception {
+ assertTrue(mojo.isRelevantProject(createStubProjectWithSourceFolder("eclipse-plugin")));
+ assertTrue(mojo.isRelevantProject(createStubProjectWithSourceFolder("eclipse-test-plugin")));
+ assertFalse(mojo.isRelevantProject(createStubProjectWithSourceFolder("foo")));
+ }
+
+ public void testIsRelevantProjectSourcePluginEnabled() throws Exception {
+ assertTrue(mojo.isRelevantProject(createStubProjectWithSourceFolder(true)));
+ assertFalse(mojo.isRelevantProject(createStubProjectWithSourceFolder(false)));
+ }
+
+ public void testIsRelevantProjectWithSourceIncludesOnly() throws Exception {
+ MavenProject stubProject = createStubProject("eclipse-plugin", "srcIncludesOnly", true);
+ assertTrue(mojo.isRelevantProject(stubProject));
+ }
+
+ public void testIsRelevantProjectNoSources() throws Exception {
+ MavenProject stubProject = createStubProject("eclipse-plugin", "noSources", true);
+ assertFalse(mojo.isRelevantProject(stubProject));
+ }
+
+ public void testIsRelevantProjectRequireSourceRootsConfigured() throws Exception {
+ MavenProject stubProject = createStubProject("eclipse-plugin", "noSources", true, true);
+ assertTrue(mojo.isRelevantProject(stubProject));
+ }
+
+ private MavenProject createStubProjectWithSourceFolder(String packaging) {
+ return createStubProject(packaging, "srcFolder", true);
+ }
+
+ private MavenProject createStubProjectWithSourceFolder(boolean sourcePluginEnabled) {
+ return createStubProject("eclipse-plugin", "srcFolder", sourcePluginEnabled);
+ }
+
+ private MavenProject createStubProject(String packaging, String testResourceFolder, boolean enableSourePlugin) {
+ return createStubProject(packaging, testResourceFolder, enableSourePlugin, false);
+ }
+
+ private MavenProject createStubProject(String packaging, String testResourceFolder, boolean enableSourePlugin,
+ boolean requireSourceRoots) {
+ MavenProject stubProject = new MavenProject();
+ stubProject.setPackaging(packaging);
+ if (enableSourePlugin) {
+ Build build = new Build();
+ stubProject.setBuild(build);
+ Plugin tychoSourcePlugin = new Plugin();
+ tychoSourcePlugin.setGroupId("org.eclipse.tycho");
+ tychoSourcePlugin.setArtifactId("tycho-source-plugin");
+ PluginExecution execution = new PluginExecution();
+ execution.setGoals(asList("plugin-source"));
+ if (requireSourceRoots) {
+ Xpp3Dom config = new Xpp3Dom("configuration");
+ Xpp3Dom requireSourceRootsDom = new Xpp3Dom("requireSourceRoots");
+ requireSourceRootsDom.setValue("true");
+ config.addChild(requireSourceRootsDom);
+ execution.setConfiguration(config);
+ }
+ tychoSourcePlugin.setExecutions(asList(execution));
+ build.setPlugins(asList(tychoSourcePlugin));
+ }
+ stubProject.setFile(new File("src/test/resources/sourceMojo/" + testResourceFolder + "/pom.xml"));
+ return stubProject;
+ }
+
+}
@@ -0,0 +1 @@
+# no source.* nor src.includes entries
@@ -0,0 +1,2 @@
+src.includes = foo/
+# no source.* entries

0 comments on commit c0fbaff

Please sign in to comment.