cluster taget reads the nbms from nbmBuildDir and creates the cluster in clusterBuildDir
diff --git a/src/main/java/org/apache/netbeans/nbm/CreateClusterMojo.java b/src/main/java/org/apache/netbeans/nbm/CreateClusterMojo.java
index 3903d41..ad1b4c4 100644
--- a/src/main/java/org/apache/netbeans/nbm/CreateClusterMojo.java
+++ b/src/main/java/org/apache/netbeans/nbm/CreateClusterMojo.java
@@ -18,7 +18,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -41,165 +40,154 @@
import org.codehaus.plexus.util.io.InputStreamFacade;
/**
- * Create the NetBeans module clusters from reactor.
- * Semi-deprecated; used only for standalone modules and "suites".
+ * Create the NetBeans module clusters from reactor. Semi-deprecated; used only
+ * for standalone modules and "suites".
+ *
* @author Milos Kleint
*/
-@Mojo( name = "cluster", aggregator = true, requiresDependencyResolution = ResolutionScope.RUNTIME )
+@Mojo(name = "cluster", aggregator = true, requiresDependencyResolution = ResolutionScope.RUNTIME)
public class CreateClusterMojo
- extends AbstractNbmMojo
-{
+ extends AbstractNbmMojo {
+
+ /**
+ * NetBeans module assembly build directory. directory where the the
+ * NetBeans jar and nbm file get constructed.
+ */
+ @Parameter(defaultValue = "${project.build.directory}/nbm", property = "maven.nbm.buildDir")
+ protected File nbmBuildDir;
+
+ /**
+ * NetBeans module's cluster. Replaces the cluster element in module
+ * descriptor.
+ *
+ */
+ @Parameter(required = true, defaultValue = "extra")
+ protected String cluster;
/**
* directory where the the NetBeans cluster will be created.
*/
- @Parameter( defaultValue = "${project.build.directory}/netbeans_clusters", required = true )
- protected File nbmBuildDir;
+ @Parameter(defaultValue = "${project.build.directory}/netbeans_clusters", required = true)
+ protected File clusterBuildDir;
/**
* default cluster value for reactor projects without cluster information,
* typically OSGi bundles
+ *
* @since 3.2
*/
- @Parameter( defaultValue = "extra" )
+ @Parameter(defaultValue = "extra")
private String defaultCluster;
/**
- * If the executed project is a reactor project, this will contains the full list of projects in the reactor.
+ * If the executed project is a reactor project, this will contains the full
+ * list of projects in the reactor.
*/
- @Parameter( required = true, readonly = true, property = "reactorProjects" )
+ @Parameter(required = true, readonly = true, property = "reactorProjects")
private List<MavenProject> reactorProjects;
public void execute()
- throws MojoExecutionException, MojoFailureException
- {
+ throws MojoExecutionException, MojoFailureException {
Project antProject = registerNbmAntTasks();
- if ( !nbmBuildDir.exists() )
- {
- nbmBuildDir.mkdirs();
+ if (!clusterBuildDir.exists()) {
+ clusterBuildDir.mkdirs();
}
- if ( reactorProjects != null && reactorProjects.size() > 0 )
- {
- for ( MavenProject proj : reactorProjects )
- {
- //TODO how to figure where the the buildDir/nbm directory is
- File nbmDir = new File( proj.getBasedir(),
- "target" + File.separator + "nbm" + File.separator + "netbeans" );
- if ( nbmDir.exists() )
- {
- Copy copyTask = (Copy) antProject.createTask( "copy" );
- copyTask.setTodir( nbmBuildDir );
- copyTask.setOverwrite( true );
- FileSet set = new FileSet();
- set.setDir( nbmDir );
- set.createInclude().setName( "**" );
- copyTask.addFileset( set );
+ if (reactorProjects != null && reactorProjects.size() > 0) {
+ for (MavenProject proj : reactorProjects) {
- try
- {
+ File nbmDir = new File(nbmBuildDir, "netbeans" + File.separator + cluster);
+
+ if (nbmDir.exists()) {
+ Copy copyTask = (Copy) antProject.createTask("copy");
+ copyTask.setTodir(clusterBuildDir);
+ copyTask.setOverwrite(true);
+ FileSet set = new FileSet();
+ set.setDir(nbmDir);
+ set.createInclude().setName("**");
+ copyTask.addFileset(set);
+
+ try {
copyTask.execute();
- }
- catch ( BuildException ex )
- {
- getLog().error( "Cannot merge modules into cluster" );
+ } catch (BuildException ex) {
+ getLog().error("Cannot merge modules into cluster");
throw new MojoExecutionException(
- "Cannot merge modules into cluster", ex );
+ "Cannot merge modules into cluster", ex);
}
- }
- else
- {
- if ( "nbm".equals( proj.getPackaging() ) )
- {
- String error =
- "The NetBeans binary directory structure for "
+ } else {
+ if ("nbm".equals(proj.getPackaging())) {
+ String error
+ = "The NetBeans binary directory structure for "
+ proj.getId()
+ " is not created yet."
+ "\n Please execute 'mvn install nbm:cluster' to build all relevant projects in the reactor.";
- throw new MojoFailureException( error );
+ throw new MojoFailureException(error);
}
- if ( "bundle".equals( proj.getPackaging() ) )
- {
+ if ("bundle".equals(proj.getPackaging())) {
Artifact art = proj.getArtifact();
- final ExamineManifest mnf = new ExamineManifest( getLog() );
+ final ExamineManifest mnf = new ExamineManifest(getLog());
- File jar = new File( proj.getBuild().getDirectory(), proj.getBuild().getFinalName() + ".jar" );
- if ( !jar.exists() )
- {
- getLog().error( "Skipping " + proj.getId()
- + ". Cannot find the main artifact in output directory." );
+ File jar = new File(proj.getBuild().getDirectory(), proj.getBuild().getFinalName() + ".jar");
+ if (!jar.exists()) {
+ getLog().error("Skipping " + proj.getId()
+ + ". Cannot find the main artifact in output directory.");
continue;
}
- mnf.setJarFile( jar );
+ mnf.setJarFile(jar);
mnf.checkFile();
- File cluster = new File( nbmBuildDir, defaultCluster );
- getLog().debug( "Copying " + art.getId() + " to cluster " + defaultCluster );
- File modules = new File( cluster, "modules" );
+ File cluster = new File(clusterBuildDir, defaultCluster);
+ getLog().debug("Copying " + art.getId() + " to cluster " + defaultCluster);
+ File modules = new File(cluster, "modules");
modules.mkdirs();
- File config = new File( cluster, "config" );
- File confModules = new File( config, "Modules" );
+ File config = new File(cluster, "config");
+ File confModules = new File(config, "Modules");
confModules.mkdirs();
- File updateTracting = new File( cluster, "update_tracking" );
+ File updateTracting = new File(cluster, "update_tracking");
updateTracting.mkdirs();
final String cnb = mnf.getModule();
- final String cnbDashed = cnb.replace( ".", "-" );
- final File moduleArt = new File( modules, cnbDashed + ".jar" ); //do we need the file in some canotical name pattern?
+ final String cnbDashed = cnb.replace(".", "-");
+ final File moduleArt = new File(modules, cnbDashed + ".jar"); //do we need the file in some canotical name pattern?
final String specVer = mnf.getSpecVersion();
- try
- {
- FileUtils.copyFile( jar, moduleArt );
- final File moduleConf = new File( confModules, cnbDashed + ".xml" );
- FileUtils.copyStreamToFile( new InputStreamFacade()
- {
- public InputStream getInputStream() throws IOException
- {
- return new StringInputStream( CreateClusterAppMojo.createBundleConfigFile( cnb, mnf.isBundleAutoload() ), "UTF-8" );
+ try {
+ FileUtils.copyFile(jar, moduleArt);
+ final File moduleConf = new File(confModules, cnbDashed + ".xml");
+ FileUtils.copyStreamToFile(new InputStreamFacade() {
+ public InputStream getInputStream() throws IOException {
+ return new StringInputStream(CreateClusterAppMojo.createBundleConfigFile(cnb, mnf.isBundleAutoload()), "UTF-8");
}
- }, moduleConf );
- FileUtils.copyStreamToFile( new InputStreamFacade()
- {
- public InputStream getInputStream() throws IOException
- {
- return new StringInputStream( CreateClusterAppMojo.createBundleUpdateTracking( cnb, moduleArt, moduleConf, specVer ), "UTF-8" );
+ }, moduleConf);
+ FileUtils.copyStreamToFile(new InputStreamFacade() {
+ public InputStream getInputStream() throws IOException {
+ return new StringInputStream(CreateClusterAppMojo.createBundleUpdateTracking(cnb, moduleArt, moduleConf, specVer), "UTF-8");
}
- }, new File( updateTracting, cnbDashed + ".xml" ) );
- }
- catch ( IOException exc )
- {
- getLog().error( exc );
+ }, new File(updateTracting, cnbDashed + ".xml"));
+ } catch (IOException exc) {
+ getLog().error(exc);
}
}
}
}
//in 6.1 the rebuilt modules will be cached if the timestamp is not touched.
- File[] files = nbmBuildDir.listFiles();
- for ( int i = 0; i < files.length; i++ )
- {
- if ( files[i].isDirectory() )
- {
- File stamp = new File( files[i], ".lastModified" );
- if ( !stamp.exists() )
- {
- try
- {
+ File[] files = clusterBuildDir.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory()) {
+ File stamp = new File(files[i], ".lastModified");
+ if (!stamp.exists()) {
+ try {
stamp.createNewFile();
- }
- catch ( IOException ex )
- {
+ } catch (IOException ex) {
ex.printStackTrace();
}
}
- stamp.setLastModified( new Date().getTime() );
+ stamp.setLastModified(new Date().getTime());
}
}
- getLog().info( "Created NetBeans module cluster(s) at " + nbmBuildDir );
- }
- else
- {
- throw new MojoExecutionException( "This goal only makes sense on reactor projects." );
+ getLog().info("Created NetBeans module cluster(s) at " + clusterBuildDir);
+ } else {
+ throw new MojoExecutionException("This goal only makes sense on reactor projects.");
}
}
}