mirror of https://github.com/apache/maven.git
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
This commit is contained in:
parent
aaaed9cf00
commit
2732a8e83c
|
@ -1,63 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<artifactId>maven-script</artifactId>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>maven-script-ant</artifactId>
|
||||
<name>Maven Ant Mojo Support</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-project</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-descriptor</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ant</groupId>
|
||||
<artifactId>ant</artifactId>
|
||||
<version>1.6.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-ant-factory</artifactId>
|
||||
<version>1.0-alpha-4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-container-default</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-archiver</artifactId>
|
||||
<version>1.0-alpha-8</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -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 ) );
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<component-set>
|
||||
<components>
|
||||
<component>
|
||||
<role>org.codehaus.plexus.component.factory.ComponentFactory</role>
|
||||
<implementation>org.apache.maven.script.ant.AntMojoComponentFactory</implementation>
|
||||
<role-hint>ant-mojo</role-hint>
|
||||
</component>
|
||||
</components>
|
||||
</component-set>
|
|
@ -1,44 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<artifactId>maven-script</artifactId>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>maven-script-beanshell</artifactId>
|
||||
<name>Maven Beanshell Mojo Support</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-bsh-factory</artifactId>
|
||||
<version>1.0-alpha-8</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -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 <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @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;
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<artifactId>maven</artifactId>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>maven-script</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>Maven Script Support Root</name>
|
||||
<modules>
|
||||
<module>maven-script-ant</module>
|
||||
<module>maven-script-beanshell</module>
|
||||
</modules>
|
||||
</project>
|
Loading…
Reference in New Issue