Subversion Repository Public Repository

litesoft

Diff Revisions 364 vs 366 for /trunk/Java/ScarPlus/src/com/esotericsoftware/scar/Project.java

Diff revisions: vs.
  @@ -31,7 +31,7 @@
31 31
32 32 public Project( ProjectParameters pParameters )
33 33 {
34 - super( pParameters );
34 + super( pParameters.validate() );
35 35 applyDefaults();
36 36 }
37 37
  @@ -40,6 +40,102 @@
40 40 return "1.6";
41 41 }
42 42
43 + protected void packageClean()
44 + {
45 + delete( getAppDirPath() );
46 + delete( getOneJarPath() );
47 + delete( getWarPath() );
48 + }
49 +
50 + protected boolean packageIt()
51 + {
52 + return appDir() | oneJAR() | war(); // Note: SINGLE '|' ORs to force full execution!
53 + }
54 +
55 + /**
56 + * Unzips all JARs in the classpath and creates a single JAR containing those files and this Project's JAR (which MUST exist).
57 + * The manifest from the project's JAR is used. Putting everything into a single JAR makes it harder to see what libraries are
58 + * being used, but makes it easier for end users to distribute the application.
59 + * <p/>
60 + * Note: Files with the same path in different JARs will be overwritten. Files in the project's JAR will never be overwritten,
61 + * but may overwrite other files.
62 + *
63 + * @param pExcludeJARs The names of any JARs to exclude.
64 + *
65 + * @return True if the "OneJAR" was created / updated or false if no OneJar is NOT requested for this project or it was not needed.
66 + */
67 + public boolean oneJAR( String... pExcludeJARs )
68 + {
69 + File zOneJarPath = getOneJarPathFile();
70 +
71 + if ( zOneJarPath == null )
72 + {
73 + return false;
74 + }
75 +
76 + File zJarPath = getJarPathFile();
77 + if ( !zJarPath.isFile() )
78 + {
79 + throw new IllegalStateException( "One JAR: " + this + " requested, BUT NO jar File produced at: " + zJarPath.getPath() );
80 + }
81 +
82 + if ( zOneJarPath.isFile() && (zOneJarPath.lastModified() >= zJarPath.lastModified()) )
83 + {
84 + progress( "One JAR: " + this + " NOT Needed!" );
85 + return false;
86 + }
87 +
88 + Paths zClasspath = classpath();
89 + if ( zClasspath.isEmpty() )
90 + {
91 + progress( "One JAR: " + this + " No supporting Jars! Simply Copying to: " + zOneJarPath.getPath() );
92 + copyFile( zJarPath, zOneJarPath );
93 + return true;
94 + }
95 + progress( "One JAR: " + this );
96 +
97 + File zOnejarDir = mkdir( new File( path( "$target$/onejar/" ) ) );
98 +
99 + List<String> zExcludeJARs = Arrays.asList( pExcludeJARs );
100 + for ( File jarFile : zClasspath.getFiles() ) // All our Class Path (dependant) JARS
101 + {
102 + if ( !zExcludeJARs.contains( jarFile.getName() ) )
103 + {
104 + unzip( jarFile, zOnejarDir );
105 + }
106 + }
107 +
108 + unzip( zJarPath, zOnejarDir ); // Our Jar! - Our Manifest will be "the" Manifest !!!!!! Need to remove class PATH!
109 + innerJar( "'ONE' JAR", zOneJarPath.getPath(), new Paths( zOnejarDir.getPath() ) );
110 + return true;
111 + }
112 +
113 + /**
114 + * Collects the distribution files using the "dist" property, the project's JAR file, and everything on the project's classpath
115 + * (including dependency project classpaths) and places them into the specified directory. This is also done for depenency projects,
116 + * recursively. This is everything the application needs to be run from JAR files.
117 + *
118 + * @return True if the AppDir was populated or false if no distribution (App Dir) is requested for this project.
119 + */
120 + public boolean appDir()
121 + {
122 + String zAppDir = getAppDirPath();
123 + if ( zAppDir == null )
124 + {
125 + return false;
126 + }
127 + progress( "AppDir: " + this + " -> " + zAppDir );
128 + String distDir = mkdir( zAppDir );
129 +
130 + // todo: xxxx
131 + classpath().copyTo( distDir );
132 + Paths distPaths = getDist();
133 + // dependencyDistPaths( distPaths );
134 + distPaths.copyTo( distDir );
135 + new Paths( getTargetPath(), "*.jar" ).copyTo( distDir );
136 + return true;
137 + }
138 +
43 139 /**
44 140 * Produce either a 'war' directory or a '.war' file, in theary ready to deploy to a servlet/web container.
45 141 *
  @@ -94,6 +190,40 @@
94 190 return true;
95 191 }
96 192
193 + // private Paths dependencyDistPaths( Paths paths )
194 + // {
195 + // Paths paths = new Paths();
196 + // for ( Project zProject : mDependantProjects )
197 + // {
198 + // zProject.addDependantProjectsDistPaths( paths );
199 + // }
200 + // return classpath;
201 + // {
202 + // }
203 + //
204 + // for ( String dependency : getDependencies() )
205 + // {
206 + // Project dependencyProject = null; // todo: project( null, path( dependency ) );
207 + // String dependencyTarget = dependencyProject.getTargetPath();
208 + // if ( !Utils.fileExists( dependencyTarget ) )
209 + // {
210 + // throw new RuntimeException( "Dependency has not been built: " + dependency );
211 + // }
212 + // paths.glob( dependencyTarget + "dist", "!*/**.jar" );
213 + // paths.add( dependencyDistPaths( paths ) );
214 + // }
215 + // return paths;
216 + // }
217 +
218 + /**
219 + * Computes the classpath for all the dependencies of the specified project, recursively.
220 + */
221 + protected void addDependantProjectsDistPaths( Paths pPathsToAddTo )
222 + {
223 + // todo: xxx addDependentProjectJar( pPathsToAddTo );
224 + // todo: xxx pPathsToAddTo.add( classpath() );
225 + }
226 +
97 227 protected boolean GWTcompileIt()
98 228 {
99 229 String[] args = //
  @@ -370,7 +500,7 @@
370 500 }
371 501
372 502 /**
373 - * Executes the buildDependencies, clean, compile, jar, and dist utility methods.
503 + * Executes the buildDependencies, clean, compile, jar, [GWTcompile], and then "packageIt" utility methods.
374 504 */
375 505 public synchronized boolean build()
376 506 {
  @@ -379,13 +509,22 @@
379 509 return false;
380 510 }
381 511 mBuilt = true;
512 + boolean zAnythingBuilt = false;
382 513 if ( !buildDependencies() && !needToBuild() )
383 514 {
384 515 progress( "Build: " + this + " NOT Needed!" );
385 - return packageIt();
386 516 }
387 - progress( "Build: " + this );
388 - return buildIt();
517 + else
518 + {
519 + progress( "Build: " + this );
520 + clean();
521 + compile();
522 + jar();
523 + zAnythingBuilt = true;
524 + }
525 + zAnythingBuilt |= GWTcompile();
526 + zAnythingBuilt |= packageIt();
527 + return zAnythingBuilt;
389 528 }
390 529
391 530 protected boolean needToBuild()
  @@ -408,30 +547,14 @@
408 547 return (zLastModified != null) && (zLastModified > pJarTimestamp);
409 548 }
410 549
411 - protected boolean buildIt()
412 - {
413 - clean();
414 - compile();
415 - String zJarFile = jar();
416 - return packageIt() || (zJarFile != null);
417 - }
418 -
419 - protected boolean packageIt()
420 - {
421 - boolean zPackaged = GWTcompile();
422 - zPackaged |= (null != dist());
423 - zPackaged |= (null != oneJAR());
424 - zPackaged |= war();
425 - return zPackaged;
426 - }
427 -
428 550 /**
429 551 * Deletes the "target" directory and all files and directories under it.
430 552 */
431 553 public void clean()
432 554 {
433 555 progress( "Clean: " + this );
434 - delete( getAppDirPath() );
556 + packageClean();
557 + delete( getGWTwarPath() );
435 558 delete( getJarPath() );
436 559 delete( getTargetPath() );
437 560 }
  @@ -649,52 +772,6 @@
649 772 }
650 773
651 774 /**
652 - * Collects the distribution files using the "dist" property, the project's JAR file, and everything on the project's classpath
653 - * (including dependency project classpaths) and places them into a "dist" directory under the "target" directory. This is also
654 - * done for depenency projects, recursively. This is everything the application needs to be run from JAR files.
655 - *
656 - * @return The path to the "dist" directory or null if no distribution (App Dir) is requested for this project.
657 - */
658 - public String dist()
659 - {
660 - String zAppDir = getAppDir();
661 - if ( zAppDir == null )
662 - {
663 - return null;
664 - }
665 - progress( "Dist: " + this );
666 -
667 - if ( !LOGGER.trace.isEnabled() )
668 - {
669 - return null; // todo: ...
670 - }
671 -
672 - String distDir = mkdir( path( "$target$/dist/" ) );
673 - classpath().copyTo( distDir );
674 - Paths distPaths = getDist();
675 - dependencyDistPaths( distPaths );
676 - distPaths.copyTo( distDir );
677 - new Paths( getTargetPath(), "*.jar" ).copyTo( distDir );
678 - return distDir;
679 - }
680 -
681 - private Paths dependencyDistPaths( Paths paths )
682 - {
683 - for ( String dependency : getDependencies() )
684 - {
685 - Project dependencyProject = null; // todo: project( null, path( dependency ) );
686 - String dependencyTarget = dependencyProject.getTargetPath();
687 - if ( !Utils.fileExists( dependencyTarget ) )
688 - {
689 - throw new RuntimeException( "Dependency has not been built: " + dependency );
690 - }
691 - paths.glob( dependencyTarget + "dist", "!*/**.jar" );
692 - paths.add( dependencyDistPaths( paths ) );
693 - }
694 - return paths;
695 - }
696 -
697 - /**
698 775 * Encodes the specified paths into a JAR file.
699 776 *
700 777 * @return The path to the JAR file.
  @@ -764,64 +841,6 @@
764 841 }
765 842
766 843 /**
767 - * Unzips all JARs in the classpath and creates a single JAR containing those files and this Project's JAR (which MUST exist).
768 - * The manifest from the project's JAR is used. Putting everything into a single JAR makes it harder to see what libraries are
769 - * being used, but makes it easier for end users to distribute the application.
770 - * <p/>
771 - * Note: Files with the same path in different JARs will be overwritten. Files in the project's JAR will never be overwritten,
772 - * but may overwrite other files.
773 - *
774 - * @param pExcludeJARs The names of any JARs to exclude.
775 - *
776 - * @return The path to the "OneJAR" file or null if no OneJar is requested for this project.
777 - */
778 - public String oneJAR( String... pExcludeJARs )
779 - {
780 - File zOneJarPath = getOneJarPathFile();
781 -
782 - if ( zOneJarPath == null )
783 - {
784 - return null;
785 - }
786 -
787 - File zJarPath = getJarPathFile();
788 - if ( !zJarPath.isFile() )
789 - {
790 - progress( "One JAR: " + this + " BUT NO jar File produced at: " + zJarPath.getPath() );
791 - return null;
792 - }
793 -
794 - if ( zOneJarPath.isFile() && (zOneJarPath.lastModified() >= zJarPath.lastModified()) )
795 - {
796 - progress( "One JAR: " + this + " NOT Needed!" );
797 - return null;
798 - }
799 -
800 - Paths zClasspath = classpath();
801 - if ( zClasspath.isEmpty() )
802 - {
803 - progress( "One JAR: " + this + " No supporting Jars! Simply Copying to: " + zOneJarPath.getPath() );
804 - copyFile( zJarPath, zOneJarPath );
805 - return zOneJarPath.getPath();
806 - }
807 - progress( "One JAR: " + this );
808 -
809 - File zOnejarDir = mkdir( new File( path( "$target$/onejar/" ) ) );
810 -
811 - List<String> zExcludeJARs = Arrays.asList( pExcludeJARs );
812 - for ( File jarFile : zClasspath.getFiles() ) // All our Class Path (dependant) JARS
813 - {
814 - if ( !zExcludeJARs.contains( jarFile.getName() ) )
815 - {
816 - unzip( jarFile, zOnejarDir );
817 - }
818 - }
819 -
820 - unzip( zJarPath, zOnejarDir ); // Our Jar! - Our Manifest will be "the" Manifest !!!!!! Need to remove class PATH!
821 - return innerJar( "'ONE' JAR", zOneJarPath.getPath(), new Paths( zOnejarDir.getPath() ) );
822 - }
823 -
824 - /**
825 844 * Decodes the specified ZIP file.
826 845 *
827 846 * @return The path to the output directory.