{
@Override
public Set<IProject> build( int kind, IProgressMonitor monitor )
throws Exception
{
BuildContext buildContext = getBuildContext();
IMavenProjectFacade facade = getMavenProjectFacade();
IProject project = facade.getProject();
MavenProject mavenProject = facade.getMavenProject( monitor );
@SuppressWarnings( "unchecked" )
Map<String, String> instructions =
maven.getMojoParameterValue( mavenProject, execution, "instructions", Map.class, monitor );
MojoExecution _execution = amendMojoExecution( mavenProject, execution, instructions );
IFile manifest = getManifestFile( facade, _execution, monitor );
// regenerate bundle manifest if any of the following is true
// - full workspace build
// - PROP_FORCE_GENERATE project session property is set (see the comment below)
// - any of included bnd files changed
boolean generate = IncrementalProjectBuilder.FULL_BUILD == kind;
// the property is set by OsgiBundleProjectConfigurator.mavenProjectChanged is a workaround for
// m2e design limitation, which does not allow project configurators trigger resource deltas
// visible to build participants. See comment in OsgiBundleProjectConfigurator.mavenProjectChanged
generate =
generate || Boolean.parseBoolean( (String) project.getSessionProperty( PROP_FORCE_GENERATE ) );
// reset FORCE flag so we don't regenerate forever
project.setSessionProperty( PROP_FORCE_GENERATE, null );
generate = generate || isIncludeBndFileChange( buildContext, instructions );
if ( !generate )
{
return null;
}
maven.execute( mavenProject, _execution, monitor );
manifest.refreshLocal( IResource.DEPTH_INFINITE, monitor ); // refresh parent?
if ( isDeclerativeServices( mavenProject.getBasedir(), instructions ) )
{
IFolder outputFolder = getOutputFolder( monitor, facade, _execution );
outputFolder.getFolder( "OSGI-OPT" ).refreshLocal( IResource.DEPTH_INFINITE, monitor );
outputFolder.getFolder( "OSGI-INF" ).refreshLocal( IResource.DEPTH_INFINITE, monitor );
}
return null;
}
protected IFolder getOutputFolder( IProgressMonitor monitor, IMavenProjectFacade facade,
MojoExecution _execution )
throws CoreException
{
File outputDirectory =
getParameterValue( facade.getMavenProject(), "outputDirectory", File.class, _execution, monitor );
IPath outputPath = facade.getProjectRelativePath( outputDirectory.getAbsolutePath() );
IFolder outputFolder = facade.getProject().getFolder( outputPath );
return outputFolder;
}
private boolean isIncludeBndFileChange( BuildContext buildContext, Map<String, String> instructions )
throws CoreException
{
for ( String path : getIncludeBndFilePaths( instructions ) )
{
// this does not detect changes in outside ${project.basedir}
if ( buildContext.hasDelta( path ) )
{
return true;
}
}