Initial revision

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163924 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-04-13 05:07:50 +00:00
parent 55d33da355
commit df06a3c5eb
13 changed files with 1060 additions and 0 deletions

23
maven-plugin-api/pom.xml Executable file
View File

@ -0,0 +1,23 @@
<project>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>maven</artifactId>
<version>2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-plugin-api</artifactId>
<name>Maven Plugin API</name>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-monitor</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,104 @@
package org.apache.maven.plugin;
/*
* 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.monitor.logging.Log;
import org.apache.maven.monitor.logging.SystemStreamLog;
/**
* @version $Id$
*/
public abstract class AbstractPlugin
implements Plugin
{
private Log log;
/**
* Default behaviour to mimic old behaviour.
*
* @deprecated
*/
public void execute( PluginExecutionRequest request )
throws PluginExecutionException
{
PluginExecutionResponse response = new PluginExecutionResponse();
try
{
execute( request, response );
}
catch ( Exception e )
{
throw new PluginExecutionException( e.getMessage(), e );
}
if ( response.isExecutionFailure() )
{
throw new PluginExecutionException( response.getFailureResponse().getSource(),
response.getFailureResponse().shortMessage(),
response.getFailureResponse().longMessage() );
}
}
/**
* @deprecated
*/
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
{
throw new UnsupportedOperationException(
"If you are using the old technique, you must override execute(req,resp)" );
}
public void setLog( Log log )
{
this.log = log;
}
public Log getLog()
{
synchronized ( this )
{
if ( log == null )
{
log = new SystemStreamLog();
}
}
return log;
}
public void execute()
throws PluginExecutionException
{
throw new PluginExecutionException( "You must override execute() if you implement the new paradigm" );
}
/**
* @todo remove - harcoding.
*/
public static String getDefaultPluginArtifactId( String id )
{
return "maven-" + id + "-plugin";
}
/**
* @todo remove - harcoding.
*/
public static String getDefaultPluginGroupId()
{
return "org.apache.maven.plugins";
}
}

View File

@ -0,0 +1,40 @@
package org.apache.maven.plugin;
/*
* 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.
*/
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public abstract class FailureResponse
{
protected Object source;
protected FailureResponse( Object source )
{
this.source = source;
}
public abstract String shortMessage();
public abstract String longMessage();
public Object getSource()
{
return source;
}
}

View File

@ -0,0 +1,38 @@
package org.apache.maven.plugin;
/*
* 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.
*/
import org.apache.maven.monitor.logging.Log;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public interface Plugin
{
String ROLE = Plugin.class.getName();
void execute()
throws PluginExecutionException;
/** @deprecated */
void execute( PluginExecutionRequest request )
throws PluginExecutionException;
// TODO: not sure about this here, and may want a getLog on here as well/instead
void setLog( Log log );
}

View File

@ -0,0 +1,52 @@
package org.apache.maven.plugin;
/*
* 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.
*/
/**
* A failure or exception occuring during the execution of a plugin.
*
* @author Brett Porter
* @version $Id$
*/
public class PluginExecutionException extends Exception
{
private Object source;
private String longMessage;
public PluginExecutionException( Object source, String shortMessage, String longMessage )
{
super( shortMessage );
this.source = source;
this.longMessage = longMessage;
}
public PluginExecutionException( String message, Exception cause )
{
super( message, cause );
}
public PluginExecutionException( String message )
{
super( message );
}
public String getLongMessage()
{
return longMessage;
}
}

View File

@ -0,0 +1,49 @@
package org.apache.maven.plugin;
/*
* 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.
*/
import java.util.Map;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
* @deprecated
*/
public class PluginExecutionRequest
{
private Map parameters;
public PluginExecutionRequest( Map parameters )
{
this.parameters = parameters;
}
public Map getParameters()
{
return parameters;
}
public void setParameters( Map parameters )
{
this.parameters = parameters;
}
public Object getParameter( String key )
{
return parameters.get( key );
}
}

View File

@ -0,0 +1,55 @@
package org.apache.maven.plugin;
/*
* 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.
*/
/**
* @deprecated
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class PluginExecutionResponse
{
private FailureResponse failureResponse = null;
public boolean isExecutionFailure()
{
return failureResponse != null;
}
public void setExecutionFailure( FailureResponse failureResponse )
{
this.failureResponse = failureResponse;
}
/**
* @deprecated please use {@link #setExecutionFailure(FailureResponse)} as there is no need to set executionFailure to false if there is a failure response
*/
public void setExecutionFailure( boolean executionFailure, FailureResponse failureResponse )
{
if ( executionFailure == false )
{
throw new IllegalArgumentException( "executionFailure should be true when passing a failureResponse" );
}
setExecutionFailure( failureResponse );
}
public FailureResponse getFailureResponse()
{
return failureResponse;
}
}

22
maven-plugin-descriptor/pom.xml Executable file
View File

@ -0,0 +1,22 @@
<project>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>maven</artifactId>
<version>2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-plugin-descriptor</artifactId>
<name>Maven Plugin Descriptor Model</name>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>plexus</groupId>
<artifactId>plexus-container-default</artifactId>
<version>1.0-alpha-2</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,60 @@
package org.apache.maven.plugin.descriptor;
/*
* LICENSE
*/
/**
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @version $Id$
*/
public class Dependency
{
private String groupId;
private String artifactId;
private String type;
private String version;
public String getGroupId()
{
return groupId;
}
public void setGroupId( String groupId )
{
this.groupId = groupId;
}
public String getArtifactId()
{
return artifactId;
}
public void setArtifactId( String artifactId )
{
this.artifactId = artifactId;
}
public String getType()
{
return type;
}
public void setType( String type )
{
this.type = type;
}
public String getVersion()
{
return version;
}
public void setVersion( String version )
{
this.version = version;
}
}

View File

@ -0,0 +1,229 @@
package org.apache.maven.plugin.descriptor;
/*
* 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.
*/
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class MojoDescriptor
implements Cloneable
{
public static final String SINGLE_PASS_EXEC_STRATEGY = "once-per-session";
public static final String MULTI_PASS_EXEC_STRATEGY = "always";
private static final String DEFAULT_LANGUAGE = "java";
private String implementation;
private String description;
private String id;
private List parameters;
private Map parameterMap;
private String instantiationStrategy = "per-lookup";
private String executionStrategy = SINGLE_PASS_EXEC_STRATEGY;
private String goal;
private String phase;
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
private List prereqs;
private String requiresDependencyResolution = null;
private boolean requiresProject = true;
private String language = DEFAULT_LANGUAGE;
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
public String getRole()
{
return "org.apache.maven.plugin.Plugin";
}
public String getImplementation()
{
return implementation;
}
public void setImplementation( String implementation )
{
this.implementation = implementation;
}
public String getDescription()
{
return description;
}
public void setDescription( String description )
{
this.description = description;
}
public String getInstantiationStrategy()
{
return instantiationStrategy;
}
public void setInstantiationStrategy( String instantiationStrategy )
{
this.instantiationStrategy = instantiationStrategy;
}
public String getLanguage()
{
return language;
}
public void setLanguage( String language )
{
this.language = language;
}
public String getId()
{
return id;
}
public void setId( String id )
{
this.id = id;
}
public List getParameters()
{
return parameters;
}
public void setParameters( List parameters )
{
this.parameters = parameters;
}
public Map getParameterMap()
{
if ( parameterMap == null )
{
parameterMap = new HashMap();
for ( Iterator iterator = parameters.iterator(); iterator.hasNext(); )
{
Parameter pd = (Parameter) iterator.next();
parameterMap.put( pd.getName(), pd );
}
}
return parameterMap;
}
// ----------------------------------------------------------------------
// Dependency requirement
// ----------------------------------------------------------------------
public void setRequiresDependencyResolution( String requiresDependencyResolution )
{
this.requiresDependencyResolution = requiresDependencyResolution;
}
public String getRequiresDependencyResolution()
{
return requiresDependencyResolution;
}
// ----------------------------------------------------------------------
// Project requirement
// ----------------------------------------------------------------------
public void setRequiresProject( boolean requiresProject )
{
this.requiresProject = requiresProject;
}
public boolean requiresProject()
{
return requiresProject;
}
// ----------------------------------------------------------------------
// Prereqs
// ----------------------------------------------------------------------
public List getPrereqs()
{
return prereqs;
}
public void setPrereqs( List prereqs )
{
this.prereqs = prereqs;
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
public String getPhase()
{
return phase;
}
public void setPhase( String phase )
{
this.phase = phase;
}
public String getGoal()
{
return goal;
}
public void setGoal( String goal )
{
this.goal = goal;
}
public boolean alwaysExecute()
{
return MULTI_PASS_EXEC_STRATEGY.equals( executionStrategy );
}
public String getExecutionStrategy()
{
return executionStrategy;
}
public void setExecutionStrategy( String executionStrategy )
{
this.executionStrategy = executionStrategy;
}
}

View File

@ -0,0 +1,112 @@
package org.apache.maven.plugin.descriptor;
/*
* 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.
*/
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class Parameter
{
private String name;
private String type;
private boolean required;
private String validator;
private String description;
private String expression;
private String defaultValue;
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
public String getName()
{
return name;
}
public void setName( String name )
{
this.name = name;
}
public String getType()
{
return type;
}
public void setType( String type )
{
this.type = type;
}
public boolean isRequired()
{
return required;
}
public void setRequired( boolean required )
{
this.required = required;
}
public String getValidator()
{
return validator;
}
public void setValidator( String validator )
{
this.validator = validator;
}
public String getDescription()
{
return description;
}
public void setDescription( String description )
{
this.description = description;
}
public String getExpression()
{
return expression;
}
public void setExpression( String expression )
{
this.expression = expression;
}
public String getDefaultValue()
{
return defaultValue;
}
public void setDefaultValue( String defaultValue )
{
this.defaultValue = defaultValue;
}
}

View File

@ -0,0 +1,90 @@
package org.apache.maven.plugin.descriptor;
/*
* 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.
*/
import java.util.LinkedList;
import java.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class PluginDescriptor
{
private List mojos;
private String groupId;
private String artifactId;
private List dependencies;
private boolean isolatedRealm;
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
public List getMojos()
{
return mojos;
}
public void setMojos( List mojos )
{
this.mojos = new LinkedList( mojos );
}
public String getGroupId()
{
return groupId;
}
public void setGroupId( String groupId )
{
this.groupId = groupId;
}
public String getArtifactId()
{
return artifactId;
}
public void setArtifactId( String artifactId )
{
this.artifactId = artifactId;
}
// ----------------------------------------------------------------------
// Dependencies
// ----------------------------------------------------------------------
public List getDependencies()
{
return dependencies;
}
public void setDependencies( List dependencies )
{
this.dependencies = new LinkedList( dependencies );
}
public boolean isIsolatedRealm()
{
return isolatedRealm;
}
}

View File

@ -0,0 +1,186 @@
package org.apache.maven.plugin.descriptor;
import org.apache.maven.plugin.AbstractPlugin;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class PluginDescriptorBuilder
{
public PluginDescriptor build( Reader reader )
throws PlexusConfigurationException
{
PlexusConfiguration c = buildConfiguration( reader );
PluginDescriptor pluginDescriptor = new PluginDescriptor();
pluginDescriptor.setGroupId( AbstractPlugin.getDefaultPluginGroupId() );
pluginDescriptor.setArtifactId( AbstractPlugin.getDefaultPluginArtifactId( c.getChild( "id" ).getValue() ) );
// ----------------------------------------------------------------------
// Components
// ----------------------------------------------------------------------
PlexusConfiguration[] mojoConfigurations = c.getChild( "mojos" ).getChildren( "mojo" );
List mojos = new ArrayList();
for ( int i = 0; i < mojoConfigurations.length; i++ )
{
PlexusConfiguration component = mojoConfigurations[i];
mojos.add( buildComponentDescriptor( component ) );
}
pluginDescriptor.setMojos( mojos );
// ----------------------------------------------------------------------
// Dependencies
// ----------------------------------------------------------------------
PlexusConfiguration[] dependencyConfigurations = c.getChild( "dependencies" ).getChildren( "dependency" );
List dependencies = new ArrayList();
for ( int i = 0; i < dependencyConfigurations.length; i++ )
{
PlexusConfiguration d = dependencyConfigurations[i];
Dependency cd = new Dependency();
cd.setArtifactId( d.getChild( "artifactId" ).getValue() );
cd.setGroupId( d.getChild( "groupId" ).getValue() );
cd.setType( d.getChild( "type" ).getValue() );
cd.setVersion( d.getChild( "version" ).getValue() );
dependencies.add( cd );
}
pluginDescriptor.setDependencies( dependencies );
return pluginDescriptor;
}
public MojoDescriptor buildComponentDescriptor( PlexusConfiguration c )
throws PlexusConfigurationException
{
MojoDescriptor mojo = new MojoDescriptor();
mojo.setId( c.getChild( "id" ).getValue() );
mojo.setImplementation( c.getChild( "implementation" ).getValue() );
PlexusConfiguration langConfig = c.getChild( "language" );
if ( langConfig != null )
{
mojo.setLanguage( langConfig.getValue() );
}
String phase = c.getChild( "phase" ).getValue();
if ( phase != null )
{
mojo.setPhase( phase );
}
mojo.setInstantiationStrategy( c.getChild( "instantiationStrategy" ).getValue() );
mojo.setDescription( c.getChild( "description" ).getValue() );
String dependencyResolution = c.getChild( "requiresDependencyResolution" ).getValue();
if ( dependencyResolution != null )
{
mojo.setRequiresDependencyResolution( dependencyResolution );
}
// ----------------------------------------------------------------------
// Parameters
// ----------------------------------------------------------------------
PlexusConfiguration[] parameterConfigurations = c.getChild( "parameters" ).getChildren( "parameter" );
List parameters = new ArrayList();
for ( int i = 0; i < parameterConfigurations.length; i++ )
{
PlexusConfiguration d = parameterConfigurations[i];
Parameter parameter = new Parameter();
parameter.setName( d.getChild( "name" ).getValue() );
parameter.setType( d.getChild( "type" ).getValue() );
String s = d.getChild( "required" ).getValue();
if ( s != null )
{
parameter.setRequired( s.equals( "true" ) ? true : false );
}
parameter.setValidator( d.getChild( "validator" ).getValue() );
parameter.setDescription( d.getChild( "description" ).getValue() );
parameter.setExpression( d.getChild( "expression" ).getValue() );
parameter.setDefaultValue( d.getChild( "default" ).getValue() );
parameters.add( parameter );
}
mojo.setParameters( parameters );
// ----------------------------------------------------------------------
// Prereqs
// ----------------------------------------------------------------------
PlexusConfiguration[] prereqConfigurations = c.getChild( "prereqs" ).getChildren( "prereq" );
List prereqs = new ArrayList();
for ( int i = 0; i < prereqConfigurations.length; i++ )
{
PlexusConfiguration d = prereqConfigurations[i];
prereqs.add( d.getValue() );
}
mojo.setPrereqs( prereqs );
return mojo;
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
// TODO: catches Exception
public PlexusConfiguration buildConfiguration( Reader configuration )
throws PlexusConfigurationException
{
try
{
return new XmlPlexusConfiguration( Xpp3DomBuilder.build( configuration ) );
}
catch ( Exception e )
{
throw new PlexusConfigurationException( "Error creating configuration", e );
}
}
}