Author: andham Date: Wed Oct 23 12:10:21 2013 New Revision: 1534999 URL: http://svn.apache.org/r1534999 Log: [MSOURCES-68] Add Maven version used to Created-By entry in manifest
Added: maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/ maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/invoker.properties (with props) maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/pom.xml (with props) maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/src/ maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/src/main/ maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/src/main/java/ maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/src/main/java/MyClass.java (with props) maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/verify.bsh (with props) Modified: maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/AbstractSourceJarMojo.java Added: maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/invoker.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/invoker.properties?rev=1534999&view=auto ============================================================================== --- maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/invoker.properties (added) +++ maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/invoker.properties Wed Oct 23 12:10:21 2013 @@ -0,0 +1,18 @@ +# 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. + +invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:jar Propchange: maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/invoker.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/invoker.properties ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Propchange: maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/invoker.properties ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/pom.xml?rev=1534999&view=auto ============================================================================== --- maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/pom.xml (added) +++ maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/pom.xml Wed Oct 23 12:10:21 2013 @@ -0,0 +1,47 @@ +<?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>org.apache.maven.its.ejb</groupId> + <artifactId>manifest-content</artifactId> + <version>1.0-SNAPSHOT</version> + + <name>Test of manifest file content in created sources jar</name> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + <version>@project.version@</version> + </plugin> + </plugins> + </pluginManagement> + </build> +</project> Propchange: maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Propchange: maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/pom.xml ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/src/main/java/MyClass.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/src/main/java/MyClass.java?rev=1534999&view=auto ============================================================================== --- maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/src/main/java/MyClass.java (added) +++ maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/src/main/java/MyClass.java Wed Oct 23 12:10:21 2013 @@ -0,0 +1,23 @@ +/* + * 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. + */ + +public class MyClass +{ + +} Propchange: maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/src/main/java/MyClass.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/src/main/java/MyClass.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Propchange: maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/src/main/java/MyClass.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/verify.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/verify.bsh?rev=1534999&view=auto ============================================================================== --- maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/verify.bsh (added) +++ maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/verify.bsh Wed Oct 23 12:10:21 2013 @@ -0,0 +1,60 @@ + +/* + * 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 java.io.*; +import java.util.*; +import java.util.jar.*; +import org.codehaus.plexus.util.*; + +boolean result = true; + +try +{ + File target = new File( basedir, "target" ); + if ( !target.exists() || !target.isDirectory() ) + { + System.err.println( "target file is missing or not a directory." ); + return false; + } + + File artifact = new File( target, "manifest-content-1.0-SNAPSHOT-sources.jar" ); + if ( !artifact.exists() || artifact.isDirectory() ) + { + System.err.println( "artifact file is missing or a directory." ); + return false; + } + + JarFile jar = new JarFile( artifact ); + + Attributes manifest = jar.getManifest().getMainAttributes(); + + if ( !manifest.getValue( new Attributes.Name( "Created-By" ) ).startsWith( "Apache Maven" ) ) + { + System.err.println( "Created-By not equals Apache Maven" ); + return false; + } +} +catch( Throwable e ) +{ + e.printStackTrace(); + result = false; +} + +return result; Propchange: maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/verify.bsh ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-source-plugin/src/it/manifest-content/verify.bsh ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision 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=1534999&r1=1534998&r2=1534999&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 Wed Oct 23 12:10:21 2013 @@ -19,9 +19,16 @@ package org.apache.maven.plugin.source; * under the License. */ +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import org.apache.maven.archiver.MavenArchiveConfiguration; import org.apache.maven.archiver.MavenArchiver; import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Resource; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -35,12 +42,6 @@ import org.codehaus.plexus.archiver.jar. import org.codehaus.plexus.archiver.jar.ManifestException; import org.codehaus.plexus.util.FileUtils; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - /** * Base class for bundling sources into a jar archive. * @@ -190,6 +191,12 @@ public abstract class AbstractSourceJarM @Parameter( property = "source.skip", defaultValue = "false" ) private boolean skipSource; + /** + * The Maven session. + */ + @Component + private MavenSession session; + // ---------------------------------------------------------------------- // Public methods // ---------------------------------------------------------------------- @@ -285,7 +292,7 @@ public abstract class AbstractSourceJarM archive.setAddMavenDescriptor( false ); archive.setForced( forceCreation ); - archiver.createArchive( project, archive ); + archiver.createArchive( session, project, archive ); } catch ( IOException e ) {