maven-antrun-extended-plugin-1.42/ 0000755 0001750 0001750 00000000000 11571451163 017623 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/pom.xml 0000644 0001750 0001750 00000014563 11562556723 021161 0 ustar jamespage jamespage 4.0.0org.jvnet.maven-antrun-extended-pluginmaven-antrun-extended-pluginmaven-pluginMaven AntRun Extended Plugin1.42This extended antrun maven plugin enables users not only to run ant scripts embedded in the POM, but also to reference maven dependencies using Ant task classes. This enables the user to delegate more complex tasks to Ant such as constructing file-based installation distros.Apache License, Version 2.0http://www.apache.org/licenses/LICENSE-2.0.htmlpsterkPaul Sterkpaul.sterk@sun.comSun Microsystemshttp://www.sun.comUS PacifickohsukeKohsuke Kawaguchikohsuke.kawaguchi@sun.comhttp://weblogs.java.net/blog/kohsuke/Sun Microsystemshttp://www.sun.comUS Pacificorg.apache.mavenmaven-plugin-api${maven.version}org.apache.mavenmaven-project${maven.version}antant-launcher1.6.5runtimeantant1.6.5org.apache.mavenmaven-embedder2.0.1testorg.apache.commonscommons-io1.3.2commons-collectionscommons-collections3.2scm:svn:https://svn.java.net/svn/maven-antrun-extended-plugin~svn/tags/maven-antrun-extended-plugin-1.42scm:svn:https://svn.java.net/svn/maven-antrun-extended-plugin~svn/tags/maven-antrun-extended-plugin-1.42maven-plugin-plugin2.4maven-compiler-plugin1.51.5org.apache.maven.pluginsmaven-release-pluginhttps://svn.java.net/svn/maven-antrun-extended-plugin~svn/tagsorg.jvnet.wagon-svnwagon-svn1.12maven2-repository.java.netJava.net Repository for Mavenhttp://download.java.net/maven/2/java.netjava-net:/maven-antrun-extended-plugin~svn/trunk/www/java.netfalsejava-net:/maven2-repository~svn/trunk/repository/integration-testsmaven.test.skiptruemaven-invoker-plugintruesrc/it**/pom.xmlintegration-testintegration-testrunorg.apache.maven.pluginsmaven-surefire-plugin2.3true2.0.7
maven-antrun-extended-plugin-1.42/src/ 0000755 0001750 0001750 00000000000 11571451163 020412 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/ 0000755 0001750 0001750 00000000000 11571451163 021026 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/test4/ 0000755 0001750 0001750 00000000000 11571451163 022071 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/test4/pom.xml 0000644 0001750 0001750 00000005172 10676560207 023420 0 ustar jamespage jamespage
4.0.0org.apache.maven.plugins.antruntest41.0-SNAPSHOTTest for MANTRUN-36properties not resolved in attributesxyzmaven-antrun-plugintestEmbedded tasks:P1: ${property1}P2: ${property2}P3: ${property3}mavenProperty: ${mavenProperty}run
maven-antrun-extended-plugin-1.42/src/it/test4/build.xml 0000644 0001750 0001750 00000002030 10676560207 023712 0 ustar jamespage jamespage
P1: ${property1}P2: ${property2}P3: ${property3}
maven-antrun-extended-plugin-1.42/src/it/test2/ 0000755 0001750 0001750 00000000000 11571451163 022067 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/test2/pom.xml 0000644 0001750 0001750 00000003126 10676560207 023413 0 ustar jamespage jamespage
4.0.0org.apache.maven.plugins.antruntest21.0-SNAPSHOTTest for MANTRUN-28maven.test.classpath doesn't contain test scope dependanciesjunitjunit3.8.1testmaven-antrun-plugintest${test.classpath}run
maven-antrun-extended-plugin-1.42/src/it/test-javac/ 0000755 0001750 0001750 00000000000 11571451163 023067 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/test-javac/pom.xml 0000644 0001750 0001750 00000002453 11137413366 024411 0 ustar jamespage jamespage
4.0.0org.apache.maven.plugins.antruntest-javac1.0-SNAPSHOTMake sure Ant gets javacThis involves some classloader hackantant1.6.5org.jvnet.maven-antrun-extended-pluginmaven-antrun-extended-plugintestrun
maven-antrun-extended-plugin-1.42/src/it/test-javac/src/ 0000755 0001750 0001750 00000000000 11571451163 023656 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/test-javac/src/main/ 0000755 0001750 0001750 00000000000 11571451163 024602 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/test-javac/src/main/java/ 0000755 0001750 0001750 00000000000 11571451163 025523 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/test-javac/src/main/java/Foo.java 0000644 0001750 0001750 00000000023 11137413366 027105 0 ustar jamespage jamespage public class Foo {} maven-antrun-extended-plugin-1.42/src/it/test3/ 0000755 0001750 0001750 00000000000 11571451163 022070 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/test3/pom.xml 0000644 0001750 0001750 00000003122 10676560207 023410 0 ustar jamespage jamespage
4.0.0org.apache.maven.plugins.antruntest31.0-SNAPSHOTTest for MANTRUN-32ant tasks don't use correct environment in antrun pluginjunitjunit3.8.1testmaven-antrun-plugintestuser.home = ${user.home}run
maven-antrun-extended-plugin-1.42/src/it/test3/build.xml 0000644 0001750 0001750 00000000515 10676560207 023717 0 ustar jamespage jamespage
user.home = ${user.home}
maven-antrun-extended-plugin-1.42/src/it/test5/ 0000755 0001750 0001750 00000000000 11571451163 022072 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/test5/pom.xml 0000644 0001750 0001750 00000002675 10676560207 023426 0 ustar jamespage jamespage
4.0.0org.apache.maven.plugins.antruntest51.0-SNAPSHOTTest for MANTRUN-34StringIndexOutOfBoundsException in custom ant task referencing 'basedir'antant1.6.5maven-antrun-plugintestrun
maven-antrun-extended-plugin-1.42/src/it/test5/src/ 0000755 0001750 0001750 00000000000 11571451163 022661 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/test5/src/main/ 0000755 0001750 0001750 00000000000 11571451163 023605 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/test5/src/main/java/ 0000755 0001750 0001750 00000000000 11571451163 024526 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/test5/src/main/java/TestTask.java 0000644 0001750 0001750 00000000763 10676560207 027146 0 ustar jamespage jamespage import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
public class TestTask extends Task {
public void execute() throws BuildException {
Project p = this.getProject();
System.out.println("sourceDirectory:" + p.getProperty("project.build.sourceDirectory"));
System.out.println("project.cmdline:" + p.getProperty("project.cmdline"));
System.out.println("basedir:" + p.getProperty("basedir"));
}
}
maven-antrun-extended-plugin-1.42/src/it/test5/build.xml 0000644 0001750 0001750 00000002030 10676560207 023713 0 ustar jamespage jamespage
P1: ${property1}P2: ${property2}P3: ${property3}
maven-antrun-extended-plugin-1.42/src/it/test1/ 0000755 0001750 0001750 00000000000 11571451163 022066 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/test1/pom.xml 0000644 0001750 0001750 00000002773 10676560207 023421 0 ustar jamespage jamespage
4.0.0org.apache.maven.plugins.antruntest11.0-SNAPSHOTTest for compile and plugin classpath referencesEnsure that maven.compile.classpath and maven.plugin.classpath referencies are setorg.apache.maven.pluginsmaven-antrun-plugincompilecompiletarget/generated/src/main/javarun
maven-antrun-extended-plugin-1.42/src/it/test1/src/ 0000755 0001750 0001750 00000000000 11571451163 022655 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/test1/src/main/ 0000755 0001750 0001750 00000000000 11571451163 023601 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/test1/src/main/java/ 0000755 0001750 0001750 00000000000 11571451163 024522 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/it/test1/src/main/java/Test.java 0000644 0001750 0001750 00000000156 10676560207 026313 0 ustar jamespage jamespage public class Test {
public static void main(String args[]) {
System.out.println("done");
}
} maven-antrun-extended-plugin-1.42/src/it/test1/build.xml 0000644 0001750 0001750 00000000363 10676560207 023716 0 ustar jamespage jamespage
maven-antrun-extended-plugin-1.42/src/site/ 0000755 0001750 0001750 00000000000 11571451163 021356 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/site/apt/ 0000755 0001750 0001750 00000000000 11571451163 022142 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/site/apt/usage.apt 0000644 0001750 0001750 00000002107 10737301112 023743 0 ustar jamespage jamespage ----
Usage
----
----
----
Usage
The following POM snippet shows how to invoke this plugin.
------
...
...
org.jvnet.maven-antrun-extended-pluginmaven-antrun-extended-plugingenerate-sourcesrun
------
The example above illustrates how to bind an ant script to a
lifecycle phase. You can add a script to each lifecycle phase,
by duplicating the <<<\>>> section and specifying
a new phase.
maven-antrun-extended-plugin-1.42/src/site/apt/index.apt 0000644 0001750 0001750 00000002567 10737301112 023760 0 ustar jamespage jamespage -----
Introduction
-----
-----
-----
Introduction
{{{http://maven.apache.org/plugins/maven-antrun-plugin/}Maven antrun plugin}} allows you to embed
Ant build script in a Maven process, but unfortunately the build script doesn't have much access
to the surrounding Maven environment, which limits the use.
This plugin enhances the maven antrun plugin by defining a series of Ant tasks that provide access
to the surrounding Maven environment. This allows you to use Ant for accessing dependencies,
performing a complex filtering of dependencies, attach files as artifacts, and much more.
A typical usage of this plugin includes the following:
* Create an assembly and attach it. Doing it in Ant is often so much easier and hassle-free than
using {{{http://maven.apache.org/plugins/maven-assembly-plugin/}maven assembly plugin}}.
* Invoke code/resource generators
[]
* How is this different from Maven ant tasks
{{{http://maven.apache.org/ant-tasks.html}Maven ant tasks}} is a series of Ant tasks
designed for your Ant based project to utilize some of Maven's capability.
While you can use them from maven antrun plugin, they are not designed together so the
Maven ant tasks don't know anything about the outer-most Maven environment.
Features
* Retrieve dependencies
* Work with dependency graphs by performing arithemetic operations
[]
maven-antrun-extended-plugin-1.42/src/site/site.xml 0000644 0001750 0001750 00000002630 10714414535 023045 0 ustar jamespage jamespage
org.jvnet.maven-javanet-skinmaven-javanet-skin1.0
${reports}
maven-antrun-extended-plugin-1.42/src/test/ 0000755 0001750 0001750 00000000000 11571451161 021367 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/test/java/ 0000755 0001750 0001750 00000000000 11571451161 022310 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/test/java/org/ 0000755 0001750 0001750 00000000000 11571451161 023077 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/test/java/org/jvnet/ 0000755 0001750 0001750 00000000000 11571451161 024225 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/test/java/org/jvnet/maven/ 0000755 0001750 0001750 00000000000 11571451161 025333 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/test/java/org/jvnet/maven/plugin/ 0000755 0001750 0001750 00000000000 11571451161 026631 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/test/java/org/jvnet/maven/plugin/antrun/ 0000755 0001750 0001750 00000000000 11571451161 030140 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/test/java/org/jvnet/maven/plugin/antrun/AntRunMojoTest.java 0000644 0001750 0001750 00000014661 10724070403 033702 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
/*
* Copyright 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.
*/
import java.io.File;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Properties;
import org.apache.maven.cli.ConsoleDownloadMonitor;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
import org.apache.maven.embedder.PlexusLoggerAdapter;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.monitor.event.DefaultEventMonitor;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.StringOutputStream;
/**
* Class to test AntRun plugin
*
* @author Vincent Siveton
* @version $Id: AntRunMojoTest.java 511210 2007-02-24 04:52:20Z brett $
*/
public class AntRunMojoTest
extends PlexusTestCase
{
/**
* @see junit.framework.TestCase#setUp()
*/
protected void setUp()
throws Exception
{
// required for mojo lookups to work
super.setUp();
}
/**
* @see junit.framework.TestCase#tearDown()
*/
protected void tearDown()
throws Exception
{
// nop
}
/**
* Method to test Default Antrun generation
*
* @throws Exception
*/
public void testDefaultProject()
throws Exception
{
try {
String result = invokeMaven( "antrun-default-test", new Properties() );
assertTrue( result.indexOf( "[echo] Hello World!" ) != -1 );
} catch (LifecycleExecutionException ex) {
String message = ex.getMessage();
if (message.contains("'org.jvnet.maven-antrun-extended-plugin:maven-antrun-extended-plugin' not found in repository")) {
System.out.println("maven-antrun-extended-plugin missing from local repository. Run mvn install and retest");
}
else {
throw ex;
}
}
}
/**
* Method to test tasks attributes
*
* @throws Exception
*/
public void testTasksAttributesProject()
throws Exception
{
try {
Properties properties = new Properties();
String result = invokeMaven( "tasksattributes-test", properties );
assertTrue( result.indexOf( "[echo] To skip me" ) != -1 );
properties.put( "maven.test.skip", "true" );
result = invokeMaven( "tasksattributes-test", properties );
assertTrue( result.indexOf( "[echo] To skip me" ) == -1 );
} catch (LifecycleExecutionException ex) {
String message = ex.getMessage();
if (message.contains("'org.jvnet.maven-antrun-extended-plugin:maven-antrun-extended-plugin' not found in repository")) {
System.out.println("maven-antrun-extended-plugin missing from local repository. Run mvn install and retest");
}
else {
throw ex;
}
}
}
/**
* Invoke Maven for a given test project name
*
* The Maven test project should be in a directory called testProject in
* "src/test/resources/unit/" directory.
* The Maven test project should be called "testProject"-plugin-config.xml.
*
* @param testProject
* @param properties
* @return the output of MavenEmbedder
* @throws Exception
*/
private String invokeMaven( String testProject, Properties properties )
throws Exception
{
MavenEmbedder maven = new MavenEmbedder();
maven.setClassLoader( Thread.currentThread().getContextClassLoader() );
maven.setLogger( new MavenEmbedderConsoleLogger() );
maven.setLocalRepositoryDirectory( getTestFile( "target/local-repo" ) );
maven.setOffline( true );
maven.start();
EventMonitor eventMonitor = new DefaultEventMonitor( new PlexusLoggerAdapter( new MavenEmbedderConsoleLogger() ) );
File testPom = new File( getBasedir(), "src/test/resources/unit/" + testProject + "/" + testProject
+ "-plugin-config.xml" );
MavenProject project = maven.readProjectWithDependencies( testPom );
PrintStream oldOut = System.out;
OutputStream outOS = new StringOutputStream();
PrintStream out = new PrintStream( outOS );
System.setOut( out );
try
{
maven.execute( project,
Arrays.asList( new String[] { "org.jvnet.maven-antrun-extended-plugin:maven-antrun-extended-plugin:run" } ),
eventMonitor, new ConsoleDownloadMonitor(), properties, new File( PlexusTestCase
.getBasedir(), "/target/test/unit/" + testProject + "/" ) );
return outOS.toString();
}
catch (LifecycleExecutionException ex) {
// if maven-antrun-extended-plugin is not in target/local-repo and not in remote repos, look in default
// local repo location: ${user.home}/.m2/repository
maven.setLocalRepositoryDirectory(null);
maven.start();
maven.execute( project,
Arrays.asList( new String[] { "org.jvnet.maven-antrun-extended-plugin:maven-antrun-extended-plugin:run" } ),
eventMonitor, new ConsoleDownloadMonitor(), properties, new File( PlexusTestCase
.getBasedir(), "/target/test/unit/" + testProject + "/" ) );
return outOS.toString();
}
finally
{
System.setOut( oldOut );
}
}
public static void main(String[] args) throws Exception {
AntRunMojoTest test = new AntRunMojoTest();
test.setUp();
test.testDefaultProject();
test.tearDown();
}
}
maven-antrun-extended-plugin-1.42/src/test/resources/ 0000755 0001750 0001750 00000000000 11571451161 023401 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/test/resources/unit/ 0000755 0001750 0001750 00000000000 11571451161 024360 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/test/resources/unit/antrun-default-test/ 0000755 0001750 0001750 00000000000 11571451161 030266 5 ustar jamespage jamespage ././@LongLink 0000000 0000000 0000000 00000000164 00000000000 011566 L ustar root root maven-antrun-extended-plugin-1.42/src/test/resources/unit/antrun-default-test/antrun-default-test-plugin-config.xml maven-antrun-extended-plugin-1.42/src/test/resources/unit/antrun-default-test/antrun-default-test-pl0000644 0001750 0001750 00000003301 10702777422 034533 0 ustar jamespage jamespage
4.0.0antrun-plugin.testantrun-plugin-testjar1.0-SNAPSHOT2006Maven Antrun Plugin Testhttp://maven.apache.orgjunitjunit3.8.1testorg.jvnet.maven-antrun-extended-pluginmaven-antrun-extended-plugin
maven-antrun-extended-plugin-1.42/src/test/resources/unit/tasksattributes-test/ 0000755 0001750 0001750 00000000000 11571451161 030571 5 ustar jamespage jamespage ././@LongLink 0000000 0000000 0000000 00000000166 00000000000 011570 L ustar root root maven-antrun-extended-plugin-1.42/src/test/resources/unit/tasksattributes-test/tasksattributes-test-plugin-config.xml maven-antrun-extended-plugin-1.42/src/test/resources/unit/tasksattributes-test/tasksattributes-test-0000644 0001750 0001750 00000003417 10702777422 035015 0 ustar jamespage jamespage
4.0.0antrun-plugin.testantrun-plugin-testjar1.0-SNAPSHOT2006Maven Antrun Plugin Testhttp://maven.apache.orgjunitjunit3.8.1testorg.jvnet.maven-antrun-extended-pluginmaven-antrun-extended-plugin
To skip me, just call mvn -Dmaven.test.skip=true
maven-antrun-extended-plugin-1.42/src/main/ 0000755 0001750 0001750 00000000000 11571451163 021336 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/main/java/ 0000755 0001750 0001750 00000000000 11571451161 022255 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/main/java/org/ 0000755 0001750 0001750 00000000000 11571451161 023044 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/ 0000755 0001750 0001750 00000000000 11571451161 024172 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/ 0000755 0001750 0001750 00000000000 11571451161 025300 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/ 0000755 0001750 0001750 00000000000 11571451161 026576 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/ 0000755 0001750 0001750 00000000000 11571451163 030107 5 ustar jamespage jamespage maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/GroupIdFilter.java 0000644 0001750 0001750 00000001210 11000001031 033427 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
/**
* @author Kohsuke Kawaguchi
*/
public class GroupIdFilter extends ListFilter {
private String groupId;
private String groupIdNot;
public void setValue(String v) {
groupId = v;
}
public void setNot(String v) {
groupIdNot = v;
}
public boolean visit(DependencyGraph.Node node) {
String p = node.getProject().getGroupId();
if(groupId !=null && groupId.equals(p))
return true; // positive match
if(groupIdNot !=null && !groupIdNot.equals(p))
return true; // negative match
return false;
}
}
maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/MavenComponentBag.java0000644 0001750 0001750 00000030257 11172203362 034315 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
/*
* 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.factory.ArtifactFactory;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.MavenProjectHelper;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Exposes maven components to the Ant tasks.
*
* @author Vincent Siveton
* @version $Id: MavenComponentBag.java 510478 2007-02-22 12:29:45Z vsiveton $
*/
final class MavenComponentBag {
/**
* Used for resolving artifacts
*/
public final ArtifactResolver resolver;
/**
* Factory for creating artifact objects
*/
public final ArtifactFactory factory;
/**
* The local repository where the artifacts are located
*/
public final ArtifactRepository localRepository;
/**
* The remote repositories where artifacts are located
*/
public final List remoteRepositories;
/*
* The maven project
*/
public final MavenProject project;
/*
* TODO: document that this is
*/
public final ArtifactMetadataSource artifactMetadataSource;
public final ArtifactHandlerManager artifactHandlerManager;
/**
* The boolean flag that indicates whether or not to verify that the
* resolved artifact is contained in the pom.xml file.
* Default is 'true'.
*/
public boolean verifyArtifact = true;
public final MavenProjectHelper projectHelper;
public final MavenProjectBuilder mavenProjectBuilder;
/**
* Creates a wrapper and associates that with the current thread.
*/
/*package*/ MavenComponentBag(
ArtifactResolver resolver,
ArtifactFactory factory,
ArtifactRepository localRepository,
List remoteRepositories,
MavenProject project,
MavenProjectHelper projectHelper,
ArtifactHandlerManager artifactHandlerManager,
ArtifactMetadataSource artifactMetadataSource,
MavenProjectBuilder mavenProjectBuilder)
{
this.resolver = resolver;
this.factory = factory;
this.localRepository = localRepository;
this.remoteRepositories = remoteRepositories;
this.project = project;
this.projectHelper = projectHelper;
this.artifactMetadataSource = artifactMetadataSource;
this.artifactHandlerManager = artifactHandlerManager;
this.mavenProjectBuilder = mavenProjectBuilder;
INSTANCES.set(this);
}
public void setVerifyArtifact(boolean verifyArtifact) {
this.verifyArtifact = verifyArtifact;
}
/**
* Return the artifact path in the local repository for an artifact defined by its groupId,
* its artifactId and its version.
*
* @param groupId
* @param artifactId
* @param version
* @return the locale artifact path
* @throws IOException if any
*/
public String getArtifactAbsolutePath( String groupId, String artifactId, String version )
throws IOException {
Artifact artifact = factory.createArtifact( groupId, artifactId, version, "compile", "jar" );
try {
resolver.resolve( artifact, remoteRepositories, localRepository );
return artifact.getFile().getAbsolutePath();
} catch ( ArtifactResolutionException e ) {
throw new IOException( "Unable to resolve artifact: " + groupId + ":" + artifactId + ":" + version );
} catch ( ArtifactNotFoundException e ) {
throw new IOException( "Unable to find artifact: " + groupId + ":" + artifactId + ":" + version );
}
}
private static final ThreadLocal INSTANCES = new ThreadLocal();
public static MavenComponentBag get() {
return INSTANCES.get();
}
/**
* Releases the instance tied to the thread to avoid memory leak.
*/
public static void reset() {
INSTANCES.set(null);
}
/**
* This is a helper method that provides a facade for creating Maven artifacts
* with a classifier. It contains additional code to scan the MavenProject
* artifacts when the groupId, version, and/or classifier values are null.
* This method will scan the artifacts to see if there is a unique match
* based on the artifactId. If there is not a match, an exception is
* thrown.
*
* @param groupId
* A String containing the maven artifact's group id
* @param artifactId
* A String containing the maven artifact's artifactId
* @param version
* A String containing the maven artifact's version
* @param type
* A String containing the maven artifact's type
* @param classifier
* A String containing the maven artifact's classifier
* @throws ArtifactResolutionException
* Thrown if artifact cannot be resolved
* @throws ArtifactNotFoundException
* Thrown if artifact is resolved and verifyArtifact is 'true' and artifact
* is not configured in the pom.xml file.
*/
public Artifact createArtifactWithClassifier(String groupId,
String artifactId,
String version,
String type,
String classifier)
throws IOException {
Artifact artifact;
if (artifactId == null) {
throw new IOException("Cannot resolve artifact: artifactId is null");
} else if (groupId == null || version == null || verifyArtifact) {
// we are missing some critical parameters, or verifyArtifact is true, in which case
// we only allow resolution in the project's dependencies
artifact = resolveArtifactUsingMavenProjectArtifacts(artifactId, groupId, version, type, classifier);
} else {
// otherwise we'll just create an artifact from what the user specified
artifact = factory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier);
}
// If no matches, throw exception
if (artifact == null) {
throw new IOException("Cannot resolve artifact. " +" groupId: "+ groupId
+ " artifactId: " + artifactId + " version: " + version
+ " type: "+ type + " classifier: "+ classifier);
}
return artifact;
}
public ArtifactResolutionResult resolveTransitively(
String groupId,
String artifactId,
String version,
String type,
String classifier)
throws ArtifactResolutionException,
ArtifactNotFoundException,
IOException {
Set artifacts = new HashSet();
Artifact artifact = createArtifactWithClassifier(
groupId,
artifactId,
version,
type,
classifier);
ResolutionGroup resolutionGroup;
try {
resolutionGroup = artifactMetadataSource.retrieve( artifact, localRepository,
project.getPluginArtifactRepositories() );
artifacts.addAll( resolutionGroup.getArtifacts() );
}
catch ( ArtifactMetadataRetrievalException e ) {
throw new ArtifactResolutionException( "Unable to download metadata from repository for artifact '" +
artifact.getId() + " " +e.getMessage(), artifact);
}
ArtifactResolutionResult result =
resolver.resolveTransitively(
artifacts,
artifact,
localRepository,
remoteRepositories,
artifactMetadataSource,
new ScopeArtifactFilter("runtime")
);
return result;
}
/**
* Works like {@link #resolveArtifactUsingMavenProjectArtifacts(String, String, String, String, String)} but
* infers everything else from the artifact ID.
*/
public Artifact resolveArtifactUsingMavenProjectArtifacts(String artifactId) throws IOException {
return resolveArtifactUsingMavenProjectArtifacts(artifactId,null,null,null,null);
}
/**
* This method tries to match a request against artifacts loaded by Maven and
* exposed through the MavenProject object.
*
* NOTE: This method may return 'null'.
*/
public Artifact resolveArtifactUsingMavenProjectArtifacts(String artifactId,
String groupId,
String version,
String type,
String classifier)
throws IOException {
Artifact artifactMatch = null;
// Do match based on artifactId. If value is null or if no match, throw exception
if (artifactId == null) {
throw new IOException("Cannot resolve artifact: artifactId is null");
}
Set artifacts = project.getArtifacts();
for (Artifact a : artifacts) {
if(match(a.getArtifactId(),artifactId)
&& match(a.getGroupId(),groupId)
&& match(a.getVersion(),version)
&& match(a.getType(),type)
&& match(a.getClassifier(),classifier)) {
if(artifactMatch!=null) {
// matched to more than one thing. Error
throw new IOException("Matched more than one artifacts: "+a+" and "+artifactMatch);
}
artifactMatch = a;
}
}
return artifactMatch;
}
private static boolean match(String valueFromPom, String valueFromTask) {
if(valueFromTask==null) return true; // no value specified in the task. Any value from artifact match
if(valueFromPom==null) return false; // the actual value in the artifact didn't match the one given by task
return valueFromPom.equalsIgnoreCase(valueFromTask);
}
/**
* Obtains/downloads the artifact file by using the current set of repositories.
*/
public void resolveArtifact(Artifact artifact, List remoteRepositories) throws ArtifactResolutionException, ArtifactNotFoundException {
if(remoteRepositories ==null)
remoteRepositories = this.remoteRepositories; // fall back to the default list
try {
resolver.resolve(artifact, remoteRepositories,localRepository);
} catch (ArtifactResolutionException e) {
// these pointless catch blocks are convenient for setting breakpoint
throw e;
} catch (ArtifactNotFoundException e) {
throw e;
}
}
public void resolveArtifact(Artifact artifact) throws ArtifactResolutionException, ArtifactNotFoundException {
resolveArtifact(artifact, remoteRepositories);
}
}
maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/GraphVisitor.java 0000644 0001750 0001750 00000001227 10752727017 033401 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
/**
* Traverses a {@link DependencyGraph} in a depth-first order.
* All the reachable nodes and edges are visited once and only once.
*
* @author Kohsuke Kawaguchi
*/
public interface GraphVisitor {
/**
* Visits an edge.
*
* @return
* false to cut the traversal here and don't visit
* its destination node.
*/
boolean visit(DependencyGraph.Edge edge);
/**
* Visits a node.
*
* @return
* false to cut the traversal here and don't visit
* any of forward edges from this node.
*/
boolean visit(DependencyGraph.Node node);
}
././@LongLink 0000000 0000000 0000000 00000000147 00000000000 011567 L ustar root root maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/DependencyGraphTask.java maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/DependencyGraphTask.ja0000644 0001750 0001750 00000007475 11040233351 034307 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import java.io.IOException;
import java.util.Collection;
/**
* Base class for tasks that work with a dependency graph defined as a nested structure.
*
* @author Kohsuke Kawaguchi
* @author Paul Sterk
*/
public abstract class DependencyGraphTask extends Task {
private String groupId,artifactId,version,type="jar",classifier;
private String baseGraph;
private boolean tolerateBrokenPOMs;
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public void setArtifactId(String artifactId) {
this.artifactId = artifactId;
}
public void setVersion(String version) {
this.version = version;
}
public void setType(String type) {
this.type = type;
}
public void setClassifier(String classifier) {
this.classifier = classifier;
}
public void setBaseGraph(String id) {
this.baseGraph = id;
}
/**
* If true, ignore an artifact that fails to resolve.
*/
public void setTolerateBrokenPOMs(boolean tolerateBrokenPOMs) {
this.tolerateBrokenPOMs = tolerateBrokenPOMs;
}
/**
* Transforms a graph by applying the given filter to thtese "source graph",
* which is determined by the various parameter to this task.
*/
protected DependencyGraph buildGraph(GraphFilter filter) {
try {
DependencyGraph g = buildSourceGraph();
if(filter==null) return g;
// apply transformation to g
final DependencyGraph old = GraphFilter.CURRENT_INPUT.get();
GraphFilter.CURRENT_INPUT.set(g);
try {
g = filter.process();
} finally {
GraphFilter.CURRENT_INPUT.set(old);
}
Collection nodes = g.getAllNodes();
log("Filtered down to "+ nodes.size()+" artifact(s)",Project.MSG_DEBUG);
for (DependencyGraph.Node n : nodes)
log(" "+n,Project.MSG_DEBUG);
return g;
} catch (AbstractArtifactResolutionException e) {
throw new BuildException(e);
} catch (IOException e) {
throw new BuildException(e);
} catch (ProjectBuildingException e) {
throw new BuildException(e);
}
}
/**
* Computes the source grpah.
*/
private DependencyGraph buildSourceGraph() throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException, IOException {
MavenComponentBag w = MavenComponentBag.get();
DependencyGraph g;
if(baseGraph!=null) {
g = (DependencyGraph)getProject().getReference(baseGraph);
if(g==null)
throw new BuildException("There's no graph with id="+baseGraph);
} else
if(groupId==null && artifactId==null && version==null) {
// if no clue is given whatsoever, use all the project dependencies
g = new DependencyGraph(w.project.getArtifact(), tolerateBrokenPOMs);
} else {
// otherwise pick up dependencies from the specified artifact
g = new DependencyGraph(w.createArtifactWithClassifier(groupId,artifactId,version,type,classifier), tolerateBrokenPOMs);
log("artifactId "+artifactId, Project.MSG_DEBUG);
}
g = new DependencyExclusionFilter().filter(g);
log("Graph="+g,Project.MSG_DEBUG);
return g;
}
}
maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/AntPropertyHelper.java0000644 0001750 0001750 00000012467 11001167270 034402 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
/*
* Copyright 2004-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.artifact.Artifact;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.apache.tools.ant.PropertyHelper;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
import java.io.File;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
/**
* Makes the ${expressions} used in Maven available to Ant as properties.
*
* @author Kenney Westerhof
*/
public class AntPropertyHelper
extends PropertyHelper
{
private Log log;
private ExpressionEvaluator exprEvaluator;
private MavenProject mavenProject;
private Map artifactMap = new Hashtable();
/**
* @deprecated use the other constructor
* @param project
* @param l
*/
public AntPropertyHelper( MavenProject project, Log l )
{
mavenProject = project;
log = l;
}
/**
* @param exprEvaluator
* @param artifacts
* @param l
*/
public AntPropertyHelper( ExpressionEvaluator exprEvaluator, Set artifacts, Log l )
{
this.mavenProject = null;
this.exprEvaluator = exprEvaluator;
this.log = l;
for (Artifact artifact : artifacts) {
String key = "maven.dependency." + artifact.getGroupId() + "." + artifact.getArtifactId() +
(artifact.getClassifier() != null ? "." + artifact.getClassifier() : "") +
(artifact.getType() != null ? "." + artifact.getType() : "") + ".path";
log.debug("Storing: " + key + "=" + artifact.getFile().getPath());
artifactMap.put(key, artifact.getFile());
}
}
/**
* @see org.apache.tools.ant.PropertyHelper#getPropertyHook(java.lang.String, java.lang.String, boolean)
*/
public synchronized Object getPropertyHook( String ns, String name, boolean user )
{
if ( log.isDebugEnabled() )
{
log.debug( "getProperty(ns="+ns+", name="+name+", user="+user+")" );
}
/* keep old behaviour */
if ( mavenProject != null )
{
return getPropertyHook( ns, name, user, mavenProject );
}
Object val = null;
if ( name.startsWith( "maven.dependency." ) )
{
val = artifactMap.get( name ).getPath();
}
if ( val == null )
{
try
{
val = exprEvaluator.evaluate( "${" + name + "}" );
}
catch (ExpressionEvaluationException e)
{
if ( log.isErrorEnabled() )
{
log.error("Failed to evaluate expression" , e);
}
}
}
if ( val == null )
{
val = super.getPropertyHook( ns, name, user );
if ( val == null )
{
val = System.getProperty( name.toString() );
}
}
return val;
}
/**
* @deprecated added to keep backwards compatibility
* @param ns
* @param name
* @param user
* @param mavenProject
* @return
*/
private Object getPropertyHook( String ns, String name, boolean user, MavenProject mavenProject )
{
Object val = null;
try
{
if ( name.startsWith( "maven.dependency." ) )
{
val = artifactMap.get( name ).getPath();
}
else if ( name.startsWith( "project." ) )
{
val = ReflectionValueExtractor.evaluate(
name,
mavenProject,
true
);
}
else if ( name.equals("basedir") )
{
val = ReflectionValueExtractor.evaluate(
"basedir.path",
mavenProject,
false
);
}
}
catch ( Exception e )
{
if ( log.isWarnEnabled() )
{
log.warn( "Error evaluating expression '" + name + "'", e );
}
e.printStackTrace();
}
if ( val == null )
{
val = super.getPropertyHook( ns, name, user );
if ( val == null )
{
val = System.getProperty(name);
}
}
if ( val instanceof File )
{
val = ((File) val).getAbsoluteFile();
}
return val;
}
}
maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/UnJarTask.java 0000644 0001750 0001750 00000007103 11430055555 032614 0 ustar jamespage jamespage /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.jvnet.maven.plugin.antrun;
import org.apache.tools.ant.taskdefs.Expand;
import org.apache.tools.ant.util.FileUtils;
import java.io.File;
/**
* Extends the unjar task to be able to specify dynamic destination directory.
*
* For example:
*
*
*
*
*
*
*
*
*
*
* produces:
*
* [unjar] Expanding: /tmp/src/a.jar into /tmp/a_jar
* [unjar] Expanding: /tmp/src/b.jar into /tmp/b_jar
* [unjar] Expanding: /tmp/src/c.jar into /tmp/c_jar
* [unjar] Expanding: /tmp/src/d.jar into /tmp/d_jar
*
*
*
* @author bhavanishankar@dev.java.net
*
*/
public class UnJarTask extends Expand {
@Override
protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
String destDirName = dir.getAbsolutePath();
if (destDirName.indexOf("@filebasename@") != -1) {
String fileBaseName = getBaseName(srcF);
destDirName = destDirName.replaceAll("@filebasename@", fileBaseName);
File destDir = new File(destDirName);
destDir.mkdirs();
super.expandFile(fileUtils, srcF, destDir);
} else {
super.expandFile(fileUtils, srcF, dir);
}
}
private String getBaseName(File file) {
String srcFileName = file.getName();
String fileBaseName = srcFileName.indexOf('.') != -1 ?
srcFileName.substring(0, srcFileName.lastIndexOf('.')) : srcFileName;
return fileBaseName;
}
}
maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/GraphVisitors.java 0000644 0001750 0001750 00000005202 10737012252 033550 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
import java.util.Arrays;
import java.util.Collection;
/**
* Factories for {@link GraphVisitor}.
*
* @author Kohsuke Kawaguchi
*/
public class GraphVisitors {
/**
* Combines multiple {@link GraphVisitor} by AND-ing its output.
* Can be used to create intersections.
*/
public static GraphVisitor and(GraphVisitor... visitors) {
return and(Arrays.asList(visitors));
}
/**
* Combines multiple {@link GraphVisitor} by AND-ing its output.
* Can be used to create intersections.
*/
public static GraphVisitor and(final Collection extends GraphVisitor> visitors) {
return new GraphVisitor() {
public boolean visit(DependencyGraph.Edge edge) {
for (GraphVisitor v : visitors) {
if(!v.visit(edge))
return false;
}
return true;
}
public boolean visit(DependencyGraph.Node node) {
for (GraphVisitor v : visitors) {
if(!v.visit(node))
return false;
}
return true;
}
};
}
/**
* Combines multiple {@link GraphVisitor} by OR-ing its output.
* Can be used to create unions.
*/
public static GraphVisitor or(GraphVisitor... visitors) {
return or(Arrays.asList(visitors));
}
/**
* Combines multiple {@link GraphVisitor} by OR-ing its output.
* Can be used to create unions.
*/
public static GraphVisitor or(final Collection extends GraphVisitor> visitors) {
return new GraphVisitor() {
public boolean visit(DependencyGraph.Edge edge) {
for (GraphVisitor v : visitors) {
if(v.visit(edge))
return true;
}
return false;
}
public boolean visit(DependencyGraph.Node node) {
for (GraphVisitor v : visitors) {
if(!v.visit(node))
return true;
}
return false;
}
};
}
/**
* Obtains a {@link GraphVisitor} that does boolean-negation of the current {@link GraphVisitor}.
*/
public static GraphVisitor not(final GraphVisitor graph) {
return new GraphVisitor() {
public boolean visit(DependencyGraph.Edge edge) {
return !graph.visit(edge);
}
public boolean visit(DependencyGraph.Node node) {
return !graph.visit(node);
}
};
}
}
maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/DumpGraphFilter.java 0000644 0001750 0001750 00000000620 10737030025 033776 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
import org.apache.tools.ant.Project;
/**
* Special {@link GraphFilter} that dumps the graph. Useful for debugging.
*
* @author Kohsuke Kawaguchi
*/
public class DumpGraphFilter extends GraphFilter {
public DependencyGraph process() {
DependencyGraph g = evaluateChild();
log(g.toString(), Project.MSG_INFO);
return g;
}
}
././@LongLink 0000000 0000000 0000000 00000000155 00000000000 011566 L ustar root root maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/DependencyExclusionFilter.java maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/DependencyExclusionFil0000644 0001750 0001750 00000007312 10752732376 034450 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
import org.apache.maven.project.MavenProject;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;
import java.util.List;
import java.util.Set;
import java.util.Stack;
import java.util.HashSet;
import java.util.Collections;
/**
* Filters out a graph by honoring dependency exclusion.
*
*
* A care is taken to handle a diamond dependency with exclusion correctly.
* For example, in the following situation X shouldn't be excluded
* because there's a valid reachable path to X.
*
*
* A -+-> B[exclude=X] -+
* | |
* +-> C ------------+-> D ---> X
*
*
* @author Kohsuke Kawaguchi
*/
public class DependencyExclusionFilter extends GraphFilter {
public DependencyGraph process() {
final DependencyGraph g = evaluateChild();
return filter(g);
}
public DependencyGraph filter(final DependencyGraph g) {
// All the reachable nodes will be accumulated here.
final Set reachables = new HashSet();
new Runnable() {
private final Stack> exclusions = new Stack>();
/**
* Nodes that are already visited without any exclusion.
* This is optimization, as if this is the case we know there's no point in visiting
* such node twice.
*/
private final Set visitedWithNoExclusion = new HashSet();
private boolean noExclusionSoFar = true;
public void run() {
visit(g.getRoot());
}
/**
* Visits all the paths.
*/
private void visit(DependencyGraph.Node node) {
// is this node excluded in the current path? If so, return.
String id = node.groupId + ':' + node.artifactId;
for (Set e : exclusions)
if(e.contains(id))
return;
// now we know that this is reachable
reachables.add(node);
if(noExclusionSoFar && !visitedWithNoExclusion.add(node))
// optimization. this node has already been visited with no exclusion,
// so no point in doing it twice
return;
// create a new environment
final boolean old = noExclusionSoFar;
Set newExc = computeExclusionSet(node);
exclusions.push(newExc);
noExclusionSoFar &= newExc.isEmpty();
// recurse
for (DependencyGraph.Edge e : node.getForwardEdges(g)) {
if(!e.optional)
visit(e.dst);
}
// then restore the old environment
exclusions.pop();
noExclusionSoFar = old;
}
/**
* Computes the exclusion set added by this node. They are strings of the form 'groupId:artifactId'.
*/
private Set computeExclusionSet(DependencyGraph.Node node) {
MavenProject p = node.getProject();
if(p==null) return Collections.emptySet();
Set excSet = new HashSet();
for( Dependency d : (List)p.getDependencies() )
for( Exclusion exc : (List)d.getExclusions() )
excSet.add(exc.getGroupId()+':'+exc.getArtifactId());
return excSet;
}
}.run();
return g.createSubGraph(g.getRoot(), reachables);
}
}
././@LongLink 0000000 0000000 0000000 00000000164 00000000000 011566 L ustar root root maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/AbstractArtifactsExclusionFilter.java maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/AbstractArtifactsExclu0000644 0001750 0001750 00000005317 11037730547 034450 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
import org.apache.maven.artifact.Artifact;
import org.apache.tools.ant.BuildException;
import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Arrays;
import java.io.IOException;
/**
* Base class for {@link ListFilter}s that takes several nested <artifact> elements as parameters
* to identify artifacts.
*
* @author Kohsuke Kawaguchi
*/
public abstract class AbstractArtifactsExclusionFilter extends ListFilter {
/**
* IDs of the artifacts to exclude. "groupId:artifactId:classifier".
* These three are sufficient to identify an artifact uniquely within the context of single project
* and its dependency.
*/
protected final Set ids = new HashSet();
private final List artifactElements = new ArrayList();
protected AbstractArtifactsExclusionFilter(Collection artifactIds) throws IOException {
for (String artifactId : artifactIds)
addArtifactId(artifactId);
}
protected AbstractArtifactsExclusionFilter(String... artifactIds) throws IOException {
this(Arrays.asList(artifactIds));
}
protected AbstractArtifactsExclusionFilter(String artifactId) throws IOException {
addArtifactId(artifactId);
}
// for Ant
protected AbstractArtifactsExclusionFilter() {}
/**
* Resolves all the artifacts and computes {@link #ids}.
*
* This normally needs to be done at {@link #visit(DependencyGraph.Node)},
* because this implementation could be used as a filter.
* Can be invoked multiple times safely.
*/
protected final void resolve() {
try {
for (ArtifactElement ae : artifactElements)
addArtifact(ae.createArtifact());
artifactElements.clear();
} catch (IOException e) {
throw new BuildException(e);
}
}
/**
* Adds the artifact ID to {@link #ids}. Note that this requires us to infer other parameters like
* groupId, version, etc.
*/
private void addArtifactId(String artifactId) throws IOException {
addArtifact(MavenComponentBag.get().resolveArtifactUsingMavenProjectArtifacts(artifactId));
}
protected void addArtifact(Artifact a) {
ids.add(a.getGroupId()+':'+a.getArtifactId()+':'+a.getClassifier());
}
/**
* Nested <artifact> element can be used to specify what artifacts to exclude.
*/
public void addConfiguredArtifact(ArtifactElement a) {
// can't resolve this to artifact yet, because we don't have MavenComponentBag here.
artifactElements.add(a);
}
}
maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/AbstractAntMojo.java 0000644 0001750 0001750 00000014446 10737013060 034007 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
/*
* Copyright 2005-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.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.PropertyHelper;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.types.Path;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.util.StringUtils;
import org.jvnet.maven.plugin.antrun.components.AntTargetConverter;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
/**
* Abstract class for the Antrun plugin
*
* @author Kenney Westerhof
* @author Vincent Siveton
* @version $Id: AbstractAntMojo.java 557320 2007-07-18 16:35:18Z kenney $
*/
public abstract class AbstractAntMojo
extends AbstractMojo
{
/**
* @deprecated use {@link AbstractAntMojo#executeTasks(Target,MavenProject,List)}.
*/
protected void executeTasks( Target antTasks, MavenProject mavenProject )
throws MojoExecutionException
{
executeTasks( antTasks, mavenProject, null );
}
/**
* @param antTasks
* @param mavenProject
* @throws MojoExecutionException
*/
protected void executeTasks( Target antTasks, MavenProject mavenProject, List pluginArtifacts )
throws MojoExecutionException
{
if ( antTasks == null )
{
getLog().info( "No ant tasks defined - SKIPPED" );
return;
}
try
{
//TODO refactor - place the manipulation of the expressionEvaluator into a separated class.
ExpressionEvaluator exprEvaluator = (ExpressionEvaluator) antTasks.getProject()
.getReference( AntTargetConverter.MAVEN_EXPRESSION_EVALUATOR_ID );
Project antProject = antTasks.getProject();
PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper( antProject );
propertyHelper.setNext( new AntPropertyHelper( exprEvaluator, mavenProject.getArtifacts(), getLog() ) );
DefaultLogger antLogger = new DefaultLogger();
antLogger.setOutputPrintStream( System.out );
antLogger.setErrorPrintStream( System.err );
antLogger.setMessageOutputLevel( getLog().isDebugEnabled() ? Project.MSG_DEBUG : Project.MSG_INFO );
antProject.addBuildListener( antLogger );
antProject.setBaseDir( mavenProject.getBasedir() );
Path p = new Path( antProject );
p.setPath( StringUtils.join( mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator ) );
/* maven.dependency.classpath it's deprecated as it's equal to maven.compile.classpath */
antProject.addReference( "maven.dependency.classpath", p );
antProject.addReference( "maven.compile.classpath", p );
p = new Path( antProject );
p.setPath( StringUtils.join( mavenProject.getRuntimeClasspathElements().iterator(), File.pathSeparator ) );
antProject.addReference( "maven.runtime.classpath", p );
p = new Path( antProject );
p.setPath( StringUtils.join( mavenProject.getTestClasspathElements().iterator(), File.pathSeparator ) );
antProject.addReference( "maven.test.classpath", p );
/* set maven.plugin.classpath with plugin dependencies */
antProject.addReference( "maven.plugin.classpath", getPathFromArtifacts( pluginArtifacts, antProject ) );
if ( getLog().isInfoEnabled() )
{
getLog().info( "Executing tasks" );
}
configureProject(antProject);
antTasks.execute();
if ( getLog().isInfoEnabled() )
{
getLog().info( "Executed tasks" );
}
}
catch ( DependencyResolutionRequiredException e )
{
throw new MojoExecutionException( "DependencyResolutionRequiredException: " + e.getMessage(), e );
}
catch ( BuildException e )
{
throw new MojoExecutionException( "An Ant BuildException has occured: " + e.getMessage(), e );
}
catch ( Exception e )
{
throw new MojoExecutionException( "Error executing ant tasks: " + e.getMessage(), e );
}
}
/**
* Provides an opportunity for derived types to customize Ant project.
*/
protected void configureProject(Project antProject) {
}
/**
* @param artifacts
* @param antProject
* @return a path
* @throws DependencyResolutionRequiredException
*/
public Path getPathFromArtifacts( Collection artifacts, Project antProject )
throws DependencyResolutionRequiredException
{
if ( artifacts == null )
{
return new Path( antProject );
}
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;
}
}
././@LongLink 0000000 0000000 0000000 00000000161 00000000000 011563 L ustar root root maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/RemoveSpecificArtifactsFilter.java maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/RemoveSpecificArtifact0000644 0001750 0001750 00000003061 10770317752 034420 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
import java.io.IOException;
import java.util.Collection;
import java.util.Set;
import java.util.HashSet;
/**
* Filter {@link DependencyGraph} by excluding artifacts that are specific to the given artifacts.
*
*
* By specific, I mean an artifact that's only depended on by one and the only one of the
* given artifacts.
*
* @author Kohsuke Kawaguchi
*/
public class RemoveSpecificArtifactsFilter extends AbstractArtifactsExclusionFilter {
/**
* Nodes to be retained.
*/
private Set nodes;
public RemoveSpecificArtifactsFilter(Collection artifactIds) throws IOException {
super(artifactIds);
}
public RemoveSpecificArtifactsFilter(String... artifactIds) throws IOException {
super(artifactIds);
}
public RemoveSpecificArtifactsFilter(String artifactId) throws IOException {
super(artifactId);
}
public RemoveSpecificArtifactsFilter() {
}
public boolean visit(DependencyGraph.Node node) {
resolve();
if(!ids.isEmpty()) {
final DependencyGraph base = evaluateChild();
nodes = new HashSet(base.getAllNodes());
for (String id : ids) {
ExcludeArtifactsTransitivelyFilter exf = new ExcludeArtifactsTransitivelyFilter();
exf.ids.add(id);
DependencyGraph x = base.createSubGraph(exf);
nodes.retainAll(x.getAllNodes());
}
}
return nodes.contains(node);
}
}
././@LongLink 0000000 0000000 0000000 00000000146 00000000000 011566 L ustar root root maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/RetentionSetFilter.java maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/RetentionSetFilter.jav0000755 0001750 0001750 00000004545 10737030751 034414 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import java.io.IOException;
/**
* Use this filter to create a retention set from a DependencyGraph. Indicate
* which artifacts you wish to include in the set by passing the artifactId(s)
* to one of the constructors.
*
* @author Paul Sterk
*/
public final class RetentionSetFilter extends GraphFilter {
private ArtifactElement root;
/**
* Nested <artifact> element can be used to specify what artifacts to exclude.
*/
public void addConfiguredArtifact(ArtifactElement a) {
// can't resolve this to artifact yet, because we don't have MavenComponentBag here.
if(root!=null)
throw new BuildException("Only one is allowed");
root = a;
}
public DependencyGraph process() {
try {
final DependencyGraph base = evaluateChild();
// Step 1. Subtract out all the artifacts specified in the artifactIds
// collection by doing set subtraction
ExcludeArtifactsTransitivelyFilter sbf = new ExcludeArtifactsTransitivelyFilter();
sbf.addConfiguredArtifact(root);
final DependencyGraph subtractionSet = base.createSubGraph(sbf);
// Step 2. Create the retention set by subtracting the artifacts in the
// subtractionSet created in Step 1 from the original dependencyGraph set
DependencyGraph g = base.createSubGraph(
base.toNode(root.createArtifact()),
new DefaultGraphVisitor() {
public boolean visit(DependencyGraph.Node node) {
return !subtractionSet.contains(node);
}
});
log(getClass().getSimpleName()+" -> "+g,Project.MSG_DEBUG);
return g;
} catch (ProjectBuildingException e) {
throw new BuildException("Failed to resolve artifacts",e);
} catch (AbstractArtifactResolutionException e) {
throw new BuildException("Failed to resolve artifacts",e);
} catch (IOException e) {
throw new BuildException("Failed to resolve artifacts",e);
}
}
}
././@LongLink 0000000 0000000 0000000 00000000166 00000000000 011570 L ustar root root maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/ExcludeArtifactsTransitivelyFilter.java maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/ExcludeArtifactsTransi0000755 0001750 0001750 00000003642 10770317752 034462 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
import org.apache.maven.artifact.Artifact;
import org.apache.tools.ant.BuildException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Filter {@link DependencyGraph} by excluding the specified set of artifacts. Any artifacts made
* unreachable by this process will be also excluded.
*
*
* Informally, a node will remain in the graph
* only when it's reachable from the root without going through
* any of the excluded artifacts.
*
*
* Here's the format definition.
*
* Let normalize(G={r,V,E}) -> G'={r,V',E'} be defined as follows.
* This is an operation to remove unreachable nodes and edges.
*
*
* V' = { v | \exists r ->* v in G }
* E' = { (u,v) | u \in V' and v \in V' }
*
*
* Given the graph G=(r,V,E) and exclusion nodes N,
* the new graph G' is defined as follows:
*
*
* G'=normalize(r,V-N),E)
*
*
* @author Paul Sterk
* @author Kohsuke Kawaguchi
* @see RemoveSpecificArtifactsFilter
*/
public final class ExcludeArtifactsTransitivelyFilter extends AbstractArtifactsExclusionFilter {
public ExcludeArtifactsTransitivelyFilter(Collection artifactIds) throws IOException {
super(artifactIds);
}
public ExcludeArtifactsTransitivelyFilter(String... artifactIds) throws IOException {
super(artifactIds);
}
public ExcludeArtifactsTransitivelyFilter(String artifactId) throws IOException {
super(artifactId);
}
public ExcludeArtifactsTransitivelyFilter() {
}
public boolean visit(DependencyGraph.Node node) {
resolve();
// If the artifact matches an artifact in the artifacts Set, do not
// include in the subgraph. Indicate this by returning 'false'.
return !ids.contains(node.getId());
}
}
maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/ResolveAllTask.java 0000644 0001750 0001750 00000015131 11066427721 033650 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.FileNameMapper;
import org.apache.tools.ant.taskdefs.Copy;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
import org.apache.maven.artifact.Artifact;
import org.jvnet.maven.plugin.antrun.DependencyGraph.Node;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Transitively resolve dependencies, perform some filtering first on the graph data model,
* then on list data model, and deliver the resulting
* set of artifacts in various forms (as a new {@link Path} object, into a directory, etc.)
*
* @author Kohsuke Kawaguchi
* @author Paul Sterk
*/
public class ResolveAllTask extends DependencyGraphTask {
private File todir;
private String pathId;
private GraphFilter filter;
private String classifier;
private final List listFilters = new ArrayList();
private boolean stripVersion;
public void setTodir(File todir) {
this.todir = todir;
todir.mkdirs();
}
public void setPathId(String pathId) {
this.pathId = pathId;
}
/**
* Instead of resolving the artifact as appeared in the dependency graph,
* resolve a specific classifier.
*
* This is normally used to gather source jars.
*/
public void setClassifier(String classifier) {
this.classifier = classifier;
}
/**
* If set to true, destination file names won't have version
* encoded in them.
* @param stripVersion destination file name to have version or not
*/
public void setStripVersion(boolean stripVersion) {
this.stripVersion = stripVersion;
}
/**
* Adds a {@link GraphFilter} child. Ant will invoke this for each child element given in build script.
*/
public void add(GraphFilter child) {
if(filter==null)
this.filter = child;
else {
if (child instanceof ListFilter) {
listFilters.add((ListFilter) child);
} else {
throw new BuildException(filter+" is not a list filter");
}
}
}
public void execute() throws BuildException {
log("Starting ResolveAllTasks.execute ", Project.MSG_DEBUG);
// first graph filtering
DependencyGraph g = buildGraph(filter);
List nodes = new ArrayList(g.getAllNodes());
// further trim down the list by list filtering
final DependencyGraph old = GraphFilter.CURRENT_INPUT.get();
GraphFilter.CURRENT_INPUT.set(g);
try {
for (ListFilter listFilter : listFilters) {
for (Iterator itr = nodes.iterator(); itr.hasNext();)
if(!listFilter.visit(itr.next()))
itr.remove();
}
} finally {
GraphFilter.CURRENT_INPUT.set(old);
}
if(pathId!=null) {
// collect all artifacts into a path and export
Path path = new Path(getProject());
for (Node n : nodes) {
try {
File f = resolve(n);
if(f!=null)
path.createPathElement().setLocation(f);
} catch (AbstractArtifactResolutionException e) {
throw new BuildException("Failed to resolve artifact. Trail="+n.getTrail(g),e);
} catch (IOException e) {
throw new BuildException("Failed to resolve artifact. Trail="+n.getTrail(g),e);
}
}
getProject().addReference(pathId,path);
}
if(todir!=null) {
boolean hasSomethingToCopy=false;
for (Node n : nodes) {
try {
File f = resolve(n);
if(f!=null) {
// copy files to the specified target directory.
// use the task implementation to do up-to-date check.
Copy cp = new Copy();
cp.setTaskName(getTaskName());
cp.setProject(getProject());
cp.setTodir(todir);
if (stripVersion) {
cp.add(new VersionStripper(n.version));
}
FileSet fs = new FileSet();
fs.setFile(f);
cp.addFileset(fs);
cp.execute();
hasSomethingToCopy=true;
}
} catch (AbstractArtifactResolutionException e) {
throw new BuildException("Failed to resolve artifact. Trail="+n.getTrail(g),e);
} catch (IOException e) {
throw new BuildException("Failed to resolve artifact. Trail="+n.getTrail(g),e);
}
}
if(!hasSomethingToCopy)
log("Nothing to copy",Project.MSG_INFO);
}
log("Exiting ResolveAllTasks.execute ", Project.MSG_DEBUG);
}
private File resolve(Node n) throws AbstractArtifactResolutionException, IOException {
if(classifier==null)
return n.getArtifactFile();
final MavenComponentBag w = MavenComponentBag.get();
Artifact a = w.factory.createArtifactWithClassifier(n.groupId, n.artifactId, n.version, n.type, classifier);
List remoteRepos=null;
if(n.getProject()!=null)
remoteRepos = n.getProject().getRemoteArtifactRepositories();
w.resolveArtifact(a,remoteRepos);
return a.getFile();
}
private class VersionStripper implements FileNameMapper {
String version;
public VersionStripper(String v) {
version = v;
}
public void setFrom(String s) {
}
public void setTo(String s) {
}
public String[] mapFileName(String s) {
int idx = s.lastIndexOf(version);
String to = s;
if (idx != -1) {
// remove version in artifactId-version(-classifier).type
String baseFilename = s.substring( 0, idx - 1 );
String extension = s.substring( idx + version.length());
to = baseFilename + extension;
}
log("mapFileName: " + s + " -> " + to, Project.MSG_DEBUG);
return new String[]{to};
}
}
}
maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/ArtifactElement.java 0000644 0001750 0001750 00000003333 10737021252 034016 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
import org.apache.maven.artifact.Artifact;
import java.io.IOException;
/**
* Represents <artifact> element in build.xml
*
*
* This Java bean is a part of the XML configuration binding via Ant.
*
* @author Kohsuke Kawaguchi
*/
public class ArtifactElement {
private String groupId, artifactId, version, type, classifier;
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 getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getClassifier() {
return classifier;
}
public void setClassifier(String classifier) {
this.classifier = classifier;
}
/**
* Creates an {@link Artifact} from the configured information,
* by possibly guessing parameters that were missing.
*/
public Artifact createArtifact() throws IOException {
MavenComponentBag bag = MavenComponentBag.get();
return bag.createArtifactWithClassifier(groupId,artifactId,version,type,classifier);
}
/**
* Retrurns the ID of this artifact after guessing omitted parameters.
* The returned string follows the {@link Artifact#getId()} format.
*/
public String getId() throws IOException {
return createArtifact().getId();
}
}
././@LongLink 0000000 0000000 0000000 00000000147 00000000000 011567 L ustar root root maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/ManifestEntryFilter.java maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/ManifestEntryFilter.ja0000644 0001750 0001750 00000002771 10774775426 034407 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
import org.apache.tools.ant.BuildException;
import java.io.File;
import java.io.IOException;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.jar.Attributes;
/**
* Filter out a {@link DependencyGraph} by looking at manifest entries in the jar file.
*
* @author Kohsuke Kawaguchi
*/
public class ManifestEntryFilter extends ListFilter {
private String entry;
/**
* The manifest main entry name that the jar has to have.
*/
public void setHas(String v) {
entry = v;
}
public boolean visit(DependencyGraph.Node node) {
try {
File v = node.getArtifactFile();
if(v==null) return false; // whether this is the right behavior is worth an argument
JarFile jar = new JarFile(v);
try {
Manifest m = jar.getManifest();
if(m==null) return false;
Attributes att = m.getMainAttributes();
if(att==null) return false; // don't know if this can ever happen
return att.getValue(entry)!=null;
} finally {
jar.close();
}
} catch (AbstractArtifactResolutionException e) {
throw new BuildException("Failed to filter "+node,e);
} catch (IOException e) {
throw new BuildException("Failed to filter "+node,e);
}
}
}
maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/AntRunMojo.java 0000644 0001750 0001750 00000025661 11155656473 033031 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
/*
* Copyright 2005-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.
*/
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.MavenProjectHelper;
import org.apache.maven.profiles.ProfileManager;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.taskdefs.Taskdef;
import org.apache.tools.ant.taskdefs.Typedef;
import java.beans.Introspector;
import java.io.File;
import java.util.List;
import java.net.URLClassLoader;
import java.net.MalformedURLException;
import java.net.URL;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
/**
* Maven AntRun Mojo.
*
* This plugin provides the capability of calling Ant tasks
* from a POM by running the nested ant tasks inside the <tasks/>
* parameter. It is encouraged to move the actual tasks to
* a separate build.xml file and call that file with an
* <ant/> task.
*
* @author Kenney Westerhof
* @author Vincent Siveton
* @version $Id: AntRunMojo.java 557316 2007-07-18 16:29:17Z kenney $
* @configurator override
* @goal run
* @requiresDependencyResolution test
*/
// TODO: phase package
public class AntRunMojo
extends AbstractAntMojo
{
/**
* The Maven project object
*
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
/**
* The plugin dependencies.
*
* @parameter expression="${plugin.artifacts}"
* @required
* @readonly
*/
private List pluginArtifacts;
/**
* The XML for the Ant task. You can add anything you can add
* between <target> and </target> in a build.xml.
*
* @parameter expression="${tasks}"
*/
private Target tasks;
/**
* This folder is added to the list of those folders
* containing source to be compiled. Use this if your
* ant script generates source code.
*
* @parameter expression="${sourceRoot}"
*/
private File sourceRoot;
/**
* This folder is added to the list of those folders
* containing source to be compiled for testing. Use this if your
* ant script generates test source code.
*
* @parameter expression="${testSourceRoot}"
*/
private File testSourceRoot;
/**
* Requires that artifacts to be resolved be defined in the dependency section of the POM.
* Setting this to false allows you to resolve arbitrary artifact.
*
* @parameter expression="${verifyArtifact}" default-value="true"
*/
private boolean verifyArtifact=true;
/**
* Used for resolving artifacts
*
* @component
*/
private ArtifactResolver resolver;
/**
* Factory for creating artifact objects
*
* @component
*/
private ArtifactFactory factory;
/**
* The local repository where the artifacts are located
*
* @parameter expression="${localRepository}"
* @required
*/
private ArtifactRepository localRepository;
/**
* The remote repositories where artifacts are located
*
* @parameter expression="${project.remoteArtifactRepositories}"
*/
private List remoteRepositories;
/**
* @component
*/
private MavenProjectHelper projectHelper;
/**
* @component
*/
protected ArtifactMetadataSource artifactMetadataSource;
private MavenComponentBag bag;
/**
* @component
*/
private ArtifactHandlerManager artifactHandlerManager;
/**
* @component
*/
private MavenProjectBuilder mavenProjectBuilder;
// this is not available as a component
// /**
// * @component
// */
// private ProfileManager profileManager;
/**
* @see org.apache.maven.plugin.Mojo#execute()
*/
public void execute()
throws MojoExecutionException
{
initArtifactResolverWrapper();
/* Uncomment the following code to debug the MavenComponentBag
bag.setVerifyArtifact(false);
try {
bag.resolveTransitively("org.glassfish.web", "gf-web-connector", "10.0-SNAPSHOT", "jar", "runtime");
} catch (Throwable t) {
t.printStackTrace();
}
*/
try {
executeTasks( tasks, project, pluginArtifacts );
} finally {
MavenComponentBag.reset();
}
if ( sourceRoot != null )
{
getLog().info( "Registering compile source root " + sourceRoot );
project.addCompileSourceRoot( sourceRoot.toString() );
}
if ( testSourceRoot != null )
{
getLog().info( "Registering compile test source root " + testSourceRoot );
project.addTestCompileSourceRoot( testSourceRoot.toString() );
}
}
/*
* This method is invoked to initialize the MavenComponentBag and
* set it in ArtifactResolverWrapperThreadLocal. This thread local class
* can be used by other classes, such as Ant tasks, to obtain the
* MavenComponentBag.
*/
private void initArtifactResolverWrapper() {
bag = new MavenComponentBag(resolver,
factory,
localRepository,
remoteRepositories,
project, projectHelper,
artifactHandlerManager,
artifactMetadataSource,
mavenProjectBuilder);
bag.setVerifyArtifact(verifyArtifact);
}
protected void configureProject(Project antProject) {
// define all tasks
for (Class task : TASKS) {
typeDef(antProject, task, new Taskdef(), inferName(task, "Task"));
}
// define all filters
for (Class filter : FILTERS) {
typeDef(antProject, filter, new Typedef(), inferName(filter, "Filter"));
}
// expose basic properties
antProject.setProperty("artifactId",project.getArtifactId());
antProject.setProperty("groupId",project.getGroupId());
antProject.setProperty("version",project.getVersion());
antProject.setProperty("packaging",project.getPackaging());
}
private void typeDef(Project antProject, Class task, Typedef def, String name) {
def.setName(name);
def.setClassname(task.getName());
def.setProject(antProject);
def.execute();
}
private String inferName(Class task, String suffix) {
String taskName = task.getSimpleName();
if(taskName.endsWith(suffix)) // chop off suffix
taskName = taskName.substring(0,taskName.length()-suffix.length());
taskName = Introspector.decapitalize(taskName);
return taskName;
}
private static final Class[] TASKS = new Class[] {
ResolveArtifactTask.class,
ResolveAllTask.class,
AttachArtifactTask.class,
GraphDefTask.class,
IfTask.class
};
private static final Class[] FILTERS = new Class[] {
RetentionSetFilter.class,
ExcludeArtifactsTransitivelyFilter.class,
GroupIdFilter.class,
PackagingFilter.class,
ManifestEntryFilter.class,
DependencyExclusionFilter.class,
RemoveSpecificArtifactsFilter.class,
ScopeFilter.class,
DumpGraphFilter.class,
SubtractFilter.class,
SubGraphFilter.class,
FullGraphFilter.class,
VisualizeFilter.class,
GraphRefFilter.class
};
/*
Mac JDKs don't have tools.jar (but they are just a part of rt.jar.
Because of this, users of this plugin cannot add tools.jar to the dependency of antrun
in a portable fashion --- doing so via plugin/dependencies/dependnecy as suggested in
http://jira.codehaus.org/browse/MANTRUN-23 would break Mac builds.
Typical error message is like this:
[INFO] [antrun-extended:run {execution: default}]
[INFO] Executing tasks
[javac] Compiling 1 source file to /home/kohsuke/ws/gfv3/antrun/src/it/test-javac/target
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An Ant BuildException has occured: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK
So here we special-case tools.jar by locating them and adding them automatically to
the classloader that loaded us.
*/
static {
try {
Class.forName("com.sun.tools.javac.Main");
} catch (ClassNotFoundException e) {
// if not found, try to locate them
File javaHome = new File(System.getProperty("java.home"));
File toolsJar = new File(javaHome,"../lib/tools.jar");
if(toolsJar.exists()) {
ClassLoader cl = AntRunMojo.class.getClassLoader();
if (cl instanceof URLClassLoader) {
URLClassLoader ucl = (URLClassLoader) cl;
try {
Method m = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
m.setAccessible(true);
m.invoke(ucl,toolsJar.toURL());
} catch (MalformedURLException e1) {
// ignore the error and hope that the ant doesn't use javac
} catch (InvocationTargetException e1) {
// ignore the error and hope that the ant doesn't use javac
} catch (NoSuchMethodException e1) {
// ignore the error and hope that the ant doesn't use javac
} catch (IllegalAccessException e1) {
// ignore the error and hope that the ant doesn't use javac
}
}
}
}
}
}
././@LongLink 0000000 0000000 0000000 00000000146 00000000000 011566 L ustar root root maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/GraphVizVisualizer.java maven-antrun-extended-plugin-1.42/src/main/java/org/jvnet/maven/plugin/antrun/GraphVizVisualizer.jav0000644 0001750 0001750 00000010705 10740504262 034420 0 ustar jamespage jamespage package org.jvnet.maven.plugin.antrun;
import org.apache.commons.io.IOUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.HashMap;
/**
* Generates a dependency diagram by using GraphViz.
*
* @author Kohsuke Kawaguchi
*/
public class GraphVizVisualizer implements GraphVisitor {
private final PrintWriter out;
private final Map