Skip to content

Commit

Permalink
Merge branch '2.1.x' of github.com:grails/grails-core into 2.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed May 10, 2012
2 parents 5c6c4b7 + 31d04e2 commit 62481c6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 33 deletions.
4 changes: 2 additions & 2 deletions grails-wrapper/build.gradle
Expand Up @@ -11,10 +11,10 @@ task copyScript(type: Copy) {
rename 'startGrails.bat', 'grailsw.bat' rename 'startGrails.bat', 'grailsw.bat'
} }
filter(ReplaceTokens, tokens: ['starter.main.class': 'org.grails.wrapper.GrailsWrapper']) filter(ReplaceTokens, tokens: ['starter.main.class': 'org.grails.wrapper.GrailsWrapper'])
filter(ReplaceTokens, tokens: ['starter.classpath': '@wrapperDir@/grails-wrapper-runtime-@grailsVersion@.jar:@wrapperDir@']) filter(ReplaceTokens, tokens: ['starter.classpath': '@wrapperDir@/grails-wrapper-runtime-@grailsVersion@.jar:@wrapperDir@:.'])
filter(ReplaceTokens, tokens: ['agent.string': '-javaagent:@wrapperDir@/springloaded-core-@springLoadedVersion@.jar -noverify -Dspringloaded=$SPRINGLOADED_PARAMS']) filter(ReplaceTokens, tokens: ['agent.string': '-javaagent:@wrapperDir@/springloaded-core-@springLoadedVersion@.jar -noverify -Dspringloaded=$SPRINGLOADED_PARAMS'])
filter(ReplaceTokens, tokens: ['startup.command': 'startGrails $STARTER_MAIN_CLASS "$@"']) filter(ReplaceTokens, tokens: ['startup.command': 'startGrails $STARTER_MAIN_CLASS "$@"'])
filter(ReplaceTokens, tokens: ['windows.starter.classpath': '@wrapperDir@/grails-wrapper-runtime-@grailsVersion@.jar;@wrapperDir@']) filter(ReplaceTokens, tokens: ['windows.starter.classpath': '@wrapperDir@/grails-wrapper-runtime-@grailsVersion@.jar;@wrapperDir@;.'])
filter(ReplaceTokens, tokens: ['windows.agent.string': "-javaagent:@wrapperDir@/springloaded-core-@springLoadedVersion@.jar -noverify -Dspringloaded=%SPRINGLOADED_PARAMS%".toString()]) filter(ReplaceTokens, tokens: ['windows.agent.string': "-javaagent:@wrapperDir@/springloaded-core-@springLoadedVersion@.jar -noverify -Dspringloaded=%SPRINGLOADED_PARAMS%".toString()])
fileMode = 0755 fileMode = 0755
} }
Expand Down
74 changes: 52 additions & 22 deletions grails-wrapper/src/main/java/org/grails/wrapper/GrailsWrapper.java
Expand Up @@ -22,28 +22,18 @@
public class GrailsWrapper { public class GrailsWrapper {


public static void main(final String[] args) throws Exception{ public static void main(final String[] args) throws Exception{
ResourceBundle bundle = ResourceBundle.getBundle("grails-wrapper"); final ResourceBundle applicationBundle = ResourceBundle.getBundle("application");
final String grailsVersion = bundle.getString("wrapper.version"); final ResourceBundle wrapperBundle = ResourceBundle.getBundle("grails-wrapper");
final File grailsCacheDir = new File(System.getProperty("user.home") + "/.grails/"); final String grailsVersion = applicationBundle.getString("app.grails.version");
final File grailsVersionDir = new File(grailsCacheDir, grailsVersion); String distUrl = wrapperBundle.getString("wrapper.dist.url");
final File wrapperDir = new File(grailsVersionDir, "wrapper");
String distUrl = bundle.getString("wrapper.dist.url");
if(distUrl == null) { if(distUrl == null) {
distUrl = "http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/"; distUrl = "http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/";
} }
if(!distUrl.endsWith("/")) { if(!distUrl.endsWith("/")) {
distUrl += "/"; distUrl += "/";
} }
final String src = distUrl + "grails-" + grailsVersion + ".zip";
final URI uri = new URI(src); final File grailsHome = configureGrailsInstallation(distUrl, grailsVersion);

final File file = new File(wrapperDir, "download.zip");
new RemoteFileHelper().retrieve(uri, file);
final File installDir = new File(wrapperDir, "install");
if(!installDir.exists()) {
extract(file, installDir);
}
final File grailsHome = new File(installDir, "grails-" + grailsVersion);


System.setProperty("grails.home", grailsHome.getAbsolutePath()); System.setProperty("grails.home", grailsHome.getAbsolutePath());


Expand All @@ -66,18 +56,58 @@ public static void main(final String[] args) throws Exception{
final String[] newArgsArray = newArgsList.toArray(new String[0]); final String[] newArgsArray = newArgsList.toArray(new String[0]);
final URL[] urls = new URL[2]; final URL[] urls = new URL[2];
urls[0] = new File(grailsHome, "dist/grails-bootstrap-" + grailsVersion + ".jar").toURI().toURL(); urls[0] = new File(grailsHome, "dist/grails-bootstrap-" + grailsVersion + ".jar").toURI().toURL();
File[] groovyJarCandidates = new File(grailsHome, "lib/org.codehaus.groovy/groovy-all/jars/").listFiles(new FilenameFilter() { final File directoryToSearchForGroovyAllJar = new File(grailsHome, "/lib/org.codehaus.groovy");
public boolean accept(final File dir, final String name) { final File groovyJar = findGroovyAllJar(directoryToSearchForGroovyAllJar);
return name.startsWith("groovy-all-") && name.endsWith(".jar"); if(groovyJar == null) {
} System.err.println("An error occurred locating the groovy jar under " + directoryToSearchForGroovyAllJar.getAbsolutePath());
}); System.exit(-1);
urls[1] = groovyJarCandidates[0].toURI().toURL(); }
final URI groovyJarUri = groovyJar.toURI();
final URL groovyJarUrl = groovyJarUri.toURL();
urls[1] = groovyJarUrl;
final URLClassLoader urlClassLoader = new URLClassLoader(urls); final URLClassLoader urlClassLoader = new URLClassLoader(urls);
final Class<?> loadClass = urlClassLoader.loadClass("org.codehaus.groovy.grails.cli.support.GrailsStarter"); final Class<?> loadClass = urlClassLoader.loadClass("org.codehaus.groovy.grails.cli.support.GrailsStarter");
final Method mainMethod = loadClass.getMethod("main", String[].class); final Method mainMethod = loadClass.getMethod("main", String[].class);


mainMethod.invoke(null, new Object[]{newArgsArray}); mainMethod.invoke(null, new Object[]{newArgsArray});
} }

private static File findGroovyAllJar(final File directoryToSearch) {
final File[] files = directoryToSearch.listFiles();
for(File file : files) {
if(file.isDirectory()) {
return findGroovyAllJar(file);
}
final String fileName = file.getName();
if(fileName.startsWith("groovy-all-") && fileName.endsWith(".jar")) {
return file;
}
}
return null;
}

/**
*
* @param distUrl URL to directory where the distribution zip is found
* @param grailsVersion version of Grails to configure
* @return a File pointing to the directory where this version of Grails is configured
*/
private static File configureGrailsInstallation(String distUrl,
final String grailsVersion) throws Exception {
final String src = distUrl + "grails-" + grailsVersion + ".zip";
final URI uri = new URI(src);

final File grailsCacheDir = new File(System.getProperty("user.home") + "/.grails/");
final File wrapperDir = new File(grailsCacheDir, "wrapper");
final File downloadFile = new File(wrapperDir, "grails-" + grailsVersion + "-download.zip");
new RemoteFileHelper().retrieve(uri, downloadFile);
final File installDir = new File(wrapperDir, grailsVersion);
if(!installDir.exists()) {
extract(downloadFile, installDir);
}
final File grailsHome = new File(installDir, "grails-" + grailsVersion);
return grailsHome;
}


public static void extract(final File zip, final File dest) throws IOException { public static void extract(final File zip, final File dest) throws IOException {
System.out.println("Extracting " + zip.getAbsolutePath() + " to " + dest.getAbsolutePath()); System.out.println("Extracting " + zip.getAbsolutePath() + " to " + dest.getAbsolutePath());
Expand Down
@@ -1,2 +1 @@
wrapper.version=@wrapperVersion@
wrapper.dist.url=@distributationUrl@ wrapper.dist.url=@distributationUrl@
11 changes: 3 additions & 8 deletions scripts/Wrapper.groovy
@@ -1,20 +1,17 @@
includeTargets << grailsScript("_GrailsInit") includeTargets << grailsScript("_GrailsInit")


USAGE = """ USAGE = """
wrapper [--wrapperVersion=version] [--wrapperDir=dir] [--distributionUrl=url] wrapper [--wrapperDir=dir] [--distributionUrl=url]
where where
--wrapperVersion = The version of Grails that the wrapper should use
--wrapperDir = Directory where wrapper support files are installed relative to project root --wrapperDir = Directory where wrapper support files are installed relative to project root
--distributationUrl = URL to the directory where the release may be downloaded from if necessary --distributationUrl = URL to the directory where the release may be downloaded from if necessary
examples examples
grails wrapper --wrapperVersion=2.0.3 grails wrapper --wrapperDir=grailsWrapper
grails wrapper --wrapperDir=grailsWrapper --wrapperVersion=2.0.3 grails wrapper --wrapperDir=grailsWrapper --distributionUrl=http://dist.springframework.org.s3.amazonaws.com/milestone/GRAILS/
grails wrapper --wrapperVersion=2.0.0.RC1 --distributionUrl=http://dist.springframework.org.s3.amazonaws.com/milestone/GRAILS/
optional argument default values optional argument default values
wrapperVersion = the version of Grails that the wrapper is being generated with ($grailsVersion)
wrapperDir = 'wrapper' wrapperDir = 'wrapper'
distributionUrl = 'http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/' distributionUrl = 'http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/'
Expand All @@ -24,7 +21,6 @@ target ('default': "Installs the Grails wrapper") {
depends(checkVersion, parseArguments) depends(checkVersion, parseArguments)
event 'InstallWrapperStart', [ 'Installing Wrapper...' ] event 'InstallWrapperStart', [ 'Installing Wrapper...' ]


grailsWrapperVersion = argsMap.wrapperVersion ?: grailsVersion
grailsDistUrl = argsMap.distributionUrl ?: 'http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/' grailsDistUrl = argsMap.distributionUrl ?: 'http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/'
grailsWrapperDir = argsMap.wrapperDir ?: 'wrapper' grailsWrapperDir = argsMap.wrapperDir ?: 'wrapper'


Expand Down Expand Up @@ -53,7 +49,6 @@ target ('default': "Installs the Grails wrapper") {
include(name: 'grailsw*') include(name: 'grailsw*')
} }
} }
ant.replace(dir: targetDir, includes: '*.properties', token: '@wrapperVersion@', value: grailsWrapperVersion)
ant.replace(dir: targetDir, includes: '*.properties', token: '@distributationUrl@', value: grailsDistUrl) ant.replace(dir: targetDir, includes: '*.properties', token: '@distributationUrl@', value: grailsDistUrl)
ant.replace(dir: basedir, includes: 'grailsw*', token: '@wrapperDir@', value: grailsWrapperDir) ant.replace(dir: basedir, includes: 'grailsw*', token: '@wrapperDir@', value: grailsWrapperDir)
ant.chmod(file: 'grailsw', perm: 'u+x') ant.chmod(file: 'grailsw', perm: 'u+x')
Expand Down

0 comments on commit 62481c6

Please sign in to comment.