| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.codehaus.mojo.nbm; |
| 18 | |
|
| 19 | |
import java.io.File; |
| 20 | |
import java.io.IOException; |
| 21 | |
import java.io.InputStream; |
| 22 | |
import java.util.Date; |
| 23 | |
import java.util.List; |
| 24 | |
import org.apache.maven.artifact.Artifact; |
| 25 | |
import org.apache.maven.plugin.MojoExecutionException; |
| 26 | |
import org.apache.maven.plugin.MojoFailureException; |
| 27 | |
import org.apache.maven.plugins.annotations.Mojo; |
| 28 | |
import org.apache.maven.plugins.annotations.Parameter; |
| 29 | |
import org.apache.maven.plugins.annotations.ResolutionScope; |
| 30 | |
import org.apache.maven.project.MavenProject; |
| 31 | |
import org.apache.tools.ant.BuildException; |
| 32 | |
import org.apache.tools.ant.Project; |
| 33 | |
import org.apache.tools.ant.filters.StringInputStream; |
| 34 | |
import org.apache.tools.ant.taskdefs.Copy; |
| 35 | |
import org.apache.tools.ant.types.FileSet; |
| 36 | |
import org.codehaus.mojo.nbm.utils.ExamineManifest; |
| 37 | |
import org.codehaus.plexus.util.FileUtils; |
| 38 | |
import org.codehaus.plexus.util.io.InputStreamFacade; |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
@Mojo(name="cluster",aggregator=true, requiresDependencyResolution= ResolutionScope.RUNTIME ) |
| 46 | 0 | public class CreateClusterMojo |
| 47 | |
extends AbstractNbmMojo |
| 48 | |
{ |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
@Parameter(defaultValue="${project.build.directory}/netbeans_clusters", required=true) |
| 54 | |
protected File nbmBuildDir; |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
@Parameter(defaultValue="extra") |
| 62 | |
private String defaultCluster; |
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
@Parameter(required=true, readonly=true, property="reactorProjects") |
| 67 | |
private List<MavenProject> reactorProjects; |
| 68 | |
|
| 69 | |
public void execute() |
| 70 | |
throws MojoExecutionException, MojoFailureException |
| 71 | |
{ |
| 72 | 0 | Project antProject = registerNbmAntTasks(); |
| 73 | |
|
| 74 | 0 | if ( !nbmBuildDir.exists() ) |
| 75 | |
{ |
| 76 | 0 | nbmBuildDir.mkdirs(); |
| 77 | |
} |
| 78 | |
|
| 79 | 0 | if ( reactorProjects != null && reactorProjects.size() > 0 ) |
| 80 | |
{ |
| 81 | 0 | for ( MavenProject proj : reactorProjects ) |
| 82 | |
{ |
| 83 | |
|
| 84 | 0 | File nbmDir = new File( proj.getBasedir(), |
| 85 | |
"target" + File.separator + "nbm" + File.separator + "netbeans" ); |
| 86 | 0 | if ( nbmDir.exists() ) |
| 87 | |
{ |
| 88 | 0 | Copy copyTask = (Copy) antProject.createTask( "copy" ); |
| 89 | 0 | copyTask.setTodir( nbmBuildDir ); |
| 90 | 0 | copyTask.setOverwrite( true ); |
| 91 | 0 | FileSet set = new FileSet(); |
| 92 | 0 | set.setDir( nbmDir ); |
| 93 | 0 | set.createInclude().setName( "**" ); |
| 94 | 0 | copyTask.addFileset( set ); |
| 95 | |
|
| 96 | |
try |
| 97 | |
{ |
| 98 | 0 | copyTask.execute(); |
| 99 | |
} |
| 100 | 0 | catch ( BuildException ex ) |
| 101 | |
{ |
| 102 | 0 | getLog().error( "Cannot merge modules into cluster" ); |
| 103 | 0 | throw new MojoExecutionException( |
| 104 | |
"Cannot merge modules into cluster", ex ); |
| 105 | 0 | } |
| 106 | 0 | } |
| 107 | |
else |
| 108 | |
{ |
| 109 | 0 | if ( "nbm".equals( proj.getPackaging() ) ) |
| 110 | |
{ |
| 111 | 0 | String error = |
| 112 | |
"The NetBeans binary directory structure for " |
| 113 | |
+ proj.getId() |
| 114 | |
+ " is not created yet." |
| 115 | |
+ "\n Please execute 'mvn install nbm:cluster' to build all relevant projects in the reactor."; |
| 116 | 0 | throw new MojoFailureException( error ); |
| 117 | |
} |
| 118 | 0 | if ( "bundle".equals( proj.getPackaging() ) ) |
| 119 | |
{ |
| 120 | 0 | Artifact art = proj.getArtifact(); |
| 121 | 0 | final ExamineManifest mnf = new ExamineManifest( getLog() ); |
| 122 | |
|
| 123 | 0 | File jar = new File( proj.getBuild().getDirectory(), proj.getBuild().getFinalName() + ".jar" ); |
| 124 | 0 | if ( !jar.exists() ) |
| 125 | |
{ |
| 126 | 0 | getLog().error( "Skipping " + proj.getId() |
| 127 | |
+ ". Cannot find the main artifact in output directory." ); |
| 128 | 0 | continue; |
| 129 | |
} |
| 130 | 0 | mnf.setJarFile( jar ); |
| 131 | 0 | mnf.checkFile(); |
| 132 | |
|
| 133 | 0 | File cluster = new File( nbmBuildDir, defaultCluster ); |
| 134 | 0 | getLog().debug( "Copying " + art.getId() + " to cluster " + defaultCluster ); |
| 135 | 0 | File modules = new File( cluster, "modules" ); |
| 136 | 0 | modules.mkdirs(); |
| 137 | 0 | File config = new File( cluster, "config" ); |
| 138 | 0 | File confModules = new File( config, "Modules" ); |
| 139 | 0 | confModules.mkdirs(); |
| 140 | 0 | File updateTracting = new File( cluster, "update_tracking" ); |
| 141 | 0 | updateTracting.mkdirs(); |
| 142 | |
|
| 143 | 0 | final String cnb = mnf.getModule(); |
| 144 | 0 | final String cnbDashed = cnb.replace( ".", "-" ); |
| 145 | 0 | final File moduleArt = new File( modules, cnbDashed + ".jar" ); |
| 146 | 0 | final String specVer = mnf.getSpecVersion(); |
| 147 | |
try |
| 148 | |
{ |
| 149 | 0 | FileUtils.copyFile( jar, moduleArt ); |
| 150 | 0 | final File moduleConf = new File( confModules, cnbDashed + ".xml" ); |
| 151 | 0 | FileUtils.copyStreamToFile( new InputStreamFacade() { |
| 152 | |
public InputStream getInputStream() throws IOException |
| 153 | |
{ |
| 154 | 0 | return new StringInputStream( CreateClusterAppMojo.createBundleConfigFile( cnb, mnf.isBundleAutoload() ), "UTF-8" ); |
| 155 | |
} |
| 156 | |
}, moduleConf ); |
| 157 | 0 | FileUtils.copyStreamToFile( new InputStreamFacade() { |
| 158 | |
public InputStream getInputStream() throws IOException |
| 159 | |
{ |
| 160 | 0 | return new StringInputStream( CreateClusterAppMojo.createBundleUpdateTracking( cnb, moduleArt, moduleConf, specVer ), "UTF-8" ); |
| 161 | |
} |
| 162 | |
}, new File( updateTracting, cnbDashed + ".xml" ) ); |
| 163 | |
} |
| 164 | 0 | catch ( IOException exc ) |
| 165 | |
{ |
| 166 | 0 | getLog().error( exc ); |
| 167 | 0 | } |
| 168 | |
|
| 169 | |
} |
| 170 | |
} |
| 171 | 0 | } |
| 172 | |
|
| 173 | 0 | File[] files = nbmBuildDir.listFiles(); |
| 174 | 0 | for ( int i = 0; i < files.length; i++ ) |
| 175 | |
{ |
| 176 | 0 | if ( files[i].isDirectory() ) |
| 177 | |
{ |
| 178 | 0 | File stamp = new File( files[i], ".lastModified" ); |
| 179 | 0 | if ( !stamp.exists() ) |
| 180 | |
{ |
| 181 | |
try |
| 182 | |
{ |
| 183 | 0 | stamp.createNewFile(); |
| 184 | |
} |
| 185 | 0 | catch ( IOException ex ) |
| 186 | |
{ |
| 187 | 0 | ex.printStackTrace(); |
| 188 | 0 | } |
| 189 | |
} |
| 190 | 0 | stamp.setLastModified( new Date().getTime() ); |
| 191 | |
} |
| 192 | |
} |
| 193 | 0 | getLog().info( "Created NetBeans module cluster(s) at " + nbmBuildDir ); |
| 194 | 0 | } |
| 195 | |
else |
| 196 | |
{ |
| 197 | 0 | throw new MojoExecutionException( "This goal only makes sense on reactor projects." ); |
| 198 | |
} |
| 199 | 0 | } |
| 200 | |
} |