Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated to use the new aardvark-aether-utils extension for Aardvark i…

…n order to grab the archetype
  • Loading branch information...
commit ec224f4304213f751ac0e974d91cd25c7118ab43 1 parent fc86093
Brian Chang authored
Showing with 38 additions and 32 deletions.
  1. +38 −32 ronin-archetype/init.vark
View
70 ronin-archetype/init.vark
@@ -5,12 +5,27 @@ 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\"): ")
}
@@ -21,36 +36,16 @@ function init(name : String = null, groupId : String = null, version : String =
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 -> {
@@ -62,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)
@@ -82,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")
+}

0 comments on commit ec224f4

Please sign in to comment.
Something went wrong with that request. Please try again.