From e37cfc42099dea3ca455c81d7b0d68695036b60e Mon Sep 17 00:00:00 2001 From: Jason Faust Date: Mon, 24 Sep 2018 21:15:33 -0400 Subject: [PATCH 1/2] Updates to allow for easer testing of Eclipse compiler. * Treating compiler output at Note level separate from warnings * Passing filename of to-be-compiled source to configureCompilerConfig() --- .../plexus/compiler/AbstractCompilerTest.java | 95 +++++++++++++++---- 1 file changed, 76 insertions(+), 19 deletions(-) diff --git a/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java b/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java index 9c1c9d42..75e45514 100644 --- a/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java +++ b/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java @@ -1,6 +1,4 @@ -package org.codehaus.plexus.compiler; - -/** +/* * The MIT License * * Copyright (c) 2004, The Codehaus @@ -23,17 +21,17 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +package org.codehaus.plexus.compiler; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.artifact.test.ArtifactTestCase; import org.apache.maven.artifact.versioning.VersionRange; - +import org.codehaus.plexus.compiler.CompilerMessage.Kind; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.StringUtils; -import javax.print.DocFlavor; import java.io.File; import java.util.ArrayList; import java.util.Collection; @@ -42,9 +40,6 @@ import java.util.List; import java.util.TreeSet; -/** - * - */ public abstract class AbstractCompilerTest extends ArtifactTestCase { @@ -91,6 +86,22 @@ protected void configureCompilerConfig( CompilerConfiguration compilerConfig ) } + + /** + * Called once per compile iteration to allow configuration customization for + * tests. + * + * @param compilerConfig + * configuration used for this compile iteration. + * @param filename + * file about to be compiled this iteration. + * @Since 2.8.6 + */ + protected void configureCompilerConfig(CompilerConfiguration compilerConfig, String filename) + { + configureCompilerConfig( compilerConfig ); + } + public void testCompilingSources() throws Exception { @@ -113,14 +124,16 @@ public void testCompilingSources() int numCompilerErrors = compilerErrorCount( messages ); - int numCompilerWarnings = messages.size() - numCompilerErrors; + int numCompilerWarnings = compilerWarningCount( messages ); + + int numCompilerNotes = compilerNoteCount( messages ); if ( expectedErrors() != numCompilerErrors ) { System.out.println( numCompilerErrors + " error(s) found:" ); for ( CompilerMessage error : messages ) { - if ( !error.isError() ) + if ( error.getKind() != Kind.ERROR ) { continue; } @@ -139,7 +152,7 @@ public void testCompilingSources() System.out.println( numCompilerWarnings + " warning(s) found:" ); for ( CompilerMessage error : messages ) { - if ( error.isError() ) + if ( error.getKind() == Kind.ERROR || error.getKind() == Kind.NOTE ) { continue; } @@ -153,6 +166,25 @@ public void testCompilingSources() assertEquals( "Wrong number of compilation warnings.", expectedWarnings(), numCompilerWarnings ); } + if ( expectedNotes() != numCompilerNotes ) + { + System.out.println( numCompilerWarnings + " notes(s) found:" ); + for (CompilerMessage error : messages) + { + if ( error.getKind() != Kind.NOTE ) + { + continue; + } + + System.out.println( "----" ); + System.out.println( error.getFile() ); + System.out.println( error.getMessage() ); + System.out.println( "----" ); + } + + assertEquals( "Wrong number of compilation notes.", expectedNotes(), numCompilerNotes ); + } + assertEquals( new TreeSet<>( normalizePaths( expectedOutputFiles() ) ), files ); } @@ -190,7 +222,7 @@ private List getCompilerConfigurations() compilerConfig.setForceJavacCompilerUse( this.forceJavacCompilerUse ); - configureCompilerConfig( compilerConfig ); + configureCompilerConfig( compilerConfig, filename ); String target = getTargetVersion(); if( StringUtils.isNotEmpty( target) ) @@ -221,7 +253,6 @@ public String getSourceVersion() return null; } - private List normalizePaths( Collection relativePaths ) { List normalizedPaths = new ArrayList(); @@ -232,16 +263,32 @@ private List normalizePaths( Collection relativePaths ) return normalizedPaths; } - protected int compilerErrorCount( List messages ) + private int compilerErrorCount(List messages) + { + return countKind( messages, Kind.ERROR ); + } + + private int compilerWarningCount(List messages) + { + return messages.size() - (compilerErrorCount( messages ) + compilerNoteCount( messages )); + } + + private int compilerNoteCount(List messages) { - int count = 0; + return countKind( messages, Kind.NOTE ); + } - for ( CompilerMessage message : messages ) + private int countKind(List messages, Kind kind) + { + int c = 0; + for (CompilerMessage message : messages) { - count += message.isError() ? 1 : 0; + if ( message.getKind() == kind ) + { + c++; + } } - - return count; + return c; } protected int expectedErrors() @@ -254,6 +301,16 @@ protected int expectedWarnings() return 0; } + /** + * Count of output generated at the {@link Kind#NOTE} level. + * + * @return count + */ + protected int expectedNotes() + { + return 0; + } + protected Collection expectedOutputFiles() { return Collections.emptyList(); From 91eee8fde501583692aa5b27124c0fbfe7bd2e70 Mon Sep 17 00:00:00 2001 From: Jason Faust Date: Mon, 24 Sep 2018 22:43:36 -0400 Subject: [PATCH 2/2] Refactored Eclipse Compiler tests * ECJ updated to 3.14.0 * Change of IllegalArgumentException into the ECJ Exception --- .../plexus-compiler-eclipse/pom.xml | 2 +- .../compiler/eclipse/EclipseJavaCompiler.java | 3 +- .../src/main/org/codehaus/foo/Info.java | 7 ++ .../eclipse/AbstractEclipseCompilerTest.java | 100 ++++++++++++++++ .../eclipse/EclipseCompilerBasicTest.java | 31 +++++ .../EclipseCompilerCustomArgumentTest.java | 58 +++++++++ .../EclipseCompilerDashedArgumentsTest.java | 89 ++++---------- .../EclipseCompilerErrorsAsWarningsTest.java | 52 ++------ ...lizeWarningsForPropertiesArgumentTest.java | 58 +++++++++ .../eclipse/EclipseCompilerTckTest.java | 14 +-- .../compiler/eclipse/EclipseCompilerTest.java | 111 ------------------ 11 files changed, 297 insertions(+), 228 deletions(-) create mode 100644 plexus-compilers/plexus-compiler-eclipse/src/test-input/src/main/org/codehaus/foo/Info.java create mode 100644 plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/AbstractEclipseCompilerTest.java create mode 100644 plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerBasicTest.java create mode 100644 plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerCustomArgumentTest.java create mode 100644 plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerInitializeWarningsForPropertiesArgumentTest.java delete mode 100644 plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTest.java diff --git a/plexus-compilers/plexus-compiler-eclipse/pom.xml b/plexus-compilers/plexus-compiler-eclipse/pom.xml index 2e1f1235..e9bc3dc6 100644 --- a/plexus-compilers/plexus-compiler-eclipse/pom.xml +++ b/plexus-compilers/plexus-compiler-eclipse/pom.xml @@ -21,7 +21,7 @@ org.eclipse.jdt ecj - 3.13.100 + 3.14.0 diff --git a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java index 3f84de5f..bf3b2054 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java @@ -35,7 +35,6 @@ import org.eclipse.jdt.core.compiler.batch.BatchCompiler; import java.io.File; -import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; @@ -143,7 +142,7 @@ else if(extras.containsKey("-errorsAsWarnings")) if(null != props) { File propFile = new File(props); if(! propFile.exists() || ! propFile.isFile()) - throw new IllegalArgumentException("Properties file specified by -properties " + propFile + " does not exist"); + throw new EcjFailureException("Properties file specified by -properties " + propFile + " does not exist"); } for(Entry entry : extras.entrySet()) diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test-input/src/main/org/codehaus/foo/Info.java b/plexus-compilers/plexus-compiler-eclipse/src/test-input/src/main/org/codehaus/foo/Info.java new file mode 100644 index 00000000..a5cf7082 --- /dev/null +++ b/plexus-compilers/plexus-compiler-eclipse/src/test-input/src/main/org/codehaus/foo/Info.java @@ -0,0 +1,7 @@ +package org.codehaus.foo; + +public class Info { + { + "".equals(1); + } +} diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/AbstractEclipseCompilerTest.java b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/AbstractEclipseCompilerTest.java new file mode 100644 index 00000000..08f28aa6 --- /dev/null +++ b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/AbstractEclipseCompilerTest.java @@ -0,0 +1,100 @@ +/* + * The MIT License + * + * Copyright (c) 2005, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.codehaus.plexus.compiler.eclipse; + +import java.util.Arrays; +import java.util.Collection; + +import org.codehaus.plexus.compiler.AbstractCompilerTest; +import org.codehaus.plexus.compiler.CompilerConfiguration; + +/** + * @author Jason van Zyl + * @author Jason Faust + */ +public abstract class AbstractEclipseCompilerTest extends AbstractCompilerTest { + + private int expectedErrors; + private int expectedWarnings; + private int expectedNotes; + private Collection expectedOutputFiles; + + protected AbstractEclipseCompilerTest() { + this(5, 1, 1); + } + + protected AbstractEclipseCompilerTest(int expectedErrors, int expectedWarnings, int expectedNotes) { + this(expectedErrors, expectedWarnings, expectedNotes, Arrays + .asList(new String[] { + "org/codehaus/foo/Deprecation.class", + "org/codehaus/foo/ExternalDeps.class", + "org/codehaus/foo/Info.class", + "org/codehaus/foo/Person.class" })); + } + + protected AbstractEclipseCompilerTest(int expectedErrors, int expectedWarnings, int expectedNotes, + Collection expectedOutputFiles) { + this.expectedErrors = expectedErrors; + this.expectedWarnings = expectedWarnings; + this.expectedNotes = expectedNotes; + this.expectedOutputFiles = expectedOutputFiles; + } + + public void setUp() throws Exception { + super.setUp(); + + setCompilerDebug(true); + setCompilerDeprecationWarnings(true); + } + + @Override + protected String getRoleHint() { + return "eclipse"; + } + + @Override + protected int expectedErrors() { + return expectedErrors; + } + + @Override + protected int expectedWarnings() { + return expectedWarnings; + } + + @Override + protected int expectedNotes() { + return expectedNotes; + } + + protected Collection expectedOutputFiles() { + return expectedOutputFiles; + } + + @Override + protected void configureCompilerConfig(CompilerConfiguration compilerConfig) { + compilerConfig.setSourceVersion("1.8"); + compilerConfig.setTargetVersion("1.8"); + } +} diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerBasicTest.java b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerBasicTest.java new file mode 100644 index 00000000..976ac71c --- /dev/null +++ b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerBasicTest.java @@ -0,0 +1,31 @@ +/* + * The MIT License + * + * Copyright (c) 2005, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.codehaus.plexus.compiler.eclipse; + +/** + * @author Jason van Zyl + * @author Jason Faust + */ +public class EclipseCompilerBasicTest extends AbstractEclipseCompilerTest { +} diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerCustomArgumentTest.java b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerCustomArgumentTest.java new file mode 100644 index 00000000..19267c10 --- /dev/null +++ b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerCustomArgumentTest.java @@ -0,0 +1,58 @@ +/* + * The MIT License + * + * Copyright (c) 2005, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.codehaus.plexus.compiler.eclipse; + +import java.util.Collections; + +import org.codehaus.plexus.compiler.CompilerConfiguration; + +/** + * @author Jason van Zyl + * @author Jason Faust + */ +public class EclipseCompilerCustomArgumentTest extends AbstractEclipseCompilerTest { + + @SuppressWarnings("unchecked") + public EclipseCompilerCustomArgumentTest() { + super(0, 0, 0, Collections.EMPTY_LIST); + } + + @Override + protected void configureCompilerConfig(CompilerConfiguration compilerConfig) { + super.configureCompilerConfig(compilerConfig); + compilerConfig.addCompilerCustomArgument("-key", "value"); + } + + @Override + public void testCompilingSources() throws Exception { + try { + super.testCompilingSources(); + fail("Compile should of thrown an exception"); + } catch (EcjFailureException e) { + assertTrue("Unexpected compiler error", + e.getMessage().startsWith("Failed to run the ecj compiler: Unrecognized option : -key")); + } + } + +} diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerDashedArgumentsTest.java b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerDashedArgumentsTest.java index 8e9486e0..7aff197d 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerDashedArgumentsTest.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerDashedArgumentsTest.java @@ -1,6 +1,4 @@ -package org.codehaus.plexus.compiler.eclipse; - -/** +/* * The MIT License * * Copyright (c) 2005, The Codehaus @@ -23,78 +21,43 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +package org.codehaus.plexus.compiler.eclipse; -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.compiler.Compiler; -import org.codehaus.plexus.compiler.CompilerConfiguration; -import org.codehaus.plexus.util.FileUtils; -import org.junit.Assert; - -import java.io.File; import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; + +import org.codehaus.plexus.compiler.CompilerConfiguration; /** + * Created on 2018-04-22. + * * @author Frits Jalvingh - * Created on 22-4-18. + * @author Jason Faust */ -public class EclipseCompilerDashedArgumentsTest extends PlexusTestCase { +public class EclipseCompilerDashedArgumentsTest extends AbstractEclipseCompilerTest { public static final String BAD_DOUBLEDASH_OPTION = "--grubbelparkplace"; - private CompilerConfiguration getConfig() throws Exception { - String sourceDir = getBasedir() + "/src/test-input/src/main"; - - List filenames = FileUtils.getFileNames( new File( sourceDir ), "**/*.java", null, false, true ); - Collections.sort( filenames ); - Set files = new HashSet<>(); - for(String filename : filenames) - { - files.add(new File(filename)); - } - - CompilerConfiguration compilerConfig = new CompilerConfiguration(); - compilerConfig.setDebug(false); - compilerConfig.setShowDeprecation(false); - -// compilerConfig.setClasspathEntries( getClasspath() ); - compilerConfig.addSourceLocation( sourceDir ); - compilerConfig.setOutputLocation( getBasedir() + "/target/eclipse/classes"); - FileUtils.deleteDirectory( compilerConfig.getOutputLocation() ); -// compilerConfig.addInclude( filename ); - compilerConfig.setForceJavacCompilerUse(false); - compilerConfig.setSourceFiles(files); - - compilerConfig.setTargetVersion("1.8"); - compilerConfig.setSourceVersion("1.8"); - return compilerConfig; + @SuppressWarnings("unchecked") + public EclipseCompilerDashedArgumentsTest() { + super(0, 0, 0, Collections.EMPTY_LIST); } - /** - * Start the eclipse compiler with a bad option that has two dashes. It should abort, and the error - * message should show the actual bad option with two dashes. This ensures that both dashes are passed - * to the compiler proper. - * - * This also tests that con-compile errors are shown properly, as the error caused by - * the invalid option is not part of the error output but part of the data sent to stdout/stderr. - */ - public void testDoubleDashOptionsArePassedWithTwoDashes() throws Exception - { - Compiler compiler = (Compiler) lookup( Compiler.ROLE, "eclipse" ); - CompilerConfiguration config = getConfig(); - config.addCompilerCustomArgument(BAD_DOUBLEDASH_OPTION, "b0rk3d"); + @Override + protected void configureCompilerConfig(CompilerConfiguration compilerConfig) { + super.configureCompilerConfig(compilerConfig); + compilerConfig.addCompilerCustomArgument(BAD_DOUBLEDASH_OPTION, "b0rk3d"); + } - try - { - compiler.performCompile(config); - Assert.fail("Expected an exception to be thrown"); - } catch(EcjFailureException x) { - String ecjOutput = x.getEcjOutput(); - Assert.assertTrue("The output should report the failure with two dashes: " + ecjOutput - , ecjOutput.contains(BAD_DOUBLEDASH_OPTION) && ! ecjOutput.contains("-" + BAD_DOUBLEDASH_OPTION) - ); + @Override + public void testCompilingSources() throws Exception { + try { + super.testCompilingSources(); + fail("Expected an exception to be thrown"); + } catch (EcjFailureException e) { + String ecjOutput = e.getEcjOutput(); + assertTrue("The output should report the failure with two dashes: " + ecjOutput, + ecjOutput.contains(BAD_DOUBLEDASH_OPTION) && !ecjOutput.contains("-" + BAD_DOUBLEDASH_OPTION)); } } + } diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerErrorsAsWarningsTest.java b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerErrorsAsWarningsTest.java index 363e0cd7..b94f588b 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerErrorsAsWarningsTest.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerErrorsAsWarningsTest.java @@ -1,52 +1,20 @@ package org.codehaus.plexus.compiler.eclipse; -import org.codehaus.plexus.compiler.AbstractCompilerTest; import org.codehaus.plexus.compiler.CompilerConfiguration; -import java.util.Arrays; -import java.util.Collection; +/** + * @author Jason Faust + */ +public class EclipseCompilerErrorsAsWarningsTest extends AbstractEclipseCompilerTest { -public class EclipseCompilerErrorsAsWarningsTest extends AbstractCompilerTest -{ - - protected void configureCompilerConfig( CompilerConfiguration compilerConfig ) - { - compilerConfig.addCompilerCustomArgument( "-errorsAsWarnings", "true" ); + public EclipseCompilerErrorsAsWarningsTest() { + super(0, 6, 1); } - public void setUp() throws Exception - { - super.setUp(); - - setCompilerDebug( true ); - setCompilerDeprecationWarnings( true ); + @Override + protected void configureCompilerConfig(CompilerConfiguration compilerConfig) { + super.configureCompilerConfig(compilerConfig); + compilerConfig.addCompilerCustomArgument("-errorsAsWarnings", "true"); } - protected String getRoleHint() - { - return "eclipse"; - } - - protected int expectedErrors() - { - return 0; - } - - protected int expectedWarnings() - { - return 6; - } - - protected Collection expectedOutputFiles() - { - return Arrays.asList( new String[] { - "org/codehaus/foo/Deprecation.class", - "org/codehaus/foo/ExternalDeps.class", - "org/codehaus/foo/Person.class", - "org/codehaus/foo/ReservedWord.class", - //"org/codehaus/foo/Bad.class", // This one has no class file generated as it's one big issue - //"org/codehaus/foo/UnknownSymbol.class", - //"org/codehaus/foo/RightClassname.class" - }); - } } diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerInitializeWarningsForPropertiesArgumentTest.java b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerInitializeWarningsForPropertiesArgumentTest.java new file mode 100644 index 00000000..fc1fe17a --- /dev/null +++ b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerInitializeWarningsForPropertiesArgumentTest.java @@ -0,0 +1,58 @@ +/* + * The MIT License + * + * Copyright (c) 2005, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.codehaus.plexus.compiler.eclipse; + +import java.util.Collections; + +import org.codehaus.plexus.compiler.CompilerConfiguration; + +/** + * @author Jason van Zyl + * @author Jason Faust + */ +public class EclipseCompilerInitializeWarningsForPropertiesArgumentTest extends AbstractEclipseCompilerTest { + + @SuppressWarnings("unchecked") + public EclipseCompilerInitializeWarningsForPropertiesArgumentTest() { + super(0, 0, 0, Collections.EMPTY_LIST); + } + + @Override + protected void configureCompilerConfig(CompilerConfiguration compilerConfig) { + super.configureCompilerConfig(compilerConfig); + compilerConfig.addCompilerCustomArgument("-properties", "file_does_not_exist"); + } + + @Override + public void testCompilingSources() throws Exception { + try { + super.testCompilingSources(); + fail("looking up the properties file should have thrown an exception"); + } catch (EcjFailureException e) { + assertTrue("Unexpected compiler error", + e.getMessage().startsWith("Failed to run the ecj compiler: Properties file")); + } + } + +} diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTckTest.java b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTckTest.java index c1999e0b..e5a28d71 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTckTest.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTckTest.java @@ -1,6 +1,4 @@ -package org.codehaus.plexus.compiler.eclipse; - -/** +/* * The MIT License * * Copyright (c) 2005, The Codehaus @@ -23,17 +21,15 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +package org.codehaus.plexus.compiler.eclipse; import org.codehaus.plexus.compiler.AbstractCompilerTckTest; /** * @author Trygve Laugstøl */ -public class EclipseCompilerTckTest - extends AbstractCompilerTckTest -{ - public EclipseCompilerTckTest() - { - super( "eclipse" ); +public class EclipseCompilerTckTest extends AbstractCompilerTckTest { + public EclipseCompilerTckTest() { + super("eclipse"); } } diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTest.java b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTest.java deleted file mode 100644 index aa5d6259..00000000 --- a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTest.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.codehaus.plexus.compiler.eclipse; - -/** - * The MIT License - * - * Copyright (c) 2005, The Codehaus - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import org.codehaus.plexus.compiler.AbstractCompilerTest; -import org.codehaus.plexus.compiler.Compiler; -import org.codehaus.plexus.compiler.CompilerConfiguration; - -import java.util.Arrays; -import java.util.Collection; - -/** - * @author Jason van Zyl - */ -public class EclipseCompilerTest - extends AbstractCompilerTest -{ - - public void setUp() - throws Exception - { - super.setUp(); - - setCompilerDebug( true ); - setCompilerDeprecationWarnings( true ); - } - - protected String getRoleHint() - { - return "eclipse"; - } - - protected int expectedErrors() - { - return 4; - } - - protected int expectedWarnings() - { - return 2; - } - - protected Collection expectedOutputFiles() - { - return Arrays.asList( new String[] { "org/codehaus/foo/Deprecation.class", "org/codehaus/foo/ExternalDeps.class", - "org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class" } ); - } - - // The test is fairly meaningless as we can not validate anything - public void testCustomArgument() - throws Exception - { - org.codehaus.plexus.compiler.Compiler compiler = (Compiler) lookup( Compiler.ROLE, getRoleHint() ); - - CompilerConfiguration compilerConfig = createMinimalCompilerConfig(); - - compilerConfig.addCompilerCustomArgument( "-key", "value" ); - - compiler.performCompile( compilerConfig ); - } - - public void testInitializeWarningsForPropertiesArgument() - throws Exception - { - org.codehaus.plexus.compiler.Compiler compiler = (Compiler) lookup( Compiler.ROLE, getRoleHint() ); - - CompilerConfiguration compilerConfig = createMinimalCompilerConfig(); - - compilerConfig.addCompilerCustomArgument( "-properties", "file_does_not_exist" ); - - try - { - compiler.performCompile( compilerConfig ); - fail( "looking up the properties file should have thrown an exception" ); - } - catch ( IllegalArgumentException e ) - { - assertTrue("Message must start with 'Properties file'", e.getMessage().startsWith("Properties file")); - } - } - - private CompilerConfiguration createMinimalCompilerConfig() - { - CompilerConfiguration compilerConfig = new CompilerConfiguration(); - compilerConfig.setOutputLocation( getBasedir() + "/target/" + getRoleHint() + "/classes-CustomArgument" ); - return compilerConfig; - } - -}