diff --git a/maven-plugin/.cvsignore b/maven-plugin/.cvsignore new file mode 100644 index 0000000000..f27d66ad10 --- /dev/null +++ b/maven-plugin/.cvsignore @@ -0,0 +1,6 @@ +*~ +*.log +target +*.ipr +*.iws +*.iml diff --git a/maven-plugin/pom.xml b/maven-plugin/pom.xml new file mode 100644 index 0000000000..0dec2c9672 --- /dev/null +++ b/maven-plugin/pom.xml @@ -0,0 +1,26 @@ + + + + 4.0.0 + + maven + maven-component + 2.0-SNAPSHOT + + maven + maven-plugin + Maven Plugin + 2.0-SNAPSHOT + + + qdox + qdox + 1.2 + + + modello + modello + 1.0-SNAPSHOT + + + diff --git a/maven-plugin/src/.cvsignore b/maven-plugin/src/.cvsignore new file mode 100644 index 0000000000..0366c1565c --- /dev/null +++ b/maven-plugin/src/.cvsignore @@ -0,0 +1,4 @@ +maven.log +target +.classpath +.project diff --git a/maven-plugin/src/main/java/org/apache/maven/plugin/AbstractPlugin.java b/maven-plugin/src/main/java/org/apache/maven/plugin/AbstractPlugin.java new file mode 100644 index 0000000000..e78cfa370e --- /dev/null +++ b/maven-plugin/src/main/java/org/apache/maven/plugin/AbstractPlugin.java @@ -0,0 +1,22 @@ +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. + */ + +public abstract class AbstractPlugin + implements Plugin +{ +} diff --git a/maven-plugin/src/main/java/org/apache/maven/plugin/BeanPluginAdapter.java b/maven-plugin/src/main/java/org/apache/maven/plugin/BeanPluginAdapter.java new file mode 100644 index 0000000000..e022fb3a5e --- /dev/null +++ b/maven-plugin/src/main/java/org/apache/maven/plugin/BeanPluginAdapter.java @@ -0,0 +1,69 @@ +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; +import java.util.HashMap; + +/** + * Adapt a maven2 plugin for use as a bean with setters that can be used + * within Jelly and Ant. + * + * @author Jason van Zyl + * @version $Id$ + */ +public class BeanPluginAdapter +{ + private Map parameters; + + private Plugin plugin; + + public BeanPluginAdapter( Plugin plugin ) + { + this.plugin = plugin; + + parameters = new HashMap(); + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + public void execute() + throws Exception + { + PluginExecutionRequest request = new PluginExecutionRequest( parameters ); + + PluginExecutionResponse response = new PluginExecutionResponse(); + + plugin.execute( request, response ); + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + protected void addParameter( String key, Object value ) + { + parameters.put( key, value ); + } + + protected Plugin getPlugin() + { + return plugin; + } +} diff --git a/maven-plugin/src/main/java/org/apache/maven/plugin/FailureResponse.java b/maven-plugin/src/main/java/org/apache/maven/plugin/FailureResponse.java new file mode 100644 index 0000000000..a400918307 --- /dev/null +++ b/maven-plugin/src/main/java/org/apache/maven/plugin/FailureResponse.java @@ -0,0 +1,35 @@ +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 Jason van Zyl + * @version $Id$ + */ +public abstract class FailureResponse +{ + protected Object source; + + protected FailureResponse( Object source ) + { + this.source = source; + } + + public abstract String shortMessage(); + + public abstract String longMessage(); +} diff --git a/maven-plugin/src/main/java/org/apache/maven/plugin/Plugin.java b/maven-plugin/src/main/java/org/apache/maven/plugin/Plugin.java new file mode 100644 index 0000000000..3d3bcb1477 --- /dev/null +++ b/maven-plugin/src/main/java/org/apache/maven/plugin/Plugin.java @@ -0,0 +1,29 @@ +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 Jason van Zyl + * @version $Id$ + */ +public interface Plugin +{ + String ROLE = Plugin.class.getName(); + + void execute( PluginExecutionRequest request, PluginExecutionResponse response ) + throws Exception; +} diff --git a/maven-plugin/src/main/java/org/apache/maven/plugin/PluginExecutionRequest.java b/maven-plugin/src/main/java/org/apache/maven/plugin/PluginExecutionRequest.java new file mode 100644 index 0000000000..bdc0442b63 --- /dev/null +++ b/maven-plugin/src/main/java/org/apache/maven/plugin/PluginExecutionRequest.java @@ -0,0 +1,63 @@ +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.HashMap; +import java.util.Map; + +/** + * @author Jason van Zyl + * @version $Id$ + */ +public class PluginExecutionRequest +{ + private Map parameters; + + private Map context; + + public PluginExecutionRequest( Map parameters ) + { + context = new HashMap(); + + 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 ); + } + + public void addContextValue( Object key, Object value ) + { + context.put( key, value ); + } + + public Object getContextValue( String key ) + { + return context.get( key ); + } +} diff --git a/maven-plugin/src/main/java/org/apache/maven/plugin/PluginExecutionResponse.java b/maven-plugin/src/main/java/org/apache/maven/plugin/PluginExecutionResponse.java new file mode 100644 index 0000000000..06a4be036a --- /dev/null +++ b/maven-plugin/src/main/java/org/apache/maven/plugin/PluginExecutionResponse.java @@ -0,0 +1,45 @@ +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 Jason van Zyl + * @version $Id$ + */ +public class PluginExecutionResponse +{ + private boolean executionFailure; + + private FailureResponse failureResponse; + + public boolean isExecutionFailure() + { + return executionFailure; + } + + public void setExecutionFailure( boolean executionFailure, FailureResponse failureResponse ) + { + this.executionFailure = executionFailure; + + this.failureResponse = failureResponse; + } + + public FailureResponse getFailureResponse() + { + return failureResponse; + } +} diff --git a/maven-plugin/src/main/java/org/apache/maven/plugin/PluginTestCase.java b/maven-plugin/src/main/java/org/apache/maven/plugin/PluginTestCase.java new file mode 100644 index 0000000000..2666c72e5b --- /dev/null +++ b/maven-plugin/src/main/java/org/apache/maven/plugin/PluginTestCase.java @@ -0,0 +1,101 @@ +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 junit.framework.TestCase; + +import java.util.Map; + +/** + * @author Jason van Zyl + * @version $Id$ + */ +public abstract class PluginTestCase + extends TestCase +{ + protected Plugin plugin; + + protected PluginExecutionRequest request; + + protected PluginExecutionResponse response; + + protected String basedir; + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + protected PluginTestCase( String s ) + { + super( s ); + } + + protected void setUp() + throws Exception + { + basedir = System.getProperty( "basedir" ); + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + protected void setupPlugin() + throws Exception + { + String mojoClassName = getClass().getName(); + + mojoClassName = mojoClassName.substring( 0, mojoClassName.length() - 4 ); + + try + { + Class mojoClass = Thread.currentThread().getContextClassLoader().loadClass( mojoClassName ); + + plugin = (Plugin) mojoClass.newInstance(); + } + catch ( Exception e ) + { + throw new Exception( + "Cannot find " + mojoClassName + "! Make sure your test case is named in the form ${mojoClassName}Test " + + "or override the setupPlugin() method to instantiate the mojo yourself." ); + } + } + + protected abstract Map getTestParameters() + throws Exception; + + protected abstract void validatePluginExecution() + throws Exception; + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + public void testPlugin() + throws Exception + { + setupPlugin(); + + request = new PluginExecutionRequest( getTestParameters() ); + + response = new PluginExecutionResponse(); + + plugin.execute( request, response ); + + validatePluginExecution(); + } +} diff --git a/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/Dependency.java b/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/Dependency.java new file mode 100644 index 0000000000..4d78e55e16 --- /dev/null +++ b/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/Dependency.java @@ -0,0 +1,60 @@ +package org.apache.maven.plugin.descriptor; + +/* + * LICENSE + */ + +/** + * @author Trygve Laugstøl + * @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; + } +} diff --git a/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java b/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java new file mode 100644 index 0000000000..393faeec1e --- /dev/null +++ b/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java @@ -0,0 +1,215 @@ +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 org.apache.maven.plugin.descriptor.Parameter; + +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 String implementation; + + private String description; + + private String id; + + private List parameters; + + private Map parameterMap; + + private String instantiationStrategy = "singleton"; + + private String executionStrategy = SINGLE_PASS_EXEC_STRATEGY; + + private String goal; + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + private List prereqs; + + private boolean requiresDependencyResolution = false; + + private boolean requiresProject = true; + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + 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 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( boolean requiresDependencyResolution ) + { + this.requiresDependencyResolution = requiresDependencyResolution; + } + + public boolean requiresDependencyResolution() + { + 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 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; + } + + public MojoDescriptor copy() + { + try + { + return (MojoDescriptor) this.clone(); + } + catch ( Exception e ) + { + } + + return null; + } +} diff --git a/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/Parameter.java b/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/Parameter.java new file mode 100644 index 0000000000..d8aeeb6310 --- /dev/null +++ b/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/Parameter.java @@ -0,0 +1,100 @@ +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 Jason van Zyl + * @version $Id$ + */ +public class Parameter +{ + private String name; + + private String type; + + private boolean required; + + private String validator; + + private String description; + + private String expression; + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + 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; + } +} diff --git a/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java b/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java new file mode 100644 index 0000000000..b3850f47a0 --- /dev/null +++ b/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java @@ -0,0 +1,67 @@ +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.List; + +/** + * @author Jason van Zyl + * @version $Id$ + */ +public class PluginDescriptor +{ + private List mojos; + + private String id; + + private List dependencies; + + private boolean isolatedRealm; + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + public List getMojos() + { + return mojos; + } + + public String getId() + { + return id; + } + + public void setId( String id ) + { + this.id = id; + } + + // ---------------------------------------------------------------------- + // Dependencies + // ---------------------------------------------------------------------- + + public List getDependencies() + { + return dependencies; + } + + public boolean isIsolatedRealm() + { + return isolatedRealm; + } +} diff --git a/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java b/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java new file mode 100644 index 0000000000..ef26fca9df --- /dev/null +++ b/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java @@ -0,0 +1,60 @@ +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 com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.alias.DefaultClassMapper; +import com.thoughtworks.xstream.alias.DefaultNameMapper; +import com.thoughtworks.xstream.objecttree.reflection.JavaReflectionObjectFactory; +import com.thoughtworks.xstream.xml.xpp3.Xpp3DomBuilder; +import com.thoughtworks.xstream.xml.xpp3.Xpp3DomXMLReader; +import com.thoughtworks.xstream.xml.xpp3.Xpp3DomXMLReaderDriver; + +import java.io.Reader; + +/** + * @author Jason van Zyl + * @version $Id$ + */ +public class PluginDescriptorBuilder +{ + private XStream xstream; + + public PluginDescriptorBuilder() + { + xstream = new XStream( new JavaReflectionObjectFactory(), + new DefaultClassMapper( new DefaultNameMapper() ), + new Xpp3DomXMLReaderDriver(), + "implementation" ); + + xstream.alias( "plugin", PluginDescriptor.class ); + + xstream.alias( "mojo", MojoDescriptor.class ); + + xstream.alias( "prereq", String.class ); + + xstream.alias( "parameter", Parameter.class ); + + xstream.alias( "dependency", Dependency.class ); + } + + public PluginDescriptor build( Reader reader ) + throws Exception + { + return (PluginDescriptor) xstream.fromXML( new Xpp3DomXMLReader( Xpp3DomBuilder.build( reader ) ) ); + } +} diff --git a/maven-plugin/src/test/java/org/apache/maven/plugin/Bean.java b/maven-plugin/src/test/java/org/apache/maven/plugin/Bean.java new file mode 100644 index 0000000000..63b1ecf53c --- /dev/null +++ b/maven-plugin/src/test/java/org/apache/maven/plugin/Bean.java @@ -0,0 +1,50 @@ +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 Jason van Zyl + * @version $Id$ + */ +public class Bean + extends BeanPluginAdapter +{ + public Bean() + { + super( new TestPlugin() ); + } + + public void setName( String name ) + { + addParameter( "name", name ); + } + + public void setArtifactId( String artifactId ) + { + addParameter( "artifactId", artifactId ); + } + + public void setFoo( String foo ) + { + addParameter( "foo", foo ); + } + + public boolean hasExecuted() + { + return ((TestPlugin)getPlugin()).hasExecuted(); + } +} diff --git a/maven-plugin/src/test/java/org/apache/maven/plugin/BeanTest.java b/maven-plugin/src/test/java/org/apache/maven/plugin/BeanTest.java new file mode 100644 index 0000000000..ad39ca3013 --- /dev/null +++ b/maven-plugin/src/test/java/org/apache/maven/plugin/BeanTest.java @@ -0,0 +1,43 @@ +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 junit.framework.TestCase; + +/** + * @author Jason van Zyl + * @version $Id$ + */ +public class BeanTest + extends TestCase +{ + public void testBean() + throws Exception + { + Bean bean = new Bean(); + + bean.setName( "jason" ); + + bean.setArtifactId( "artifactId" ); + + bean.setFoo( "bar" ); + + bean.execute(); + + assertTrue( bean.hasExecuted() ); + } +} diff --git a/maven-plugin/src/test/java/org/apache/maven/plugin/TestPlugin.java b/maven-plugin/src/test/java/org/apache/maven/plugin/TestPlugin.java new file mode 100644 index 0000000000..0b01fd8c44 --- /dev/null +++ b/maven-plugin/src/test/java/org/apache/maven/plugin/TestPlugin.java @@ -0,0 +1,68 @@ +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 Jason van Zyl + * + * @version $Id$ + */ +public class TestPlugin + implements Plugin +{ + protected boolean executed; + + protected String name; + + protected String artifactId; + + protected String foo; + + public boolean hasExecuted() + { + return executed; + } + + public String getName() + { + return name; + } + + public String getArtifactId() + { + return artifactId; + } + + public String getFoo() + { + return foo; + } + + public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) + throws Exception + { + name = (String) request.getParameter( "name" ); + + artifactId = (String) request.getParameter( "artifactId" ); + + foo = (String) request.getParameter( "foo" ); + + executed = true; + } +} diff --git a/maven-plugin/src/test/java/org/apache/maven/plugin/TestPluginTest.java b/maven-plugin/src/test/java/org/apache/maven/plugin/TestPluginTest.java new file mode 100644 index 0000000000..495cb9de19 --- /dev/null +++ b/maven-plugin/src/test/java/org/apache/maven/plugin/TestPluginTest.java @@ -0,0 +1,58 @@ +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 junit.framework.TestCase; + +import java.util.Map; +import java.util.HashMap; + +/** + * @author Jason van Zyl + * @version $Id$ + */ +public class TestPluginTest + extends TestCase +{ + public void testIntegratedPluginExecution() + throws Exception + { + TestPlugin plugin = new TestPlugin(); + + Map parameters = new HashMap(); + + parameters.put( "name", "Maven" ); + + parameters.put( "artifactId", "maven-core" ); + + parameters.put( "foo", "bar" ); + + PluginExecutionRequest request = new PluginExecutionRequest( parameters ); + + PluginExecutionResponse response = new PluginExecutionResponse(); + + plugin.execute( request, response ); + + assertTrue( plugin.hasExecuted() ); + + assertEquals( "Maven", plugin.getName() ); + + assertEquals( "maven-core", plugin.getArtifactId() ); + + assertEquals( "bar", plugin.getFoo() ); + } +}