|
@@ -7,7 +7,6 @@ |
7 |
7 |
|
import java.util.Map.*; |
8 |
8 |
|
import java.util.jar.*; |
9 |
9 |
|
import java.util.zip.*; |
10 |
|
- |
import javax.tools.*; |
11 |
10 |
|
|
12 |
11 |
|
import org.litesoft.logger.*; |
13 |
12 |
|
import org.litesoft.logger.nonpublic.*; |
|
@@ -49,6 +48,7 @@ |
49 |
48 |
|
mArgs = (pArgs != null) ? pArgs : new Arguments(); |
50 |
49 |
|
} |
51 |
50 |
|
|
|
51 |
+ |
@SuppressWarnings({"UnusedDeclaration"}) |
52 |
52 |
|
public Project getLaunchProject() |
53 |
53 |
|
{ |
54 |
54 |
|
return mLaunchProject; |
|
@@ -66,12 +66,12 @@ |
66 |
66 |
|
{ |
67 |
67 |
|
Util.assertNotNull( "CurrentDirectory", pCurrentDirectory ); |
68 |
68 |
|
pPath = Util.assertNotEmpty( "Path", pPath ); |
69 |
|
- |
File zFile = new File(pPath); |
|
69 |
+ |
File zFile = new File( pPath ); |
70 |
70 |
|
if ( !zFile.isAbsolute() ) |
71 |
71 |
|
{ |
72 |
72 |
|
zFile = new File( pCurrentDirectory, pPath ); |
73 |
73 |
|
} |
74 |
|
- |
zFile = Utils.canonical( zFile ); |
|
74 |
+ |
zFile = zFile.getCanonicalFile(); |
75 |
75 |
|
|
76 |
76 |
|
String zPath = zFile.getPath(); |
77 |
77 |
|
Project zProject = mProjectCache.getByPath( zPath ); |
|
@@ -129,43 +129,43 @@ |
129 |
129 |
|
return rv; |
130 |
130 |
|
} |
131 |
131 |
|
|
132 |
|
- |
protected Project createProject( File pPossibleBuildFile, File pProjectDir ) |
|
132 |
+ |
protected Project createProject( File pPossibleBuildFile, File pCanonicalProjectDir ) |
133 |
133 |
|
throws IOException |
134 |
134 |
|
{ |
135 |
135 |
|
String zBuildFileName = pPossibleBuildFile.getName(); |
136 |
136 |
|
int zDotAt = zBuildFileName.lastIndexOf( '.' ); |
137 |
|
- |
if ( (zDotAt != -1) && (pProjectDir != null) ) |
|
137 |
+ |
if ( (zDotAt != -1) && (pCanonicalProjectDir != null) ) |
138 |
138 |
|
{ |
139 |
139 |
|
String zName = zBuildFileName.substring( 0, zDotAt ).trim(); |
140 |
140 |
|
if ( DEFAULT_PROJECT_FILE_NAME.equalsIgnoreCase( zName ) ) |
141 |
141 |
|
{ |
142 |
|
- |
zName = pProjectDir.getName(); |
|
142 |
+ |
zName = pCanonicalProjectDir.getName(); |
143 |
143 |
|
} |
144 |
|
- |
return createProject( pPossibleBuildFile, pProjectDir, zName ); |
|
144 |
+ |
return createProject( pPossibleBuildFile, pCanonicalProjectDir, zName ); |
145 |
145 |
|
} |
146 |
146 |
|
throw new IllegalArgumentException( "Unacceptable Project Path or Name, Project File " + pPossibleBuildFile ); |
147 |
147 |
|
} |
148 |
148 |
|
|
149 |
|
- |
protected Project createProject( File pBuildFile, File pProjectDir, String pProjectName ) |
|
149 |
+ |
protected Project createProject( File pBuildFile, File pCanonicalProjectDir, String pProjectName ) |
150 |
150 |
|
throws IOException |
151 |
151 |
|
{ |
152 |
152 |
|
if ( pBuildFile == null ) |
153 |
153 |
|
{ |
154 |
|
- |
throw new IllegalArgumentException( "No 'Build.java' or 'Build.yaml' file found in Project Directory: " + pProjectDir ); |
|
154 |
+ |
throw new IllegalArgumentException( "No 'Build.java' or 'Build.yaml' file found in Project Directory: " + pCanonicalProjectDir ); |
155 |
155 |
|
} |
156 |
156 |
|
String zBuildFileName = pBuildFile.getName(); |
157 |
157 |
|
if ( zBuildFileName.endsWith( JAVA_EXTENSION ) ) |
158 |
158 |
|
{ |
159 |
|
- |
return createJavaProject( pBuildFile, pProjectDir, pProjectName ); |
|
159 |
+ |
return createJavaProject( pBuildFile, pCanonicalProjectDir, pProjectName ); |
160 |
160 |
|
} |
161 |
161 |
|
if ( zBuildFileName.endsWith( YAML_EXTENSION ) ) |
162 |
162 |
|
{ |
163 |
|
- |
return createYamlProject( pBuildFile, pProjectDir, pProjectName ); |
|
163 |
+ |
return createYamlProject( pBuildFile, pCanonicalProjectDir, pProjectName ); |
164 |
164 |
|
} |
165 |
165 |
|
throw new IllegalArgumentException( pBuildFile + " was NOT either a '.java' or a '.yaml' file!" ); |
166 |
166 |
|
} |
167 |
167 |
|
|
168 |
|
- |
protected Project createYamlProject( File zYamlBuildFile, File pProjectDir, String pProjectName ) |
|
168 |
+ |
protected Project createYamlProject( File zYamlBuildFile, File pCanonicalProjectDir, String pProjectName ) |
169 |
169 |
|
throws IOException |
170 |
170 |
|
{ |
171 |
171 |
|
List<String> zLines = readLines( zYamlBuildFile ); |
|
@@ -180,27 +180,27 @@ |
180 |
180 |
|
zYAML = mergeLines( zLines, 0, at ); |
181 |
181 |
|
zCode = Util.noEmpty( mergeLines( zLines, at + 1 ) ); |
182 |
182 |
|
} |
183 |
|
- |
Map<Object, Object> zData = (zYAML.length() == 0) ? new HashMap<Object, Object>() : parseYAML( pProjectDir, zYAML ); |
|
183 |
+ |
Map<Object, Object> zData = (zYAML.length() == 0) ? new HashMap<Object, Object>() : parseYAML( pCanonicalProjectDir, zYAML ); |
184 |
184 |
|
Class<? extends Project> zClass = createYamlProjectClass(); |
185 |
185 |
|
if ( zCode != null ) |
186 |
186 |
|
{ |
187 |
187 |
|
zClass = createYamlCodeProjectClass( zClass, zCode, at + 1 ); |
188 |
188 |
|
} |
189 |
|
- |
return instantiate( zClass, pProjectDir, pProjectName, zData ); |
|
189 |
+ |
return instantiate( zClass, pCanonicalProjectDir, pProjectName, zData ); |
190 |
190 |
|
} |
191 |
191 |
|
|
192 |
|
- |
protected Project createJavaProject( File zJavaBuildFile, File pProjectDir, String pProjectName ) |
|
192 |
+ |
protected Project createJavaProject( File zJavaBuildFile, File pCanonicalProjectDir, String pProjectName ) |
193 |
193 |
|
throws IOException |
194 |
194 |
|
{ |
195 |
195 |
|
String zFile = mergeLines( readLines( zJavaBuildFile ), 0 ); |
196 |
196 |
|
Class<? extends Project> zClass = createJavaProjectClass(); |
197 |
197 |
|
zClass = createJavaCodeProjectClass( zClass, zFile ); |
198 |
|
- |
return instantiate( zClass, pProjectDir, pProjectName, null ); |
|
198 |
+ |
return instantiate( zClass, pCanonicalProjectDir, pProjectName, null ); |
199 |
199 |
|
} |
200 |
200 |
|
|
201 |
|
- |
protected Project instantiate( Class<? extends Project> pClass, File pProjectDir, String pProjectName, Map<Object, Object> pData ) |
|
201 |
+ |
protected Project instantiate( Class<? extends Project> pClass, File pCanonicalProjectDir, String pProjectName, Map<Object, Object> pData ) |
202 |
202 |
|
{ |
203 |
|
- |
return instantiate( pClass, new ProjectParameters( pProjectName, pProjectDir, pData ) ); |
|
203 |
+ |
return instantiate( pClass, new ProjectParameters( pProjectName, pCanonicalProjectDir, pData ) ); |
204 |
204 |
|
} |
205 |
205 |
|
|
206 |
206 |
|
protected Project instantiate( Class<? extends Project> pClass, ProjectParameters pParameters ) |
|
@@ -235,7 +235,7 @@ |
235 |
235 |
|
{ |
236 |
236 |
|
zCause = e; |
237 |
237 |
|
} |
238 |
|
- |
throw new RuntimeException( "Unable to Instantiate Project Class for Project: " + pParameters.getName() + " in dir " + pParameters.getDirectory(), zCause ); |
|
238 |
+ |
throw new RuntimeException( "Unable to Instantiate Project Class for Project: " + pParameters.getName() + " in dir " + pParameters.getCanonicalProjectDir(), zCause ); |
239 |
239 |
|
} |
240 |
240 |
|
|
241 |
241 |
|
protected Class<? extends Project> createYamlProjectClass() |
|
@@ -376,13 +376,25 @@ |
376 |
376 |
|
throw new UnsupportedOperationException(); // todo: See - executeDocument()!; |
377 |
377 |
|
} |
378 |
378 |
|
|
|
379 |
+ |
/** |
|
380 |
+ |
* Cleans All projects - Normally called reflectively |
|
381 |
+ |
*/ |
|
382 |
+ |
@SuppressWarnings({"UnusedDeclaration"}) |
379 |
383 |
|
public void cleanAll() |
380 |
384 |
|
throws IOException |
381 |
385 |
|
{ |
382 |
|
- |
System.out.println( "cleanAll" ); |
383 |
|
- |
// todo: ... |
|
386 |
+ |
progress( "CleanAll" ); |
|
387 |
+ |
Set<Project> zProjects = mProjectCache.getAllProjects(); |
|
388 |
+ |
for ( Project zProject : zProjects ) |
|
389 |
+ |
{ |
|
390 |
+ |
zProject.clean(); |
|
391 |
+ |
} |
384 |
392 |
|
} |
385 |
393 |
|
|
|
394 |
+ |
/** |
|
395 |
+ |
* Builds the Launch Project - Normally called reflectively |
|
396 |
+ |
*/ |
|
397 |
+ |
@SuppressWarnings({"UnusedDeclaration"}) |
386 |
398 |
|
public void build() |
387 |
399 |
|
throws IOException |
388 |
400 |
|
{ |
|
@@ -452,312 +464,6 @@ |
452 |
464 |
|
// } |
453 |
465 |
|
|
454 |
466 |
|
/** |
455 |
|
- |
* Deletes the "target" directory and all files and directories under it. |
456 |
|
- |
*/ |
457 |
|
- |
public void clean( Project project ) |
458 |
|
- |
{ |
459 |
|
- |
Util.assertNotNull( "Project", project ); |
460 |
|
- |
LOGGER.info.log( "Clean: ", project ); |
461 |
|
- |
new Paths( project.path( "$target$" ) ).delete(); |
462 |
|
- |
} |
463 |
|
- |
|
464 |
|
- |
/** |
465 |
|
- |
* Computes the classpath for the specified project and all its dependency projects, recursively. |
466 |
|
- |
*/ |
467 |
|
- |
public Paths classpath( Project project, boolean errorIfDependenciesNotBuilt ) |
468 |
|
- |
throws IOException |
469 |
|
- |
{ |
470 |
|
- |
Util.assertNotNull( "Project", project ); |
471 |
|
- |
Paths classpath = project.getClasspath(); |
472 |
|
- |
classpath.add( dependencyClasspaths( project, classpath, true, errorIfDependenciesNotBuilt ) ); |
473 |
|
- |
return classpath; |
474 |
|
- |
} |
475 |
|
- |
|
476 |
|
- |
/** |
477 |
|
- |
* Computes the classpath for all the dependencies of the specified project, recursively. |
478 |
|
- |
*/ |
479 |
|
- |
private Paths dependencyClasspaths( Project project, Paths paths, boolean includeDependencyJAR, boolean errorIfDependenciesNotBuilt ) |
480 |
|
- |
throws IOException |
481 |
|
- |
{ |
482 |
|
- |
Util.assertNotNull( "Project", project ); |
483 |
|
- |
for ( String dependency : project.getDependencies() ) |
484 |
|
- |
{ |
485 |
|
- |
Project dependencyProject = project( null, project.path( dependency ) ); |
486 |
|
- |
String dependencyTarget = dependencyProject.path( "$target$/" ); |
487 |
|
- |
if ( errorIfDependenciesNotBuilt && !fileExists( dependencyTarget ) ) |
488 |
|
- |
{ |
489 |
|
- |
throw new RuntimeException( "Dependency has not been built: " + dependency + "\nAbsolute dependency path: " + canonical( dependency ) + "\nMissing dependency target: " + canonical( dependencyTarget ) ); |
490 |
|
- |
} |
491 |
|
- |
if ( includeDependencyJAR ) |
492 |
|
- |
{ |
493 |
|
- |
paths.glob( dependencyTarget, "*.jar" ); |
494 |
|
- |
} |
495 |
|
- |
paths.add( classpath( dependencyProject, errorIfDependenciesNotBuilt ) ); |
496 |
|
- |
} |
497 |
|
- |
return paths; |
498 |
|
- |
} |
499 |
|
- |
|
500 |
|
- |
/** |
501 |
|
- |
* Collects the source files using the "source" property and compiles them into a "classes" directory under the target |
502 |
|
- |
* directory. It uses "classpath" and "dependencies" to find the libraries required to compile the source. |
503 |
|
- |
* <p/> |
504 |
|
- |
* Note: Each dependency project is not built automatically. Each needs to be built before the dependent project. |
505 |
|
- |
* |
506 |
|
- |
* @return The path to the "classes" directory. |
507 |
|
- |
*/ |
508 |
|
- |
public String compile( Project project ) |
509 |
|
- |
throws IOException |
510 |
|
- |
{ |
511 |
|
- |
Util.assertNotNull( "Project", project ); |
512 |
|
- |
Paths classpath = classpath( project, true ); |
513 |
|
- |
Paths source = project.getSource(); |
514 |
|
- |
|
515 |
|
- |
String classesDir = mkdir( project.path( "$target$/classes/" ) ); |
516 |
|
- |
|
517 |
|
- |
if ( source.isEmpty() ) |
518 |
|
- |
{ |
519 |
|
- |
LOGGER.warn.log( "Compile: ", project, " --- No source files found." ); |
520 |
|
- |
return classesDir; |
521 |
|
- |
} |
522 |
|
- |
|
523 |
|
- |
if ( LOGGER.debug.isEnabled() ) |
524 |
|
- |
{ |
525 |
|
- |
LOGGER.debug.log( "Compile: ", project, "\n Classpath: ", classpath, "\n Source: " + source.count() + " files" ); |
526 |
|
- |
} |
527 |
|
- |
else |
528 |
|
- |
{ |
529 |
|
- |
LOGGER.info.log( "Compile: ", project ); |
530 |
|
- |
} |
531 |
|
- |
|
532 |
|
- |
File tempFile = File.createTempFile( "scar", "compile" ); |
533 |
|
- |
|
534 |
|
- |
List<String> args = new ArrayList<String>(); |
535 |
|
- |
if ( LOGGER.trace.isEnabled() ) |
536 |
|
- |
{ |
537 |
|
- |
args.add( "-verbose" ); |
538 |
|
- |
} |
539 |
|
- |
args.add( "-d" ); |
540 |
|
- |
args.add( classesDir ); |
541 |
|
- |
args.add( "-g:source,lines" ); |
542 |
|
- |
args.add( "-target" ); |
543 |
|
- |
args.add( "1.5" ); |
544 |
|
- |
args.addAll( source.getPaths() ); |
545 |
|
- |
if ( !classpath.isEmpty() ) |
546 |
|
- |
{ |
547 |
|
- |
args.add( "-classpath" ); |
548 |
|
- |
args.add( classpath.toString( ";" ) ); |
549 |
|
- |
} |
550 |
|
- |
|
551 |
|
- |
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
552 |
|
- |
if ( compiler == null ) |
553 |
|
- |
{ |
554 |
|
- |
throw new RuntimeException( "No compiler available. Ensure you are running from a 1.6+ JDK, and not a JRE." ); |
555 |
|
- |
} |
556 |
|
- |
if ( compiler.run( null, null, null, args.toArray( new String[args.size()] ) ) != 0 ) |
557 |
|
- |
{ |
558 |
|
- |
throw new RuntimeException( "Error during compilation of project: " + project + "\nSource: " + source.count() + " files\nClasspath: " + classpath ); |
559 |
|
- |
} |
560 |
|
- |
try |
561 |
|
- |
{ |
562 |
|
- |
Thread.sleep( 100 ); |
563 |
|
- |
} |
564 |
|
- |
catch ( InterruptedException ex ) |
565 |
|
- |
{ |
566 |
|
- |
// Whatever |
567 |
|
- |
} |
568 |
|
- |
return classesDir; |
569 |
|
- |
} |
570 |
|
- |
|
571 |
|
- |
/** |
572 |
|
- |
* Collects the class files from the "classes" directory and all the resource files using the "resources" property and encodes |
573 |
|
- |
* them into a JAR file. |
574 |
|
- |
* <p/> |
575 |
|
- |
* If the resources don't contain a META-INF/MANIFEST.MF file, one is generated. If the project has a main property, the |
576 |
|
- |
* generated manifest will include "Main-Class" and "Class-Path" entries to allow the main class to be run with "java -jar". |
577 |
|
- |
* |
578 |
|
- |
* @return The path to the created JAR file. |
579 |
|
- |
*/ |
580 |
|
- |
public String jar( Project project ) |
581 |
|
- |
throws IOException |
582 |
|
- |
{ |
583 |
|
- |
Util.assertNotNull( "Project", project ); |
584 |
|
- |
|
585 |
|
- |
LOGGER.info.log( "JAR: ", project ); |
586 |
|
- |
|
587 |
|
- |
String jarDir = mkdir( project.path( "$target$/jar/" ) ); |
588 |
|
- |
|
589 |
|
- |
String classesDir = project.path( "$target$/classes/" ); |
590 |
|
- |
new Paths( classesDir, "**/*.class" ).copyTo( jarDir ); |
591 |
|
- |
project.getResources().copyTo( jarDir ); |
592 |
|
- |
|
593 |
|
- |
String jarFile; |
594 |
|
- |
if ( project.hasVersion() ) |
595 |
|
- |
{ |
596 |
|
- |
jarFile = project.path( "$target$/$name$-$version$.jar" ); |
597 |
|
- |
} |
598 |
|
- |
else |
599 |
|
- |
{ |
600 |
|
- |
jarFile = project.path( "$target$/$name$.jar" ); |
601 |
|
- |
} |
602 |
|
- |
|
603 |
|
- |
File manifestFile = new File( jarDir, "META-INF/MANIFEST.MF" ); |
604 |
|
- |
if ( !manifestFile.exists() ) |
605 |
|
- |
{ |
606 |
|
- |
LOGGER.debug.log( "Generating JAR manifest: ", manifestFile ); |
607 |
|
- |
mkdir( manifestFile.getParent() ); |
608 |
|
- |
Manifest manifest = new Manifest(); |
609 |
|
- |
manifest.getMainAttributes().putValue( Attributes.Name.MANIFEST_VERSION.toString(), "1.0" ); |
610 |
|
- |
if ( project.hasMain() ) |
611 |
|
- |
{ |
612 |
|
- |
LOGGER.debug.log( "Main class: ", project.getMain() ); |
613 |
|
- |
manifest.getMainAttributes().putValue( Attributes.Name.MAIN_CLASS.toString(), project.getMain() ); |
614 |
|
- |
StringBuilder buffer = new StringBuilder( 512 ); |
615 |
|
- |
buffer.append( fileName( jarFile ) ); |
616 |
|
- |
buffer.append( " ." ); |
617 |
|
- |
Paths classpath = classpath( project, true ); |
618 |
|
- |
for ( String name : classpath.getRelativePaths() ) |
619 |
|
- |
{ |
620 |
|
- |
buffer.append( ' ' ); |
621 |
|
- |
buffer.append( name ); |
622 |
|
- |
} |
623 |
|
- |
manifest.getMainAttributes().putValue( Attributes.Name.CLASS_PATH.toString(), buffer.toString() ); |
624 |
|
- |
} |
625 |
|
- |
FileOutputStream output = new FileOutputStream( manifestFile ); |
626 |
|
- |
try |
627 |
|
- |
{ |
628 |
|
- |
manifest.write( output ); |
629 |
|
- |
} |
630 |
|
- |
finally |
631 |
|
- |
{ |
632 |
|
- |
try |
633 |
|
- |
{ |
634 |
|
- |
output.close(); |
635 |
|
- |
} |
636 |
|
- |
catch ( Exception ignored ) |
637 |
|
- |
{ |
638 |
|
- |
} |
639 |
|
- |
} |
640 |
|
- |
} |
641 |
|
- |
|
642 |
|
- |
jar( jarFile, new Paths( jarDir ) ); |
643 |
|
- |
return jarFile; |
644 |
|
- |
} |
645 |
|
- |
|
646 |
|
- |
/** |
647 |
|
- |
* Encodes the specified paths into a JAR file. |
648 |
|
- |
* |
649 |
|
- |
* @return The path to the JAR file. |
650 |
|
- |
*/ |
651 |
|
- |
public String jar( String jarFile, Paths paths ) |
652 |
|
- |
throws IOException |
653 |
|
- |
{ |
654 |
|
- |
Util.assertNotNull( "jarFile", jarFile ); |
655 |
|
- |
Util.assertNotNull( "paths", paths ); |
656 |
|
- |
|
657 |
|
- |
paths = paths.filesOnly(); |
658 |
|
- |
|
659 |
|
- |
LOGGER.debug.log( "Creating JAR (", paths.count(), " entries): ", jarFile ); |
660 |
|
- |
|
661 |
|
- |
List<String> fullPaths = paths.getPaths(); |
662 |
|
- |
List<String> relativePaths = paths.getRelativePaths(); |
663 |
|
- |
// Ensure MANIFEST.MF is first. |
664 |
|
- |
int manifestIndex = relativePaths.indexOf( "META-INF/MANIFEST.MF" ); |
665 |
|
- |
if ( manifestIndex > 0 ) |
666 |
|
- |
{ |
667 |
|
- |
relativePaths.remove( manifestIndex ); |
668 |
|
- |
relativePaths.add( 0, "META-INF/MANIFEST.MF" ); |
669 |
|
- |
String manifestFullPath = fullPaths.get( manifestIndex ); |
670 |
|
- |
fullPaths.remove( manifestIndex ); |
671 |
|
- |
fullPaths.add( 0, manifestFullPath ); |
672 |
|
- |
} |
673 |
|
- |
JarOutputStream output = new JarOutputStream( new BufferedOutputStream( new FileOutputStream( jarFile ) ) ); |
674 |
|
- |
try |
675 |
|
- |
{ |
676 |
|
- |
for ( int i = 0, n = fullPaths.size(); i < n; i++ ) |
677 |
|
- |
{ |
678 |
|
- |
output.putNextEntry( new JarEntry( relativePaths.get( i ).replace( '\\', '/' ) ) ); |
679 |
|
- |
FileInputStream input = new FileInputStream( fullPaths.get( i ) ); |
680 |
|
- |
try |
681 |
|
- |
{ |
682 |
|
- |
byte[] buffer = new byte[4096]; |
683 |
|
- |
while ( true ) |
684 |
|
- |
{ |
685 |
|
- |
int length = input.read( buffer ); |
686 |
|
- |
if ( length == -1 ) |
687 |
|
- |
{ |
688 |
|
- |
break; |
689 |
|
- |
} |
690 |
|
- |
output.write( buffer, 0, length ); |
691 |
|
- |
} |
692 |
|
- |
} |
693 |
|
- |
finally |
694 |
|
- |
{ |
695 |
|
- |
try |
696 |
|
- |
{ |
697 |
|
- |
input.close(); |
698 |
|
- |
} |
699 |
|
- |
catch ( Exception ignored ) |
700 |
|
- |
{ |
701 |
|
- |
} |
702 |
|
- |
} |
703 |
|
- |
} |
704 |
|
- |
} |
705 |
|
- |
finally |
706 |
|
- |
{ |
707 |
|
- |
try |
708 |
|
- |
{ |
709 |
|
- |
output.close(); |
710 |
|
- |
} |
711 |
|
- |
catch ( Exception ignored ) |
712 |
|
- |
{ |
713 |
|
- |
} |
714 |
|
- |
} |
715 |
|
- |
return jarFile; |
716 |
|
- |
} |
717 |
|
- |
|
718 |
|
- |
/** |
719 |
|
- |
* Collects the distribution files using the "dist" property, the project's JAR file, and everything on the project's classpath |
720 |
|
- |
* (including dependency project classpaths) and places them into a "dist" directory under the "target" directory. This is also |
721 |
|
- |
* done for depenency projects, recursively. This is everything the application needs to be run from JAR files. |
722 |
|
- |
* |
723 |
|
- |
* @return The path to the "dist" directory. |
724 |
|
- |
*/ |
725 |
|
- |
public String dist( Project project ) |
726 |
|
- |
throws IOException |
727 |
|
- |
{ |
728 |
|
- |
Util.assertNotNull( "Project", project ); |
729 |
|
- |
|
730 |
|
- |
LOGGER.info.log( "Dist: ", project ); |
731 |
|
- |
|
732 |
|
- |
String distDir = mkdir( project.path( "$target$/dist/" ) ); |
733 |
|
- |
classpath( project, true ).copyTo( distDir ); |
734 |
|
- |
Paths distPaths = project.getDist(); |
735 |
|
- |
dependencyDistPaths( project, distPaths ); |
736 |
|
- |
distPaths.copyTo( distDir ); |
737 |
|
- |
new Paths( project.path( "$target$" ), "*.jar" ).copyTo( distDir ); |
738 |
|
- |
return distDir; |
739 |
|
- |
} |
740 |
|
- |
|
741 |
|
- |
private Paths dependencyDistPaths( Project project, Paths paths ) |
742 |
|
- |
throws IOException |
743 |
|
- |
{ |
744 |
|
- |
Util.assertNotNull( "Project", project ); |
745 |
|
- |
|
746 |
|
- |
for ( String dependency : project.getDependencies() ) |
747 |
|
- |
{ |
748 |
|
- |
Project dependencyProject = project( null, project.path( dependency ) ); |
749 |
|
- |
String dependencyTarget = dependencyProject.path( "$target$/" ); |
750 |
|
- |
if ( !fileExists( dependencyTarget ) ) |
751 |
|
- |
{ |
752 |
|
- |
throw new RuntimeException( "Dependency has not been built: " + dependency ); |
753 |
|
- |
} |
754 |
|
- |
paths.glob( dependencyTarget + "dist", "!*/**.jar" ); |
755 |
|
- |
paths.add( dependencyDistPaths( dependencyProject, paths ) ); |
756 |
|
- |
} |
757 |
|
- |
return paths; |
758 |
|
- |
} |
759 |
|
- |
|
760 |
|
- |
/** |
761 |
467 |
|
* Removes any code signatures on the specified JAR. Removes any signature files in the META-INF directory and removes any |
762 |
468 |
|
* signature entries from the JAR's manifest. |
763 |
469 |
|
* |
|
@@ -768,7 +474,7 @@ |
768 |
474 |
|
{ |
769 |
475 |
|
Util.assertNotNull( "jarFile", jarFile ); |
770 |
476 |
|
|
771 |
|
- |
LOGGER.debug.log( "Removing signature from JAR: ", jarFile ); |
|
477 |
+ |
progress( "Removing signature from JAR: " + jarFile ); |
772 |
478 |
|
|
773 |
479 |
|
File tempFile = File.createTempFile( "scar", "removejarsig" ); |
774 |
480 |
|
JarOutputStream jarOutput = null; |
|
@@ -861,7 +567,7 @@ |
861 |
567 |
|
{ |
862 |
568 |
|
throw new IllegalArgumentException( "password must be 6 or more characters." ); |
863 |
569 |
|
} |
864 |
|
- |
LOGGER.debug.log( "Signing JAR (", keystoreFile, ", ", alias, ":", password, "): ", jarFile ); |
|
570 |
+ |
progress( "Signing JAR (" + keystoreFile + ", " + alias + ":" + password + "): " + jarFile ); |
865 |
571 |
|
|
866 |
572 |
|
shell( "jarsigner", "-keystore", keystoreFile, "-storepass", password, "-keypass", password, jarFile, alias ); |
867 |
573 |
|
return jarFile; |
|
@@ -892,7 +598,7 @@ |
892 |
598 |
|
Util.assertNotNull( "jarFile", jarFile ); |
893 |
599 |
|
Util.assertNotNull( "packedFile", packedFile ); |
894 |
600 |
|
|
895 |
|
- |
LOGGER.debug.log( "Packing JAR: ", jarFile, " -> ", packedFile ); |
|
601 |
+ |
progress( "Packing JAR: " + jarFile + " -> " + packedFile ); |
896 |
602 |
|
|
897 |
603 |
|
shell( "pack200", "--no-gzip", "--segment-limit=-1", "--no-keep-file-order", "--effort=7", "--modification-time=latest", packedFile, jarFile ); |
898 |
604 |
|
return packedFile; |
|
@@ -929,7 +635,7 @@ |
929 |
635 |
|
Util.assertNotNull( "packedFile", packedFile ); |
930 |
636 |
|
Util.assertNotNull( "jarFile", jarFile ); |
931 |
637 |
|
|
932 |
|
- |
LOGGER.debug.log( "Unpacking JAR: ", packedFile, " -> ", jarFile ); |
|
638 |
+ |
progress( "Unpacking JAR: " + packedFile + " -> " + jarFile ); |
933 |
639 |
|
|
934 |
640 |
|
shell( "unpack200", packedFile, jarFile ); |
935 |
641 |
|
return jarFile; |
|
@@ -959,7 +665,7 @@ |
959 |
665 |
|
Util.assertNotNull( "file", file ); |
960 |
666 |
|
Util.assertNotNull( "gzipFile", gzipFile ); |
961 |
667 |
|
|
962 |
|
- |
LOGGER.debug.log( "GZIP encoding: ", file, " -> ", gzipFile ); |
|
668 |
+ |
progress( "GZIP encoding: " + file + " -> " + gzipFile ); |
963 |
669 |
|
|
964 |
670 |
|
InputStream input = new FileInputStream( file ); |
965 |
671 |
|
try |
|
@@ -1009,7 +715,7 @@ |
1009 |
715 |
|
{ |
1010 |
716 |
|
Util.assertNotNull( "gzipFile", gzipFile ); |
1011 |
717 |
|
Util.assertNotNull( "file", file ); |
1012 |
|
- |
LOGGER.debug.log( "GZIP decoding: ", gzipFile, " -> ", file ); |
|
718 |
+ |
progress( "GZIP decoding: " + gzipFile + " -> " + file ); |
1013 |
719 |
|
|
1014 |
720 |
|
InputStream input = new GZIPInputStream( new FileInputStream( gzipFile ) ); |
1015 |
721 |
|
try |
|
@@ -1039,7 +745,7 @@ |
1039 |
745 |
|
{ |
1040 |
746 |
|
Util.assertNotNull( "paths", paths ); |
1041 |
747 |
|
Util.assertNotNull( "zipFile", zipFile ); |
1042 |
|
- |
LOGGER.debug.log( "Creating ZIP (", paths.count(), " entries): ", zipFile ); |
|
748 |
+ |
progress( "Creating ZIP (" + paths.count() + " entries): " + zipFile ); |
1043 |
749 |
|
|
1044 |
750 |
|
paths.zip( zipFile ); |
1045 |
751 |
|
return zipFile; |
|
@@ -1055,7 +761,7 @@ |
1055 |
761 |
|
{ |
1056 |
762 |
|
Util.assertNotNull( "zipFile", zipFile ); |
1057 |
763 |
|
Util.assertNotNull( "outputDir", outputDir ); |
1058 |
|
- |
LOGGER.debug.log( "ZIP decoding: ", zipFile, " -> ", outputDir ); |
|
764 |
+ |
progress( "ZIP decoding: " + zipFile + " -> " + outputDir ); |
1059 |
765 |
|
|
1060 |
766 |
|
ZipInputStream input = new ZipInputStream( new FileInputStream( zipFile ) ); |
1061 |
767 |
|
try |
|
@@ -1137,7 +843,7 @@ |
1137 |
843 |
|
{ |
1138 |
844 |
|
Util.assertNotNull( "file", file ); |
1139 |
845 |
|
Util.assertNotNull( "lzmaFile", lzmaFile ); |
1140 |
|
- |
LOGGER.debug.log( "LZMA encoding: ", file, " -> ", lzmaFile ); |
|
846 |
+ |
progress( "LZMA encoding: " + file + " -> " + lzmaFile ); |
1141 |
847 |
|
|
1142 |
848 |
|
try |
1143 |
849 |
|
{ |
|
@@ -1180,7 +886,7 @@ |
1180 |
886 |
|
{ |
1181 |
887 |
|
Util.assertNotNull( "lzmaFile", lzmaFile ); |
1182 |
888 |
|
Util.assertNotNull( "file", file ); |
1183 |
|
- |
LOGGER.debug.log( "LZMA decoding: ", lzmaFile, " -> ", file ); |
|
889 |
+ |
progress( "LZMA decoding: " + lzmaFile + " -> " + file ); |
1184 |
890 |
|
|
1185 |
891 |
|
try |
1186 |
892 |
|
{ |
|
@@ -1210,7 +916,7 @@ |
1210 |
916 |
|
throw new IllegalArgumentException( "password must be 6 or more characters." ); |
1211 |
917 |
|
} |
1212 |
918 |
|
|
1213 |
|
- |
LOGGER.info.log( "JWS: ", project ); |
|
919 |
+ |
progress( "JWS: " + project ); |
1214 |
920 |
|
|
1215 |
921 |
|
String jwsDir = mkdir( project.path( "$target$/jws/" ) ); |
1216 |
922 |
|
String distDir = project.path( "$target$/dist/" ); |
|
@@ -1243,7 +949,7 @@ |
1243 |
949 |
|
{ |
1244 |
950 |
|
Util.assertNotNull( "Project", project ); |
1245 |
951 |
|
|
1246 |
|
- |
LOGGER.info.log( "JWS htaccess: ", project ); |
|
952 |
+ |
progress( "JWS htaccess: " + project ); |
1247 |
953 |
|
|
1248 |
954 |
|
String jwsDir = mkdir( project.path( "$target$/jws/" ) ); |
1249 |
955 |
|
for ( String packedFile : new Paths( jwsDir + "packed", "*.jar.pack.gz" ) ) |
|
@@ -1316,11 +1022,11 @@ |
1316 |
1022 |
|
|
1317 |
1023 |
|
if ( LOGGER.debug.isEnabled() ) |
1318 |
1024 |
|
{ |
1319 |
|
- |
LOGGER.debug.log( "JNLP: " + project + " (" + url + ", " + company + ", " + title + ", " + splashImage + ")" ); |
|
1025 |
+ |
progress( "JNLP: " + project + " (" + url + ", " + company + ", " + title + ", " + splashImage + ")" ); |
1320 |
1026 |
|
} |
1321 |
1027 |
|
else |
1322 |
1028 |
|
{ |
1323 |
|
- |
LOGGER.info.log( "JNLP: ", project ); |
|
1029 |
+ |
progress( "JNLP: " + project ); |
1324 |
1030 |
|
} |
1325 |
1031 |
|
|
1326 |
1032 |
|
if ( !project.hasMain() ) |
|
@@ -1439,7 +1145,7 @@ |
1439 |
1145 |
|
throw new IllegalArgumentException( "password must be 6 or more characters." ); |
1440 |
1146 |
|
} |
1441 |
1147 |
|
|
1442 |
|
- |
LOGGER.info.log( "LWJGL applet: ", project ); |
|
1148 |
+ |
progress( "LWJGL applet: " + project ); |
1443 |
1149 |
|
|
1444 |
1150 |
|
String appletDir = mkdir( project.path( "$target$/applet-lwjgl/" ) ); |
1445 |
1151 |
|
String distDir = project.path( "$target$/dist/" ); |
|
@@ -1471,7 +1177,7 @@ |
1471 |
1177 |
|
LOGGER.debug.log( "Unable to generate applet.html: project has no main class" ); |
1472 |
1178 |
|
return appletDir; |
1473 |
1179 |
|
} |
1474 |
|
- |
LOGGER.info.log( "Generating: applet.html" ); |
|
1180 |
+ |
progress( "Generating: applet.html" ); |
1475 |
1181 |
|
FileWriter writer = new FileWriter( appletDir + "applet.html" ); |
1476 |
1182 |
|
try |
1477 |
1183 |
|
{ |
|
@@ -1551,7 +1257,7 @@ |
1551 |
1257 |
|
{ |
1552 |
1258 |
|
Util.assertNotNull( "Project", project ); |
1553 |
1259 |
|
|
1554 |
|
- |
LOGGER.info.log( "One JAR: ", project ); |
|
1260 |
+ |
progress( "One JAR: " + project ); |
1555 |
1261 |
|
|
1556 |
1262 |
|
String onejarDir = mkdir( project.path( "$target$/onejar/" ) ); |
1557 |
1263 |
|
String distDir = project.path( "$target$/dist/" ); |
|
@@ -1592,7 +1298,7 @@ |
1592 |
1298 |
|
onejarFile = project.path( "$target$/dist/onejar/$name$-all.jar" ); |
1593 |
1299 |
|
} |
1594 |
1300 |
|
mkdir( parent( onejarFile ) ); |
1595 |
|
- |
jar( onejarFile, new Paths( onejarDir ) ); |
|
1301 |
+ |
// todo: jar( onejarFile, new Paths( onejarDir ) ); |
1596 |
1302 |
|
} |
1597 |
1303 |
|
|
1598 |
1304 |
|
/** |
|
@@ -1645,7 +1351,7 @@ |
1645 |
1351 |
|
|
1646 |
1352 |
|
// Append code, collecting imports statements and classpath URLs. |
1647 |
1353 |
|
StringBuilder importBuffer = new StringBuilder( 512 ); |
1648 |
|
- |
ArrayList<URL> classpathURLs = new ArrayList(); |
|
1354 |
+ |
ArrayList<URL> classpathURLs = new ArrayList<URL>(); |
1649 |
1355 |
|
BufferedReader reader = new BufferedReader( new StringReader( code ) ); |
1650 |
1356 |
|
boolean header = true; |
1651 |
1357 |
|
while ( true ) |
|
@@ -1686,8 +1392,10 @@ |
1686 |
1392 |
|
classBuffer.append( "}}" ); |
1687 |
1393 |
|
|
1688 |
1394 |
|
final String classCode = importBuffer.append( classBuffer ).toString(); |
1689 |
|
- |
LOGGER.trace.log( "Executing code:\n", classCode ); |
1690 |
|
- |
|
|
1395 |
+ |
if ( LOGGER.trace.isEnabled() ) |
|
1396 |
+ |
{ |
|
1397 |
+ |
progress( "Executing code:\n" + classCode ); |
|
1398 |
+ |
} |
1691 |
1399 |
|
// Compile class. |
1692 |
1400 |
|
Class generatedClass = compileDynamicCodeToClass( pOverheadStartLines, classCode, classpathURLs.toArray( new URL[classpathURLs.size()] ) ); |
1693 |
1401 |
|
|
|
@@ -1734,7 +1442,7 @@ |
1734 |
1442 |
|
|
1735 |
1443 |
|
static |
1736 |
1444 |
|
{ |
1737 |
|
- |
Paths.setDefaultGlobExcludes( "**/.svn/**" ); |
|
1445 |
+ |
Paths.addDefaultGlobExcludes( "**/.svn/**" ); |
1738 |
1446 |
|
} |
1739 |
1447 |
|
|
1740 |
1448 |
|
/// todo: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Here be Dragons ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
|
@@ -1800,6 +1508,11 @@ |
1800 |
1508 |
|
pProject.initialize( pFactory ); |
1801 |
1509 |
|
return pProject; |
1802 |
1510 |
|
} |
|
1511 |
+ |
|
|
1512 |
+ |
public Set<Project> getAllProjects() |
|
1513 |
+ |
{ |
|
1514 |
+ |
return new HashSet<Project>( mProjectByName.values() ); |
|
1515 |
+ |
} |
1803 |
1516 |
|
} |
1804 |
1517 |
|
|
1805 |
1518 |
|
protected Runnable createRunnableFor( String pMethodName ) |
|
@@ -1860,7 +1573,7 @@ |
1860 |
1573 |
|
protected void createLaunchProject() |
1861 |
1574 |
|
throws IOException |
1862 |
1575 |
|
{ |
1863 |
|
- |
mLaunchProject = project( new File( System.getProperty("user.dir") ), mArgs.get( "file", "." ) ); |
|
1576 |
+ |
mLaunchProject = project( new File( System.getProperty( "user.dir" ) ), mArgs.get( "file", "." ) ); |
1864 |
1577 |
|
} |
1865 |
1578 |
|
|
1866 |
1579 |
|
protected int run() |