From 2732a8e83c7c04c3af0ce028b2fcb6d78395b0de Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Tue, 4 Sep 2007 01:12:55 +0000 Subject: [PATCH] o moving the scripting stuff out of the core git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@572473 13f79535-47bb-0310-9956-ffa450edef68 --- maven-script/maven-script-ant/pom.xml | 63 ------ .../script/ant/AntMojoComponentFactory.java | 38 ---- .../maven/script/ant/AntMojoWrapper.java | 211 ------------------ .../resources/META-INF/plexus/components.xml | 28 --- maven-script/maven-script-beanshell/pom.xml | 44 ---- .../beanshell/BeanshellMojoAdapter.java | 73 ------ maven-script/pom.xml | 37 --- 7 files changed, 494 deletions(-) delete mode 100644 maven-script/maven-script-ant/pom.xml delete mode 100644 maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntMojoComponentFactory.java delete mode 100644 maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntMojoWrapper.java delete mode 100644 maven-script/maven-script-ant/src/main/resources/META-INF/plexus/components.xml delete mode 100644 maven-script/maven-script-beanshell/pom.xml delete mode 100644 maven-script/maven-script-beanshell/src/main/java/org/apache/maven/script/beanshell/BeanshellMojoAdapter.java delete mode 100644 maven-script/pom.xml diff --git a/maven-script/maven-script-ant/pom.xml b/maven-script/maven-script-ant/pom.xml deleted file mode 100644 index b4acd99346..0000000000 --- a/maven-script/maven-script-ant/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - maven-script - org.apache.maven - 2.1-SNAPSHOT - - 4.0.0 - maven-script-ant - Maven Ant Mojo Support - - - org.apache.maven - maven-project - 2.1-SNAPSHOT - - - org.apache.maven - maven-plugin-descriptor - 2.1-SNAPSHOT - - - ant - ant - 1.6.2 - - - org.codehaus.plexus - plexus-ant-factory - 1.0-alpha-4 - - - org.codehaus.plexus - plexus-container-default - - - org.codehaus.plexus - plexus-archiver - 1.0-alpha-8 - - - diff --git a/maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntMojoComponentFactory.java b/maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntMojoComponentFactory.java deleted file mode 100644 index 3269f7e0b3..0000000000 --- a/maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntMojoComponentFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.apache.maven.script.ant; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.classworlds.realm.ClassRealm; -import org.codehaus.plexus.component.factory.ComponentInstantiationException; -import org.codehaus.plexus.component.factory.ant.AntComponentFactory; -import org.codehaus.plexus.component.factory.ant.AntScriptInvoker; -import org.codehaus.plexus.component.repository.ComponentDescriptor; - -public class AntMojoComponentFactory - extends AntComponentFactory -{ - public Object newInstance( ComponentDescriptor descriptor, ClassRealm realm, PlexusContainer container ) - throws ComponentInstantiationException - { - return new AntMojoWrapper( (AntScriptInvoker) super.newInstance( descriptor, realm, container ) ); - } - -} diff --git a/maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntMojoWrapper.java b/maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntMojoWrapper.java deleted file mode 100644 index 8d2bf14b80..0000000000 --- a/maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntMojoWrapper.java +++ /dev/null @@ -1,211 +0,0 @@ -package org.apache.maven.script.ant; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.DependencyResolutionRequiredException; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.ContextEnabled; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.project.MavenProject; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.types.Path; -import org.codehaus.plexus.archiver.ArchiverException; -import org.codehaus.plexus.archiver.UnArchiver; -import org.codehaus.plexus.archiver.zip.ZipUnArchiver; -import org.codehaus.plexus.component.MapOrientedComponent; -import org.codehaus.plexus.component.configurator.ComponentConfigurationException; -import org.codehaus.plexus.component.factory.ant.AntComponentExecutionException; -import org.codehaus.plexus.component.factory.ant.AntScriptInvoker; -import org.codehaus.plexus.component.repository.ComponentRequirement; -import org.codehaus.plexus.util.StringUtils; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - - -/** - * @author John Casey - * @author Jason van Zyl - */ -public class AntMojoWrapper - extends AbstractMojo - implements ContextEnabled, - MapOrientedComponent -{ - private AntScriptInvoker scriptInvoker; - - private Map pluginContext; - - private Project antProject; - - private MavenProject mavenProject; - - private PluginDescriptor pluginDescriptor; - - public AntMojoWrapper( AntScriptInvoker scriptInvoker ) - { - this.scriptInvoker = scriptInvoker; - - } - - public void execute() - throws MojoExecutionException - { - antProject = scriptInvoker.getProject(); - - mavenProject = (MavenProject) pluginContext.get( "project" ); - - pluginDescriptor = (PluginDescriptor) pluginContext.get( "pluginDescriptor" ); - - unpackFileBasedResources(); - - addClasspathReferences(); - - try - { - scriptInvoker.invoke(); - } - catch ( AntComponentExecutionException e ) - { - throw new MojoExecutionException( "Failed to execute: " + e.getMessage(), e ); - } - } - - public void setPluginContext( Map pluginContext ) - { - this.pluginContext = pluginContext; - } - - public Map getPluginContext() - { - return pluginContext; - } - - public void addComponentRequirement( ComponentRequirement requirementDescriptor, - Object requirementValue ) - throws ComponentConfigurationException - { - scriptInvoker.addComponentRequirement( requirementDescriptor, requirementValue ); - } - - public void setComponentConfiguration( Map componentConfiguration ) - throws ComponentConfigurationException - { - scriptInvoker.setComponentConfiguration( componentConfiguration ); - } - - private void unpackFileBasedResources() - throws MojoExecutionException - { - // What we need to write out any resources in the plugin to the target directory of the - // mavenProject using the Ant-based plugin: - // - // 1. Need a reference to the plugin JAR itself - // 2. Need a reference to the ${basedir} of the mavenProject - - File pluginJar = pluginDescriptor.getPluginArtifact().getFile(); - - String resourcesPath = pluginDescriptor.getArtifactId(); - - File outputDirectory = new File( mavenProject.getBuild().getDirectory() ); - - try - { - UnArchiver ua = new ZipUnArchiver( pluginJar ); - - ua.extract( resourcesPath, outputDirectory ); - } - catch ( ArchiverException e ) - { - throw new MojoExecutionException( "Error extracting resources from your Ant-based plugin.", e ); - } - } - - private void addClasspathReferences() - throws MojoExecutionException - { - try - { - // Compile classpath - Path p = new Path( antProject ); - - p.setPath( StringUtils.join( mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator ) ); - - antProject.addReference( "maven.compile.classpath", p ); - - // Runtime classpath - p = new Path( antProject ); - - p.setPath( StringUtils.join( mavenProject.getRuntimeClasspathElements().iterator(), File.pathSeparator ) ); - - antProject.addReference( "maven.runtime.classpath", p ); - - // Test classpath - p = new Path( antProject ); - - p.setPath( StringUtils.join( mavenProject.getTestClasspathElements().iterator(), File.pathSeparator ) ); - - antProject.addReference( "maven.test.classpath", p ); - - // Plugin dependency classpath - - p = getPathFromArtifacts( pluginDescriptor.getArtifacts(), antProject ); - System.out.println( "p = " + p ); - antProject.addReference( "maven.plugin.classpath", p ); - } - catch ( DependencyResolutionRequiredException e ) - { - throw new MojoExecutionException( "Error creating classpath references for Ant-based plugin scripts.", e ); - } - } - - public Path getPathFromArtifacts( Collection artifacts, - Project antProject ) - throws DependencyResolutionRequiredException - { - List list = new ArrayList( artifacts.size() ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - - File file = a.getFile(); - - if ( file == null ) - { - throw new DependencyResolutionRequiredException( a ); - } - - list.add( file.getPath() ); - } - - Path p = new Path( antProject ); - - p.setPath( StringUtils.join( list.iterator(), File.pathSeparator ) ); - - return p; - } -} diff --git a/maven-script/maven-script-ant/src/main/resources/META-INF/plexus/components.xml b/maven-script/maven-script-ant/src/main/resources/META-INF/plexus/components.xml deleted file mode 100644 index cadddea959..0000000000 --- a/maven-script/maven-script-ant/src/main/resources/META-INF/plexus/components.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - org.codehaus.plexus.component.factory.ComponentFactory - org.apache.maven.script.ant.AntMojoComponentFactory - ant-mojo - - - diff --git a/maven-script/maven-script-beanshell/pom.xml b/maven-script/maven-script-beanshell/pom.xml deleted file mode 100644 index 2d2b01561f..0000000000 --- a/maven-script/maven-script-beanshell/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - maven-script - org.apache.maven - 2.1-SNAPSHOT - - 4.0.0 - maven-script-beanshell - Maven Beanshell Mojo Support - - - org.apache.maven - maven-plugin-api - 2.1-SNAPSHOT - - - org.codehaus.plexus - plexus-bsh-factory - 1.0-alpha-8 - - - diff --git a/maven-script/maven-script-beanshell/src/main/java/org/apache/maven/script/beanshell/BeanshellMojoAdapter.java b/maven-script/maven-script-beanshell/src/main/java/org/apache/maven/script/beanshell/BeanshellMojoAdapter.java deleted file mode 100644 index 8ec8cad594..0000000000 --- a/maven-script/maven-script-beanshell/src/main/java/org/apache/maven/script/beanshell/BeanshellMojoAdapter.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.apache.maven.script.beanshell; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import bsh.EvalError; -import bsh.Interpreter; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.Mojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.codehaus.plexus.component.factory.bsh.BshComponent; - -/** - * Mojo adapter for a Beanshell Mojo. - * - * @todo should log be passed in, or rely on getLog() ? - * - * @author Brett Porter - * @version $Id$ - */ -public class BeanshellMojoAdapter - extends AbstractMojo - implements BshComponent -{ - private Mojo mojo; - - private Interpreter interpreter; - - public BeanshellMojoAdapter( Mojo mojo, Interpreter interpreter ) - { - this.mojo = mojo; - this.interpreter = interpreter; - } - - public void execute() - throws MojoExecutionException, MojoFailureException - { - try - { - interpreter.set( "logger", getLog() ); - - // TODO: set out, err to a print stream that will log at info, error respectively - } - catch ( EvalError evalError ) - { - throw new MojoExecutionException( "Unable to establish mojo", evalError ); - } - - mojo.execute(); - } - - public Interpreter getInterpreter() - { - return interpreter; - } -} diff --git a/maven-script/pom.xml b/maven-script/pom.xml deleted file mode 100644 index 54d82bff6d..0000000000 --- a/maven-script/pom.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - maven - org.apache.maven - 2.1-SNAPSHOT - - 4.0.0 - maven-script - pom - Maven Script Support Root - - maven-script-ant - maven-script-beanshell - -