Skip to content
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

[MCOMPILER-516] upgrade plexus-compiler to improve compiling message #164

Merged
merged 1 commit into from
Dec 20, 2022
Merged
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
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