[MDEPLOY-48] Add options to deploy sources and javadoc along with main jar when using deploy-file.
git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1073530 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/it/deploy-attached-sources/invoker.properties b/src/it/deploy-attached-sources/invoker.properties
new file mode 100644
index 0000000..7a3452a
--- /dev/null
+++ b/src/it/deploy-attached-sources/invoker.properties
@@ -0,0 +1,5 @@
+# Clean build of the jars
+invoker.goals = clean package
+
+# Deploy the jars in a separate step
+invoker.goals.2 = ${project.groupId}:${project.artifactId}:${project.version}:deploy-file
diff --git a/src/it/deploy-attached-sources/pom.xml b/src/it/deploy-attached-sources/pom.xml
new file mode 100644
index 0000000..d0aac26
--- /dev/null
+++ b/src/it/deploy-attached-sources/pom.xml
@@ -0,0 +1,85 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.deploy</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>deploy-attached-sources</name>
+ <description>sample jar project with attached sources</description>
+ <url>http://jira.codehaus.org/browse/MDEPLOY-48</url>
+
+ <distributionManagement>
+ <repository>
+ <id>repo1</id>
+ <name>Maven Central Repository</name>
+ <url>scp://foo.org/m2/release</url>
+ </repository>
+ <snapshotRepository>
+ <id>repo1</id>
+ <name>Maven Central Repository</name>
+ <url>scp://foo.org/m2/snapshot</url>
+ </snapshotRepository>
+ </distributionManagement>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <version>2.1.2</version>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar-no-fork</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.7</version>
+ <executions>
+ <execution>
+ <id>attach-javadoc</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <!-- Deployments will be written to ${basedir}/target -->
+ <altDeploymentRepository>mine::default::file://${basedir}/target</altDeploymentRepository>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/deploy-attached-sources/setup.bsh b/src/it/deploy-attached-sources/setup.bsh
new file mode 100644
index 0000000..50f77bd
--- /dev/null
+++ b/src/it/deploy-attached-sources/setup.bsh
@@ -0,0 +1,7 @@
+import java.io.*;
+import java.util.*;
+
+file = new File( basedir, "target/repo" );
+file.mkdirs();
+
+return true;
diff --git a/src/it/deploy-attached-sources/src/main/java/org/apache/maven/test/HelloWorld.java b/src/it/deploy-attached-sources/src/main/java/org/apache/maven/test/HelloWorld.java
new file mode 100644
index 0000000..4af3292
--- /dev/null
+++ b/src/it/deploy-attached-sources/src/main/java/org/apache/maven/test/HelloWorld.java
@@ -0,0 +1,38 @@
+package org.apache.maven.test;
+
+/*
+ * 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 class
+ */
+public class HelloWorld
+{
+
+ /**
+ * Main method
+ * @param args
+ */
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello world" );
+
+ }
+
+}
diff --git a/src/it/deploy-attached-sources/src/main/resources/foo.txt b/src/it/deploy-attached-sources/src/main/resources/foo.txt
new file mode 100755
index 0000000..5559e0d
--- /dev/null
+++ b/src/it/deploy-attached-sources/src/main/resources/foo.txt
@@ -0,0 +1,2 @@
+nothing to see here
+
diff --git a/src/it/deploy-attached-sources/test.properties b/src/it/deploy-attached-sources/test.properties
new file mode 100644
index 0000000..831c07a
--- /dev/null
+++ b/src/it/deploy-attached-sources/test.properties
@@ -0,0 +1,8 @@
+# Properties passed to invocations of the deploy plugin
+pomFile = ${basedir}/pom.xml
+
+file = ${basedir}/target/${project.artifactId}-${project.version}.jar
+sources = ${basedir}/target/${project.artifactId}-${project.version}-sources.jar
+javadoc = ${basedir}/target/${project.artifactId}-${project.version}-javadoc.jar
+
+url = file://${basedir}/target/repo
diff --git a/src/it/deploy-attached-sources/verify.bsh b/src/it/deploy-attached-sources/verify.bsh
new file mode 100644
index 0000000..a0fd776
--- /dev/null
+++ b/src/it/deploy-attached-sources/verify.bsh
@@ -0,0 +1,79 @@
+
+/*
+ * 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 deployedDir = new File ( target, "repo/org/apache/maven/its/deploy/test/1.0-SNAPSHOT/" );
+ if ( !deployedDir.isDirectory() )
+ {
+ System.err.println( "deployedDir is missing or is not a directory." );
+ return false;
+ }
+
+ boolean sourcesExists = false;
+ boolean javadocsExists = false;
+
+ String [] fileList = deployedDir.list();
+ for ( int i=0; i<fileList.length; ++i )
+ {
+ if ( fileList[i].endsWith( "-1-sources.jar" ) )
+ {
+ sourcesExists = true;
+ }
+ if ( fileList[i].endsWith( "-1-javadoc.jar" ) )
+ {
+ javadocsExists = true;
+ }
+ }
+
+ if ( !sourcesExists )
+ {
+ System.err.println( "Unable to find deployed sources jar" );
+ return false;
+ }
+
+ if ( !javadocsExists )
+ {
+ System.err.println( "Unable to find deployed javadocs jar" );
+ return false;
+ }
+
+}
+catch( Throwable e )
+{
+ e.printStackTrace();
+ result = false;
+}
+
+return result;
diff --git a/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java b/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
index a0a6ad5..15c91ca 100644
--- a/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
+++ b/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
@@ -21,6 +21,7 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
+import org.apache.maven.artifact.installer.ArtifactInstallationException;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
@@ -99,6 +100,22 @@
private File file;
/**
+ * The bundled API docs for the artifact.
+ *
+ * @parameter expression="${javadoc}"
+ * @since 2.6
+ */
+ private File javadoc;
+
+ /**
+ * The bundled sources for the artifact.
+ *
+ * @parameter expression="${sources}"
+ * @since 2.6
+ */
+ private File sources;
+
+ /**
* Server Id to map on the <id> under <server> section of settings.xml
* In most cases, this parameter will be required for authentication.
*
@@ -238,6 +255,33 @@
{
throw new MojoExecutionException( e.getMessage(), e );
}
+
+ if ( sources != null )
+ {
+ artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, "jar", "sources" );
+ try
+ {
+ getDeployer().deploy( sources, artifact, deploymentRepository, getLocalRepository() );
+ }
+ catch ( ArtifactDeploymentException e )
+ {
+ throw new MojoExecutionException( "Error deploying sources " + sources + ": " + e.getMessage(), e );
+ }
+ }
+
+ if ( javadoc != null )
+ {
+ artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, "jar", "javadoc" );
+ try
+ {
+ getDeployer().deploy( javadoc, artifact, deploymentRepository, getLocalRepository() );
+ }
+ catch ( ArtifactDeploymentException e )
+ {
+ throw new MojoExecutionException( "Error deploying API docs " + javadoc + ": " + e.getMessage(), e );
+ }
+ }
+
}
/**