Skip to content

Commit 63b5fa6

Browse files
fjalvingholamy
authored andcommitted
Fix passing extra options (do not remove dashes), let the compiler itself check the version number as Java releases now come every half year.
1 parent c4537b5 commit 63b5fa6

File tree

2 files changed

+6
-49
lines changed

2 files changed

+6
-49
lines changed

plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import java.io.StringWriter;
4141
import java.util.ArrayList;
4242
import java.util.Collections;
43-
import java.util.LinkedHashMap;
4443
import java.util.List;
4544
import java.util.Map;
4645
import java.util.Map.Entry;
@@ -125,7 +124,7 @@ public CompilerResult performCompile(CompilerConfiguration config )
125124

126125
// Set Eclipse-specific options
127126
// compiler-specific extra options override anything else in the config object...
128-
Map<String, String> extras = removeDashesFromAllKeys( config.getCustomCompilerArgumentsAsMap() );
127+
Map<String, String> extras = config.getCustomCompilerArgumentsAsMap();
129128
if( extras.containsKey( "errorsAsWarnings" ) )
130129
{
131130
extras.remove( "errorsAsWarnings" );
@@ -137,21 +136,19 @@ else if(extras.containsKey("-errorsAsWarnings"))
137136
this.errorsAsWarnings = true;
138137
}
139138

140-
//-- Handle the properties silliness
141-
String props = extras.get("properties");
142-
if(null == props)
143-
props = extras.get("properties");
139+
//-- check for existence of the properties file manually
140+
String props = extras.get("-properties");
144141
if(null != props) {
145142
File propFile = new File(props);
146143
if(! propFile.exists() || ! propFile.isFile())
147-
throw new IllegalArgumentException("Properties file " + propFile + " does not exist");
144+
throw new IllegalArgumentException("Properties file specified by -properties " + propFile + " does not exist");
148145
}
149146

150147
for(Entry<String, String> entry : extras.entrySet())
151148
{
152149
String opt = entry.getKey();
153150
if(! opt.startsWith("-"))
154-
opt = "-" + opt; // This is beyond sad
151+
opt = "-" + opt; // compiler mojo apparently messes with this; make sure we are safe
155152
args.add(opt);
156153
String value = entry.getValue();
157154
if(null != value && ! value.isEmpty())
@@ -201,7 +198,7 @@ else if(extras.containsKey("-errorsAsWarnings"))
201198
}
202199

203200
//-- Write .class files even when error occur, but make sure methods with compile errors do abort when called
204-
if(extras.containsKey("-proceedOnError") || extras.containsKey("proceedOnError"))
201+
if(extras.containsKey("-proceedOnError"))
205202
args.add("-proceedOnError:Fatal"); // Generate a class file even with errors, but make methods with errors fail when called
206203

207204
//-- classpath
@@ -299,26 +296,6 @@ private boolean isPreJava16(CompilerConfiguration config) {
299296
|| s.startsWith( "1.1" ) || s.startsWith( "1.0" );
300297
}
301298

302-
/**
303-
* The compiler mojo adds a dash to all keys which does not make sense for the eclipse compiler
304-
*/
305-
Map<String, String> removeDashesFromAllKeys(Map<String, String> customCompilerArgumentsAsMap )
306-
{
307-
LinkedHashMap<String, String> cleanedMap = new LinkedHashMap<String, String>();
308-
309-
for ( Map.Entry<String, String> entry : customCompilerArgumentsAsMap.entrySet() )
310-
{
311-
String key = entry.getKey();
312-
if ( key.startsWith( "-" ) )
313-
{
314-
key = key.substring( 1 );
315-
}
316-
cleanedMap.put( key, entry.getValue() );
317-
}
318-
319-
return cleanedMap;
320-
}
321-
322299
public String[] createCommandLine( CompilerConfiguration config )
323300
throws CompilerException
324301
{

plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTest.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
import java.util.Arrays;
3232
import java.util.Collection;
33-
import java.util.Map;
3433

3534
/**
3635
* @author <a href="mailto:[email protected]">Jason van Zyl</a>
@@ -82,25 +81,6 @@ public void testCustomArgument()
8281
compiler.performCompile( compilerConfig );
8382
}
8483

85-
public void testCustomArgumentCleanup()
86-
{
87-
EclipseJavaCompiler compiler = new EclipseJavaCompiler();
88-
89-
CompilerConfiguration compilerConfig = createMinimalCompilerConfig();
90-
91-
compilerConfig.addCompilerCustomArgument( "-key", "value" );
92-
compilerConfig.addCompilerCustomArgument( "cleanKey", "value" );
93-
94-
Map<String, String> cleaned = compiler.removeDashesFromAllKeys( compilerConfig.getCustomCompilerArgumentsAsMap() );
95-
96-
assertTrue( "Key should have been cleaned", cleaned.containsKey( "key" ) );
97-
98-
assertFalse( "Key should have been cleaned", cleaned.containsKey( "-key" ) );
99-
100-
assertTrue( "This key should not have been cleaned does not start with dash", cleaned.containsKey( "cleanKey" ) );
101-
102-
}
103-
10484
public void testInitializeWarningsForPropertiesArgument()
10585
throws Exception
10686
{

0 commit comments

Comments
 (0)