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 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
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
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 }