// go!
init();
String generationDate = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm'Z'" ).format( new Date() );
Reporter reporter = new Processor();
try
{
Set<Info> infoSet = new Baseline( reporter, new DiffPluginImpl() )
.baseline( currentBundle, previousBundle, packageFilters );
startBaseline( generationDate, project.getArtifactId(), project.getVersion(), comparisonVersion );
final Info[] infos = infoSet.toArray( new Info[infoSet.size()] );
Arrays.sort( infos, new InfoComparator() );
for ( Info info : infos )
{
DiffMessage diffMessage = null;
Version newerVersion = info.newerVersion;
Version suggestedVersion = info.suggestedVersion;
if ( suggestedVersion != null )
{
if ( newerVersion.compareTo( suggestedVersion ) > 0 )
{
diffMessage = new DiffMessage( "Excessive version increase", DiffMessage.Type.warning );
reporter.warning( "%s: %s; detected %s, suggested %s",
info.packageName, diffMessage, info.newerVersion, info.suggestedVersion );
}
else if ( newerVersion.compareTo( suggestedVersion ) < 0 )
{
diffMessage = new DiffMessage( "Version increase required", DiffMessage.Type.error );
reporter.error( "%s: %s; detected %s, suggested %s",
info.packageName, diffMessage, info.newerVersion, info.suggestedVersion );
}
}
Diff packageDiff = info.packageDiff;
Delta delta = packageDiff.getDelta();
switch ( delta )
{
case UNCHANGED:
if ( ( suggestedVersion.getMajor() != newerVersion.getMajor() )
|| ( suggestedVersion.getMicro() != newerVersion.getMicro() )
|| ( suggestedVersion.getMinor() != newerVersion.getMinor() ) )
{
diffMessage = new DiffMessage( "Version has been increased but analysis detected no changes", DiffMessage.Type.warning );
reporter.warning( "%s: %s; detected %s, suggested %s",
info.packageName, diffMessage, info.newerVersion, info.suggestedVersion );
}
break;
case REMOVED:
diffMessage = new DiffMessage( "Package removed", DiffMessage.Type.info );
reporter.trace( "%s: %s ", info.packageName, diffMessage );
break;
case CHANGED:
case MICRO:
case MINOR:
case MAJOR:
case ADDED:
default:
// ok
break;
}
boolean mismatch = info.mismatch;
String packageName = info.packageName;
String shortDelta = getShortDelta( info.packageDiff.getDelta() );
String deltaString = StringUtils.lowerCase( String.valueOf( info.packageDiff.getDelta() ) );
String newerVersionString = String.valueOf( info.newerVersion );
String olderVersionString = String.valueOf( info.olderVersion );
String suggestedVersionString = String.valueOf( ( info.suggestedVersion == null ) ? "-" : info.suggestedVersion );
Map<String,String> attributes = info.attributes;
startPackage( mismatch,
packageName,
shortDelta,
deltaString,
newerVersionString,
olderVersionString,
suggestedVersionString,
diffMessage,
attributes );
if ( Delta.REMOVED != delta )
{
doPackageDiff( packageDiff );
}
endPackage();
}
endBaseline();
}
catch ( Exception e )
{
throw new MojoExecutionException( "Impossible to calculate the baseline", e );
}
finally
{
closeJars( currentBundle, previousBundle );
}
// check if it has to fail if some error has been detected
boolean fail = false;
if ( !reporter.isOk() )
{
for ( String errorMessage : reporter.getErrors() )
{
getLog().error( errorMessage );
}
if ( failOnError )
{
fail = true;
}
}
// check if it has to fail if some warning has been detected
if ( !reporter.getWarnings().isEmpty() )
{
for ( String warningMessage : reporter.getWarnings() )
{
getLog().warn( warningMessage );
}
if ( failOnWarning )
{
fail = true;
}
}
getLog().info( String.format( "Baseline analysis complete, %s error(s), %s warning(s)",
reporter.getErrors().size(),
reporter.getWarnings().size() ) );
if ( fail )
{
throw new MojoFailureException( "Baseline failed, see generated report" );
}