Created
February 3, 2013 19:09
-
-
Save renatoathaydes/4703201 to your computer and use it in GitHub Desktop.
Creates a simple Osgi Blueprint Project using a Maven Archetype.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creates an empty OSGi Blueprint project using the Maven archetype | |
// http://karaf.apache.org/manual/2.2.6/developers-guide/archetypes.html | |
def MAVEN_HOME = 'C:/Program Files/Maven/apache-maven-3.0.3/bin' | |
def cli = new CliBuilder() | |
cli.with { | |
g args: 1, 'GroupId of the artifact being created' | |
a args: 1, 'ID of the artifact being created' | |
v args: 1, 'Version of the artifact being created' | |
d args: 1, 'Destination folder (current dir is default)' | |
h 'Usage Information' | |
} | |
def opt = cli.parse args | |
if ( !opt ) return | |
if ( opt.h ) { | |
cli.usage() | |
return | |
} | |
def groupId = ( opt.g ) ? opt.g : 'com.athaydes.renato' | |
def artifactId = ( opt.a ) ? opt.a : 'example' | |
def version = ( opt.v ) ? opt.v : '0.0.1-SNAPSHOT' | |
def command = """cmd /c mvn archetype:generate | |
-DarchetypeGroupId=org.apache.karaf.archetypes | |
-DarchetypeArtifactId=karaf-blueprint-archetype | |
-DarchetypeVersion=2.2.6 | |
-DgroupId=com.athaydes.renato.$groupId | |
-DartifactId=$artifactId | |
-Dversion=$version | |
-Dpackage=${groupId}.${artifactId}.api""" | |
.replace("\n", '') | |
def proc = command.execute() | |
def writer = new PrintWriter(new BufferedOutputStream(proc.out)) | |
proc.in.eachLine { | |
println it | |
if ( it.startsWith( 'package:' ) ) { // last line before asking for confirmation | |
writer.println 'Y' | |
writer.close() | |
} | |
} | |
println "return code: ${ proc.exitValue()}" | |
println "stderr: ${proc.err.text}" | |
if ( opt.d ) { | |
println 'Moving project to ' + opt.d | |
new File( opt.a ).renameTo new File( opt.d, opt.a ) | |
} | |
println 'Done!' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment