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