This repository has been archived by the owner on Oct 14, 2020. It is now read-only.
forked from develar/flexmojos
/
DefaultFlexCompiler.java
137 lines (125 loc) · 4.56 KB
/
DefaultFlexCompiler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package org.sonatype.flexmojos.compiler;
import java.lang.reflect.Method;
import java.util.List;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.sonatype.flexmojos.compiler.command.Command;
import org.sonatype.flexmojos.compiler.command.CommandUtil;
import org.sonatype.flexmojos.compiler.command.Result;
import org.sonatype.flexmojos.compiler.util.FlexCompilerArgumentParser;
import flex2.tools.ASDoc;
import flex2.tools.Compc;
import flex2.tools.DigestTool;
import flex2.tools.Mxmlc;
import flex2.tools.Optimizer;
@Component( role = FlexCompiler.class )
public class DefaultFlexCompiler
extends AbstractLogEnabled
implements FlexCompiler
{
@Requirement
private FlexCompilerArgumentParser parser;
public Result compileSwc( final ICompcConfiguration configuration, boolean sychronize )
throws Exception
{
return CommandUtil.execute( new Command()
{
public void command()
throws Exception
{
String[] args = parser.parseArguments( configuration, ICompcConfiguration.class );
logArgs( args );
Compc.compc( args );
}
}, sychronize );
}
public Result compileSwf( MxmlcConfigurationHolder cfgHolder, boolean sychronize )
throws Exception
{
final List<String> argsList =
parser.getArgumentsList( cfgHolder.configuration, ICommandLineConfiguration.class );
if ( cfgHolder.sourceFile != null )
{
argsList.add( cfgHolder.sourceFile.getAbsolutePath() );
}
return CommandUtil.execute( new Command()
{
public void command()
{
String[] args = argsList.toArray( new String[argsList.size()] );
logArgs( args );
Mxmlc.mxmlc( args );
}
}, sychronize );
}
public Result asdoc( final IASDocConfiguration configuration, boolean sychronize )
throws Exception
{
return CommandUtil.execute( new Command()
{
public void command()
{
String[] args = parser.parseArguments( configuration, IASDocConfiguration.class );
logArgs( args );
// Force the XML Transformer to the Xalan version that comes with Flex
String defaultTransfomer = System.getProperty( "javax.xml.transform.TransformerFactory" );
System.setProperty( "javax.xml.transform.TransformerFactory",
"org.apache.xalan.processor.TransformerFactoryImpl" );
ASDoc.main( args );
// and set it back to the default
System.setProperty( "javax.xml.transform.TransformerFactory", defaultTransfomer );
}
}, sychronize );
}
public Result digest( final IDigestConfiguration configuration, boolean sychronize )
throws Exception
{
return CommandUtil.execute( new Command()
{
public void command()
throws Exception
{
String[] args = parser.parseArguments( configuration, IDigestConfiguration.class );
logArgs( args );
Method m = DigestTool.class.getDeclaredMethod( "digestTool", String[].class );
m.setAccessible( true );
m.invoke( null, new Object[] { args } );
}
}, sychronize );
}
public Result optimize( final IOptimizerConfiguration configuration, boolean sychronize )
throws Exception
{
return CommandUtil.execute( new Command()
{
public void command()
throws Exception
{
String[] args = parser.parseArguments( configuration, IOptimizerConfiguration.class );
logArgs( args );
Optimizer.main( args );
}
}, sychronize );
}
private void logArgs( String[] args )
{
if ( getLogger().isDebugEnabled() )
{
StringBuilder sb = new StringBuilder();
for ( String arg : args )
{
if ( arg.startsWith( "-" ) )
{
sb.append( '\n' );
}
sb.append( arg );
sb.append( ' ' );
}
synchronized ( getLogger() )
{
getLogger().debug( "Compilation arguments:" + sb );
}
}
}
}