Skip to content

Eclipse test refactor #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package org.codehaus.plexus.compiler;

/**
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
Expand All @@ -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;
Expand All @@ -42,9 +40,6 @@
import java.util.List;
import java.util.TreeSet;

/**
*
*/
public abstract class AbstractCompilerTest
extends ArtifactTestCase
{
Expand Down Expand Up @@ -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
{
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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 );
}

Expand Down Expand Up @@ -190,7 +222,7 @@ private List<CompilerConfiguration> getCompilerConfigurations()

compilerConfig.setForceJavacCompilerUse( this.forceJavacCompilerUse );

configureCompilerConfig( compilerConfig );
configureCompilerConfig( compilerConfig, filename );

String target = getTargetVersion();
if( StringUtils.isNotEmpty( target) )
Expand Down Expand Up @@ -221,7 +253,6 @@ public String getSourceVersion()
return null;
}


private List<String> normalizePaths( Collection<String> relativePaths )
{
List<String> normalizedPaths = new ArrayList<String>();
Expand All @@ -232,16 +263,32 @@ private List<String> normalizePaths( Collection<String> relativePaths )
return normalizedPaths;
}

protected int compilerErrorCount( List<CompilerMessage> messages )
private int compilerErrorCount(List<CompilerMessage> messages)
{
return countKind( messages, Kind.ERROR );
}

private int compilerWarningCount(List<CompilerMessage> messages)
{
return messages.size() - (compilerErrorCount( messages ) + compilerNoteCount( messages ));
}

private int compilerNoteCount(List<CompilerMessage> messages)
{
int count = 0;
return countKind( messages, Kind.NOTE );
}

for ( CompilerMessage message : messages )
private int countKind(List<CompilerMessage> 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()
Expand All @@ -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<String> expectedOutputFiles()
{
return Collections.emptyList();
Expand Down
2 changes: 1 addition & 1 deletion plexus-compilers/plexus-compiler-eclipse/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>3.13.100</version>
<version>3.14.0</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> entry : extras.entrySet())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.codehaus.foo;

public class Info {
{
"".equals(1);
}
}
Original file line number Diff line number Diff line change
@@ -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 <a href="mailto:[email protected]">Jason van Zyl</a>
* @author <a href="[email protected]">Jason Faust</a>
*/
public abstract class AbstractEclipseCompilerTest extends AbstractCompilerTest {

private int expectedErrors;
private int expectedWarnings;
private int expectedNotes;
private Collection<String> 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<String> 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<String> expectedOutputFiles() {
return expectedOutputFiles;
}

@Override
protected void configureCompilerConfig(CompilerConfiguration compilerConfig) {
compilerConfig.setSourceVersion("1.8");
compilerConfig.setTargetVersion("1.8");
}
}
Original file line number Diff line number Diff line change
@@ -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 <a href="mailto:[email protected]">Jason van Zyl</a>
* @author <a href="[email protected]">Jason Faust</a>
*/
public class EclipseCompilerBasicTest extends AbstractEclipseCompilerTest {
}
Loading