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 4;
57      }
58  
59      @Override
60      protected int expectedWarnings() {
61          return 2;
62      }
63  
64      @Override
65      protected Collection<String> expectedOutputFiles() {
66          return Arrays.asList(
67                  "org/codehaus/foo/Deprecation.class",
68                  "org/codehaus/foo/ExternalDeps.class",
69                  "org/codehaus/foo/Person.class",
70                  "org/codehaus/foo/ReservedWord.class");
71      }
72  
73      // The test is fairly meaningless as we can not validate anything
74      @Test
75      public void testCustomArgument() throws Exception {
76          CompilerConfiguration compilerConfig = createMinimalCompilerConfig();
77  
78          compilerConfig.addCompilerCustomArgument("-key", "value");
79  
80          getCompiler().performCompile(compilerConfig);
81      }
82  
83      @Test
84      public void testInitializeWarningsForPropertiesArgument() {
85          CompilerConfiguration compilerConfig = createMinimalCompilerConfig();
86  
87          compilerConfig.addCompilerCustomArgument("-properties", "file_does_not_exist");
88  
89          IllegalArgumentException e =
90                  assertThrows(IllegalArgumentException.class, () -> getCompiler().performCompile(compilerConfig));
91          assertThat("Message must start with 'Properties file'", e.getMessage(), startsWith("Properties file"));
92      }
93  
94      private CompilerConfiguration createMinimalCompilerConfig() {
95          CompilerConfiguration compilerConfig = new CompilerConfiguration();
96          compilerConfig.setOutputLocation("target/" + getRoleHint() + "/classes-CustomArgument");
97          return compilerConfig;
98      }
99  }