Skip to content
Browse files

Merge branch '2.1.x' of github.com:grails/grails-core into 2.1.x

  • Loading branch information...
2 parents 5c6c4b7 + 31d04e2 commit 62481c6244faa4f207572627ded12a78fffef97c @graemerocher graemerocher committed
View
4 grails-wrapper/build.gradle
@@ -11,10 +11,10 @@ task copyScript(type: Copy) {
rename 'startGrails.bat', 'grailsw.bat'
}
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: ['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()])
fileMode = 0755
}
View
74 grails-wrapper/src/main/java/org/grails/wrapper/GrailsWrapper.java
@@ -22,28 +22,18 @@
public class GrailsWrapper {
public static void main(final String[] args) throws Exception{
- ResourceBundle bundle = ResourceBundle.getBundle("grails-wrapper");
- final String grailsVersion = bundle.getString("wrapper.version");
- final File grailsCacheDir = new File(System.getProperty("user.home") + "/.grails/");
- final File grailsVersionDir = new File(grailsCacheDir, grailsVersion);
- final File wrapperDir = new File(grailsVersionDir, "wrapper");
- String distUrl = bundle.getString("wrapper.dist.url");
+ final ResourceBundle applicationBundle = ResourceBundle.getBundle("application");
+ final ResourceBundle wrapperBundle = ResourceBundle.getBundle("grails-wrapper");
+ final String grailsVersion = applicationBundle.getString("app.grails.version");
+ String distUrl = wrapperBundle.getString("wrapper.dist.url");
if(distUrl == null) {
distUrl = "http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/";
}
if(!distUrl.endsWith("/")) {
distUrl += "/";
}
- final String src = distUrl + "grails-" + grailsVersion + ".zip";
- final URI uri = new URI(src);
-
- 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);
+
+ final File grailsHome = configureGrailsInstallation(distUrl, grailsVersion);
System.setProperty("grails.home", grailsHome.getAbsolutePath());
@@ -66,18 +56,58 @@ public static void main(final String[] args) throws Exception{
final String[] newArgsArray = newArgsList.toArray(new String[0]);
final URL[] urls = new URL[2];
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() {
- public boolean accept(final File dir, final String name) {
- return name.startsWith("groovy-all-") && name.endsWith(".jar");
- }
- });
- urls[1] = groovyJarCandidates[0].toURI().toURL();
+ final File directoryToSearchForGroovyAllJar = new File(grailsHome, "/lib/org.codehaus.groovy");
+ final File groovyJar = findGroovyAllJar(directoryToSearchForGroovyAllJar);
+ if(groovyJar == null) {
+ System.err.println("An error occurred locating the groovy jar under " + directoryToSearchForGroovyAllJar.getAbsolutePath());
+ System.exit(-1);
+ }
+ final URI groovyJarUri = groovyJar.toURI();
+ final URL groovyJarUrl = groovyJarUri.toURL();
+ urls[1] = groovyJarUrl;
final URLClassLoader urlClassLoader = new URLClassLoader(urls);
final Class<?> loadClass = urlClassLoader.loadClass("org.codehaus.groovy.grails.cli.support.GrailsStarter");
final Method mainMethod = loadClass.getMethod("main", String[].class);
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 {
System.out.println("Extracting " + zip.getAbsolutePath() + " to " + dest.getAbsolutePath());
View
1 grails-wrapper/src/main/resources/grails-wrapper.properties
@@ -1,2 +1 @@
-wrapper.version=@wrapperVersion@
wrapper.dist.url=@distributationUrl@
View
11 scripts/Wrapper.groovy
@@ -1,20 +1,17 @@
includeTargets << grailsScript("_GrailsInit")
USAGE = """
- wrapper [--wrapperVersion=version] [--wrapperDir=dir] [--distributionUrl=url]
+ wrapper [--wrapperDir=dir] [--distributionUrl=url]
where
- --wrapperVersion = The version of Grails that the wrapper should use
--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
examples
- grails wrapper --wrapperVersion=2.0.3
- grails wrapper --wrapperDir=grailsWrapper --wrapperVersion=2.0.3
- grails wrapper --wrapperVersion=2.0.0.RC1 --distributionUrl=http://dist.springframework.org.s3.amazonaws.com/milestone/GRAILS/
+ grails wrapper --wrapperDir=grailsWrapper
+ grails wrapper --wrapperDir=grailsWrapper --distributionUrl=http://dist.springframework.org.s3.amazonaws.com/milestone/GRAILS/
optional argument default values
- wrapperVersion = the version of Grails that the wrapper is being generated with ($grailsVersion)
wrapperDir = 'wrapper'
distributionUrl = 'http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/'
@@ -24,7 +21,6 @@ target ('default': "Installs the Grails wrapper") {
depends(checkVersion, parseArguments)
event 'InstallWrapperStart', [ 'Installing Wrapper...' ]
- grailsWrapperVersion = argsMap.wrapperVersion ?: grailsVersion
grailsDistUrl = argsMap.distributionUrl ?: 'http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/'
grailsWrapperDir = argsMap.wrapperDir ?: 'wrapper'
@@ -53,7 +49,6 @@ target ('default': "Installs the Grails wrapper") {
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: basedir, includes: 'grailsw*', token: '@wrapperDir@', value: grailsWrapperDir)
ant.chmod(file: 'grailsw', perm: 'u+x')

0 comments on commit 62481c6

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