Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -87,9 +87,21 @@
87 87 return true;
88 88 }
89 89
90 - public boolean needToBuild()
90 + protected boolean needToBuild()
91 91 {
92 - return true; // todo
92 + File zJarFile = new File( path( getJar() ) );
93 + if ( !zJarFile.isFile() )
94 + {
95 + return true;
96 + }
97 + long zJarTimestamp = zJarFile.lastModified();
98 + return checkNewer( zJarTimestamp, classpath() ) || checkNewer( zJarTimestamp, getSource() ) || checkNewer( zJarTimestamp, getResources() );
99 + }
100 +
101 + protected boolean checkNewer( long pJarTimestamp, Paths pPaths )
102 + {
103 + Long zLastModified = pPaths.getGreatestLastModified();
104 + return (zLastModified != null) && (zLastModified > pJarTimestamp);
93 105 }
94 106
95 107 protected void buildIt()
  @@ -130,14 +142,16 @@
130 142
131 143 String classesDir = mkdir( path( "$target$/classes/" ) );
132 144
145 + String zMessage = "Compile: " + this;
133 146 if ( LOGGER.debug.isEnabled() )
134 147 {
135 - progress( "Compile: " + this + "\nSource: " + source.count() + " files\nClasspath: " + classpath );
136 - }
137 - else
138 - {
139 - progress( "Compile: " + this );
148 + zMessage += " | " + source.count() + " source files";
149 + if ( !classpath.isEmpty() )
150 + {
151 + zMessage += "\n Classpath: " + classpath;
152 + }
140 153 }
154 + progress( zMessage );
141 155
142 156 List<String> zCompileArgs = createCompileJavaArgs( classpath, source, classesDir );
143 157
  @@ -174,7 +188,7 @@
174 188 {
175 189 throw new RuntimeException( "No compiler available. Ensure you are running from a " + getTargetJavaVersion() + "+ JDK, and not a JRE." );
176 190 }
177 - int zError = compiler.run( null, null, null, pCompileArgs.toArray( new String[pCompileArgs.size()] ) );
191 + int zError = compiler.run( getCompile_in(), getCompile_out(), getCompile_err(), pCompileArgs.toArray( new String[pCompileArgs.size()] ) );
178 192 if ( zError != 0 )
179 193 {
180 194 throw new RuntimeException( "Error (" + zError + ") during compilation of project: " + this + "\nSource: " + pSource.count() + " files\nClasspath: " + pClasspath );
  @@ -189,6 +203,62 @@
189 203 }
190 204 }
191 205
206 + protected InputStream getCompile_in()
207 + {
208 + return null;
209 + }
210 +
211 + protected OutputStream getCompile_out()
212 + {
213 + return null;
214 + }
215 +
216 + protected OutputStream getCompile_err()
217 + {
218 + return new OutputStream()
219 + {
220 + private StringBuilder mBuffer = new StringBuilder();
221 + private boolean mLastWasCRtreatedAsLF = false;
222 +
223 + private void dumpLine( int pByte )
224 + {
225 + if ( pByte == 13 )
226 + {
227 + mLastWasCRtreatedAsLF = true;
228 + pByte = 10;
229 + }
230 + else
231 + {
232 + boolean zLastWasCRtreatedAsLF = mLastWasCRtreatedAsLF;
233 + mLastWasCRtreatedAsLF = false;
234 + if ( (pByte == 10) && zLastWasCRtreatedAsLF )
235 + {
236 + return;
237 + }
238 + }
239 + mBuffer.append( (char) pByte ); // Assuming Ascii!
240 + String line = mBuffer.toString();
241 + mBuffer = new StringBuilder();
242 + if ( !line.startsWith( "Note: " ) )
243 + {
244 + System.err.print( line );
245 + }
246 + }
247 +
248 + @Override
249 + public void write( int pByte ) // Not a Unicode character, just a BYTE! --- Asumming Ascii ---
250 + throws IOException
251 + {
252 + if ( (10 <= pByte) && (pByte <= 13) ) // New Line Indicator
253 + { // LF: Line Feed, U+000A
254 + dumpLine( pByte ); // VT: Vertical Tab, U+000B
255 + return; // FF: Form Feed, U+000C
256 + } // CR: Carriage Return, U+000D
257 + mBuffer.append( (char) pByte ); // Assuming Ascii!
258 + }
259 + };
260 + }
261 +
192 262 /**
193 263 * Collects the class files from the "classes" directory and all the resource files using the "resources" property and encodes
194 264 * them into a JAR file.
  @@ -372,12 +442,12 @@
372 442 /**
373 443 * Computes the classpath for the specified project and all its dependency projects, recursively.
374 444 */
375 - public Paths classpath()
445 + protected Paths classpath()
376 446 {
377 447 Paths classpath = getClasspath();
378 448 for ( Project zProject : mDependantProjects )
379 449 {
380 - zProject.addDependantProjectsClassPaths( classpath, getCanonicalProjectDir() );
450 + zProject.addDependantProjectsClassPaths( classpath );
381 451 }
382 452 return classpath;
383 453 }
  @@ -385,23 +455,15 @@
385 455 /**
386 456 * Computes the classpath for all the dependencies of the specified project, recursively.
387 457 */
388 - protected void addDependantProjectsClassPaths( Paths pPathsToAddTo, File pMasterProjectDirectory )
458 + protected void addDependantProjectsClassPaths( Paths pPathsToAddTo )
389 459 {
390 - return;
391 - // for ( String dependency : getDependencies() )
392 - // {
393 - // Project dependencyProject = null; // todo: project( null, path( dependency ) );
394 - // String dependencyTarget = dependencyProject.path( "$target$/" );
395 - // if ( errorIfDependenciesNotBuilt && !Utils.fileExists( dependencyTarget ) )
396 - // {
397 - // throw new RuntimeException( "Dependency has not been built: " + dependency ); // todo: + "\nAbsolute dependency path: " + canonical( dependency ) + "\nMissing dependency target: " + canonical( dependencyTarget ) );
398 - // }
399 - // if ( includeDependencyJAR )
400 - // {
401 - // pPathsToAddTo.glob( dependencyTarget, "*.jar" );
402 - // }
403 - // pPathsToAddTo.add( classpath() );
404 - // }
460 + File zJarFile = new File( path( getJar() ) );
461 + if ( !zJarFile.isFile() )
462 + {
463 + throw new RuntimeException( "Dependency (" + this + ") Jar not found, not built?" );
464 + }
465 + pPathsToAddTo.add( new FilePath( zJarFile.getParentFile(), zJarFile.getName() ) );
466 + pPathsToAddTo.add( classpath() );
405 467 }
406 468
407 469 /**