View Javadoc
1   package org.codehaus.plexus.compiler.eclipse;
2   
3   /**
4    * The MIT License
5    *
6    * Copyright (c) 2005, The Codehaus
7    *
8    * Permission is hereby granted, free of charge, to any person obtaining a copy of
9    * this software and associated documentation files (the "Software"), to deal in
10   * the Software without restriction, including without limitation the rights to
11   * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12   * of the Software, and to permit persons to whom the Software is furnished to do
13   * so, subject to the following conditions:
14   *
15   * The above copyright notice and this permission notice shall be included in all
16   * copies or substantial portions of the Software.
17   *
18   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24   * SOFTWARE.
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   * @author <a href="mailto:jason@plexus.org">Jason van Zyl</a>
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      // The test is fairly meaningless as we can not validate anything
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 }