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  import java.util.Arrays;
27  import java.util.Collection;
28  
29  import org.codehaus.plexus.compiler.AbstractCompilerTest;
30  import org.codehaus.plexus.compiler.CompilerConfiguration;
31  import org.junit.jupiter.api.BeforeEach;
32  import org.junit.jupiter.api.Test;
33  
34  import static org.junit.jupiter.api.Assertions.assertThrows;
35  import static org.junit.jupiter.api.Assertions.assertTrue;
36  
37  /**
38   * @author <a href="mailto:jason@plexus.org">Jason van Zyl</a>
39   */
40  public class EclipseCompilerTest extends AbstractCompilerTest {
41  
42      @BeforeEach
43      public void setUp() {
44          setCompilerDebug(true);
45          setCompilerDeprecationWarnings(true);
46      }
47  
48      @Override
49      protected String getRoleHint() {
50          return "eclipse";
51      }
52  
53      @Override
54      protected int expectedErrors() {
55          return 5;
56      }
57  
58      @Override
59      protected int expectedWarnings() {
60          return 1;
61      }
62  
63      @Override
64      protected Collection<String> expectedOutputFiles() {
65          String javaVersion = getJavaVersion();
66          if (javaVersion.contains("9.0")
67                  || javaVersion.contains("11")
68                  || javaVersion.contains("17")
69                  || javaVersion.contains("21")
70                  || javaVersion.contains("25")) {
71              return Arrays.asList(
72                      "org/codehaus/foo/Deprecation.class",
73                      "org/codehaus/foo/ExternalDeps.class",
74                      "org/codehaus/foo/Person.class");
75          }
76          return Arrays.asList(
77                  "org/codehaus/foo/Deprecation.class",
78                  "org/codehaus/foo/ExternalDeps.class",
79                  "org/codehaus/foo/Person.class",
80                  "org/codehaus/foo/ReservedWord.class");
81      }
82  
83      // The test is fairly meaningless as we can not validate anything
84      @Test
85      public void testCustomArgument() throws Exception {
86          CompilerConfiguration compilerConfig = createMinimalCompilerConfig();
87  
88          compilerConfig.addCompilerCustomArgument("-key", "value");
89  
90          getCompiler().performCompile(compilerConfig);
91      }
92  
93      @Test
94      public void testInitializeWarningsForPropertiesArgument() {
95          CompilerConfiguration compilerConfig = createMinimalCompilerConfig();
96  
97          compilerConfig.addCompilerCustomArgument("-properties", "file_does_not_exist");
98  
99          IllegalArgumentException e =
100                 assertThrows(IllegalArgumentException.class, () -> getCompiler().performCompile(compilerConfig));
101         assertTrue(e.getMessage().startsWith("Properties file"), "Message must start with 'Properties file'");
102     }
103 
104     private CompilerConfiguration createMinimalCompilerConfig() {
105         CompilerConfiguration compilerConfig = new CompilerConfiguration();
106         compilerConfig.setOutputLocation("target/" + getRoleHint() + "/classes-CustomArgument");
107         return compilerConfig;
108     }
109 }