You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jd...@apache.org on 2005/06/19 01:27:42 UTC
svn commit: r191311 - in /maven/components/trunk: maven-core-it/it0015/
maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/
maven-plugin-tools/maven-plugin-tools-marmalade/src/test/java/org/apache/maven/tools/plugin/extractor/marmalade/
Author: jdcasey
Date: Sat Jun 18 16:27:40 2005
New Revision: 191311
URL: http://svn.apache.org/viewcvs?rev=191311&view=rev
Log:
PR: MNG-414
Modified:
maven/components/trunk/maven-core-it/it0015/pom.xml
maven/components/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/AbstractScriptedMojoDescriptorExtractor.java
maven/components/trunk/maven-plugin-tools/maven-plugin-tools-marmalade/src/test/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractorTest.java
Modified: maven/components/trunk/maven-core-it/it0015/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0015/pom.xml?rev=191311&r1=191310&r2=191311&view=diff
==============================================================================
--- maven/components/trunk/maven-core-it/it0015/pom.xml (original)
+++ maven/components/trunk/maven-core-it/it0015/pom.xml Sat Jun 18 16:27:40 2005
@@ -22,15 +22,10 @@
</dependency>
</dependencies>
<build>
+ <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
- </resource>
- <resource>
- <directory>src/main/scripts</directory>
- <includes>
- <include>**/*.mmld</include>
- </includes>
</resource>
</resources>
</build>
Modified: maven/components/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/AbstractScriptedMojoDescriptorExtractor.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/AbstractScriptedMojoDescriptorExtractor.java?rev=191311&r1=191310&r2=191311&view=diff
==============================================================================
--- maven/components/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/AbstractScriptedMojoDescriptorExtractor.java (original)
+++ maven/components/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/AbstractScriptedMojoDescriptorExtractor.java Sat Jun 18 16:27:40 2005
@@ -5,8 +5,12 @@
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.IOUtil;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -29,7 +33,76 @@
List mojoDescriptors = extractMojoDescriptors( scriptFilesKeyedByBasedir, pluginDescriptor );
+ copyScriptsToOutputDirectory( scriptFilesKeyedByBasedir, project.getBuild().getOutputDirectory() );
+
return mojoDescriptors;
+ }
+
+ private void copyScriptsToOutputDirectory( Map scriptFilesKeyedByBasedir, String outputDirectory )
+ throws ExtractionException
+ {
+ File outputDir = new File( outputDirectory );
+
+ if ( !outputDir.exists() )
+ {
+ outputDir.mkdirs();
+ }
+
+ for ( Iterator it = scriptFilesKeyedByBasedir.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+
+ File sourceDir = new File( (String) entry.getKey() );
+
+ Set scripts = (Set) entry.getValue();
+
+ for ( Iterator scriptIterator = scripts.iterator(); scriptIterator.hasNext(); )
+ {
+ File scriptFile = (File) scriptIterator.next();
+
+ String relativePath = scriptFile.getPath().substring( sourceDir.getPath().length() );
+
+ if ( relativePath.charAt( 0 ) == File.separatorChar )
+ {
+ relativePath = relativePath.substring( 1 );
+ }
+
+ File outputFile = new File( outputDir, relativePath ).getAbsoluteFile();
+
+ if ( !outputFile.getParentFile().exists() )
+ {
+ outputFile.getParentFile().mkdirs();
+ }
+
+ FileInputStream in = null;
+ FileOutputStream out = null;
+
+ try
+ {
+ in = new FileInputStream( scriptFile );
+ out = new FileOutputStream( outputFile );
+
+ byte[] buffer = new byte[16];
+ int read = -1;
+
+ while ( ( read = in.read( buffer ) ) > -1 )
+ {
+ out.write( buffer, 0, read );
+ }
+
+ out.flush();
+ }
+ catch ( IOException e )
+ {
+ throw new ExtractionException( "Cannot copy script file: " + scriptFile + " to output: " + outputFile, e );
+ }
+ finally
+ {
+ IOUtil.close( in );
+ IOUtil.close( out );
+ }
+ }
+ }
}
protected abstract List extractMojoDescriptors( Map scriptFilesKeyedByBasedir, PluginDescriptor pluginDescriptor )
Modified: maven/components/trunk/maven-plugin-tools/maven-plugin-tools-marmalade/src/test/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractorTest.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-tools/maven-plugin-tools-marmalade/src/test/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractorTest.java?rev=191311&r1=191310&r2=191311&view=diff
==============================================================================
--- maven/components/trunk/maven-plugin-tools/maven-plugin-tools-marmalade/src/test/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractorTest.java (original)
+++ maven/components/trunk/maven-plugin-tools/maven-plugin-tools-marmalade/src/test/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractorTest.java Sat Jun 18 16:27:40 2005
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
@@ -33,6 +34,19 @@
public class MarmaladeMojoDescriptorExtractorTest
extends PlexusTestCase
{
+
+ private String findThisBasedir()
+ {
+ String myClassFile = getClass().getName().replace('.', '/') + ".class";
+
+ ClassLoader cloader = getClass().getClassLoader();
+
+ URL myClassResource = cloader.getResource( myClassFile );
+
+ String fullPath = myClassResource.getPath();
+
+ return fullPath.substring( 0, fullPath.length() - myClassFile.length() );
+ }
public void testShouldFindOneMojo()
throws Exception
@@ -48,6 +62,12 @@
System.out.println( "Basedir: " + basedir );
project.addScriptSourceRoot( basedir.getPath() );
+
+ Build build = new Build();
+
+ build.setOutputDirectory( findThisBasedir() );
+
+ project.setBuild( build );
MarmaladeMojoDescriptorExtractor extractor = (MarmaladeMojoDescriptorExtractor) lookup(
MojoDescriptorExtractor.ROLE, "marmalade" );
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org