Moved source plugins to main plugin

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@378781 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
snicoll 2006-02-18 21:28:29 +00:00
parent 9329c2c354
commit 009e7bceab
23 changed files with 1363 additions and 0 deletions

144
source/plugin.jelly Normal file
View File

@ -0,0 +1,144 @@
<?xml version="1.0"?>
<!--
/*
* 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.
*/
-->
<project
xmlns:j="jelly:core"
xmlns:ant="jelly:ant"
xmlns:artifact="artifact"
xmlns:util="jelly:util"
xmlns:i="jelly:interaction"
xmlns:define="jelly:define"
xmlns:maven="jelly:maven"
xmlns:source="source">
<define:taglib uri="source">
<define:jellybean
name="download-java-sources"
className="org.apache.maven.plugin.source.JavaSourcesDownloader"
method="downloadJavaSources"/>
</define:taglib>
<j:new var="javaSourceTypeHandler" className="org.apache.maven.plugin.source.JavaSourceArtifactTypeHandler" />
<!-- ================================================================== -->
<!-- S O U R C E -->
<!-- ================================================================== -->
<goal name="source" prereqs="source:source"
description="Create the source archive."/>
<goal name="source:source"
description="Create the source archive."
prereqs="java:compile">
<j:choose>
<j:when test="${pom.currentVersion == null}">
<ant:fail>You must define currentVersion in your POM.</ant:fail>
</j:when>
</j:choose>
<!-- Convert the path to fileset -->
<ant:pathconvert pathsep=";" property="java.source.paths" refid="maven.compile.src.set"/>
<util:tokenize var="java.source.paths.split" delim=";">${java.source.paths}</util:tokenize>
<ant:jar
jarfile="${maven.build.dir}/${maven.source.final.name}"
excludes="${maven.source.excludes}">
<!-- Create a fileset for each directory added to maven.compile.src.set -->
<j:forEach var="var" items="${java.source.paths.split}">
<ant:fileset dir="${var}"/>
</j:forEach>
</ant:jar>
</goal>
<!-- ================================================================== -->
<!-- D E P L O Y S O U R C E -->
<!-- ================================================================== -->
<goal
name="source:deploy"
prereqs="source:source"
description="Deploy the source archive to the remote repository">
<artifact:deploy
artifact="${maven.build.dir}/${maven.source.final.name}"
type="java-source"
project="${pom}"
typeHandler="${javaSourceTypeHandler}"/>
</goal>
<!-- ================================================================== -->
<!-- I N S T A L L S O U R C E -->
<!-- ================================================================== -->
<goal name="source:install" prereqs="source:source"
description="Install the source archive in the local repository">
<artifact:install
artifact="${maven.build.dir}/${maven.source.final.name}"
type="java-source"
project="${pom}"
typeHandler="${javaSourceTypeHandler}"/>
</goal>
<!-- ================================================================== -->
<!-- D O W N L O A D S O U R C E -->
<!-- ================================================================== -->
<goal name="source:download" description="Download a source archive from the repository">
<j:if test="${empty(artifactId)}">
<i:ask question="What is the artifactId of the source archive to download?"
answer="artifactId"/>
</j:if>
<maven:param-check value="${artifactId}" fail="true" message="'artifactId' must be specified"/>
<j:if test="${empty(groupId)}">
<i:ask question="What is the groupId of the source archive to download?"
answer="groupId"/>
</j:if>
<maven:param-check value="${groupId}" fail="true" message="'groupId' must be specified"/>
<j:if test="${empty(version)}">
<i:ask question="What is the version of the source archive to download?"
answer="version"/>
</j:if>
<maven:param-check value="${version}" fail="true" message="'version' must be specified"/>
<j:if test="${empty(ignoreErrors)}">
<j:set var="ignoreErrors" value="false"/>
</j:if>
<j:if test="${empty(backwardCompatible)}">
<j:set var="backwardCompatible" value="false"/>
</j:if>
<source:download-java-sources
project="${pom}"
groupId="${groupId}"
artifactId="${artifactId}"
version="${version}"
ignoreErrors="${ignoreErrors}"
backwardCompatible="${backwardCompatible}"
/>
</goal>
</project>

21
source/plugin.properties Normal file
View File

@ -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

24
source/project.properties Normal file
View File

@ -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

84
source/project.xml Normal file
View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*
* Copyright 2001-2006 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.
*/
-->
<project xmlns="http://maven.apache.org/POM/3.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/3.0.0 http://maven.apache.org/maven-v3_0_0.xsd">
<extend>../plugins-parent/project.xml</extend>
<pomVersion>3</pomVersion>
<id>maven-source-plugin</id>
<name>Maven Source Plugin</name>
<currentVersion>1.0-SNAPSHOT</currentVersion>
<description>Plugin for creating Java sources archive.</description>
<shortDescription>Create Java source archive</shortDescription>
<versions>
</versions>
<developers>
<developer>
<name>Stephane Nicoll</name>
<id>snicoll</id>
<email>snicoll@apache.org</email>
<roles>
<role>Java Developer</role>
</roles>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>maven</groupId>
<artifactId>maven</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>maven</groupId>
<artifactId>maven-model</artifactId>
<version>3.0.1</version>
<properties>
<comment>This library is already loaded by maven's core. Be careful to use the same version number as in the core.</comment>
</properties>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
<properties>
<comment>This library is already loaded by maven's core. Be careful to use the same version number as in the core.</comment>
</properties>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.0</version>
<type>jar</type>
<properties>
<comment>This library is already loaded by maven's core. Be careful to use the same version number as in the core.</comment>
</properties>
</dependency>
<dependency>
<groupId>commons-jelly</groupId>
<artifactId>commons-jelly</artifactId>
<version>1.0</version>
<properties>
<comment>This library is already loaded by maven's core. Be careful to use the same version number as in the core.</comment>
</properties>
</dependency>
<dependency>
<groupId>commons-jelly</groupId>
<artifactId>commons-jelly-tags-interaction</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>

View File

@ -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 <a href="snicoll@apache.org">Stephane Nicoll</a>
* @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();
}
}

View File

@ -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 <a href="snicoll@apache.org">Stephane Nicoll</a>
* @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 <code>remoteFile</code> from the maven remote repositories
* and store it at <code>destinationFile</code>
*
* @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;
}
}

View File

@ -0,0 +1,27 @@
<!--
/*
* 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.
*/
-->
<html>
<head>
<title>org.apache.maven.plugin.source</title>
</head>
<body>
<p>Handles source archive artifact.</p>
</body>
</html>

View File

@ -0,0 +1,56 @@
<!--
/*
* 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.
*/
-->
<project xmlns:j="jelly:core"
xmlns:u="jelly:util"
xmlns:x="jelly:xml"
xmlns:assert="assert"
xmlns:maven="jelly:maven">
<preGoal name="java:compile">
<!-- Invoke fake xdoclet plugin and update maven.compile.src.set -->
<path id="fake.xdoclet.compile.src.set" location="src/xdoclet/java"/>
<maven:addPath id="maven.compile.src.set" refid="fake.xdoclet.compile.src.set"/>
</preGoal>
<goal name="testPlugin" prereqs="source:source,test-source">
<attainGoal name="clean"/>
</goal>
<goal name="test-source">
<j:set var="sourceFile" value="${maven.build.dir}/${maven.source.final.name}"/>
<!-- tests that the source is generated -->
<assert:assertFileExists file="${sourceFile}"/>
<!-- unzip the source and look for the App in the right package structure -->
<j:set var="unzipDir" value= "${maven.build.dir}/sourceTest"/>
<mkdir dir="${unzipDir}"/>
<unzip src="${sourceFile}" dest="${unzipDir}"/>
<!-- check for source -->
<assert:assertFileExists file="${unzipDir}/org/apache/maven/plugin/source/test/FakeSessionBean.java"
msg="FakeSessionBean.java was not bundled"/>
<!-- check for generated code -->
<assert:assertFileExists file="${unzipDir}/org/apache/maven/plugin/source/test/FakeSessionLocal.java"
msg="FakeSessionLocal.java was not bundled"/>
<assert:assertFileExists file="${unzipDir}/org/apache/maven/plugin/source/test/FakeSessionLocalHome.java"
msg="FakeSessionLocalHome.java was not bundled"/>
</goal>
</project>

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*
* 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.
*/
-->
<project>
<pomVersion>3</pomVersion>
<id>test-maven-source-plugin-codeGenerationTest</id>
<name>Code Generation Test Case for Maven Source Plugin</name>
<groupId>maven</groupId>
<currentVersion>1.0-SNAPSHOT</currentVersion>
<organization>
<name>Apache Software Foundation</name>
<url>http://www.apache.org/</url>
<logo>http://maven.apache.org/images/apache-maven-project.png</logo>
</organization>
<inceptionYear>2006</inceptionYear>
<package>org.apache.maven</package>
<logo>http://maven.apache.org/images/maven.gif</logo>
<description>Test for Maven Source plugin</description>
<shortDescription>Test for Maven Source plugin</shortDescription>
<url>http://maven.apache.org/maven-1.x/reference/plugins/source/</url>
<siteDirectory>/www/maven.apache.org/maven-1.x/reference/plugins/source/</siteDirectory>
<repository>
<connection>scm:svn:http://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk/source/</connection>
<url>http://svn.apache.org/viewcvs.cgi/maven/maven-1/plugins/trunk/source/</url>
</repository>
<build>
<defaultGoal>testPlugin</defaultGoal>
<sourceDirectory>src/main/java</sourceDirectory>
</build>
</project>

View File

@ -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 <a href="mailto:snicoll@apache.org">Stephane Nicoll</a>
* @version $Id: App.java 232640 2005-08-14 20:46:54Z snicoll $
*/
public class FakeSessionBean
{
// Only for testing purposes!!
private FakeSessionLocal local;
public FakeSessionBean()
{
}
}

View File

@ -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 <a href="mailto:snicoll@apache.org">Stephane Nicoll</a>
* @version $Id: App.java 232640 2005-08-14 20:46:54Z snicoll $
*/
public class FakeSessionLocal
{
// Fake just as if xdoclet generated it
}

View File

@ -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 <a href="mailto:snicoll@apache.org">Stephane Nicoll</a>
* @version $Id: App.java 232640 2005-08-14 20:46:54Z snicoll $
*/
public class FakeSessionLocalHome
{
// Fake just as if xdoclet generated it
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*
* Copyright 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.
*/
-->
<project
xmlns:maven="jelly:maven">
<goal name="testPlugin">
<maven:reactor basedir="${basedir}"
includes="*Test/project.xml"
goals="testPlugin"
banner="Test"
ignoreFailures="false"/>
</goal>
</project>

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*
* 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.
*/
-->
<project>
<pomVersion>3</pomVersion>
<name>Test project for Maven Source Plugin</name>
<groupId>maven</groupId>
<currentVersion>1.0</currentVersion>
<organization>
<name>Apache Software Foundation</name>
<url>http://www.apache.org/</url>
<logo>http://maven.apache.org/images/apache-maven-project.png</logo>
</organization>
<inceptionYear>2006</inceptionYear>
<package>org.apache.maven</package>
<logo>http://maven.apache.org/images/maven.gif</logo>
<description>Test for Maven Source plugin</description>
<shortDescription>Test for Maven Source plugin</shortDescription>
<url>http://maven.apache.org/maven-1.x/reference/plugins/source/</url>
<siteDirectory>/www/maven.apache.org/maven-1.x/reference/plugins/source/</siteDirectory>
<repository>
<connection>scm:svn:http://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk/source/</connection>
<url>http://svn.apache.org/viewcvs.cgi/maven/maven-1/plugins/trunk/source/</url>
</repository>
<build>
<defaultGoal>testPlugin</defaultGoal>
</build>
</project>

View File

@ -0,0 +1,43 @@
<!--
/*
* 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.
*/
-->
<project xmlns:j="jelly:core"
xmlns:u="jelly:util"
xmlns:x="jelly:xml"
xmlns:assert="assert">
<goal name="testPlugin" prereqs="source:source,test-source">
<attainGoal name="clean"/>
</goal>
<goal name="test-source">
<j:set var="sourceFile" value="${maven.build.dir}/${maven.source.final.name}"/>
<!-- tests that the source is generated -->
<assert:assertFileExists file="${sourceFile}"/>
<!-- unzip the source and look for the App in the right package structure -->
<j:set var="unzipDir" value= "${maven.build.dir}/sourceTest"/>
<mkdir dir="${unzipDir}"/>
<unzip src="${sourceFile}" dest="${unzipDir}"/>
<!-- check for source -->
<assert:assertFileExists file="${unzipDir}/org/apache/maven/plugin/source/test/App.java"
msg="App.java was not bundled"/>
</goal>
</project>

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*
* 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.
*/
-->
<project>
<pomVersion>3</pomVersion>
<id>test-maven-source-plugin-simpleTest</id>
<name>Simple Test Case for Maven Source Plugin</name>
<groupId>maven</groupId>
<currentVersion>1.0-SNAPSHOT</currentVersion>
<organization>
<name>Apache Software Foundation</name>
<url>http://www.apache.org/</url>
<logo>http://maven.apache.org/images/apache-maven-project.png</logo>
</organization>
<inceptionYear>2006</inceptionYear>
<package>org.apache.maven</package>
<logo>http://maven.apache.org/images/maven.gif</logo>
<description>Test for Maven Source plugin</description>
<shortDescription>Test for Maven Source plugin</shortDescription>
<url>http://maven.apache.org/maven-1.x/reference/plugins/source/</url>
<siteDirectory>/www/maven.apache.org/maven-1.x/reference/plugins/source/</siteDirectory>
<repository>
<connection>scm:svn:http://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk/source/</connection>
<url>http://svn.apache.org/viewcvs.cgi/maven/maven-1/plugins/trunk/source/</url>
</repository>
<build>
<defaultGoal>testPlugin</defaultGoal>
<sourceDirectory>src/main/java</sourceDirectory>
</build>
</project>

View File

@ -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 <a href="mailto:snicoll@apache.org">Stephane Nicoll</a>
* @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!");
}
}

View File

@ -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 <a href="mailto:snicoll@apache.org">Stephane Nicoll</a>
* @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() );
}
}
}

30
source/xdocs/changes.xml Normal file
View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/*
* 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.
*/
-->
<document>
<properties>
<title>Changes</title>
<author email="snicoll@apache.org">Stephane Nicoll</author>
</properties>
<body>
<release version="1.0" date="in SVN">
<action dev="snicoll" type="add">Initial release.</action>
</release>
</body>
</document>

31
source/xdocs/goals.xml Normal file
View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<document>
<properties>
<title>Maven Source Plug-in Goals</title>
</properties>
<body>
<goals>
<goal>
<name>source</name>
<description>Create the source archive.</description>
</goal>
<goal>
<name>source:deploy</name>
<description>Deploy the source archive to the remote repository</description>
</goal>
<goal>
<name>source:install</name>
<description>Install the source archive in the local repository</description>
</goal>
<goal>
<name>source:source</name>
<description>Create the source archive.</description>
</goal>
<goal>
<name>source:download</name>
<description>Download a source archive from the repository.</description>
</goal>
</goals>
</body>
</document>

73
source/xdocs/index.xml Normal file
View File

@ -0,0 +1,73 @@
<?xml version="1.0"?>
<!--
/*
* 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.
*/
-->
<document>
<properties>
<title>Maven Source Plug-in</title>
<author email="snicoll@apache.org">Stephane Nicoll</author>
</properties>
<body>
<section name="Maven Source Plug-in">
<p>
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.
</p>
<p>
The generated source archive will be deployed at
<code>${groupId}/java-sources/${artifactId}-{version}-sources.jar</code>.
</p>
<p>
For more information on the functionality provided by this plugin,
please see the <a href="goals.html">Goals</a> document.
</p>
<p>
For more information on how to customise the functionality provided
by this plugin, please see the <a href="properties.html">properties</a>
document.
</p>
</section>
<section name="Downloading a source archive">
<p>
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:
<ul>
<li>groupId: the groupId of the source archive to download</li>
<li>artifactId: the artifactId of the source archive to download</li>
<li>version: the version of the source archive to download</li>
<li>ignoreErrors (optional - default to false): specificy if the build should fail if the source archive is not found</li>
<li>backwardCompatible (optional - default to false): specificy if the old source archive location should be checked as well</li>
</ul>
</p>
<p>
Example:
</p>
<source>
maven source:download
-DartifactId=someArtifact
-DgroupId=theGroup
-Dversion=1.0.0-SNAPSHOT
-DbackwardCompatible=true
</source>
</section>
</body>
</document>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Maven Source Plug-in">
<title>Maven Source Plug-in</title>
<body>
<links>
<item href="http://maven.apache.org/" name="Maven">
</item>
</links>
<menu name="Overview">
<item href="/goals.html" name="Goals">
</item>
<item href="/properties.html" name="Properties">
</item>
</menu>
</body>
</project>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<document>
<properties>
<title>Maven Source Plug-in Properties</title>
</properties>
<body>
<section name="Maven Source Plug-in Settings">
<table>
<tr>
<th>Property</th>
<th>Optional?</th>
<th>Description</th>
</tr>
<tr>
<td>maven.source.excludes</td>
<td>Yes</td>
<td>
<p>Default value is
<code>**/package.html</code>.</p>
</td>
</tr>
<tr>
<td>maven.source.final.name</td>
<td>Yes</td>
<td>
<p>Default value is
<code>${maven.final.name}-sources.jar</code>.</p>
</td>
</tr>
</table>
</section>
</body>
</document>