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.*; |
20 | |
import java.lang.reflect.Field; |
21 | |
import java.util.ArrayList; |
22 | |
import java.util.Arrays; |
23 | |
import java.util.Collection; |
24 | |
import java.util.Collections; |
25 | |
import java.util.HashMap; |
26 | |
import java.util.Hashtable; |
27 | |
import java.util.List; |
28 | |
import java.util.Map; |
29 | |
import java.util.Properties; |
30 | |
import java.util.jar.Attributes; |
31 | |
import java.util.jar.JarEntry; |
32 | |
import java.util.jar.JarInputStream; |
33 | |
import java.util.jar.JarOutputStream; |
34 | |
import java.util.jar.Manifest; |
35 | |
import java.util.logging.Level; |
36 | |
import java.util.logging.Logger; |
37 | |
import org.apache.maven.artifact.Artifact; |
38 | |
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; |
39 | |
|
40 | |
import org.apache.maven.execution.MavenSession; |
41 | |
import org.apache.maven.model.Resource; |
42 | |
import org.apache.maven.plugin.MojoExecutionException; |
43 | |
import org.apache.maven.plugin.MojoFailureException; |
44 | |
import org.apache.maven.plugins.annotations.Component; |
45 | |
import org.apache.maven.plugins.annotations.Parameter; |
46 | |
import org.apache.maven.shared.filtering.MavenFilteringException; |
47 | |
import org.codehaus.mojo.nbm.model.NbmResource; |
48 | |
import org.apache.maven.project.MavenProject; |
49 | |
import org.apache.maven.shared.filtering.MavenResourcesExecution; |
50 | |
import org.apache.maven.shared.filtering.MavenResourcesFiltering; |
51 | |
import org.apache.tools.ant.BuildException; |
52 | |
import org.apache.tools.ant.Project; |
53 | |
import org.apache.tools.ant.taskdefs.Copy; |
54 | |
import org.apache.tools.ant.taskdefs.Jar; |
55 | |
import org.apache.tools.ant.types.FileSet; |
56 | |
import org.apache.tools.ant.types.Path; |
57 | |
import org.apache.tools.ant.types.PatternSet; |
58 | |
import org.apache.tools.ant.util.FileUtils; |
59 | |
import org.netbeans.nbbuild.CreateModuleXML; |
60 | |
import org.netbeans.nbbuild.MakeListOfNBM; |
61 | |
import org.codehaus.mojo.nbm.model.NetBeansModule; |
62 | |
import org.codehaus.mojo.nbm.utils.ExamineManifest; |
63 | |
import org.codehaus.plexus.util.ReaderFactory; |
64 | |
import org.codehaus.plexus.util.StringUtils; |
65 | |
import org.netbeans.nbbuild.JHIndexer; |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | 0 | public abstract class CreateNetBeansFileStructure |
75 | |
extends AbstractNbmMojo |
76 | |
{ |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
@Parameter(defaultValue="${project.build.directory}/nbm", property="maven.nbm.buildDir") |
83 | |
protected File nbmBuildDir; |
84 | |
|
85 | |
|
86 | |
|
87 | |
@Parameter(required=true, readonly=true, property="project.build.directory") |
88 | |
protected File buildDir; |
89 | |
|
90 | |
|
91 | |
|
92 | |
@Parameter(alias="jarname", property="project.build.finalName") |
93 | |
protected String finalName; |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
@Parameter(defaultValue="${basedir}/src/main/nbm/module.xml") |
99 | |
protected File descriptor; |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
@Parameter(required=true, defaultValue="extra") |
105 | |
protected String cluster; |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
@Deprecated |
115 | |
@Parameter(defaultValue="${basedir}/src/main/javahelp") |
116 | |
protected File nbmJavahelpSource; |
117 | |
|
118 | |
@Parameter(required=true, readonly=true, property="project") |
119 | |
protected MavenProject project; |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
@Parameter |
141 | |
protected Resource[] nbmResources; |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
@Parameter(property="encoding", defaultValue="${project.build.sourceEncoding}") |
149 | |
|
150 | |
protected String encoding; |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
@Parameter(defaultValue="normal") |
177 | |
protected String moduleType; |
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
@Parameter(defaultValue="${project.groupId}.${project.artifactId}") |
186 | |
private String codeNameBase; |
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
@Parameter |
197 | |
private List<String> externals; |
198 | |
|
199 | |
|
200 | |
@Component |
201 | |
protected MavenResourcesFiltering mavenResourcesFiltering; |
202 | |
|
203 | |
@Parameter(property="session", readonly=true, required=true) |
204 | |
protected MavenSession session; |
205 | |
|
206 | |
|
207 | |
|
208 | |
protected Project antProject; |
209 | |
protected NetBeansModule module; |
210 | |
protected File clusterDir; |
211 | |
protected String moduleJarName; |
212 | |
|
213 | |
public void execute() |
214 | |
throws MojoExecutionException, MojoFailureException |
215 | |
{ |
216 | 0 | antProject = registerNbmAntTasks(); |
217 | 0 | if ( descriptor != null && descriptor.exists() ) |
218 | |
{ |
219 | 0 | module = readModuleDescriptor( descriptor ); |
220 | |
} else |
221 | |
{ |
222 | 0 | module = createDefaultDescriptor( project, false ); |
223 | |
} |
224 | |
|
225 | 0 | String type = moduleType; |
226 | 0 | if ("normal".equals(type) && module.getModuleType() != null) { |
227 | 0 | type = module.getModuleType(); |
228 | 0 | getLog().warn( "moduleType in module descriptor is deprecated, use the plugin's parameter moduleType"); |
229 | |
} |
230 | 0 | if (!"normal".equals(type) && !"autoload".equals(type) && !"eager".equals(type) && !"disabled".equals(type)) { |
231 | 0 | getLog().error( "Only 'normal,autoload,eager,disabled' are allowed values in the moduleType parameter"); |
232 | |
} |
233 | 0 | boolean autoload = "autoload".equals( type ); |
234 | 0 | boolean eager = "eager".equals( type ); |
235 | 0 | boolean disabled = "disabled".equals( type ); |
236 | |
|
237 | 0 | String moduleName = codeNameBase; |
238 | 0 | if (module.getCodeNameBase() != null) { |
239 | 0 | moduleName = module.getCodeNameBase(); |
240 | 0 | getLog().warn( "codeNameBase in module descriptor is deprecated, use the plugin's parameter codeNameBase"); |
241 | |
} |
242 | 0 | moduleName = NetBeansManifestUpdateMojo.stripVersionFromCodebaseName( moduleName.replaceAll( "-", "." ) ); |
243 | 0 | moduleJarName = moduleName.replace( '.', '-' ); |
244 | 0 | if ( "extra".equals( cluster ) && module.getCluster() != null ) |
245 | |
{ |
246 | 0 | getLog().warn( |
247 | |
"Parameter cluster in module descriptor is deprecated, use the plugin configuration element." ); |
248 | 0 | cluster = module.getCluster(); |
249 | |
} |
250 | 0 | File jarFile = new File( buildDir, finalName + ".jar" ); |
251 | 0 | clusterDir = new File( nbmBuildDir, "netbeans" + File.separator + cluster ); |
252 | 0 | File moduleJarLocation = new File( clusterDir, "modules" ); |
253 | 0 | moduleJarLocation.mkdirs(); |
254 | |
|
255 | |
|
256 | 0 | File moduleFile = new File( moduleJarLocation, moduleJarName + ".jar" ); |
257 | |
|
258 | |
try |
259 | |
{ |
260 | 0 | boolean needPlainCopy = false; |
261 | 0 | InputStream is = new FileInputStream( jarFile ); |
262 | |
try |
263 | |
{ |
264 | 0 | JarInputStream jis = new JarInputStream( is ); |
265 | 0 | Manifest m = jis.getManifest(); |
266 | 0 | Attributes a = m.getMainAttributes(); |
267 | 0 | String classPath = ( String ) a.remove( new Attributes.Name( "X-Class-Path" ) ); |
268 | 0 | if ( classPath == null ) |
269 | |
{ |
270 | 0 | needPlainCopy = true; |
271 | |
} |
272 | |
else |
273 | |
{ |
274 | 0 | getLog().info( "Copying module JAR to " + moduleJarLocation + " with manifest updates" ); |
275 | 0 | a.putValue( "Class-Path", classPath ); |
276 | 0 | a.remove( new Attributes.Name( "Maven-Class-Path" ) ); |
277 | 0 | OutputStream os = new FileOutputStream( moduleFile ); |
278 | |
try |
279 | |
{ |
280 | 0 | JarOutputStream jos = new JarOutputStream( os, m ); |
281 | |
JarEntry entry; |
282 | 0 | while ( ( entry = jis.getNextJarEntry() ) != null ) |
283 | |
{ |
284 | 0 | JarEntry entry2 = new JarEntry( entry ); |
285 | 0 | jos.putNextEntry( entry2 ); |
286 | |
int c; |
287 | 0 | while ( ( c = jis.read() ) != -1 ) |
288 | |
{ |
289 | 0 | jos.write( c ); |
290 | |
} |
291 | 0 | jos.closeEntry(); |
292 | 0 | } |
293 | 0 | jos.finish(); |
294 | 0 | jos.close(); |
295 | |
} |
296 | |
finally |
297 | |
{ |
298 | 0 | os.close(); |
299 | 0 | } |
300 | |
} |
301 | |
} |
302 | |
finally |
303 | |
{ |
304 | 0 | is.close(); |
305 | 0 | } |
306 | 0 | if ( needPlainCopy ) |
307 | |
{ |
308 | 0 | getLog().info( "Copying module JAR to " + moduleJarLocation ); |
309 | 0 | FileUtils.getFileUtils().copyFile( jarFile, moduleFile, null, true, false ); |
310 | |
} |
311 | |
} |
312 | 0 | catch ( IOException x ) |
313 | |
{ |
314 | 0 | throw new MojoExecutionException( "Cannot copy module jar", x ); |
315 | 0 | } |
316 | |
|
317 | 0 | ExamineManifest modExaminator = new ExamineManifest( getLog() ); |
318 | 0 | modExaminator.setJarFile( moduleFile ); |
319 | 0 | modExaminator.checkFile(); |
320 | 0 | String classpathValue = modExaminator.getClasspath(); |
321 | |
|
322 | 0 | if ( module != null ) |
323 | |
{ |
324 | |
|
325 | |
@SuppressWarnings("unchecked") |
326 | 0 | List<Artifact> artifacts = project.getRuntimeArtifacts(); |
327 | 0 | for ( Artifact artifact : artifacts ) |
328 | |
{ |
329 | 0 | File source = artifact.getFile(); |
330 | |
|
331 | 0 | String path = NetBeansManifestUpdateMojo.artifactToClassPathEntry( artifact, codeNameBase ); |
332 | |
|
333 | 0 | if ( classpathValue.contains( path ) ) |
334 | |
{ |
335 | 0 | File target = new File( moduleJarLocation, path ); |
336 | |
|
337 | 0 | File targetDir = target.getParentFile(); |
338 | 0 | targetDir.mkdirs(); |
339 | |
|
340 | |
try |
341 | |
{ |
342 | 0 | FileUtils.getFileUtils().copyFile( source, target, null, true, false ); |
343 | 0 | if ( externals != null && externals.contains(artifact.getGroupId() + ":" + artifact.getArtifactId())) |
344 | |
{ |
345 | 0 | String name = target.getName(); |
346 | 0 | getLog().info( "Using *.external replacement for " + name ); |
347 | 0 | PrintWriter external = new PrintWriter( new File( targetDir, name + ".external" ), "UTF-8" ); |
348 | |
try |
349 | |
{ |
350 | 0 | writeExternal( external, artifact ); |
351 | |
} |
352 | |
finally |
353 | |
{ |
354 | 0 | external.close(); |
355 | 0 | } |
356 | |
} |
357 | |
} |
358 | 0 | catch ( IOException ex ) |
359 | |
{ |
360 | 0 | getLog().error( "Cannot copy library jar" ); |
361 | 0 | throw new MojoExecutionException( "Cannot copy library jar", ex ); |
362 | 0 | } |
363 | |
} |
364 | 0 | } |
365 | 0 | if ( nbmResources != null ) |
366 | |
{ |
367 | 0 | copyNbmResources(); |
368 | |
} |
369 | 0 | copyDeprecatedNbmResources(); |
370 | |
} |
371 | |
|
372 | |
|
373 | 0 | if ( nbmJavahelpSource.exists() ) |
374 | |
{ |
375 | 0 | getLog().warn( "src/main/javahelp/ deprecated; use @HelpSetRegistration instead" ); |
376 | 0 | File javahelp_target = new File( buildDir, "javahelp" ); |
377 | 0 | String javahelpbase = moduleJarName.replace( '-', File.separatorChar ) + File.separator + "docs"; |
378 | 0 | String javahelpSearch = "JavaHelpSearch"; |
379 | 0 | File b = new File( javahelp_target, javahelpbase ); |
380 | 0 | File p = new File( b, javahelpSearch ); |
381 | 0 | p.mkdirs(); |
382 | 0 | Copy cp = (Copy) antProject.createTask( "copy" ); |
383 | 0 | cp.setTodir( javahelp_target ); |
384 | 0 | FileSet set = new FileSet(); |
385 | 0 | set.setDir( nbmJavahelpSource ); |
386 | 0 | cp.addFileset( set ); |
387 | 0 | cp.execute(); |
388 | 0 | getLog().info( "Generating JavaHelp Index..." ); |
389 | |
|
390 | 0 | JHIndexer jhTask = (JHIndexer) antProject.createTask( "jhindexer" ); |
391 | 0 | jhTask.setBasedir( b ); |
392 | 0 | jhTask.setDb( p ); |
393 | 0 | jhTask.setIncludes( "**/*.html" ); |
394 | 0 | jhTask.setExcludes( javahelpSearch ); |
395 | 0 | Path path = new Path( antProject ); |
396 | 0 | jhTask.setClassPath( path ); |
397 | 0 | clearStaticFieldsInJavaHelpIndexer(); |
398 | |
try |
399 | |
{ |
400 | 0 | jhTask.execute(); |
401 | |
} |
402 | 0 | catch ( BuildException e ) |
403 | |
{ |
404 | 0 | getLog().error( "Cannot generate JavaHelp index." ); |
405 | 0 | throw new MojoExecutionException( e.getMessage(), e ); |
406 | 0 | } |
407 | 0 | File helpJarLocation = new File( clusterDir, "modules/docs" ); |
408 | 0 | helpJarLocation.mkdirs(); |
409 | 0 | Jar jar = (Jar) antProject.createTask( "jar" ); |
410 | 0 | jar.setDestFile( new File( helpJarLocation, moduleJarName + ".jar" ) ); |
411 | 0 | set = new FileSet(); |
412 | 0 | set.setDir( javahelp_target ); |
413 | 0 | jar.addFileset( set ); |
414 | 0 | jar.execute(); |
415 | |
} |
416 | |
|
417 | 0 | File configDir = new File( clusterDir, "config" + File.separator + "Modules" ); |
418 | 0 | configDir.mkdirs(); |
419 | 0 | CreateModuleXML moduleXmlTask = (CreateModuleXML) antProject.createTask( "createmodulexml" ); |
420 | 0 | moduleXmlTask.setXmldir( configDir ); |
421 | 0 | FileSet fs = new FileSet(); |
422 | 0 | fs.setDir( clusterDir ); |
423 | 0 | fs.setIncludes( "modules" + File.separator + moduleJarName + ".jar" ); |
424 | 0 | if ( autoload ) |
425 | |
{ |
426 | 0 | moduleXmlTask.addAutoload( fs ); |
427 | |
} |
428 | 0 | else if ( eager ) |
429 | |
{ |
430 | 0 | moduleXmlTask.addEager( fs ); |
431 | |
} |
432 | 0 | else if ( disabled ) |
433 | |
{ |
434 | 0 | moduleXmlTask.addDisabled( fs ); |
435 | |
} |
436 | |
else |
437 | |
{ |
438 | 0 | moduleXmlTask.addEnabled( fs ); |
439 | |
} |
440 | |
try |
441 | |
{ |
442 | 0 | moduleXmlTask.execute(); |
443 | |
} |
444 | 0 | catch ( BuildException e ) |
445 | |
{ |
446 | 0 | getLog().error( "Cannot generate config file." ); |
447 | 0 | throw new MojoExecutionException( e.getMessage(), e ); |
448 | 0 | } |
449 | 0 | MakeListOfNBM makeTask = (MakeListOfNBM) antProject.createTask( "genlist" ); |
450 | 0 | antProject.setNewProperty( "module.name", finalName ); |
451 | 0 | antProject.setProperty( "cluster.dir", cluster ); |
452 | 0 | FileSet set = makeTask.createFileSet(); |
453 | 0 | set.setDir( clusterDir ); |
454 | 0 | PatternSet pattern = set.createPatternSet(); |
455 | 0 | pattern.setIncludes( "**" ); |
456 | 0 | makeTask.setModule( "modules" + File.separator + moduleJarName + ".jar" ); |
457 | 0 | makeTask.setOutputfiledir( clusterDir ); |
458 | |
try |
459 | |
{ |
460 | 0 | makeTask.execute(); |
461 | |
} |
462 | 0 | catch ( BuildException e ) |
463 | |
{ |
464 | 0 | getLog().error( "Cannot Generate nbm list" ); |
465 | 0 | throw new MojoExecutionException( e.getMessage(), e ); |
466 | 0 | } |
467 | |
|
468 | 0 | } |
469 | |
|
470 | |
private void copyDeprecatedNbmResources() |
471 | |
throws BuildException, MojoExecutionException |
472 | |
{ |
473 | |
|
474 | 0 | List<NbmResource> ress = module.getNbmResources(); |
475 | 0 | if ( ress.size() > 0 ) |
476 | |
{ |
477 | 0 | getLog().warn( "NBM resources defined in module descriptor are deprecated. Please configure NBM resources in plugin configuration." ); |
478 | 0 | Copy cp = (Copy) antProject.createTask( "copy" ); |
479 | 0 | cp.setTodir( clusterDir ); |
480 | 0 | HashMap<File, Collection<FileSet>> customPaths = new HashMap<File, Collection<FileSet>>(); |
481 | 0 | boolean hasStandard = false; |
482 | 0 | for ( NbmResource res : ress ) |
483 | |
{ |
484 | 0 | if ( res.getBaseDirectory() != null ) |
485 | |
{ |
486 | 0 | File base = new File( project.getBasedir(), res.getBaseDirectory() ); |
487 | 0 | FileSet set = new FileSet(); |
488 | 0 | set.setDir( base ); |
489 | 0 | for ( String inc : res.getIncludes() ) |
490 | |
{ |
491 | 0 | set.createInclude().setName( inc ); |
492 | 0 | } |
493 | 0 | for ( String exc : res.getExcludes() ) |
494 | |
{ |
495 | 0 | set.createExclude().setName( exc ); |
496 | 0 | } |
497 | |
|
498 | 0 | if ( res.getRelativeClusterPath() != null ) |
499 | |
{ |
500 | 0 | File path = new File( clusterDir, res.getRelativeClusterPath() ); |
501 | 0 | Collection<FileSet> col = customPaths.get( path ); |
502 | 0 | if ( col == null ) |
503 | |
{ |
504 | 0 | col = new ArrayList<FileSet>(); |
505 | 0 | customPaths.put( path, col ); |
506 | |
} |
507 | 0 | col.add( set ); |
508 | 0 | } |
509 | |
else |
510 | |
{ |
511 | 0 | cp.addFileset( set ); |
512 | 0 | hasStandard = true; |
513 | |
} |
514 | |
} |
515 | 0 | } |
516 | |
try |
517 | |
{ |
518 | 0 | if ( hasStandard ) |
519 | |
{ |
520 | 0 | cp.execute(); |
521 | |
} |
522 | 0 | if ( customPaths.size() > 0 ) |
523 | |
{ |
524 | 0 | for ( Map.Entry<File, Collection<FileSet>> ent : customPaths.entrySet() ) |
525 | |
{ |
526 | 0 | cp = (Copy) antProject.createTask( "copy" ); |
527 | 0 | cp.setTodir( ent.getKey() ); |
528 | 0 | for ( FileSet set : ent.getValue() ) |
529 | |
{ |
530 | 0 | cp.addFileset( set ); |
531 | 0 | } |
532 | 0 | cp.execute(); |
533 | 0 | } |
534 | |
} |
535 | |
} |
536 | 0 | catch ( BuildException e ) |
537 | |
{ |
538 | 0 | getLog().error( "Cannot copy additional resources into the nbm file" ); |
539 | 0 | throw new MojoExecutionException( e.getMessage(), e ); |
540 | 0 | } |
541 | |
} |
542 | 0 | } |
543 | |
|
544 | |
|
545 | |
|
546 | |
|
547 | |
|
548 | |
|
549 | |
private void clearStaticFieldsInJavaHelpIndexer() |
550 | |
{ |
551 | |
try |
552 | |
{ |
553 | 0 | Class clazz = Class.forName( "com.sun.java.help.search.Indexer" ); |
554 | 0 | Field fld = clazz.getDeclaredField( "kitRegistry" ); |
555 | 0 | fld.setAccessible( true ); |
556 | 0 | Hashtable hash = (Hashtable) fld.get( null ); |
557 | 0 | hash.clear(); |
558 | |
|
559 | 0 | clazz = Class.forName( "com.sun.java.help.search.HTMLIndexerKit" ); |
560 | 0 | fld = clazz.getDeclaredField( "defaultParser" ); |
561 | 0 | fld.setAccessible( true ); |
562 | 0 | fld.set( null, null); |
563 | |
|
564 | 0 | fld = clazz.getDeclaredField( "defaultCallback" ); |
565 | 0 | fld.setAccessible( true ); |
566 | 0 | fld.set( null, null); |
567 | |
|
568 | |
} |
569 | 0 | catch ( IllegalArgumentException ex ) |
570 | |
{ |
571 | 0 | Logger.getLogger( CreateNetBeansFileStructure.class.getName() ).log( Level.SEVERE, null, ex ); |
572 | |
} |
573 | 0 | catch ( IllegalAccessException ex ) |
574 | |
{ |
575 | 0 | Logger.getLogger( CreateNetBeansFileStructure.class.getName() ).log( Level.SEVERE, null, ex ); |
576 | |
} |
577 | 0 | catch ( NoSuchFieldException ex ) |
578 | |
{ |
579 | 0 | Logger.getLogger( CreateNetBeansFileStructure.class.getName() ).log( Level.SEVERE, null, ex ); |
580 | |
} |
581 | 0 | catch ( SecurityException ex ) |
582 | |
{ |
583 | 0 | Logger.getLogger( CreateNetBeansFileStructure.class.getName() ).log( Level.SEVERE, null, ex ); |
584 | |
} |
585 | 0 | catch ( ClassNotFoundException ex ) |
586 | |
{ |
587 | 0 | Logger.getLogger( CreateNetBeansFileStructure.class.getName() ).log( Level.SEVERE, null, ex ); |
588 | 0 | } |
589 | 0 | } |
590 | |
|
591 | |
private void copyNbmResources() |
592 | |
throws MojoExecutionException |
593 | |
{ |
594 | |
try |
595 | |
{ |
596 | 0 | if ( StringUtils.isEmpty( encoding ) && isFilteringEnabled( nbmResources ) ) |
597 | |
{ |
598 | 0 | getLog().warn( "File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING |
599 | |
+ ", i.e. build is platform dependent!" ); |
600 | |
} |
601 | 0 | MavenResourcesExecution mavenResourcesExecution = |
602 | |
new MavenResourcesExecution( Arrays.asList( nbmResources ), clusterDir, project, encoding, |
603 | |
Collections.EMPTY_LIST, Collections.EMPTY_LIST, session ); |
604 | 0 | mavenResourcesExecution.setEscapeWindowsPaths( true ); |
605 | 0 | mavenResourcesFiltering.filterResources( mavenResourcesExecution ); |
606 | |
} |
607 | 0 | catch ( MavenFilteringException ex ) |
608 | |
{ |
609 | 0 | throw new MojoExecutionException( ex.getMessage(), ex ); |
610 | 0 | } |
611 | 0 | } |
612 | |
|
613 | |
|
614 | |
|
615 | |
|
616 | |
|
617 | |
|
618 | |
|
619 | |
private boolean isFilteringEnabled( Resource[] resources ) |
620 | |
{ |
621 | 0 | for ( Resource resource : resources ) |
622 | |
{ |
623 | 0 | if ( resource.isFiltering() ) |
624 | |
{ |
625 | 0 | return true; |
626 | |
} |
627 | |
} |
628 | 0 | return false; |
629 | |
} |
630 | |
|
631 | |
static void writeExternal( PrintWriter w, Artifact artifact ) |
632 | |
throws IOException |
633 | |
{ |
634 | 0 | w.write( "CRC:" ); |
635 | 0 | File file = artifact.getFile(); |
636 | 0 | w.write( Long.toString( CreateClusterAppMojo.crcForFile( file ).getValue() ) ); |
637 | 0 | w.write( "\nSIZE:" ); |
638 | 0 | w.write( Long.toString( file.length() ) ); |
639 | 0 | w.write( "\nURL:m2:/" ); |
640 | 0 | w.write( artifact.getGroupId() ); |
641 | 0 | w.write( ':' ); |
642 | 0 | w.write( artifact.getArtifactId() ); |
643 | 0 | w.write( ':' ); |
644 | 0 | w.write( artifact.getVersion() ); |
645 | 0 | w.write( ':' ); |
646 | 0 | w.write( artifact.getType() ); |
647 | 0 | if ( artifact.getClassifier() != null ) |
648 | |
{ |
649 | 0 | w.write( ':' ); |
650 | 0 | w.write( artifact.getClassifier() ); |
651 | |
} |
652 | 0 | w.write( "\nURL:" ); |
653 | |
|
654 | 0 | w.write( "http://repo.maven.apache.org/maven2/" ); |
655 | 0 | w.write( new DefaultRepositoryLayout().pathOf( artifact ) ); |
656 | 0 | w.write( '\n' ); |
657 | 0 | w.flush(); |
658 | 0 | } |
659 | |
|
660 | |
} |