mirror of https://github.com/apache/maven.git
PR: MNG-414
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191311 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
385b7c96ae
commit
3e2449750d
|
@ -22,16 +22,11 @@
|
|||
</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>
|
||||
</model>
|
||||
|
|
|
@ -5,8 +5,12 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
|||
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,9 +33,78 @@ public abstract class AbstractScriptedMojoDescriptorExtractor
|
|||
|
||||
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 )
|
||||
throws ExtractionException, InvalidPluginDescriptorException;
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ package org.apache.maven.tools.plugin.extractor.marmalade;
|
|||
* 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 @@ import java.util.List;
|
|||
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 @@ public class MarmaladeMojoDescriptorExtractorTest
|
|||
|
||||
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" );
|
||||
|
|
Loading…
Reference in New Issue