1 package org.codehaus.plexus.compiler.eclipse;
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 import java.util.Arrays;
28 import java.util.Collection;
29 import java.util.Map;
30
31 import org.codehaus.plexus.compiler.AbstractCompilerTest;
32 import org.codehaus.plexus.compiler.Compiler;
33 import org.codehaus.plexus.compiler.CompilerConfiguration;
34
35
36
37
38 public class EclipseCompilerTest
39 extends AbstractCompilerTest
40 {
41
42 public void setUp()
43 throws Exception
44 {
45 super.setUp();
46
47 setCompilerDebug( true );
48 setCompilerDeprecationWarnings( true );
49 }
50
51 protected String getRoleHint()
52 {
53 return "eclipse";
54 }
55
56 protected int expectedErrors()
57 {
58 return 4;
59 }
60
61 protected int expectedWarnings()
62 {
63 return 2;
64 }
65
66 protected Collection<String> expectedOutputFiles()
67 {
68 return Arrays.asList( new String[] { "org/codehaus/foo/Deprecation.class", "org/codehaus/foo/ExternalDeps.class",
69 "org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class" } );
70 }
71
72
73 public void testCustomArgument()
74 throws Exception
75 {
76 org.codehaus.plexus.compiler.Compiler compiler = (Compiler) lookup( Compiler.ROLE, getRoleHint() );
77
78 CompilerConfiguration compilerConfig = createMinimalCompilerConfig();
79
80 compilerConfig.addCompilerCustomArgument( "-key", "value" );
81
82 compiler.performCompile( compilerConfig );
83 }
84
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.cleanKeyNames( 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
104 public void testInitializeWarningsForPropertiesArgument()
105 throws Exception
106 {
107 org.codehaus.plexus.compiler.Compiler compiler = (Compiler) lookup( Compiler.ROLE, getRoleHint() );
108
109 CompilerConfiguration compilerConfig = createMinimalCompilerConfig();
110
111 compilerConfig.addCompilerCustomArgument( "-properties", "file_does_not_exist" );
112
113 try
114 {
115 compiler.performCompile( compilerConfig );
116 fail( "looking up the properties file should have thrown an exception" );
117 }
118 catch ( IllegalArgumentException e )
119 {
120 assertEquals( "Properties file not exist", e.getMessage() );
121 }
122 }
123
124 private CompilerConfiguration createMinimalCompilerConfig()
125 {
126 CompilerConfiguration compilerConfig = new CompilerConfiguration();
127 compilerConfig.setOutputLocation( getBasedir() + "/target/" + getRoleHint() + "/classes-CustomArgument" );
128 return compilerConfig;
129 }
130
131 }