enumEntries = jar.entries();
18 | while (enumEntries.hasMoreElements()) {
19 | JarEntry file = enumEntries.nextElement();
20 | Path f = destDir.resolve(file.getName());
21 | if (!f.startsWith(toPath)) {
22 | throw new IOException("Bad zip entry");
23 | }
24 | if (file.isDirectory()) {
25 | Files.createDirectories(f);
26 | continue;
27 | }
28 | try (InputStream is = jar.getInputStream(file);
29 | OutputStream fos = Files.newOutputStream(f)) {
30 | while (is.available() > 0) {
31 | fos.write(is.read());
32 | }
33 | }
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-csharp/src/site/markdown/index.md:
--------------------------------------------------------------------------------
1 | Plexus C# Compiler
2 | ------------------
3 |
4 | C# Compiler support for Plexus Compiler component.
5 |
6 | **Requires** `JDK 8+`
7 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-csharp/src/site/site.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.codehaus.plexus
7 | plexus-compilers
8 | 2.15.1-SNAPSHOT
9 |
10 |
11 | plexus-compiler-eclipse
12 |
13 | Plexus Eclipse Compiler
14 | Eclipse Compiler support for Plexus Compiler component.
15 |
16 |
17 | 17
18 |
19 |
20 |
21 |
22 | org.codehaus.plexus
23 | plexus-utils
24 |
25 |
26 | org.eclipse.jdt
27 | ecj
28 | 3.41.0
29 |
30 |
31 | javax.inject
32 | javax.inject
33 |
34 |
35 | org.slf4j
36 | slf4j-api
37 |
38 |
39 | org.junit.jupiter
40 | junit-jupiter-params
41 | test
42 |
43 |
44 | org.hamcrest
45 | hamcrest
46 | test
47 |
48 |
49 | org.codehaus.plexus
50 | plexus-testing
51 | test
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EcjFailureException.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.compiler.eclipse;
2 |
3 | /**
4 | * @author Frits Jalvingh
5 | * Created on 22-4-18.
6 | */
7 | public class EcjFailureException extends RuntimeException {
8 | private final String ecjOutput;
9 |
10 | public EcjFailureException(String ecjOutput) {
11 | super("Failed to run the ecj compiler: " + ecjOutput);
12 | this.ecjOutput = ecjOutput;
13 | }
14 |
15 | public String getEcjOutput() {
16 | return ecjOutput;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/SourceCodeLocator.java:
--------------------------------------------------------------------------------
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.io.File;
27 | import java.util.HashMap;
28 | import java.util.List;
29 | import java.util.Map;
30 |
31 | /**
32 | * @author Trygve Laugstøl
33 | */
34 | public class SourceCodeLocator {
35 | private List sourceRoots;
36 |
37 | private Map cache;
38 |
39 | public SourceCodeLocator(List sourceRoots) {
40 | this.sourceRoots = sourceRoots;
41 |
42 | cache = new HashMap<>();
43 | }
44 |
45 | public File findSourceCodeForClass(String className) {
46 | File f = cache.get(className);
47 |
48 | if (f != null) {
49 | return f;
50 | }
51 |
52 | String sourceName =
53 | className.replace('.', System.getProperty("file.separator").charAt(0));
54 |
55 | sourceName += ".java";
56 |
57 | f = findInRoots(sourceName);
58 |
59 | cache.put(className, f);
60 |
61 | return f;
62 | }
63 |
64 | private File findInRoots(String s) {
65 | for (String root : sourceRoots) {
66 | File f = new File(root, s);
67 |
68 | if (f.exists()) {
69 | return f;
70 | }
71 | }
72 |
73 | return null;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/site/markdown/index.md:
--------------------------------------------------------------------------------
1 | Plexus Eclipse Compiler
2 | -----------------------
3 |
4 | Eclipse Compiler support for Plexus Compiler component.
5 |
6 | **Requires** `JDK 17+` and `Maven 3.9.6+`
7 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/site/site.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/test-input/src/main/org/codehaus/foo/Bad.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.foo;
2 |
3 | public class Bad
4 | {
5 | // Intentionally misspelled modifier.
6 | pubic String name;
7 | }
8 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/test-input/src/main/org/codehaus/foo/Deprecation.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.foo;
2 |
3 | public class Deprecation
4 | {
5 | public Deprecation()
6 | {
7 | new java.util.Date("testDate");
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/test-input/src/main/org/codehaus/foo/ExternalDeps.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.foo;
2 |
3 |
4 | import org.apache.commons.lang.StringUtils;
5 |
6 |
7 | public class ExternalDeps
8 | {
9 |
10 | public void hello( String str )
11 | {
12 | System.out.println( StringUtils.upperCase( str) );
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/test-input/src/main/org/codehaus/foo/Person.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.foo;
2 |
3 | public class Person
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/test-input/src/main/org/codehaus/foo/ReservedWord.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.foo;
2 |
3 | public class ReservedWord
4 | {
5 | String assert;
6 | }
7 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/test-input/src/main/org/codehaus/foo/UnknownSymbol.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.foo;
2 |
3 | public class UnknownSymbol
4 | {
5 | public UnknownSymbol()
6 | {
7 | foo();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/test-input/src/main/org/codehaus/foo/WrongClassname.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.foo;
2 |
3 | public class RightClassname
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerDashedArgumentsTest.java:
--------------------------------------------------------------------------------
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 javax.inject.Inject;
27 | import javax.inject.Named;
28 |
29 | import java.io.File;
30 | import java.util.Collections;
31 | import java.util.HashSet;
32 | import java.util.List;
33 | import java.util.Set;
34 |
35 | import org.codehaus.plexus.compiler.Compiler;
36 | import org.codehaus.plexus.compiler.CompilerConfiguration;
37 | import org.codehaus.plexus.testing.PlexusTest;
38 | import org.codehaus.plexus.util.FileUtils;
39 | import org.hamcrest.MatcherAssert;
40 | import org.hamcrest.Matchers;
41 | import org.junit.jupiter.api.Assertions;
42 | import org.junit.jupiter.api.Test;
43 |
44 | import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
45 |
46 | /**
47 | * @author Frits Jalvingh
48 | * Created on 22-4-18.
49 | */
50 | @PlexusTest
51 | public class EclipseCompilerDashedArgumentsTest {
52 |
53 | public static final String BAD_DOUBLEDASH_OPTION = "--grubbelparkplace";
54 |
55 | @Inject
56 | @Named("eclipse")
57 | Compiler compiler;
58 |
59 | private CompilerConfiguration getConfig() throws Exception {
60 | String sourceDir = getBasedir() + "/src/test-input/src/main";
61 |
62 | List filenames = FileUtils.getFileNames(new File(sourceDir), "**/*.java", null, false, true);
63 | Collections.sort(filenames);
64 | Set files = new HashSet<>();
65 | for (String filename : filenames) {
66 | files.add(new File(filename));
67 | }
68 |
69 | CompilerConfiguration compilerConfig = new CompilerConfiguration();
70 | compilerConfig.setDebug(false);
71 | compilerConfig.setShowDeprecation(false);
72 |
73 | // compilerConfig.setClasspathEntries( getClasspath() );
74 | compilerConfig.addSourceLocation(sourceDir);
75 | compilerConfig.setOutputLocation(getBasedir() + "/target/eclipse/classes");
76 | FileUtils.deleteDirectory(compilerConfig.getOutputLocation());
77 | // compilerConfig.addInclude( filename );
78 | compilerConfig.setForceJavacCompilerUse(false);
79 | compilerConfig.setSourceFiles(files);
80 |
81 | compilerConfig.setTargetVersion("1.8");
82 | compilerConfig.setSourceVersion("1.8");
83 | return compilerConfig;
84 | }
85 |
86 | /**
87 | * Start the eclipse compiler with a bad option that has two dashes. It should abort, and the error
88 | * message should show the actual bad option with two dashes. This ensures that both dashes are passed
89 | * to the compiler proper.
90 | *
91 | * This also tests that con-compile errors are shown properly, as the error caused by
92 | * the invalid option is not part of the error output but part of the data sent to stdout/stderr.
93 | */
94 | @Test
95 | public void testDoubleDashOptionsArePassedWithTwoDashes() throws Exception {
96 | CompilerConfiguration config = getConfig();
97 | config.addCompilerCustomArgument(BAD_DOUBLEDASH_OPTION, "b0rk3d");
98 |
99 | EcjFailureException x =
100 | Assertions.assertThrows(EcjFailureException.class, () -> compiler.performCompile(config));
101 |
102 | MatcherAssert.assertThat(x.getEcjOutput(), Matchers.containsString(BAD_DOUBLEDASH_OPTION));
103 | MatcherAssert.assertThat(x.getEcjOutput(), Matchers.not(Matchers.containsString("-" + BAD_DOUBLEDASH_OPTION)));
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerErrorsAsWarningsTest.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.compiler.eclipse;
2 |
3 | import java.util.Arrays;
4 | import java.util.Collection;
5 |
6 | import org.codehaus.plexus.compiler.AbstractCompilerTest;
7 | import org.codehaus.plexus.compiler.CompilerConfiguration;
8 | import org.junit.jupiter.api.BeforeEach;
9 |
10 | public class EclipseCompilerErrorsAsWarningsTest extends AbstractCompilerTest {
11 |
12 | protected void configureCompilerConfig(CompilerConfiguration compilerConfig) {
13 | compilerConfig.addCompilerCustomArgument("-errorsAsWarnings", "true");
14 | }
15 |
16 | @BeforeEach
17 | public void setUp() throws Exception {
18 | setCompilerDebug(true);
19 | setCompilerDeprecationWarnings(true);
20 | }
21 |
22 | @Override
23 | protected String getRoleHint() {
24 | return "eclipse";
25 | }
26 |
27 | @Override
28 | protected int expectedErrors() {
29 | return 0;
30 | }
31 |
32 | @Override
33 | protected int expectedWarnings() {
34 | return 6;
35 | }
36 |
37 | @Override
38 | protected Collection expectedOutputFiles() {
39 | String javaVersion = getJavaVersion();
40 | if (javaVersion.contains("9.0")
41 | || javaVersion.contains("11")
42 | || javaVersion.contains("17")
43 | || javaVersion.contains("21")
44 | || javaVersion.contains("24")) {
45 | return Arrays.asList(
46 | "org/codehaus/foo/Deprecation.class",
47 | "org/codehaus/foo/ExternalDeps.class",
48 | "org/codehaus/foo/Person.class");
49 | }
50 | return Arrays.asList(
51 | "org/codehaus/foo/Deprecation.class",
52 | "org/codehaus/foo/ExternalDeps.class",
53 | "org/codehaus/foo/Person.class",
54 | "org/codehaus/foo/ReservedWord.class");
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerFailOnWarningsTest.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.compiler.eclipse;
2 |
3 | import java.util.Arrays;
4 | import java.util.Collection;
5 |
6 | import org.codehaus.plexus.compiler.AbstractCompilerTest;
7 | import org.codehaus.plexus.compiler.CompilerConfiguration;
8 |
9 | public class EclipseCompilerFailOnWarningsTest extends AbstractCompilerTest {
10 |
11 | protected void configureCompilerConfig(CompilerConfiguration compilerConfig) {
12 | compilerConfig.setFailOnWarning(true);
13 | }
14 |
15 | @Override
16 | protected String getRoleHint() {
17 | return "eclipse";
18 | }
19 |
20 | @Override
21 | protected int expectedErrors() {
22 | return 5;
23 | }
24 |
25 | @Override
26 | protected int expectedWarnings() {
27 | return 0;
28 | }
29 |
30 | @Override
31 | protected Collection expectedOutputFiles() {
32 | String javaVersion = getJavaVersion();
33 | if (javaVersion.contains("9.0")
34 | || javaVersion.contains("11")
35 | || javaVersion.contains("17")
36 | || javaVersion.contains("21")
37 | || javaVersion.contains("24")) {
38 | return Arrays.asList(
39 | "org/codehaus/foo/Deprecation.class",
40 | "org/codehaus/foo/ExternalDeps.class",
41 | "org/codehaus/foo/Person.class");
42 | }
43 | return Arrays.asList(
44 | "org/codehaus/foo/Deprecation.class",
45 | "org/codehaus/foo/ExternalDeps.class",
46 | "org/codehaus/foo/Person.class",
47 | "org/codehaus/foo/ReservedWord.class");
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTckTest.java:
--------------------------------------------------------------------------------
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 org.codehaus.plexus.compiler.AbstractCompilerTckTest;
27 |
28 | /**
29 | * @author Trygve Laugstøl
30 | */
31 | public class EclipseCompilerTckTest extends AbstractCompilerTckTest {
32 | public EclipseCompilerTckTest() {
33 | this.roleHint = "eclipse";
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTest.java:
--------------------------------------------------------------------------------
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 Jason van Zyl
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 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("24")) {
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 | }
111 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompilerTest.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.compiler.eclipse;
2 |
3 | import java.util.List;
4 | import java.util.stream.Stream;
5 |
6 | import org.junit.jupiter.params.ParameterizedTest;
7 | import org.junit.jupiter.params.provider.Arguments;
8 | import org.junit.jupiter.params.provider.MethodSource;
9 |
10 | import static java.util.Arrays.asList;
11 | import static org.junit.jupiter.api.Assertions.assertEquals;
12 |
13 | class EclipseJavaCompilerTest {
14 | @ParameterizedTest
15 | @MethodSource("sources")
16 | void testReorderedSources(List expected, List inputSources) {
17 | List resorted = EclipseJavaCompiler.resortSourcesToPutModuleInfoFirst(inputSources);
18 |
19 | assertEquals(expected, resorted);
20 | }
21 |
22 | static Stream sources() {
23 | List expectedOrder = asList("module-info.java", "plexus/A.java", "plexus/B.java", "eclipse/A.java");
24 |
25 | List moduleInfoAlreadyFirst =
26 | asList("module-info.java", "plexus/A.java", "plexus/B.java", "eclipse/A.java");
27 |
28 | List moduleInfoSomewhereInTheMiddle =
29 | asList("plexus/A.java", "module-info.java", "plexus/B.java", "eclipse/A.java");
30 |
31 | List moduleInfoAsLast = asList("plexus/A.java", "plexus/B.java", "eclipse/A.java", "module-info.java");
32 |
33 | return Stream.of(
34 | Arguments.arguments(expectedOrder, moduleInfoAlreadyFirst),
35 | Arguments.arguments(expectedOrder, moduleInfoSomewhereInTheMiddle),
36 | Arguments.arguments(expectedOrder, moduleInfoAsLast));
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-eclipse/src/test/resources/org/codehaus/plexus/compiler/eclipse/EclipseCompilerConfigurationTest-test.properties:
--------------------------------------------------------------------------------
1 | foo=bar
2 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac-errorprone/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.codehaus.plexus
7 | plexus-compilers
8 | 2.15.1-SNAPSHOT
9 |
10 |
11 | plexus-compiler-javac-errorprone
12 |
13 | Plexus Javac+error-prone Component
14 | Javac Compiler support for Plexus Compiler component,
15 | with error-prone static analysis checks enabled.
16 | See https://errorprone.info
17 |
18 |
19 | 17
20 |
21 |
22 |
23 |
24 | org.codehaus.plexus
25 | plexus-compiler-javac
26 | ${project.version}
27 |
28 |
29 | com.google.errorprone
30 | error_prone_core
31 | ${errorprone.version}
32 |
33 |
34 | javax.inject
35 | javax.inject
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.apache.maven.plugins
43 | maven-surefire-plugin
44 |
45 | --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
46 | --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
47 | --add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
48 | --add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
49 | --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
50 | --add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
51 | --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
52 | --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
53 | --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
54 | --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac-errorprone/src/site/markdown/index.md:
--------------------------------------------------------------------------------
1 | Plexus Javac+error-prone Component
2 | ----------------------------------
3 |
4 | Javac Compiler support for Plexus Compiler component,
5 | with error-prone static analysis checks enabled.
6 |
7 | See https://errorprone.info
8 |
9 | **Requires** `JDK 17+`
10 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac-errorprone/src/site/site.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac-errorprone/src/test-input/src/main/ShortSet.java:
--------------------------------------------------------------------------------
1 | import java.util.Set;
2 | import java.util.HashSet;
3 |
4 | public class ShortSet {
5 | public static void main (String[] args) {
6 | Set s = new HashSet<>();
7 | for (short i = 0; i < 100; i++) {
8 | s.add(i);
9 | s.remove(i - 1);
10 | }
11 | System.out.println(s.size());
12 | }
13 | }
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac-errorprone/src/test/java/org/codehaus/plexus/compiler/javac/JavacErrorProneCompilerTest.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.compiler.javac;
2 |
3 | import org.codehaus.plexus.compiler.AbstractCompilerTest;
4 |
5 | /**
6 | * @author Jason van Zyl
7 | */
8 | public class JavacErrorProneCompilerTest extends AbstractCompilerTest {
9 |
10 | @Override
11 | protected String getRoleHint() {
12 | return "javac-with-errorprone";
13 | }
14 |
15 | @Override
16 | protected int expectedWarnings() {
17 | String javaVersion = getJavaVersion();
18 | if (javaVersion.startsWith("1.8")) {
19 | return 1;
20 | } else if (javaVersion.contains("18")
21 | || javaVersion.contains("19")
22 | || javaVersion.contains("20")
23 | || javaVersion.contains("21")
24 | || javaVersion.contains("22")
25 | || javaVersion.contains("23")
26 | || javaVersion.contains("24")) {
27 | return 5;
28 | }
29 | return 2;
30 | }
31 |
32 | @Override
33 | protected int expectedErrors() {
34 | return 1;
35 | }
36 |
37 | @Override
38 | public String getSourceVersion() {
39 | return "1.8";
40 | }
41 |
42 | @Override
43 | public String getTargetVersion() {
44 | return "1.8";
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.codehaus.plexus
7 | plexus-compilers
8 | 2.15.1-SNAPSHOT
9 |
10 |
11 | plexus-compiler-javac
12 |
13 | Plexus Javac Component
14 | Javac Compiler support for Plexus Compiler component.
15 |
16 |
17 |
18 | org.codehaus.plexus
19 | plexus-utils
20 |
21 |
22 | javax.inject
23 | javax.inject
24 |
25 |
26 | org.slf4j
27 | slf4j-api
28 |
29 |
30 | org.junit.jupiter
31 | junit-jupiter-params
32 | test
33 |
34 |
35 | org.hamcrest
36 | hamcrest
37 | test
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/InProcessCompiler.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.compiler.javac;
2 |
3 | import org.codehaus.plexus.compiler.CompilerConfiguration;
4 | import org.codehaus.plexus.compiler.CompilerException;
5 | import org.codehaus.plexus.compiler.CompilerResult;
6 |
7 | public interface InProcessCompiler {
8 |
9 | CompilerResult compileInProcess(String[] args, final CompilerConfiguration config, String[] sourceFiles)
10 | throws CompilerException;
11 | }
12 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/IsolatedClassLoader.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.compiler.javac;
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.net.URL;
27 | import java.net.URLClassLoader;
28 |
29 | public class IsolatedClassLoader extends URLClassLoader {
30 | private ClassLoader parentClassLoader = ClassLoader.getSystemClassLoader();
31 |
32 | public IsolatedClassLoader() {
33 | super(new URL[0], null);
34 | }
35 |
36 | public void addURL(URL url) {
37 | super.addURL(url);
38 | }
39 |
40 | public synchronized Class> loadClass(String className) throws ClassNotFoundException {
41 | Class> c = findLoadedClass(className);
42 |
43 | ClassNotFoundException ex = null;
44 |
45 | if (c == null) {
46 | try {
47 | c = findClass(className);
48 | } catch (ClassNotFoundException e) {
49 | ex = e;
50 |
51 | if (parentClassLoader != null) {
52 | c = parentClassLoader.loadClass(className);
53 | }
54 | }
55 | }
56 |
57 | if (c == null) {
58 | throw ex;
59 | }
60 |
61 | return c;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac/src/site/markdown/index.md:
--------------------------------------------------------------------------------
1 | Plexus Javac Component
2 | ----------------------
3 |
4 | Javac Compiler support for Plexus Compiler component.
5 |
6 | **Requires** `JDK 8+`
7 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac/src/site/site.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac/src/test-input/src/main/org/codehaus/foo/Bad.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.foo;
2 |
3 | public class Bad
4 | {
5 | // Intentionally misspelled modifier.
6 | pubic String name;
7 | }
8 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac/src/test-input/src/main/org/codehaus/foo/Deprecation.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.foo;
2 |
3 | public class Deprecation
4 | {
5 | public Deprecation()
6 | {
7 | new java.util.Date("testDate");
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac/src/test-input/src/main/org/codehaus/foo/ExternalDeps.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.foo;
2 |
3 | import org.apache.commons.lang.StringUtils;
4 |
5 | public class ExternalDeps
6 | {
7 | public void hello( String str )
8 | {
9 | System.out.println( StringUtils.upperCase( str) );
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac/src/test-input/src/main/org/codehaus/foo/Person.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.foo;
2 |
3 | public class Person
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac/src/test-input/src/main/org/codehaus/foo/ReservedWord.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.foo;
2 |
3 | public class ReservedWord
4 | {
5 | String assert;
6 | }
7 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac/src/test-input/src/main/org/codehaus/foo/UnknownSymbol.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.foo;
2 |
3 | public class UnknownSymbol
4 | {
5 | public UnknownSymbol()
6 | {
7 | foo();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac/src/test-input/src/main/org/codehaus/foo/WrongClassname.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.foo;
2 |
3 | public class RightClassname
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavaxToolsCompilerTest.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.compiler.javac;
2 | /*
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | */
20 |
21 | /**
22 | * @author Olivier Lamy
23 | */
24 | public class JavaxToolsCompilerTest extends AbstractJavacCompilerTest {
25 | // no op default is to javax.tools if available
26 |
27 | @Override
28 | protected int expectedWarnings() {
29 | String javaVersion = getJavaVersion();
30 | if (javaVersion.contains("21") || javaVersion.contains("24")) {
31 | return 1;
32 | } else {
33 | return super.expectedWarnings();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/plexus-compilers/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.codehaus.plexus
7 | plexus-compiler
8 | 2.15.1-SNAPSHOT
9 |
10 |
11 | plexus-compilers
12 | pom
13 |
14 | Plexus Compilers
15 |
16 |
17 | plexus-compiler-aspectj
18 | plexus-compiler-csharp
19 | plexus-compiler-eclipse
20 | plexus-compiler-javac
21 | plexus-compiler-javac-errorprone
22 |
23 |
24 |
25 |
26 | org.junit.jupiter
27 | junit-jupiter-api
28 | test
29 |
30 |
31 | org.codehaus.plexus
32 | plexus-compiler-api
33 |
34 |
35 | org.codehaus.plexus
36 | plexus-compiler-test
37 | test
38 |
39 |
40 |
41 | commons-lang
42 | commons-lang
43 | 2.0
44 | test
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/src/site/apt/index.apt:
--------------------------------------------------------------------------------
1 | ------
2 | Plexus Compiler
3 | ------
4 | Hervé Boutemy
5 | ------
6 | 2012-05-08
7 | ------
8 |
9 | ~~ Licensed to the Apache Software Foundation (ASF) under one
10 | ~~ or more contributor license agreements. See the NOTICE file
11 | ~~ distributed with this work for additional information
12 | ~~ regarding copyright ownership. The ASF licenses this file
13 | ~~ to you under the Apache License, Version 2.0 (the
14 | ~~ "License"); you may not use this file except in compliance
15 | ~~ with the License. You may obtain a copy of the License at
16 | ~~
17 | ~~ http://www.apache.org/licenses/LICENSE-2.0
18 | ~~
19 | ~~ Unless required by applicable law or agreed to in writing,
20 | ~~ software distributed under the License is distributed on an
21 | ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22 | ~~ KIND, either express or implied. See the License for the
23 | ~~ specific language governing permissions and limitations
24 | ~~ under the License.
25 |
26 | ~~ NOTE: For help with the syntax of this file, see:
27 | ~~ http://maven.apache.org/doxia/references/apt-format.html
28 |
29 | Plexus Compiler
30 |
31 | Plexus Compiler is a Plexus component to use different compilers through a uniform API.
32 |
33 | It is composed by:
34 |
35 | * {{{./plexus-compiler-api/}<<>>}}: the API to use compilers,
36 |
37 | * {{{./plexus-compiler-manager/}<<>>}}: a manager to choose a compiler,
38 |
39 | * {{{./plexus-compilers/}<<>>}}: different compilers
40 |
41 | * {{{./plexus-compilers/plexus-compiler-aspectj/}<<>>}}: AspectJ compiler, <> <<>> and <<>>
42 |
43 | * {{{./plexus-compilers/plexus-compiler-csharp/}<<>>}}: C#/Mono compiler, <> <<>>
44 |
45 | * {{{./plexus-compilers/plexus-compiler-eclipse/}<<>>}}: Eclipse compiler, <> <<>> and <<>>
46 |
47 | * {{{./plexus-compilers/plexus-compiler-javac/}<<>>}}: javac compiler, <> <<>>
48 |
49 | * {{{./plexus-compilers/plexus-compiler-javac-errorprone/}<<>>}}: javac compiler with {{{https://errorprone.info}error-prone}} static analysis checks enabled, <> <<>>
50 |
51 | []
52 |
53 | * {{{./plexus-compiler-test/}<<>>}}: a test harness.
54 |
55 | []
56 |
--------------------------------------------------------------------------------
/src/site/site.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------