下面列出了org.apache.maven.plugin.MojoExecutionException#getCause ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private WatchingException buildWatchingException(String stream, File file, MojoExecutionException e) {
String[] lines = stream.split("\n");
for (String l : lines) {
if (!Strings.isNullOrEmpty(l)) {
stream = l.trim();
break;
}
}
final Matcher matcher = LESS_ERROR_PATTERN.matcher(stream);
if (matcher.matches()) {
String line = matcher.group(2);
String character = matcher.group(3);
String reason = matcher.group(1);
return new WatchingException("Less Compilation Error", reason, file,
Integer.valueOf(line), Integer.valueOf(character), null);
} else {
return new WatchingException("Less Compilation Error", stream, file, e.getCause());
}
}
/**
* {@inheritDoc}
*/
public void check( JnlpDependencyConfig config )
{
if ( config == null )
{
throw new NullPointerException( "config can't be null" );
}
if ( config.getArtifact() == null )
{
throw new NullPointerException( "config.artifact can't be null" );
}
if ( config.getArtifact().getFile() == null )
{
throw new NullPointerException( "config.artifact.file can't be null" );
}
if ( !config.isSign() )
{
throw new IllegalStateException( "Can't sign if config.isSign is false" );
}
File file = config.getArtifact().getFile();
boolean jarSigned;
try
{
jarSigned = signTool.isJarSigned( file );
}
catch ( MojoExecutionException e )
{
throw new RuntimeException( e.getMessage(), e.getCause() );
}
if ( jarSigned && !config.isCanUnsign() )
{
throw new IllegalStateException( "Can't unsign the config.artifact.file if config.isCanUsign is false" );
}
}
/**
* {@inheritDoc}
*/
public void check( JnlpDependencyConfig config )
{
if ( config == null )
{
throw new NullPointerException( "config can't be null" );
}
if ( config.getArtifact() == null )
{
throw new NullPointerException( "config.artifact can't be null" );
}
if ( config.getArtifact().getFile() == null )
{
throw new NullPointerException( "config.artifact.file can't be null" );
}
if ( !config.isSign() )
{
throw new IllegalStateException( "Can't sign if config.isSign is false" );
}
File file = config.getArtifact().getFile();
boolean jarSigned;
try
{
jarSigned = signTool.isJarSigned( file );
}
catch ( MojoExecutionException e )
{
throw new RuntimeException( e.getMessage(), e.getCause() );
}
if ( jarSigned && !config.isCanUnsign() )
{
throw new IllegalStateException( "Can't unsign the config.artifact.file if config.isCanUsign is false" );
}
}
private void compile() throws WatchingException {
try {
execute();
} catch (MojoExecutionException e) {
if (e.getCause() != null
&& e.getCause().getClass().getName().equals("org.apache.maven.plugin.compiler" +
".CompilationFailureException")) {
throw CompilerExecutor.build(this, e.getCause());
}
throw new WatchingException("Compilation error", e);
}
}
private void compile() throws WatchingException {
try {
execute();
} catch (MojoExecutionException e) {
if (e.getCause() != null
&& e.getCause().getClass().getName().equals("org.apache.maven.plugin.compiler" +
".CompilationFailureException")) {
throw CompilerExecutor.build(this, e.getCause());
}
throw new WatchingException("Compilation error", e);
}
}
@Override
public void runUnitTests() throws PluginExecutionException, PluginScenarioException {
try {
runTestMojo("org.apache.maven.plugins", "maven-surefire-plugin", "test");
runTestMojo("org.apache.maven.plugins", "maven-surefire-report-plugin", "report-only");
} catch (MojoExecutionException e) {
Throwable cause = e.getCause();
if (cause != null && cause instanceof MojoFailureException) {
throw new PluginScenarioException("Unit tests failed: " + cause.getLocalizedMessage(), e);
} else {
throw new PluginExecutionException("Failed to run unit tests", e);
}
}
}
@Override
public void runIntegrationTests() throws PluginExecutionException, PluginScenarioException {
try {
runTestMojo("org.apache.maven.plugins", "maven-failsafe-plugin", "integration-test");
runTestMojo("org.apache.maven.plugins", "maven-surefire-report-plugin", "failsafe-report-only");
runTestMojo("org.apache.maven.plugins", "maven-failsafe-plugin", "verify");
} catch (MojoExecutionException e) {
Throwable cause = e.getCause();
if (cause != null && cause instanceof MojoFailureException) {
throw new PluginScenarioException("Integration tests failed: " + cause.getLocalizedMessage(), e);
} else {
throw new PluginExecutionException("Failed to run integration tests", e);
}
}
}