diff --git a/source/plugin.jelly b/source/plugin.jelly new file mode 100644 index 00000000..3afad77d --- /dev/null +++ b/source/plugin.jelly @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + You must define currentVersion in your POM. + + + + + + ${java.source.paths} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/plugin.properties b/source/plugin.properties new file mode 100644 index 00000000..7e5b0e6d --- /dev/null +++ b/source/plugin.properties @@ -0,0 +1,21 @@ +# ------------------------------------------------------------------- +# Copyright 2001-2004 The Apache Software Foundation. +# +# Licensed 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. +# ------------------------------------------------------------------- + +# ------------------------------------------------------------------- +# P L U G I N P R O P E R T I E S +# ------------------------------------------------------------------- +maven.source.excludes = **/package.html +maven.source.final.name = ${maven.final.name}-sources.jar diff --git a/source/project.properties b/source/project.properties new file mode 100644 index 00000000..7883d747 --- /dev/null +++ b/source/project.properties @@ -0,0 +1,24 @@ +# ------------------------------------------------------------------- +# Copyright 2001-2004 The Apache Software Foundation. +# +# Licensed 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. +# ------------------------------------------------------------------- + +# ------------------------------------------------------------------- +# P R O J E C T P R O P E R T I E S +# ------------------------------------------------------------------- +# Dependencies locally overrode can't be resolved in the generated POM +# This setting must be kept in the plugin +# Versions overriding are resolved thus they are defined in the parent project +maven.jar.override=on +maven.jar.maven = ${maven.home}/lib/maven.jar \ No newline at end of file diff --git a/source/project.xml b/source/project.xml new file mode 100644 index 00000000..1a2c6564 --- /dev/null +++ b/source/project.xml @@ -0,0 +1,84 @@ + + + + ../plugins-parent/project.xml + 3 + maven-source-plugin + Maven Source Plugin + 1.0-SNAPSHOT + Plugin for creating Java sources archive. + Create Java source archive + + + + + Stephane Nicoll + snicoll + snicoll@apache.org + + Java Developer + + + + + + maven + maven + 1.0.2 + + + maven + maven-model + 3.0.1 + + This library is already loaded by maven's core. Be careful to use the same version number as in the core. + + + + commons-logging + commons-logging + 1.0.4 + + This library is already loaded by maven's core. Be careful to use the same version number as in the core. + + + + commons-lang + commons-lang + 2.0 + jar + + This library is already loaded by maven's core. Be careful to use the same version number as in the core. + + + + commons-jelly + commons-jelly + 1.0 + + This library is already loaded by maven's core. Be careful to use the same version number as in the core. + + + + commons-jelly + commons-jelly-tags-interaction + 1.0 + + + diff --git a/source/src/main/org/apache/maven/plugin/source/JavaSourceArtifactTypeHandler.java b/source/src/main/org/apache/maven/plugin/source/JavaSourceArtifactTypeHandler.java new file mode 100644 index 00000000..34f13b4f --- /dev/null +++ b/source/src/main/org/apache/maven/plugin/source/JavaSourceArtifactTypeHandler.java @@ -0,0 +1,78 @@ +package org.apache.maven.plugin.source; + +/* ==================================================================== + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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.MavenException; +import org.apache.maven.project.Project; +import org.apache.maven.repository.ArtifactTypeHandler; + +/** + * Java sources artifact type handler. + * + * @author Stephane Nicoll + * @version $Id: JavaSourceArtifactTypeHandler.java 371078 2006-01-21 15:55:44Z snicoll $ + */ +public class JavaSourceArtifactTypeHandler + implements ArtifactTypeHandler +{ + /** + * Map an artifact to a repository directory path. + * + * @param project the project for the artifact + * @param type The type of the artifact + * @return the path + * @throws MavenException if an error occured while building the path + */ + public String constructRepositoryDirectoryPath( String type, Project project ) + throws MavenException + { + StringBuffer path = new StringBuffer(); + path.append( project.getArtifactDirectory() ); + path.append( "/java-sources/" ); + return path.toString(); + } + + /** + * Map an artifact to a repository path. + * + * @param project the project for the artifact + * @param type The type of the artifact + * @param version The version of the artifact (may be a snapshot) + * @return the path + * @throws MavenException if an error occured while building the path + */ + public String constructRepositoryFullPath( String type, Project project, String version ) + throws MavenException + { + StringBuffer path = new StringBuffer( constructRepositoryDirectoryPath( type, project ) ); + path.append( project.getArtifactId() ); + path.append( "-" ); + path.append( version ); + + if ( type.equals( "java-source" ) ) + { + path.append( "-sources.jar" ); + } + else + { + throw new MavenException( "Unrecognised java-source type (is " + type + ")" ); + } + + return path.toString(); + } +} diff --git a/source/src/main/org/apache/maven/plugin/source/JavaSourcesDownloader.java b/source/src/main/org/apache/maven/plugin/source/JavaSourcesDownloader.java new file mode 100644 index 00000000..4f6d37fc --- /dev/null +++ b/source/src/main/org/apache/maven/plugin/source/JavaSourcesDownloader.java @@ -0,0 +1,339 @@ +/* + * Copyright (c) 2006 Your Corporation. All Rights Reserved. + */ +package org.apache.maven.plugin.source; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.maven.AbstractMavenComponent; +import org.apache.maven.project.Project; +import org.apache.maven.util.HttpUtils; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Iterator; + +/** + * An helper class used to download java sources archives. + * + * @author Stephane Nicoll + * @version $Id: JavaSourcesDownloader.java 371078 2006-01-21 15:55:44Z snicoll $ + */ +public class JavaSourcesDownloader + extends AbstractMavenComponent +{ + private static final String PROXY_LOGINHOST = "maven.proxy.ntlm.host"; + + private static final String PROXY_LOGINDOMAIN = "maven.proxy.ntlm.domain"; + + private static final Log log = LogFactory.getLog( JavaSourcesDownloader.class ); + + private Project project; + + private String groupId; + + private String artifactId; + + private String version; + + private boolean ignoreErrors; + + private boolean backwardCompatible; + + + /** + * Download the Java sources archive from the configured repositories. + * + * @throws NullPointerException if a mandatory parameter is not initialized + * @throws FileNotFoundException if ignoreErrors is false and the archive is not found + */ + public void downloadJavaSources() + throws NullPointerException, FileNotFoundException + { + if ( project == null ) + { + throw new NullPointerException( "project should be set." ); + } + + if ( groupId == null ) + { + throw new NullPointerException( "groupId should be set." ); + } + + if ( artifactId == null ) + { + throw new NullPointerException( "artifactId should be set." ); + } + + if ( version == null ) + { + throw new NullPointerException( "version should be set." ); + } + + final String dependencyId = groupId + ":" + artifactId + ":" + version; + + final String relativePath = buildRelativePath(); + final File localFile = new File( project.getContext().getMavenRepoLocal(), relativePath ); + final String backwareCompatibleRelativePath = buildBackwardCompatibleRelativePath(); + final File backwardCompatibleLocalFile = + new File( project.getContext().getMavenRepoLocal(), backwareCompatibleRelativePath ); + + boolean artifactFound; + if ( isSnapshot() ) + { + artifactFound = getRemoteArtifact( localFile, relativePath, dependencyId ); + if ( backwardCompatible ) + { + artifactFound = + getRemoteArtifact( backwardCompatibleLocalFile, backwareCompatibleRelativePath, dependencyId ); + } + + // Do not go further if the artifact is in the local repository + if ( localFile.exists() || ( backwardCompatible && backwardCompatibleLocalFile.exists() ) ) + { + return; + } + } + else + { + if ( localFile.exists() || ( backwardCompatible && backwardCompatibleLocalFile.exists() ) ) + { + log.debug( "source for " + dependencyId + " is available in the local repository." ); + return; + } + else + { + // download it + artifactFound = getRemoteArtifact( localFile, relativePath, dependencyId ); + if ( !artifactFound && backwardCompatible ) + { + artifactFound = + getRemoteArtifact( backwardCompatibleLocalFile, backwareCompatibleRelativePath, dependencyId ); + } + } + } + + if ( !ignoreErrors && !artifactFound ) + { + throw new FileNotFoundException( "Could not download source for " + dependencyId + " from any repository " + + getProject().getContext().getMavenRepoRemote() ); + } + } + + // Getters & Setters + + + public Project getProject() + { + return project; + } + + public void setProject( final Project project ) + { + this.project = project; + } + + public String getGroupId() + { + return groupId; + } + + public void setGroupId( final String groupId ) + { + this.groupId = groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public void setArtifactId( final String artifactId ) + { + this.artifactId = artifactId; + } + + public String getVersion() + { + return version; + } + + public void setVersion( final String version ) + { + this.version = version; + } + + public boolean isIgnoreErrors() + { + return ignoreErrors; + } + + public void setIgnoreErrors( final boolean ignoreErrors ) + { + this.ignoreErrors = ignoreErrors; + } + + public boolean isBackwardCompatible() + { + return backwardCompatible; + } + + public void setBackwardCompatible( final boolean backwardCompatible ) + { + this.backwardCompatible = backwardCompatible; + } + + /** + * Builds the relative path to the source archive. + * + * @return the relative path to the source archive + */ + private String buildRelativePath() + { + StringBuffer sb = new StringBuffer(); + sb.append( groupId ).append( "/java-sources/" ).append( artifactId ).append( "-" ).append( version ).append( + "-sources.jar" ); + return sb.toString(); + } + + /** + * Build the backware compatible relative path to the source archive. + * + * @return the backware compatible relative path to the source archive + */ + private String buildBackwardCompatibleRelativePath() + { + StringBuffer sb = new StringBuffer(); + sb.append( groupId ).append( "/src/" ).append( artifactId ).append( "-" ).append( version ).append( ".zip" ); + return sb.toString(); + } + + /** + * Specify whether the source archive to download is a SNAPSHOT or not. + * + * @return true if the source archive is a SNAPSHOT, false otherwise + */ + private boolean isSnapshot() + { + return version.endsWith( "SNAPSHOT" ); + } + + // Taken from maven core code in order to mimic the current behavior + + /** + * Retrieve a remoteFile from the maven remote repositories + * and store it at destinationFile + * + * @param destinationFile the destination file in the local repository + * @param relativePath the relative path to the dependency + * @param dependencyId the dependency Id + * @return true if the retrieval succeeds, false otherwise. + */ + private boolean getRemoteArtifact( File destinationFile, String relativePath, String dependencyId ) + { + + // The directory structure for the project this dependency belongs to + // may not exists so attempt to create the project directory structure + // before attempting to download the dependency. + File directory = destinationFile.getParentFile(); + + if ( !directory.exists() ) + { + directory.mkdirs(); + } + + log.info( "Attempting to download sources for " + dependencyId + " ("+relativePath+")" ); + + boolean artifactFound = false; + + for ( Iterator i = getProject().getContext().getMavenRepoRemote().iterator(); i.hasNext(); ) + { + String remoteRepo = (String) i.next(); + + if ( remoteRepo.endsWith( "/" ) ) + { + remoteRepo = remoteRepo.substring( 0, remoteRepo.length() - 1 ); + } + + // The username and password parameters are not being + // used here. Those are the "" parameters you see below. + String url = remoteRepo + "/" + relativePath; + url = StringUtils.replace( url, "//", "/" ); + + if ( !url.startsWith( "file" ) ) + { + if ( url.startsWith( "https" ) ) + { + url = StringUtils.replace( url, "https:/", "https://" ); + } + else + { + url = StringUtils.replace( url, "http:/", "http://" ); + } + } + log.debug( "Trying to download source at " + url ); + + // Attempt to retrieve the artifact and set the checksum if retrieval + // of the checksum file was successful. + try + { + String loginHost = (String) getProject().getContext().getVariable( PROXY_LOGINHOST ); + String loginDomain = (String) getProject().getContext().getVariable( PROXY_LOGINDOMAIN ); + HttpUtils.getFile( url, destinationFile, false, true, getProject().getContext().getProxyHost(), + getProject().getContext().getProxyPort(), + getProject().getContext().getProxyUserName(), + getProject().getContext().getProxyPassword(), loginHost, loginDomain, true ); + + // Artifact was found, continue checking additional remote repos (if any) + // in case there is a newer version (i.e. snapshots) in another repo + artifactFound = true; + + if ( !isSnapshot() ) + { + log.info( "Downloded source for " + dependencyId + " at " + url ); + break; + } + } + catch ( FileNotFoundException e ) + { + // Multiple repositories may exist, and if the file is not found + // in just one of them, it's no problem, and we don't want to + // even print out an error. + // if it's not found at all, artifactFound will be false, and the + // build _will_ break, and the user will get an error message + log.debug( "File not found on one of the repos", e ); + } + catch ( Exception e ) + { + // If there are additional remote repos, then ignore exception + // as artifact may be found in another remote repo. If there + // are no more remote repos to check and the artifact wasn't found in + // a previous remote repo, then artifactFound is false indicating + // that the artifact could not be found in any of the remote repos + // + // arguably, we need to give the user better control (another command- + // line switch perhaps) of what to do in this case? Maven already has + // a command-line switch to work in offline mode, but what about when + // one of two or more remote repos is unavailable? There may be multiple + // remote repos for redundancy, in which case you probably want the build + // to continue. There may however be multiple remote repos because some + // artifacts are on one, and some are on another. In this case, you may + // want the build to break. + // + // print a warning, in any case, so user catches on to mistyped + // hostnames, or other snafus + // FIXME: localize this message + String[] parsedUrl = HttpUtils.parseUrl( url ); + log.warn( "Error retrieving artifact from [" + parsedUrl[2] + "]: " + e ); + if ( parsedUrl[0] != null ) + { + log.debug( "Username was '" + parsedUrl[0] + "', password hidden" ); + } + log.debug( "Error details", e ); + } + } + + return artifactFound; + } +} diff --git a/source/src/main/org/apache/maven/plugin/source/package.html b/source/src/main/org/apache/maven/plugin/source/package.html new file mode 100644 index 00000000..695d7183 --- /dev/null +++ b/source/src/main/org/apache/maven/plugin/source/package.html @@ -0,0 +1,27 @@ + + + + org.apache.maven.plugin.source + + + +

Handles source archive artifact.

+ + + diff --git a/source/src/plugin-test/codeGenerationTest/maven.xml b/source/src/plugin-test/codeGenerationTest/maven.xml new file mode 100644 index 00000000..911f7da0 --- /dev/null +++ b/source/src/plugin-test/codeGenerationTest/maven.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/src/plugin-test/codeGenerationTest/project.xml b/source/src/plugin-test/codeGenerationTest/project.xml new file mode 100644 index 00000000..c9236fe4 --- /dev/null +++ b/source/src/plugin-test/codeGenerationTest/project.xml @@ -0,0 +1,46 @@ + + + + + 3 + test-maven-source-plugin-codeGenerationTest + Code Generation Test Case for Maven Source Plugin + maven + 1.0-SNAPSHOT + + Apache Software Foundation + http://www.apache.org/ + http://maven.apache.org/images/apache-maven-project.png + + 2006 + org.apache.maven + http://maven.apache.org/images/maven.gif + Test for Maven Source plugin + Test for Maven Source plugin + http://maven.apache.org/maven-1.x/reference/plugins/source/ + /www/maven.apache.org/maven-1.x/reference/plugins/source/ + + scm:svn:http://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk/source/ + http://svn.apache.org/viewcvs.cgi/maven/maven-1/plugins/trunk/source/ + + + testPlugin + src/main/java + + \ No newline at end of file diff --git a/source/src/plugin-test/codeGenerationTest/src/main/java/org/apache/maven/plugin/source/test/FakeSessionBean.java b/source/src/plugin-test/codeGenerationTest/src/main/java/org/apache/maven/plugin/source/test/FakeSessionBean.java new file mode 100644 index 00000000..8a2ea94a --- /dev/null +++ b/source/src/plugin-test/codeGenerationTest/src/main/java/org/apache/maven/plugin/source/test/FakeSessionBean.java @@ -0,0 +1,35 @@ +package org.apache.maven.plugin.source.test; + +/* ==================================================================== + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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. + * ==================================================================== + */ + +/** + * @author Stephane Nicoll + * @version $Id: App.java 232640 2005-08-14 20:46:54Z snicoll $ + */ +public class FakeSessionBean +{ + + // Only for testing purposes!! + private FakeSessionLocal local; + + public FakeSessionBean() + { + + } + +} diff --git a/source/src/plugin-test/codeGenerationTest/src/xdoclet/java/org/apache/maven/plugin/source/test/FakeSessionLocal.java b/source/src/plugin-test/codeGenerationTest/src/xdoclet/java/org/apache/maven/plugin/source/test/FakeSessionLocal.java new file mode 100644 index 00000000..7faff94e --- /dev/null +++ b/source/src/plugin-test/codeGenerationTest/src/xdoclet/java/org/apache/maven/plugin/source/test/FakeSessionLocal.java @@ -0,0 +1,27 @@ +package org.apache.maven.plugin.source.test; + +/* ==================================================================== + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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. + * ==================================================================== + */ + +/** + * @author Stephane Nicoll + * @version $Id: App.java 232640 2005-08-14 20:46:54Z snicoll $ + */ +public class FakeSessionLocal +{ + // Fake just as if xdoclet generated it +} diff --git a/source/src/plugin-test/codeGenerationTest/src/xdoclet/java/org/apache/maven/plugin/source/test/FakeSessionLocalHome.java b/source/src/plugin-test/codeGenerationTest/src/xdoclet/java/org/apache/maven/plugin/source/test/FakeSessionLocalHome.java new file mode 100644 index 00000000..6b2f9664 --- /dev/null +++ b/source/src/plugin-test/codeGenerationTest/src/xdoclet/java/org/apache/maven/plugin/source/test/FakeSessionLocalHome.java @@ -0,0 +1,27 @@ +package org.apache.maven.plugin.source.test; + +/* ==================================================================== + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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. + * ==================================================================== + */ + +/** + * @author Stephane Nicoll + * @version $Id: App.java 232640 2005-08-14 20:46:54Z snicoll $ + */ +public class FakeSessionLocalHome +{ + // Fake just as if xdoclet generated it +} diff --git a/source/src/plugin-test/maven.xml b/source/src/plugin-test/maven.xml new file mode 100644 index 00000000..d6f21e93 --- /dev/null +++ b/source/src/plugin-test/maven.xml @@ -0,0 +1,30 @@ + + + + + + + + + diff --git a/source/src/plugin-test/project.xml b/source/src/plugin-test/project.xml new file mode 100644 index 00000000..caad7123 --- /dev/null +++ b/source/src/plugin-test/project.xml @@ -0,0 +1,44 @@ + + + + + 3 + Test project for Maven Source Plugin + maven + 1.0 + + Apache Software Foundation + http://www.apache.org/ + http://maven.apache.org/images/apache-maven-project.png + + 2006 + org.apache.maven + http://maven.apache.org/images/maven.gif + Test for Maven Source plugin + Test for Maven Source plugin + http://maven.apache.org/maven-1.x/reference/plugins/source/ + /www/maven.apache.org/maven-1.x/reference/plugins/source/ + + scm:svn:http://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk/source/ + http://svn.apache.org/viewcvs.cgi/maven/maven-1/plugins/trunk/source/ + + + testPlugin + + \ No newline at end of file diff --git a/source/src/plugin-test/simpleTest/maven.xml b/source/src/plugin-test/simpleTest/maven.xml new file mode 100644 index 00000000..3b25c7b0 --- /dev/null +++ b/source/src/plugin-test/simpleTest/maven.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/src/plugin-test/simpleTest/project.xml b/source/src/plugin-test/simpleTest/project.xml new file mode 100644 index 00000000..8d4c07c6 --- /dev/null +++ b/source/src/plugin-test/simpleTest/project.xml @@ -0,0 +1,46 @@ + + + + + 3 + test-maven-source-plugin-simpleTest + Simple Test Case for Maven Source Plugin + maven + 1.0-SNAPSHOT + + Apache Software Foundation + http://www.apache.org/ + http://maven.apache.org/images/apache-maven-project.png + + 2006 + org.apache.maven + http://maven.apache.org/images/maven.gif + Test for Maven Source plugin + Test for Maven Source plugin + http://maven.apache.org/maven-1.x/reference/plugins/source/ + /www/maven.apache.org/maven-1.x/reference/plugins/source/ + + scm:svn:http://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk/source/ + http://svn.apache.org/viewcvs.cgi/maven/maven-1/plugins/trunk/source/ + + + testPlugin + src/main/java + + \ No newline at end of file diff --git a/source/src/plugin-test/simpleTest/src/main/java/org/apache/maven/plugin/source/test/App.java b/source/src/plugin-test/simpleTest/src/main/java/org/apache/maven/plugin/source/test/App.java new file mode 100644 index 00000000..5400136a --- /dev/null +++ b/source/src/plugin-test/simpleTest/src/main/java/org/apache/maven/plugin/source/test/App.java @@ -0,0 +1,31 @@ +package org.apache.maven.plugin.source.test; + +/* ==================================================================== + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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. + * ==================================================================== + */ + +/** + * @author Stephane Nicoll + * @version $Id: App.java 232640 2005-08-14 20:46:54Z snicoll $ + */ +public class App +{ + + public static void main( String[] args ) + { + System.out.println("Hello World!"); + } +} diff --git a/source/src/test/org/apache/maven/plugin/source/JavaSourceArtifactTypeHandlerTest.java b/source/src/test/org/apache/maven/plugin/source/JavaSourceArtifactTypeHandlerTest.java new file mode 100644 index 00000000..dcc5aeb5 --- /dev/null +++ b/source/src/test/org/apache/maven/plugin/source/JavaSourceArtifactTypeHandlerTest.java @@ -0,0 +1,76 @@ +package org.apache.maven.plugin.source; + +/* ==================================================================== + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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.project.Project; +import org.apache.maven.repository.ArtifactTypeHandler; +import org.apache.maven.MavenException; +import junit.framework.TestCase; + +/** + * Tests the java source artifact type handler implementation. + * + * @author Stephane Nicoll + * @version $Id: JavaSourceArtifactTypeHandlerTest.java 232640 2005-08-14 20:46:54Z snicoll $ + */ +public class JavaSourceArtifactTypeHandlerTest + extends TestCase +{ + private Project project; + + private ArtifactTypeHandler handler; + + private static final String VERSION = "VERSION"; + + public void setUp() + throws Exception + { + project = new Project(); + project.setGroupId( "groupId" ); + project.setArtifactId( "artifactId" ); + handler = new JavaSourceArtifactTypeHandler(); + } + + public void testConstructRepositoryDirectoryPath() + throws Exception + { + assertEquals( "check artifact directory", "groupId/java-sources/", + handler.constructRepositoryDirectoryPath( "java-source", project ) ); + } + + public void testConstructRepositoryFullPath() + throws Exception + { + assertEquals( "check artifact path", "groupId/java-sources/artifactId-VERSION-sources.jar", + handler.constructRepositoryFullPath( "java-source", project, VERSION ) ); + } + + public void testConstructRepositoryFullPathWithInvalidType() + throws Exception + { + try + { + handler.constructRepositoryFullPath( "foo", project, VERSION ); + fail( "expected exception" ); + } + catch ( MavenException expected ) + { + assertEquals( "Unrecognised java-source type (is foo)", expected.getMessage() ); + } + } +} \ No newline at end of file diff --git a/source/xdocs/changes.xml b/source/xdocs/changes.xml new file mode 100644 index 00000000..aaf14043 --- /dev/null +++ b/source/xdocs/changes.xml @@ -0,0 +1,30 @@ + + + + + + Changes + Stephane Nicoll + + + + Initial release. + + + diff --git a/source/xdocs/goals.xml b/source/xdocs/goals.xml new file mode 100644 index 00000000..e45cd170 --- /dev/null +++ b/source/xdocs/goals.xml @@ -0,0 +1,31 @@ + + + + + Maven Source Plug-in Goals + + + + + source + Create the source archive. + + + source:deploy + Deploy the source archive to the remote repository + + + source:install + Install the source archive in the local repository + + + source:source + Create the source archive. + + + source:download + Download a source archive from the repository. + + + + \ No newline at end of file diff --git a/source/xdocs/index.xml b/source/xdocs/index.xml new file mode 100644 index 00000000..3909be73 --- /dev/null +++ b/source/xdocs/index.xml @@ -0,0 +1,73 @@ + + + + + + + Maven Source Plug-in + Stephane Nicoll + + + +
+

+ This plug-in builds an archive of the source code. It is based + on the maven.compile.src.set property so every directory specified + in this property is used to generate the source archive. +

+

+ The generated source archive will be deployed at + ${groupId}/java-sources/${artifactId}-{version}-sources.jar. +

+

+ For more information on the functionality provided by this plugin, + please see the Goals document. +

+

+ For more information on how to customise the functionality provided + by this plugin, please see the properties + document. +

+
+
+

+ Similarly to the plugin plugin, the source plugin is able to download + a source archive from the configured repository(ies). The following + parameters might be set at runtime: +

+

+

+ Example: +

+ + maven source:download + -DartifactId=someArtifact + -DgroupId=theGroup + -Dversion=1.0.0-SNAPSHOT + -DbackwardCompatible=true + +
+ +
diff --git a/source/xdocs/navigation.xml b/source/xdocs/navigation.xml new file mode 100644 index 00000000..b1d7e729 --- /dev/null +++ b/source/xdocs/navigation.xml @@ -0,0 +1,17 @@ + + + + Maven Source Plug-in + + + + + + + + + + + + + \ No newline at end of file diff --git a/source/xdocs/properties.xml b/source/xdocs/properties.xml new file mode 100644 index 00000000..665a8442 --- /dev/null +++ b/source/xdocs/properties.xml @@ -0,0 +1,34 @@ + + + + + Maven Source Plug-in Properties + + +
+ + + + + + + + + + + + + + + + +
PropertyOptional?Description
maven.source.excludesYes +

Default value is + **/package.html.

+
maven.source.final.nameYes +

Default value is + ${maven.final.name}-sources.jar.

+
+
+ +
\ No newline at end of file