@@ -193,14 +193,18 @@ case class ScalatronUser(name: String, scalatron: ScalatronImpl) extends Scalatr
193
193
// no versions there yet!
194
194
Iterable .empty
195
195
} else {
196
- versionDirectories.filter(_.isDirectory).map(dir => {
196
+ versionDirectories
197
+ .filter(_.isDirectory)
198
+ .map(dir => {
197
199
val versionId = dir.getName.toInt
198
200
val versionConfigFilename = dir.getAbsolutePath + " /" + ConfigFilename
199
201
val paramMap = loadConfigFile(versionConfigFilename)
200
202
val label = paramMap.getOrElse(" label" , " " )
201
203
val date = paramMap.getOrElse(" date" , " " ).toLong
202
204
ScalatronVersion (versionId, label, date, this )
203
205
})
206
+ .toArray
207
+ .sortBy(_.id)
204
208
}
205
209
}
206
210
@@ -256,20 +260,20 @@ case class ScalatronUser(name: String, scalatron: ScalatronImpl) extends Scalatr
256
260
// write the given source files into the version directory
257
261
SourceFileCollection .writeTo(versionDirectoryPath, sourceFiles, scalatron.verbose)
258
262
259
- /*
260
- // 2012-04-16 was: copy the current contents of the source directory into the version directory
261
- val sourceDirectory = new File(sourceDirectoryPath)
262
- val sourceFiles = sourceDirectory.listFiles()
263
- if( sourceFiles == null || sourceFiles.isEmpty ) {
264
- // no source files there yet! -> nothing to do
265
- } else {
266
- sourceFiles.foreach(sourceFile => {
267
- val destPath = versionDirectoryPath + "/" + sourceFile.getName
268
- copyFile(sourceFile.getAbsolutePath, destPath)
269
- if( scalatron.verbose ) println("copied user source file for '" + name + "' to version: " + destPath)
270
- })
271
- }
272
- */
263
+ /*
264
+ // 2012-04-16 was: copy the current contents of the source directory into the version directory
265
+ val sourceDirectory = new File(sourceDirectoryPath)
266
+ val sourceFiles = sourceDirectory.listFiles()
267
+ if( sourceFiles == null || sourceFiles.isEmpty ) {
268
+ // no source files there yet! -> nothing to do
269
+ } else {
270
+ sourceFiles.foreach(sourceFile => {
271
+ val destPath = versionDirectoryPath + "/" + sourceFile.getName
272
+ copyFile(sourceFile.getAbsolutePath, destPath)
273
+ if( scalatron.verbose ) println("copied user source file for '" + name + "' to version: " + destPath)
274
+ })
275
+ }
276
+ */
273
277
274
278
ScalatronVersion (versionId, label, date, this )
275
279
}
@@ -278,51 +282,24 @@ case class ScalatronUser(name: String, scalatron: ScalatronImpl) extends Scalatr
278
282
def createBackupVersion (policy : VersionPolicy , label : String , updatedSourceFiles : SourceFileCollection ) =
279
283
policy match {
280
284
case VersionPolicy .IfDifferent =>
281
- val oldSourceFiles = sourceFiles
282
- val different =
283
- (oldSourceFiles.size == updatedSourceFiles.size) &&
284
- (oldSourceFiles.forall(oldSF => {
285
- updatedSourceFiles.find(_.filename == oldSF.filename) match {
286
- case None =>
287
- if (scalatron.verbose) println(" VersionPolicy.IfDifferent: file no longer exists: " + oldSF.filename)
288
- true // file present in old, but not in new => different
289
- case Some (newSF) =>
290
- if (scalatron.verbose) {
291
- // 2012-05-04 temp debugging information
292
- println(" VersionPolicy.IfDifferent: file still exists: " + oldSF.filename)
293
- if (newSF.code != oldSF.code) {
294
- println(" file contents different" )
295
-
296
- if (newSF.code.length != oldSF.code.length) {
297
- println(" file sizes are different: old %d vs new %d" .format(oldSF.code.length, newSF.code.length))
298
- }
299
-
300
- val newLineCount = newSF.code.lines.length
301
- val oldLineCount = oldSF.code.lines.length
302
- if (newLineCount > oldLineCount) {
303
- println(" new file contains more lines: %d vs %d" .format(newLineCount, oldLineCount))
304
- val newLines = newSF.code.lines
305
- val oldLines = oldSF.code.lines
306
- val linesWithIndex = newLines.zip(oldLines).zipWithIndex.map(l => " %04d: %60s %60s" .format(l._2, l._1._1, l._1._2))
307
- println(linesWithIndex.mkString(" \n " ))
308
- } else
309
- if (newLineCount < oldLineCount) {
310
- println(" old file contains more lines: %d vs %d" .format(newLineCount, oldLineCount))
311
- } else {
312
- println(" old file and new file contain same number of lines" )
313
- }
314
- }
315
- }
316
- newSF.code != oldSF.code // file present in old and new, so compare code
317
- }
318
- }))
285
+ val sourceFilesCurrentlyInWorkspace = sourceFiles
319
286
320
- if (different) {
321
- if (scalatron.verbose) println(" VersionPolicy.IfDifferent, files are different => creating backup version" )
322
- Some (createVersion(label, oldSourceFiles)) // backup old files as a version
323
- } else {
287
+ val workspaceEqualsUpdated = SourceFileCollection .areEqual(sourceFilesCurrentlyInWorkspace, updatedSourceFiles, scalatron.verbose)
288
+
289
+ val workspaceEqualsLatestVersion = latestVersion match {
290
+ case None =>
291
+ false
292
+ case Some (latestVersionInHistory) =>
293
+ val sourceFilesOfLatestVersion = latestVersionInHistory.sourceFiles
294
+ SourceFileCollection .areEqual(sourceFilesCurrentlyInWorkspace, sourceFilesOfLatestVersion, scalatron.verbose)
295
+ }
296
+
297
+ if (workspaceEqualsUpdated || workspaceEqualsLatestVersion) {
324
298
if (scalatron.verbose) println(" VersionPolicy.IfDifferent, files are unchanged => not creating backup version" )
325
299
None
300
+ } else {
301
+ if (scalatron.verbose) println(" VersionPolicy.IfDifferent, files are different => creating backup version" )
302
+ Some (createVersion(label, sourceFilesCurrentlyInWorkspace)) // backup old files as a version
326
303
}
327
304
328
305
case VersionPolicy .Always =>
0 commit comments