Subversion Repository Public Repository

litesoft

Diff Revisions 314 vs 315 for /trunk/Java/ScarPlus/src/com/esotericsoftware/scar/Project.java

Diff revisions: vs.
  @@ -24,7 +24,8 @@
24 24
25 25 public Project( ProjectParameters pParameters )
26 26 {
27 - super( pParameters.getName(), pParameters.getCanonicalProjectDir(), pParameters.mData );
27 + super( pParameters );
28 + applyDefaults();
28 29 }
29 30
30 31 public String getTargetJavaVersion()
  @@ -32,35 +33,23 @@
32 33 return "1.6";
33 34 }
34 35
35 - public synchronized void set( Object key, Object object )
36 + public void set( Object key, Object object )
36 37 {
37 - mData.put( updatableKey( key ), object );
38 + mManager.put( updatableKey( key ), object );
38 39 }
39 40
40 - public synchronized void remove( Object key )
41 + public void remove( Object key )
41 42 {
42 - mData.remove( updatableKey( key ) );
43 + set( key, null );
43 44 }
44 45
45 46 /**
46 47 * Removes an item from a list or map. If the mData under the specified key is a list, the entry equal to the specified value is
47 48 * removed. If the mData under the specified key is a map, the entry with the key specified by value is removed.
48 49 */
49 - public synchronized void remove( Object key, Object value )
50 + public void remove( Object key, Object value )
50 51 {
51 - Object object = mData.get( key = updatableKey( key ) );
52 - if ( object instanceof Map )
53 - {
54 - ((Map) object).remove( value );
55 - }
56 - else if ( object instanceof List )
57 - {
58 - ((List) object).remove( value );
59 - }
60 - else
61 - {
62 - mData.remove( key );
63 - }
52 + mManager.remove( updatableKey( key ), value );
64 53 }
65 54
66 55 private Object updatableKey( Object pKey )
  @@ -82,30 +71,28 @@
82 71 * Executes the buildDependencies, clean, compile, jar, and dist utility methods.
83 72 */
84 73 public synchronized boolean build()
85 - throws IOException
86 74 {
87 75 if ( mBuilt )
88 76 {
89 77 return false;
90 78 }
79 + mBuilt = true;
91 80 if ( !buildDependencies() && !needToBuild() )
92 81 {
93 82 progress( "Build: " + this + " NOT Needed!" );
94 - return false;
83 + return (null != dist());
95 84 }
96 85 progress( "Build: " + this );
97 86 buildIt();
98 - return (mBuilt = true);
87 + return true;
99 88 }
100 89
101 90 public boolean needToBuild()
102 - throws IOException
103 91 {
104 92 return true; // todo
105 93 }
106 94
107 95 protected void buildIt()
108 - throws IOException
109 96 {
110 97 clean();
111 98 compile();
  @@ -117,10 +104,11 @@
117 104 * Deletes the "target" directory and all files and directories under it.
118 105 */
119 106 public void clean()
120 - throws IOException
121 107 {
122 108 progress( "Clean: " + this );
123 - delete( path( "$target$" ) );
109 + deletePath( getAppDir() );
110 + deletePath( getJar() );
111 + deletePath( getTarget() );
124 112 }
125 113
126 114 /**
  @@ -129,24 +117,18 @@
129 117 * <p/>
130 118 * Note: Each dependency project is not built automatically. Each needs to be built before the dependent project.
131 119 *
132 - * @return The path to the "classes" directory.
120 + * @return The path to the "classes" directory or null if there was no sources to compile
133 121 */
134 122 public String compile()
135 - throws IOException
136 123 {
137 - Paths classpath = classpath();
138 124 Paths source = getSource();
139 -
140 - String classesDir = mkdir( path( "$target$/classes/" ) );
141 -
142 125 if ( source.isEmpty() )
143 126 {
144 - if ( LOGGER.warn.isEnabled() )
145 - {
146 - progress( "Compile: " + this + " --- No source files found." );
147 - }
148 - return classesDir;
127 + return null;
149 128 }
129 + Paths classpath = classpath();
130 +
131 + String classesDir = mkdir( path( "$target$/classes/" ) );
150 132
151 133 if ( LOGGER.debug.isEnabled() )
152 134 {
  @@ -157,8 +139,6 @@
157 139 progress( "Compile: " + this );
158 140 }
159 141
160 - // File tempFile = File.createTempFile( "scar", "compile" );
161 -
162 142 List<String> zCompileArgs = createCompileJavaArgs( classpath, source, classesDir );
163 143
164 144 compileJava( classpath, source, zCompileArgs );
  @@ -216,32 +196,36 @@
216 196 * If the resources don't contain a META-INF/MANIFEST.MF file, one is generated. If the project has a main property, the
217 197 * generated manifest will include "Main-Class" and "Class-Path" entries to allow the main class to be run with "java -jar".
218 198 *
219 - * @return The path to the created JAR file.
199 + * @return The path to the created JAR file or null if No JAR created.
220 200 */
221 201 public String jar()
222 - throws IOException
223 202 {
224 - progress( "JAR: " + this );
203 + String zJarFile = path( getJar() );
225 204
226 - String jarDir = mkdir( path( "$target$/jar/" ) );
205 + Paths zClasses = new Paths( path( "$target$/classes/" ), "**/*.class" );
206 + Paths zResources = getResources();
207 + if ( zClasses.isEmpty() && zResources.isEmpty() )
208 + {
209 + delete( zJarFile );
210 + return null;
211 + }
212 + progress( "JAR: " + this + " -> " + zJarFile );
227 213
228 - String classesDir = path( "$target$/classes/" );
229 - new Paths( classesDir, "**/*.class" ).copyTo( jarDir );
230 - getResources().copyTo( jarDir );
214 + String jarDir = mkdir( path( "$target$/jar/" ) );
231 215
232 - String jarFile = path( "$target$/$name$" + (hasVersion() ? "-$version$" : "") + ".jar" );
216 + zClasses.copyTo( jarDir );
217 + zResources.copyTo( jarDir );
233 218
234 219 File manifestFile = new File( jarDir, "META-INF/MANIFEST.MF" );
235 220 if ( !manifestFile.exists() )
236 221 {
237 - createDefaultManifestFile( jarFile, manifestFile );
222 + createDefaultManifestFile( zJarFile, manifestFile );
238 223 }
239 224
240 - return jar( jarFile, new Paths( jarDir ) );
225 + return jar( zJarFile, new Paths( jarDir ) );
241 226 }
242 227
243 228 protected void createDefaultManifestFile( String pJarFile, File pManifestFile )
244 - throws IOException
245 229 {
246 230 LOGGER.debug.log( "Generating JAR manifest: ", pManifestFile );
247 231 mkdir( pManifestFile.getParent() );
  @@ -262,13 +246,17 @@
262 246 }
263 247 manifest.getMainAttributes().putValue( Attributes.Name.CLASS_PATH.toString(), buffer.toString() );
264 248 }
265 - OutputStream output = new FileOutputStream( pManifestFile );
249 + OutputStream output = createFileOutputStream( pManifestFile );
266 250 try
267 251 {
268 252 manifest.write( output );
269 253 Closeable zCloseable = output;
270 254 output = null;
271 - zCloseable.close();
255 + close( zCloseable );
256 + }
257 + catch ( IOException e )
258 + {
259 + throw new WrappedIOException( e );
272 260 }
273 261 finally
274 262 {
  @@ -281,11 +269,15 @@
281 269 * (including dependency project classpaths) and places them into a "dist" directory under the "target" directory. This is also
282 270 * done for depenency projects, recursively. This is everything the application needs to be run from JAR files.
283 271 *
284 - * @return The path to the "dist" directory.
272 + * @return The path to the "dist" directory or null if no distribution (App Dir) is requested for this project.
285 273 */
286 274 public String dist()
287 - throws IOException
288 275 {
276 + String zAppDir = getAppDir();
277 + if ( zAppDir == null )
278 + {
279 + return null;
280 + }
289 281 progress( "Dist: " + this );
290 282
291 283 if ( !LOGGER.trace.isEnabled() )
  @@ -303,7 +295,6 @@
303 295 }
304 296
305 297 private Paths dependencyDistPaths( Paths paths )
306 - throws IOException
307 298 {
308 299 for ( String dependency : getDependencies() )
309 300 {
  @@ -325,7 +316,6 @@
325 316 * @return The path to the JAR file.
326 317 */
327 318 public String jar( String jarFile, Paths paths )
328 - throws IOException
329 319 {
330 320 Util.assertNotNull( "jarFile", jarFile );
331 321 Util.assertNotNull( "paths", paths );
  @@ -336,10 +326,16 @@
336 326 {
337 327 @Override
338 328 public ZipOutputStream createZOS( String pFilePath, List<FilePath> pPaths )
339 - throws IOException
340 329 {
341 330 putManifestFirst( pPaths );
342 - return new JarOutputStream( new BufferedOutputStream( new FileOutputStream( pFilePath ) ) );
331 + try
332 + {
333 + return new JarOutputStream( new BufferedOutputStream( new FileOutputStream( pFilePath ) ) );
334 + }
335 + catch ( IOException e )
336 + {
337 + throw new WrappedIOException( e );
338 + }
343 339 }
344 340
345 341 @Override
  @@ -377,7 +373,6 @@
377 373 * Computes the classpath for the specified project and all its dependency projects, recursively.
378 374 */
379 375 public Paths classpath()
380 - throws IOException
381 376 {
382 377 Paths classpath = getClasspath();
383 378 for ( Project zProject : mDependantProjects )
  @@ -391,7 +386,6 @@
391 386 * Computes the classpath for all the dependencies of the specified project, recursively.
392 387 */
393 388 protected void addDependantProjectsClassPaths( Paths pPathsToAddTo, File pMasterProjectDirectory )
394 - throws IOException
395 389 {
396 390 return;
397 391 // for ( String dependency : getDependencies() )
  @@ -414,7 +408,6 @@
414 408 * Calls {@link #build(Project)} for each dependency project in the specified project.
415 409 */
416 410 public boolean buildDependencies()
417 - throws IOException
418 411 {
419 412 boolean anyBuilt = false;
420 413 for ( Project zProject : mDependantProjects )
  @@ -430,7 +423,6 @@
430 423 * affected.
431 424 */
432 425 // public void replace( Project project )
433 - // throws IOException
434 426 // {
435 427 // Util.assertNotNull( "project", project );
436 428 // mData.putAll( project.mData );
  @@ -438,7 +430,6 @@
438 430 // dir = project.dir;
439 431 // }
440 432 public synchronized void initialize( ProjectFactory pProjectFactory )
441 - throws IOException
442 433 {
443 434 List<String> zDependencies = getDependencies();
444 435 if ( zDependencies != null )