Skip to content

Instantly share code, notes, and snippets.

/build.gradle Secret

Created March 19, 2013 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/185dac54c667a763e99f to your computer and use it in GitHub Desktop.
Save anonymous/185dac54c667a763e99f to your computer and use it in GitHub Desktop.
import java.text.*
apply plugin: 'java'
task commit {
doLast {
boolean wasSomethingCommited = commitWorkspaceChanges('test')
}
}
/**
* cvsDirToCommit - relative directory
*/
boolean commitWorkspaceChanges(String cvsDirToCommit, boolean noexec = false) {
println "********* commitWorkspaceChanges() **************"
File tempDir = new File("${buildDir}/cvs")
tempDir.mkdirs()
int counter = prepareDirectoryForCommit(cvsDirToCommit, tempDir, noexec)
//Workspace commiten
String commitMessage = 'Automatischer commit durch Gradle'
ant.cvs(command: "commit -m \"$commitMessage\"",
dest: "$cvsDirToCommit",
//output: "$changesFile",
//error: "$errorFile",
noexec: noexec,
//quiet: 'true',
failonerror: 'true')
return wasSomethingCommited
}
/**
* cvsDirToCommit - relative path
*/
int prepareDirectoryForCommit(String cvsDirToCommit, File tempDir, boolean noexec) {
println "********* prepareDirectoryForCommit() **************"
println "cvsDirToCommit: $cvsDirToCommit"
String cvsDirToCommitForLogFile = cvsDirToCommit.replace('/', '.')
if (!tempDir.isDirectory()) {
println "tempDir ist kein Verzeichnis: $tempDir"
assert false
}
//File dirToCommit = new File(parentDir.absolutePath + "/" + cvsDirToCommit)
File dirToCommit = new File(cvsDirToCommit)
println "dirToCommit: " + dirToCommit.getAbsolutePath()
if (!dirToCommit.isDirectory()) {
println "dirToCommit ist kein Verzeichnis: $dirToCommit"
assert false
}
File changesFile = new File("$tempDir/cvs.update.${cvsDirToCommitForLogFile}.txt")
changesFile.delete()
File errorFile = new File("$tempDir/cvs.update.${cvsDirToCommitForLogFile}.error.txt")
errorFile.delete()
// Durch einen update ohne was zu machen (-n) die geänderten Dateien und Verzeichnisse finden
ant.cvs(command: "update -d",
dest: "$dirToCommit",
output: "$changesFile",
error: "$errorFile",
noexec: 'true',
quiet: 'true',
//append: 'false',
failonerror: 'true')
int counter = 0
// Ausgabe des CVS updates bearbeiten
changesFile.eachLine {
counter = counter + prepareEntryForCommit(it, cvsDirToCommit, tempDir, noexec)
}
if (counter == 0) {
println "Nichts neues zum Commiten in Verzeichnis " + cvsDirToCommit
}
return counter;
}
int prepareEntryForCommit(String line, String cvsDirToCommit, File tempDir, boolean noexec) {
println "********* prepareEntryForCommit() **************"
println "line: $line"
println "currentDir: " + new File(".").getAbsolutePath()
int counter = 0
String[] parts = line.split(" ")
if (parts.length != 2) {
println "Eine Zeile muss immer aus zwei Strings mit einem Leerzeichen dazwischen bestehen " +
"z.B. U testdir/file3.txt"
assert false;
}
String cvsAction = parts[0];
String cvsFileString = parts[1];
String cvsFilesStringAll = cvsDirToCommit + "/" + cvsFileString
String cvsFilesStringAllForLoagFile = cvsFilesStringAll.replace('/', '.')
File cvsFile = new File(cvsFilesStringAll)
boolean isFile = false;
boolean isDirectory = false
boolean isMissing = false
println "cvsFile: " + cvsFile.getAbsolutePath()
if (cvsFile.isFile()) {
println "File: $cvsFile"
isFile = true
} else if (cvsFile.isDirectory()) {
println "Directory: $cvsFile"
isDirectory = true
} else {
//println "Eintrag ist weder Datei noch Verzeichnis: " + cvsFilesStringAll
//Kann aber auch geloescht worden sein
isMissing = true
}
if (cvsAction.equals('?')) {
//Datei oder Verzeichnis sind neu
println "Datei " + "$cvsFilesStringAll" + " wird hinzugefuegt (cvs add $cvsFilesStringAll)"
// def proc = "cvs add $cvsFilesStringAll".execute()
// proc.waitForOrKill(1000)
ant.cvs(command: "add $cvsFilesStringAll",
output: tempDir.getAbsolutePath() + "/" + "cvs.commit.add.${cvsFilesStringAllForLoagFile}.log",
error: tempDir.getAbsolutePath() + "/" + "cvs.commit.add.${cvsFilesStringAllForLoagFile}.error.log",
append: 'true',
noexec: noexec,
//quiet: 'false',
failonerror: 'true')
sleep 200
if (isDirectory) {
//Recursion: Neue Verzeichnis auch prüfen nach cvs add
counter = prepareDirectoryForCommit(cvsFilesStringAll, tempDir, true)
} else {
counter++
}
} else if (cvsAction.equals('M')) {
//Datei wurde seit dem letzten Checkout modifiziert
println "Ok, $cvsFilesStringAll already added to cvs"
counter++
} else if (cvsAction.equals('U')) {
//Es gibt eine aktuellere Version am CVS-Server oder die Datei wurde geloescht lokal.
//Ein cvs update gibt nicht direkt aus, dass eine Datei lokal geloescht wurde, sondern eine zusaetzliche Fehlermeldung
// Check ob die Datei wirklich geloescht wurde
if (isMissing) {
println "Datei " + "$cvsFilesStringAll" + " wird geloescht (cvs remove)"
ant.cvs(command: "remove $cvsFilesStringAll",
output: tempDir.getAbsolutePath() + "/" + "cvs.commit.del.${cvsFilesStringAllForLoagFile}.log",
error: tempDir.getAbsolutePath() + "/" + "cvs.commit.del.${cvsFilesStringAllForLoagFile}.error.log",
append: 'true',
noexec: noexec,
//quiet: 'false',
failonerror: 'true')
} else {
println "Die Datei $cvsFilesStringAll ist nicht aktuell. Es gibt eine neuere Version am CVS-Server."
assert false
}
counter++
} else if (cvsAction.equals('R')) {
//Datei wurde geloescht lokal (removed X)
//ok, Datei wurde bereits als removed gekennzeichnet
counter++
} else if (cvsAction.equals('A')) {
//Datei wurde hinzugefuegt (added)
println "Ok, $cvsFilesStringAll already added to cvs"
counter++
//} else if (cvsAction.equals('W')) { //The working copy of a file was deleted during update (because it was gone from the repository).
//} else if (cvsAction.equals('G')) { //A merge was necessary and it succeeded.
//} else if (cvsAction.equals('C')) { //A merge was necessary but collisions were detected (requiring manual merging).
} else {
println "Unbekannte CVS Aktion: " + cvsAction
assert false;
}
return counter
}
project
| build.gradle
|
+---test (CVS controled)
| file0.txt (CVS controled)
|
+---testdir1
| file1.txt
|
\---testdir7
| file7_1.txt
|
\---testdir72
\---testdir721
file721_1.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment