1 |
|
package org.apache.maven.tools.plugin.extractor.beanshell; |
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
import bsh.EvalError; |
23 |
|
import bsh.Interpreter; |
24 |
|
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; |
25 |
|
import org.apache.maven.plugin.descriptor.MojoDescriptor; |
26 |
|
import org.apache.maven.plugin.descriptor.PluginDescriptor; |
27 |
|
import org.apache.maven.tools.plugin.extractor.AbstractScriptedMojoDescriptorExtractor; |
28 |
|
import org.apache.maven.tools.plugin.extractor.ExtractionException; |
29 |
|
|
30 |
|
import java.io.File; |
31 |
|
import java.io.InputStreamReader; |
32 |
|
import java.util.ArrayList; |
33 |
|
import java.util.Iterator; |
34 |
|
import java.util.List; |
35 |
|
import java.util.Map; |
36 |
|
import java.util.Set; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
0 |
public class BeanshellMojoDescriptorExtractor |
45 |
|
extends AbstractScriptedMojoDescriptorExtractor |
46 |
|
{ |
47 |
|
private MojoDescriptor createMojoDescriptor( String basedir, String resource, PluginDescriptor pluginDescriptor ) |
48 |
|
throws InvalidPluginDescriptorException |
49 |
|
{ |
50 |
0 |
MojoDescriptor mojoDescriptor = new MojoDescriptor(); |
51 |
0 |
mojoDescriptor.setPluginDescriptor( pluginDescriptor ); |
52 |
|
|
53 |
0 |
mojoDescriptor.setLanguage( "bsh" ); |
54 |
0 |
mojoDescriptor.setComponentConfigurator( "bsh" ); |
55 |
|
|
56 |
0 |
mojoDescriptor.setImplementation( resource ); |
57 |
|
|
58 |
0 |
Interpreter interpreter = new Interpreter(); |
59 |
|
|
60 |
|
try |
61 |
|
{ |
62 |
0 |
interpreter.set( "file", new File( basedir, resource ) ); |
63 |
|
|
64 |
0 |
interpreter.set( "mojoDescriptor", mojoDescriptor ); |
65 |
|
|
66 |
0 |
interpreter.eval( new InputStreamReader( getClass().getResourceAsStream( "/extractor.bsh" ) ) ); |
67 |
|
} |
68 |
0 |
catch ( EvalError evalError ) |
69 |
|
{ |
70 |
0 |
throw new InvalidPluginDescriptorException( "Error scanning beanshell script", evalError ); |
71 |
0 |
} |
72 |
|
|
73 |
0 |
return mojoDescriptor; |
74 |
|
} |
75 |
|
|
76 |
|
protected String getScriptFileExtension() |
77 |
|
{ |
78 |
0 |
return ".bsh"; |
79 |
|
} |
80 |
|
|
81 |
|
protected List extractMojoDescriptors( Map scriptFilesKeyedByBasedir, PluginDescriptor pluginDescriptor ) |
82 |
|
throws ExtractionException, InvalidPluginDescriptorException |
83 |
|
{ |
84 |
0 |
List descriptors = new ArrayList(); |
85 |
|
|
86 |
0 |
for ( Iterator mapIterator = scriptFilesKeyedByBasedir.entrySet().iterator(); mapIterator.hasNext(); ) |
87 |
|
{ |
88 |
0 |
Map.Entry entry = (Map.Entry) mapIterator.next(); |
89 |
|
|
90 |
0 |
String basedir = (String) entry.getKey(); |
91 |
0 |
Set metadataFiles = (Set) entry.getValue(); |
92 |
|
|
93 |
0 |
for ( Iterator it = metadataFiles.iterator(); it.hasNext(); ) |
94 |
|
{ |
95 |
0 |
File scriptFile = (File) it.next(); |
96 |
|
|
97 |
0 |
String relativePath = null; |
98 |
|
|
99 |
0 |
if ( basedir.endsWith( "/" ) ) |
100 |
|
{ |
101 |
0 |
basedir = basedir.substring( 0, basedir.length() - 2 ); |
102 |
|
} |
103 |
|
|
104 |
0 |
relativePath = scriptFile.getPath().substring( basedir.length() ); |
105 |
|
|
106 |
0 |
relativePath = relativePath.replace( '\\', '/' ); |
107 |
|
|
108 |
0 |
MojoDescriptor mojoDescriptor = createMojoDescriptor( basedir, relativePath, pluginDescriptor ); |
109 |
0 |
descriptors.add( mojoDescriptor ); |
110 |
0 |
} |
111 |
0 |
} |
112 |
|
|
113 |
0 |
return descriptors; |
114 |
|
} |
115 |
|
} |