Permalink
Browse files

Merge pull request #53 from bchang/master

Updated to work with the official release of Aardvark 0.4
  • Loading branch information...
2 parents 30351e2 + 8bacf15 commit 5793011ae81cc0fd7e121640d3470de4e044b7d9 @kprevas committed Jun 9, 2012
View
@@ -1,53 +1,51 @@
+classpath "remote:releases:gosu-lang.org-releases:http://gosu-lang.org/nexus/content/groups/releases"
+classpath "org.gosu-lang.aardvark:aardvark-aether-utils:1.0-SNAPSHOT"
+
uses java.net.URL
uses java.io.File
uses gw.util.Shell
uses gw.xml.simple.SimpleXmlNode
+uses gw.vark.Aardvark
+uses gw.vark.aether.AetherUtil
+uses org.sonatype.aether.ant.types.Dependencies
+uses org.sonatype.aether.ant.types.Dependency
+uses org.sonatype.aether.ant.types.RemoteRepository
DefaultTarget = "init"
+var releasesRepo = new RemoteRepository() {
+ :Id = "gosu-lang.org-releases",
+ :Url = "http://gosu-lang.org/nexus/content/groups/releases"
+}
+var snapshotsRepo = new RemoteRepository() {
+ :Snapshots = true,
+ :Releases = false,
+ :Id = "gosu-lang.org-snapshots",
+ :Url = "http://gosu-lang.org/nexus/content/repositories/snapshots"
+}
/* Initializes a new Ronin application */
@Target
-function init(name : String = null, groupId : String = null, version : String = "1.0-SNAPSHOT", snapshot : boolean = false) {
+function init(name : String = null, groupId : String = null, version : String = "1.0-SNAPSHOT", roninVersion : String = null) {
while (not groupId?.HasContent) {
groupId = Shell.readLine("Please enter a group ID (e.g. \"com.yourcompany\"): ")
}
while (not name?.HasContent) {
name = Shell.readLine("Please enter a name for your application: ")
}
- var targetDir = new File(".", name)
+ var targetDir = file(name)
if(targetDir.exists()) {
Ant.fail(:message = "The directory ${targetDir.AbsolutePath} already exists. Please delete it or choose another name.")
} else {
- var archetype : File
- if (snapshot) {
- var metadata = get("http://gosu-lang.org/nexus/content/repositories/snapshots/org/gosu-lang/ronin/ronin/maven-metadata.xml",
- "maven-metadata", ".xml").read()
- var roninVersion = SimpleXmlNode.parse(metadata)
- .Children.firstWhere(\n -> n.Name == "versioning")
- .Children.firstWhere(\n -> n.Name == "versions")
- .Children.lastWhere(\n -> n.Name == "version")
- .Text
- var archetypeMetadata = get("http://gosu-lang.org/nexus/content/repositories/snapshots/org/gosu-lang/ronin/ronin-archetype/${roninVersion}/maven-metadata.xml",
- "archetype-metadata", ".xml").read()
- var snapshotVersion = SimpleXmlNode.parse(archetypeMetadata)
- .Children.firstWhere(\n -> n.Name == "versioning")
- .Children.firstWhere(\n -> n.Name == "snapshot")
- var snapshotTimestamp = snapshotVersion.Children.firstWhere(\n -> n.Name == "timestamp").Text
- var snapshotBuildNumber = snapshotVersion.Children.firstWhere(\n -> n.Name == "buildNumber").Text
- var snapshotJarName = roninVersion.substring(0, roninVersion.Length - "-SNAPSHOT".Length)
- + "-${snapshotTimestamp}-${snapshotBuildNumber}"
- archetype = get("http://gosu-lang.org/nexus/content/repositories/snapshots/org/gosu-lang/ronin/ronin-archetype/${roninVersion}/ronin-archetype-${snapshotJarName}.jar",
- "ronin-archetype", ".jar")
- } else {
- var metadata = get("http://gosu-lang.org/nexus/content/repositories/osprojects/org/gosu-lang/ronin/ronin/maven-metadata.xml",
+ if (roninVersion == null) {
+ var metadata = get(releasesRepo.Url + "/org/gosu-lang/ronin/ronin/maven-metadata.xml",
"maven-metadata", ".xml").read()
- var roninVersion = SimpleXmlNode.parse(metadata)
+ roninVersion = SimpleXmlNode.parse(metadata)
.Children.firstWhere(\n -> n.Name == "versioning")
.Children.firstWhere(\n -> n.Name == "release")
.Text
- archetype = get("http://gosu-lang.org/nexus/content/repositories/osprojects/org/gosu-lang/ronin/ronin-archetype/${roninVersion}/ronin-archetype-${roninVersion}.jar",
- "ronin-archetype", ".jar")
+ Ant.echo(:message = "Using the latest published version of Ronin: ${roninVersion}")
}
+ var archetype = resolveArchetype(roninVersion)
Ant.unzip(:src = archetype, :dest = targetDir)
targetDir.file("META-INF").deleteRecursively()
targetDir.file("archetype-resources").eachChild(\c -> {
@@ -59,14 +57,13 @@ function init(name : String = null, groupId : String = null, version : String =
var pomContent = pomTemplate.replace("\${artifactId}", name)
.replace("\${groupId}", groupId)
.replace("\${version}", version)
- if (snapshot) {
- pomContent = pomContent.replace("http://gosu-lang.org/nexus/content/groups/releases",
- "http://gosu-lang.org/nexus/content/repositories/snapshots")
+ if (isSnapshot(roninVersion)) {
+ pomContent = pomContent.replace(releasesRepo.Url, snapshotsRepo.Url)
var buildVark = targetDir.file("build.vark").read()
buildVark = buildVark.replace("remote:releases:gosu-lang.org-releases:http://gosu-lang.org/repositories/m2/releases",
"remote:snapshots:gosu-lang.org-snapshots:http://gosu-lang.org/repositories/m2/snapshots")
- .replace("remote:releases:gosu-lang.org-releases:http://gosu-lang.org/nexus/content/groups/releases",
- "remote:snapshots:gosu-lang.org-snapshots:http://gosu-lang.org/nexus/content/repositories/snapshots")
+ .replace("remote:releases:${releasesRepo.Id}:${releasesRepo.Url}",
+ "remote:snapshots:${snapshotsRepo.Id}:${snapshotsRepo.Url}")
targetDir.file("build.vark").write(buildVark)
}
targetDir.file("pom.xml").write(pomContent)
@@ -79,4 +76,16 @@ function get(url : String, name : String, ext : String) : File {
var file = File.createTempFile(name, ext)
Ant.get(:src = new URL(url), :dest = file)
return file
-}
+}
+
+private function resolveArchetype(roninVersion : String) : File {
+ var aether = new AetherUtil(Aardvark.getProject(), { isSnapshot(roninVersion) ? snapshotsRepo : releasesRepo })
+ var dependencies = new Dependencies()
+ dependencies.addDependency(new Dependency() {:Coords = "org.gosu-lang.ronin:ronin-archetype:${roninVersion}"})
+ var archetype = aether.resolve(dependencies).asFileList().single()
+ return archetype
+}
+
+private function isSnapshot(roninVersion : String) : boolean {
+ return roninVersion.endsWith("-SNAPSHOT")
+}
@@ -1,4 +1,5 @@
classpath "remote:releases:gosu-lang.org-releases:http://gosu-lang.org/nexus/content/groups/releases"
+classpath "org.gosu-lang.aardvark:aardvark-aether-utils:1.0-SNAPSHOT"
classpath "org.gosu-lang.ronin:ronin-init:${project.version}"
/* This vark file is used to develop your ronin application. Ronin provies
View
@@ -1,8 +0,0 @@
-
-/* Creates the init template */
-function buildTemplate() {
- var target = file( "target/ronin-template" )
- target.mkdirs()
- Ant.zip( :destfile = target.file( "ronin-template.zip" ), :basedir = file( "template" ) )
- Ant.copy( :todir = target, :file = file("init.vark") )
-}
@@ -26,8 +26,8 @@ enhancement RoninVarkTargets : gw.vark.AardvarkFile {
classesDir.mkdirs()
Ant.javac( :srcdir = this.path(this.file("src")),
:destdir = classesDir,
- :classpath = this.classpath(this.file("src").fileset())
- .withPath(fixedPom().dependencies(COMPILE, :additionalDeps = {
+ :classpath = this.path(this.file("src")) // blc - I don't think this is necessary
+ .withPath(this.pom().resolve(COMPILE, :additionalDeps = {
new() { : GroupId = "org.gosu-lang.gosu", :ArtifactId = "gosu-core", :Version = "0.9-12" }
}).Path),
:debug = true,
@@ -42,7 +42,7 @@ enhancement RoninVarkTargets : gw.vark.AardvarkFile {
@Param("dontStartDB", "Suppress starting the H2 web server.")
@Param("env", "A comma-separated list of environment variables, formatted as \"ronin.name=value\".")
function server(waitForDebugger : boolean, dontStartDB : boolean, port : int = 8080, env : String = "") {
- var cp = fixedPom().dependencies(RUNTIME, :additionalDeps = {
+ var cp = this.pom().resolve(RUNTIME, :additionalDeps = {
new() { : GroupId = "org.gosu-lang.gosu", :ArtifactId = "gosu-core", :Version = "0.9-12" }
}).Path.withFile(this.file("classes"))
Ant.java(:classpath=cp,
@@ -57,7 +57,7 @@ enhancement RoninVarkTargets : gw.vark.AardvarkFile {
@Target
@Param("waitForDebugger", "Suspend the server until a debugger connects.")
function resetDb(waitForDebugger : boolean) {
- var cp = fixedPom().dependencies(RUNTIME, :additionalDeps = {
+ var cp = this.pom().resolve(RUNTIME, :additionalDeps = {
new() { : GroupId = "org.gosu-lang.gosu", :ArtifactId = "gosu-core", :Version = "0.9-12" }
}).Path
Ant.java(:classpath=cp,
@@ -74,7 +74,7 @@ enhancement RoninVarkTargets : gw.vark.AardvarkFile {
@Param("waitForDebugger", "Suspend the server until a debugger connects.")
@Param("env", "A comma-separated list of environment variables, formatted as \"ronin.name=value\".")
function verifyApp(waitForDebugger : boolean, env : String = "") {
- var cp = fixedPom().dependencies(TEST, :additionalDeps = {
+ var cp = this.pom().resolve(TEST, :additionalDeps = {
new(){ : GroupId = "org.gosu-lang.gosu", :ArtifactId = "gosu-core", :Version = "0.9-12" }
}).Path
Ant.java(:classpath=cp,
@@ -132,14 +132,11 @@ enhancement RoninVarkTargets : gw.vark.AardvarkFile {
var libDir = webInfDir.file("lib")
libDir.mkdirs()
- var cp = fixedPom().dependencies(TEST, :additionalDeps = {
- new(){ : GroupId = "org.gosu-lang.gosu", :ArtifactId = "gosu", :Version = "0.9-12" }
- }).Path
+ var libs = this.pom().resolve(TEST, :additionalDeps = {
+ new(){ :GroupId = "org.gosu-lang.gosu", :ArtifactId = "gosu", :Version = "0.9-12", :Type = "pom" }
+ }).FileSet
- cp.list().each( \ elt -> {
- print( "Adding ${elt} to the WAR")
- Ant.copy(:file = this.file(elt), : todir = libDir)
- } )
+ Ant.copy(:filesetList = {libs}, :todir = libDir, :flatten = true)
var warName = this.file(".").ParentFile.Name + ".war"
var warDest = this.file("build/${warName}")
@@ -158,7 +155,7 @@ enhancement RoninVarkTargets : gw.vark.AardvarkFile {
@Param("env", "A comma-separated list of environment variables, formatted as \"ronin.name=value\".")
@Param("trace", "Enable detailed tracing.")
function test(waitForDebugger : boolean, parallelClasses : boolean, parallelMethods : boolean, trace : boolean, env : String = "") {
- var cp = fixedPom().dependencies(TEST, :additionalDeps = {
+ var cp = this.pom().resolve(TEST, :additionalDeps = {
new(){ : GroupId = "org.gosu-lang.gosu", :ArtifactId = "gosu-core", :Version = "0.9-12" }
}).Path
@@ -182,7 +179,7 @@ enhancement RoninVarkTargets : gw.vark.AardvarkFile {
@Param("env", "A comma-separated list of environment variables, formatted as \"ronin.name=value\".")
@Param("trace", "Enable detailed tracing.")
function uiTest(waitForDebugger : boolean, parallelClasses : boolean, parallelMethods : boolean, trace : boolean, port : int = 8080, env : String = "") {
- var cp = fixedPom().dependencies(TEST, :additionalDeps = {
+ var cp = this.pom().resolve(TEST, :additionalDeps = {
new() { : GroupId = "org.gosu-lang.gosu", :ArtifactId = "gosu-core", :Version = "0.9-12" }
}).Path
@@ -203,7 +200,7 @@ enhancement RoninVarkTargets : gw.vark.AardvarkFile {
@Param("username", "The username with which to connect to the admin console.")
@Param("password", "The password with which to connect to the admin console.")
function console(port : String = "8022", username : String = "admin", password : String = "password") {
- var cp = fixedPom().dependencies(RUNTIME, :additionalDeps = {
+ var cp = this.pom().resolve(RUNTIME, :additionalDeps = {
new() { : GroupId = "org.gosu-lang.gosu", :ArtifactId = "gosu-core", :Version = "0.9-12" }
}).Path
@@ -224,11 +221,4 @@ enhancement RoninVarkTargets : gw.vark.AardvarkFile {
}
return debugStr
}
-
- function fixedPom() : PomHelper {
- var pom = this.pom()
- pom.Pom.addRemoteRepo(new() {:Id = "gosu-lang.org-snapshots", :Url = "http://gosu-lang.org/nexus/content/repositories/snapshots", :Snapshots = true, :Releases = false})
- pom.Pom.addRemoteRepo(new() {:Id = "gosu-lang.org-releases", :Url = "http://gosu-lang.org/nexus/content/groups/releases", :Snapshots = false, :Releases = true})
- return pom
- }
}

0 comments on commit 5793011

Please sign in to comment.