Skip to content

Commit

Permalink
[MCOMPILER-516] upgrade plexus-compiler to improve compiling message
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Dec 20, 2022
1 parent 9b5605c commit 81de779
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 61 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ under the License.
! The following property is used in the integration tests MCOMPILER-157
-->
<mavenPluginPluginVersion>3.5</mavenPluginPluginVersion>
<plexusCompilerVersion>2.12.1</plexusCompilerVersion>
<plexusCompilerVersion>2.13.0</plexusCompilerVersion>

<groovyVersion>2.4.21</groovyVersion>
<groovyEclipseCompilerVersion>3.7.0</groovyEclipseCompilerVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/it/MCOMPILER-192/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ assert logFile.exists()
def content = logFile.getText('UTF-8')

def causedByExpected = content.contains ( 'Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure' )
def twoFilesBeingCompiled = content.contains ( '[INFO] Compiling 2 source files to ' )
def twoFilesBeingCompiled = content.contains ( '[INFO] Compiling 2 source files with javac ' )
def checkResult = content.contains ( '[INFO] BUILD FAILURE' )
def compilationFailure1 = content.contains( '[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@
import org.apache.maven.toolchain.ToolchainManager;
import org.codehaus.plexus.compiler.Compiler;
import org.codehaus.plexus.compiler.CompilerConfiguration;
import org.codehaus.plexus.compiler.CompilerError;
import org.codehaus.plexus.compiler.CompilerException;
import org.codehaus.plexus.compiler.CompilerMessage;
import org.codehaus.plexus.compiler.CompilerNotImplementedException;
import org.codehaus.plexus.compiler.CompilerOutputStyle;
import org.codehaus.plexus.compiler.CompilerResult;
import org.codehaus.plexus.compiler.manager.CompilerManager;
Expand Down Expand Up @@ -1255,15 +1253,7 @@ else if ( !values[0].equals( descriptor.name() ) )

try
{
try
{
compilerResult = compiler.performCompile( compilerConfiguration );
}
catch ( CompilerNotImplementedException cnie )
{
List<CompilerError> messages = compiler.compile( compilerConfiguration );
compilerResult = convertToCompilerResult( messages );
}
compilerResult = compiler.performCompile( compilerConfiguration );
}
catch ( Exception e )
{
Expand Down Expand Up @@ -1472,29 +1462,6 @@ protected boolean isTestCompile()
return false;
}

protected CompilerResult convertToCompilerResult( List<CompilerError> compilerErrors )
{
if ( compilerErrors == null )
{
return new CompilerResult();
}
List<CompilerMessage> messages = new ArrayList<>( compilerErrors.size() );
boolean success = true;
for ( CompilerError compilerError : compilerErrors )
{
messages.add(
new CompilerMessage( compilerError.getFile(), compilerError.getKind(), compilerError.getStartLine(),
compilerError.getStartColumn(), compilerError.getEndLine(),
compilerError.getEndColumn(), compilerError.getMessage() ) );
if ( compilerError.isError() )
{
success = false;
}
}

return new CompilerResult( success, messages );
}

/**
* @return all source files for the compiler
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

import org.codehaus.plexus.compiler.CompilerConfiguration;
import org.codehaus.plexus.compiler.CompilerError;
import org.codehaus.plexus.compiler.CompilerException;
import org.codehaus.plexus.compiler.CompilerMessage;
import org.codehaus.plexus.compiler.CompilerOutputStyle;
Expand All @@ -29,7 +28,6 @@
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;

/**
* @author Edwin Punzalan
Expand Down Expand Up @@ -74,29 +72,6 @@ public boolean canUpdateTarget( CompilerConfiguration compilerConfiguration )
return false;
}

public List<CompilerError> compile( CompilerConfiguration compilerConfiguration )
throws CompilerException
{
File outputDir = new File( compilerConfiguration.getOutputLocation() );

try
{
outputDir.mkdirs();

File outputFile = new File( outputDir, "compiled.class" );
if ( !outputFile.exists() && !outputFile.createNewFile() )
{
throw new CompilerException( "could not create output file: " + outputFile.getAbsolutePath() );
}
}
catch ( IOException e )
{
throw new CompilerException( "An exception occurred while creating output file", e );
}

return Collections.singletonList( new CompilerError( "message 1", shouldFail ) );
}

public CompilerResult performCompile( CompilerConfiguration compilerConfiguration )
throws CompilerException
{
Expand Down

0 comments on commit 81de779

Please sign in to comment.