Skip to content

Instantly share code, notes, and snippets.

@ndeloof
Created April 6, 2012 17:00
Show Gist options
  • Save ndeloof/2321337 to your computer and use it in GitHub Desktop.
Save ndeloof/2321337 to your computer and use it in GitHub Desktop.
new File("plugins").eachLine { p ->
println "--- ${p} ---"
File d = new File("${p}-plugin")
if (!d.exists()) {
checkout(p)
}
injectRepo(d)
// commit(d)
}
def checkout(String p) {
def proc = "git clone [email protected]:jenkinsci/${p}-plugin.git".execute()
proc.waitFor()
if (proc.exitValue() != 0) {
println ">>> stderr: ${proc.err.text}"
return
}
proc = "git --git-dir=${p}-plugin/.git rev-parse origin/master".execute()
proc.waitFor()
if (proc.exitValue() != 0) {
println ">>> stderr: ${proc.err.text}"
return
}
def master = proc.in.text
proc = "git --git-dir=${p}-plugin/.git rev-parse origin/svn".execute()
proc.waitFor()
if (proc.exitValue() != 0) {
def err = proc.err.text
if (err.contains("unknown revision or path")) {
// no svn branch, just a pure git repo
} else {
println ">>> stderr: ${err}"
return
}
}
def svn = proc.in.text
if (svn == master) {
println "still hosted on svn"
new AntBuilder().delete(dir: "${p}-plugin")
proc = "svn co --username ndeloof https://svn.jenkins-ci.org/trunk/hudson/plugins/${p} ${p}-plugin".execute()
proc.waitFor()
if (proc.exitValue() != 0) {
println ">>> stderr: ${proc.err.text}"
return
}
}
}
def commit(File d) {
if (new File(d, ".git").exists()) {
def proc = "git add pom.xml".execute(null, d)
proc.waitFor()
proc = "git ci -F ../commit".execute(null, d)
proc.waitFor()
proc = "git push origin master".execute(null, d)
proc.waitFor()
} else {
proc = "svn ci -F ../commit".execute(null, d)
proc.waitFor()
}
}
def injectRepo(File f) {
File pom = new File(f, "pom.xml")
def model = pom.text
def updated = model
.replaceAll("http://maven.glassfish.org/content/groups/public/", "http://repo.jenkins-ci.org/public/")
.replaceAll("m.g.o-public", "repo.jenkins-ci.org")
def xml = new XmlParser().parseText(updated)
def repo = xml.'**'.repositories.repository
if (repo.size() == 0) {
updated = updated.replace("</project>",
"""
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
</project>
""")
} else {
checkRepo(repo)
}
def pluginrepo = xml.'**'.pluginRepositories.pluginRepository
if (pluginrepo.size() == 0) {
updated = updated.replace("</project>",
"""
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
</project>
""")
} else {
checkRepo(pluginrepo)
}
if (model != updated) {
println( "pom.xml updated to use repo.jenkins-ci.org")
pom.write(updated)
}
}
def checkRepo(repos) {
repos.each {
def id = it.id.text()
def url = it.url.text()
if ((url == "http://repo.jenkins-ci.org/public/") && (id == "repo.jenkins-ci.org")) {
// good citizen
} else {
println "incorrect repository found : ${id}::${url}"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment