You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by de...@apache.org on 2009/02/24 22:57:10 UTC
svn commit: r747562 - in /maven/plugins/trunk/maven-source-plugin/src:
main/java/org/apache/maven/plugin/source/
test/java/org/apache/maven/plugin/source/
test/java/org/apache/maven/plugin/source/stubs/
test/resources/unit/project-009/ test/resources/u...
Author: dennisl
Date: Tue Feb 24 21:57:09 2009
New Revision: 747562
URL: http://svn.apache.org/viewvc?rev=747562&view=rev
Log:
[MSOURCES-39] Add an includePom option to the sources:jar goal
Submitted by: Moritz Havelock
Reviewed by: Dennis Lundberg
o Applied patch with modifications
o Added a test case
Added:
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugin/source/stubs/Project009Stub.java (with props)
maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/
maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/pom.xml (with props)
maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/
maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/
maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/java/
maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/java/foo/
maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/java/foo/project009/
maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/java/foo/project009/App.java (with props)
maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/resources/
maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/resources/default-configuration.properties (with props)
Modified:
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/AbstractSourceJarMojo.java
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugin/source/SourceJarMojoTest.java
Modified: maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/AbstractSourceJarMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/AbstractSourceJarMojo.java?rev=747562&r1=747561&r2=747562&view=diff
==============================================================================
--- maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/AbstractSourceJarMojo.java (original)
+++ maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/AbstractSourceJarMojo.java Tue Feb 24 21:57:09 2009
@@ -74,6 +74,14 @@
protected boolean excludeResources;
/**
+ * Specifies whether or not to include the POM file in the sources-jar.
+ *
+ * @parameter expression="${source.includePom}" default-value="false"
+ * @since 2.1
+ */
+ protected boolean includePom;
+
+ /**
* Used for attaching the source jar to the project.
*
* @component
@@ -207,6 +215,18 @@
protected void archiveProjectContent( MavenProject p, Archiver archiver )
throws MojoExecutionException
{
+ if ( includePom )
+ {
+ try
+ {
+ archiver.addFile( p.getFile(), p.getFile().getName() );
+ }
+ catch ( ArchiverException e )
+ {
+ throw new MojoExecutionException( "Error adding POM file to target jar file.", e );
+ }
+ }
+
for ( Iterator i = getSources( p ).iterator(); i.hasNext(); )
{
String s = (String) i.next();
Modified: maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugin/source/SourceJarMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugin/source/SourceJarMojoTest.java?rev=747562&r1=747561&r2=747562&view=diff
==============================================================================
--- maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugin/source/SourceJarMojoTest.java (original)
+++ maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugin/source/SourceJarMojoTest.java Tue Feb 24 21:57:09 2009
@@ -27,7 +27,6 @@
public class SourceJarMojoTest
extends AbstractSourcePluginTestCase
{
-
protected String getGoal()
{
return "jar";
@@ -40,7 +39,6 @@
"foo/project001/App.java", "foo/project001/", "foo/", "META-INF/MANIFEST.MF", "META-INF/"} );
}
-
public void testExcludes()
throws Exception
{
@@ -50,7 +48,6 @@
} );
}
-
public void testNoSources()
throws Exception
{
@@ -70,5 +67,10 @@
} );
}
-
+ public void testIncludePom()
+ throws Exception
+ {
+ doTestProjectWithSourceArchive( "project-009", new String[]{"default-configuration.properties", "pom.xml",
+ "foo/project009/App.java", "foo/project009/", "foo/", "META-INF/MANIFEST.MF", "META-INF/"} );
+ }
}
Added: maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugin/source/stubs/Project009Stub.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugin/source/stubs/Project009Stub.java?rev=747562&view=auto
==============================================================================
--- maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugin/source/stubs/Project009Stub.java (added)
+++ maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugin/source/stubs/Project009Stub.java Tue Feb 24 21:57:09 2009
@@ -0,0 +1,120 @@
+package org.apache.maven.plugin.source.stubs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.codehaus.plexus.util.ReaderFactory;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Dennis Lundberg
+ */
+public class Project009Stub
+ extends MavenProjectStub
+{
+ private Build build;
+
+ private List resources;
+
+ private List testResources;
+
+ public Project009Stub()
+ {
+ MavenXpp3Reader pomReader = new MavenXpp3Reader();
+ Model model;
+
+ try
+ {
+ final File pomFile = new File( getBasedir(), "target/test-classes/unit/project-009/pom.xml" );
+ model = pomReader.read( ReaderFactory.newXmlReader( pomFile ) );
+ setModel( model );
+ setFile( pomFile );
+
+ setGroupId( model.getGroupId() );
+ setArtifactId( model.getArtifactId() );
+ setVersion( model.getVersion() );
+ setName( model.getName() );
+ setUrl( model.getUrl() );
+ setPackaging( model.getPackaging() );
+
+ Build build = new Build();
+ build.setFinalName( getArtifactId() + "-" + getVersion() );
+ build.setDirectory( getBasedir() + "/target/test/unit/project-009/target" );
+ setBuild( build );
+
+ String basedir = getBasedir().getAbsolutePath();
+ List compileSourceRoots = new ArrayList();
+ compileSourceRoots.add( basedir + "/target/test-classes/unit/project-009/src/main/java" );
+ setCompileSourceRoots( compileSourceRoots );
+
+ List testCompileSourceRoots = new ArrayList();
+ testCompileSourceRoots.add( basedir + "/target/test-classes/unit/project-009/src/test/java" );
+ setTestCompileSourceRoots( testCompileSourceRoots );
+
+ setResources( model.getBuild().getResources() );
+ setTestResources( model.getBuild().getTestResources() );
+
+ Artifact artifact =
+ new SourcePluginArtifactStub( getGroupId(), getArtifactId(), getVersion(), getPackaging(), null );
+ setArtifact( artifact );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public Build getBuild()
+ {
+ return build;
+ }
+
+ public void setBuild( Build build )
+ {
+ this.build = build;
+ }
+
+ public List getResources()
+ {
+ return resources;
+ }
+
+ public void setResources( List resources )
+ {
+ this.resources = resources;
+ }
+
+ public List getTestResources()
+ {
+ return testResources;
+ }
+
+ public void setTestResources( List testResources )
+ {
+ this.testResources = testResources;
+ }
+}
Propchange: maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugin/source/stubs/Project009Stub.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/pom.xml?rev=747562&view=auto
==============================================================================
--- maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/pom.xml (added)
+++ maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/pom.xml Tue Feb 24 21:57:09 2009
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>source</groupId>
+ <artifactId>maven-source-plugin-test-project-009</artifactId>
+ <version>99.0</version>
+ <name>Maven</name>
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <resources>
+ <resource>
+ <directory>target/test-classes/unit/project-009/src/main/resources</directory>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <configuration>
+ <includePom>true</includePom>
+ <project implementation="org.apache.maven.plugin.source.stubs.Project009Stub"/>
+ <outputDirectory>${basedir}/target/test/unit/project-009/target</outputDirectory>
+ <finalName>maven-source-plugin-test-project-009-99.0</finalName>
+ <reactorProjects/>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/java/foo/project009/App.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/java/foo/project009/App.java?rev=747562&view=auto
==============================================================================
--- maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/java/foo/project009/App.java (added)
+++ maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/java/foo/project009/App.java Tue Feb 24 21:57:09 2009
@@ -0,0 +1,32 @@
+package foo.project009;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello World!" );
+ }
+}
Propchange: maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/java/foo/project009/App.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/resources/default-configuration.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/resources/default-configuration.properties?rev=747562&view=auto
==============================================================================
--- maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/resources/default-configuration.properties (added)
+++ maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/resources/default-configuration.properties Tue Feb 24 21:57:09 2009
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
Propchange: maven/plugins/trunk/maven-source-plugin/src/test/resources/unit/project-009/src/main/resources/default-configuration.properties
------------------------------------------------------------------------------
svn:eol-style = native