Skip to content
Browse files

Merge branch 'master' of github.com:grails/grails-core

  • Loading branch information...
2 parents 806301f + b14aa4f commit 0c3fc90efb568c304e7237daaa5785399678c23d @graemerocher graemerocher committed
View
1 .gitignore
@@ -63,6 +63,7 @@ target
/grails-test/bin/
/grails-web/bin/
/grails-webflow/bin/
+/grails-wrapper/bin/
/grails-plugin-log4j/bin/
/grails-plugin-logging/bin/
/grails-logging/bin/
View
16 gradle/assemble.gradle
@@ -122,8 +122,12 @@ task installResources(type: Copy) {
into(homeBinDir.name) {
from("grails-resources/src/grails/home/bash")
filter(ReplaceTokens, tokens: ['grails.version': grailsVersion])
- filter(ReplaceTokens, tokens: ['groovy.version': groovyVersion])
- filter(ReplaceTokens, tokens: ['spring.loaded.version': springLoadedVersion])
+ filter(ReplaceTokens, tokens: ['starter.main.class': 'org.codehaus.groovy.grails.cli.support.GrailsStarter'])
+ filter(ReplaceTokens, tokens: ['windows.starter.classpath': "%GRAILS_HOME%\\lib\\org.codehaus.groovy\\groovy-all\\jars\\groovy-all-${groovyVersion}.jar;%GRAILS_HOME%\\dist\\grails-bootstrap-${grailsVersion}.jar".toString()])
+ filter(ReplaceTokens, tokens: ['starter.classpath': "\$GRAILS_HOME/lib/org.codehaus.groovy/groovy-all/jars/groovy-all-${groovyVersion}.jar:\$GRAILS_HOME/dist/grails-bootstrap-${grailsVersion}.jar".toString()])
+ filter(ReplaceTokens, tokens: ['agent.string': "-javaagent:\$AGENT_GRAILS_HOME/lib/com.springsource.springloaded/springloaded-core/jars/springloaded-core-${springLoadedVersion}.jar -noverify -Dspringloaded=\$SPRINGLOADED_PARAMS".toString()])
+ filter(ReplaceTokens, tokens: ['windows.agent.string': "-javaagent:%GRAILS_HOME:\\=/%/lib/com.springsource.springloaded/springloaded-core/jars/springloaded-core-${springLoadedVersion}.jar -noverify -Dspringloaded=%SPRINGLOADED_PARAMS%".toString()])
+ filter(ReplaceTokens, tokens: ['startup.command': ''])
fileMode = 0755
}
@@ -211,8 +215,12 @@ task zipDist(type: Zip, dependsOn: [sourcesJars, install]) {
from("grails-resources/src/grails/home/bash") {
into "bin"
filter(ReplaceTokens, tokens: ['grails.version': grailsVersion])
- filter(ReplaceTokens, tokens: ['groovy.version': groovyVersion])
- filter(ReplaceTokens, tokens: ['spring.loaded.version': springLoadedVersion])
+ filter(ReplaceTokens, tokens: ['starter.main.class': 'org.codehaus.groovy.grails.cli.support.GrailsStarter'])
+ filter(ReplaceTokens, tokens: ['windows.starter.classpath': "%GRAILS_HOME%\\lib\\org.codehaus.groovy\\groovy-all\\jars\\groovy-all-${groovyVersion}.jar;%GRAILS_HOME%\\dist\\grails-bootstrap-${grailsVersion}.jar".toString()])
+ filter(ReplaceTokens, tokens: ['starter.classpath': "\$GRAILS_HOME/lib/org.codehaus.groovy/groovy-all/jars/groovy-all-${groovyVersion}.jar:\$GRAILS_HOME/dist/grails-bootstrap-${grailsVersion}.jar".toString()])
+ filter(ReplaceTokens, tokens: ['agent.string': "-javaagent:\$AGENT_GRAILS_HOME/lib/com.springsource.springloaded/springloaded-core/jars/springloaded-core-${springLoadedVersion}.jar -noverify -Dspringloaded=\$SPRINGLOADED_PARAMS".toString()])
+ filter(ReplaceTokens, tokens: ['windows.agent.string': "-javaagent:%GRAILS_HOME:\\=/%/lib/com.springsource.springloaded/springloaded-core/jars/springloaded-core-${springLoadedVersion}.jar -noverify -Dspringloaded=%SPRINGLOADED_PARAMS%".toString()])
+ filter(ReplaceTokens, tokens: ['startup.command': ''])
fileMode = 0755
}
from("grails-resources/src/grails/home/conf") {
View
2 grails-resources/src/grails/home/bash/grails.bat
@@ -12,4 +12,4 @@ if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.\
-CALL "%DIRNAME%\startGrails.bat" "%DIRNAME%" org.codehaus.groovy.grails.cli.GrailsScriptRunner %*
+CALL "%DIRNAME%\startGrails.bat" "%DIRNAME%" %*
View
14 grails-resources/src/grails/home/bash/startGrails
@@ -118,7 +118,7 @@ fi
if [ -z "$STARTER_CONF" ]; then
STARTER_CONF="$GRAILS_HOME/conf/groovy-starter.conf"
fi
-STARTER_CLASSPATH="$GRAILS_HOME/lib/org.codehaus.groovy/groovy-all/jars/groovy-all-@groovy.version@.jar:$GRAILS_HOME/dist/grails-bootstrap-@grails.version@.jar"
+STARTER_CLASSPATH="@starter.classpath@"
# Allow access to Cocoa classes on OS X
if $darwin; then
@@ -188,7 +188,7 @@ if [ -n "$GRAILS_AGENT_CACHE_DIR" ]; then
fi
# Process JVM args
-AGENT_STRING="-javaagent:$AGENT_GRAILS_HOME/lib/com.springsource.springloaded/springloaded-core/jars/springloaded-core-@spring.loaded.version@.jar -noverify -Dspringloaded=$SPRINGLOADED_PARAMS"
+AGENT_STRING="@agent.string@"
CMD_LINE_ARGS=""
DISABLE_RELOADING=false
@@ -211,6 +211,12 @@ while true; do
break
fi
+ if [ "$1" = "-debug" ]; then
+ JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Dgrails.full.stacktrace=true -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
+ shift
+ break
+ fi
+
if [ "$1" != -* ]; then
break
fi
@@ -285,7 +291,7 @@ if $cygwin; then
done
fi
-STARTER_MAIN_CLASS=org.codehaus.groovy.grails.cli.support.GrailsStarter
+STARTER_MAIN_CLASS=@starter.main.class@
lateInit
@@ -325,3 +331,5 @@ startGrails() {
fi
fi
}
+
+@startup.command@
View
14 grails-resources/src/grails/home/bash/startGrails.bat
@@ -11,8 +11,7 @@ if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~1
shift
-set CLASS=%~1
-shift
+set CLASS=@starter.main.class@
if exist "%USERPROFILE%/.groovy/preinit.bat" call "%USERPROFILE%/.groovy/preinit.bat"
@@ -68,7 +67,7 @@ if not "%GRAILS_AGENT_CACHE_DIR%" == "" (
set SPRINGLOADED_PARAMS="%SPRINGLOADED_PARAMS%;cacheDir=%GRAILS_AGENT_CACHE_DIR%"
if not exist "%GRAILS_AGENT_CACHE_DIR%" mkdir "%GRAILS_AGENT_CACHE_DIR%"
)
-set AGENT_STRING=-javaagent:%GRAILS_HOME:\=/%/lib/com.springsource.springloaded/springloaded-core/jars/springloaded-core-@spring.loaded.version@.jar -noverify -Dspringloaded=%SPRINGLOADED_PARAMS%
+set AGENT_STRING=@windows.agent.string@
set DISABLE_RELOADING=
if "%GRAILS_OPTS%" == "" set GRAILS_OPTS=-server -Xmx768M -Xms768M -XX:PermSize=256m -XX:MaxPermSize=256m -Dfile.encoding=UTF-8
@@ -95,6 +94,11 @@ if "x%~1" == "x-cp" (
shift
goto win9xME_args_slurp
)
+if "x%~1" == "x-debug" (
+ set JAVA_OPTS=%JAVA_OPTS% -Xdebug -Xnoagent -Dgrails.full.stacktrace=true -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
+ shift
+ goto win9xME_args_slurp
+)
if "x%~1" == "x-classpath" (
set CP=%~2
shift
@@ -129,7 +133,7 @@ set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
-set STARTER_CLASSPATH=%GRAILS_HOME%\lib\org.codehaus.groovy\groovy-all\jars\groovy-all-@groovy.version@.jar;%GRAILS_HOME%\dist\grails-bootstrap-@grails.version@.jar
+set STARTER_CLASSPATH=@windows.starter.classpath@
if exist "%USERPROFILE%/.groovy/init.bat" call "%USERPROFILE%/.groovy/init.bat"
@@ -148,7 +152,7 @@ if "x%DISABLE_RELOADING%" == "xtrue" (
)
)
-set STARTER_MAIN_CLASS=org.codehaus.groovy.grails.cli.support.GrailsStarter
+set STARTER_MAIN_CLASS=@starter.main.class@
set STARTER_CONF=%GRAILS_HOME%\conf\groovy-starter.conf
set JAVA_EXE=%JAVA_HOME%\bin\java.exe
View
2 grails-test-suite-uber/src/test/groovy/grails/util/PluginBuildSettingsTests.groovy
@@ -135,7 +135,7 @@ class PluginBuildSettingsTests extends GroovyTestCase {
nonUserScripts << script
}
}
- assertEquals 53, nonUserScripts.size()
+ assertEquals 54, nonUserScripts.size()
}
void testGetPluginScripts() {
View
4 grails-web/src/main/groovy/org/codehaus/groovy/grails/web/taglib/GroovyPageTagBody.java
@@ -237,4 +237,8 @@ public int getMaximumNumberOfParameters() {
public Class[] getParameterTypes() {
return PARAMETER_TYPES;
}
+
+ public Closure<?> getBodyClosure() {
+ return bodyClosure;
+ }
}
View
46 grails-wrapper/build.gradle
@@ -0,0 +1,46 @@
+import org.apache.tools.ant.filters.ReplaceTokens
+
+task copyScript(type: Copy) {
+ into "$buildDir/"
+
+ into('scripts') {
+ from("../grails-resources/src/grails/home/bash/startGrails") {
+ rename 'startGrails', 'grailsw'
+ }
+ from("../grails-resources/src/grails/home/bash/startGrails.bat") {
+ 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: ['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.agent.string': "-javaagent:@wrapperDir@/springloaded-core-@springLoadedVersion@.jar -noverify -Dspringloaded=%SPRINGLOADED_PARAMS%".toString()])
+ fileMode = 0755
+ }
+
+}
+
+task runtimeJar(type: Jar) {
+ // TODO
+ from('build/classes/main')
+}
+
+jar {
+ from runtimeJar
+ from "${buildDir}/scripts", {
+ filter org.apache.tools.ant.filters.ReplaceTokens, tokens: [springLoadedVersion: springLoadedVersion, grailsVersion: grailsVersion]
+ }
+ // TODO
+ exclude 'org/**'
+}
+
+//supportJar.appendix = 'wrapper-support'
+jar.appendix = 'wrapper-support'
+runtimeJar.appendix = 'wrapper-runtime'
+
+artifacts {
+ runtime /*supportJar,*/ runtimeJar
+}
+
+jar.dependsOn copyScript
View
102 grails-wrapper/src/main/java/org/grails/wrapper/GrailsWrapper.java
@@ -0,0 +1,102 @@
+package org.grails.wrapper;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Enumeration;
+import java.util.ResourceBundle;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+
+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");
+ 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);
+
+ System.setProperty("grails.home", grailsHome.getAbsolutePath());
+ 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 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);
+ final String[] args2 = new String[args.length];
+ System.arraycopy(args, 0, args2, 0, args.length);
+ for(int i = 0; i < args2.length; i++) {
+ if("--conf".equals(args2[i]) && (i < (args2.length - 1))) {
+ final File groovyStarterConf = new File(grailsHome, "conf/groovy-starter.conf");
+ args2[i + 1] = groovyStarterConf.getAbsolutePath();
+ break;
+ }
+ }
+ mainMethod.invoke(null, new Object[]{args2});
+ }
+
+ public static void extract(final File zip, final File dest) throws IOException {
+ System.out.println("Extracting " + zip.getAbsolutePath() + " to " + dest.getAbsolutePath());
+ Enumeration<?> entries;
+ final ZipFile zipFile = new ZipFile(zip);
+
+ entries = zipFile.entries();
+
+ while (entries.hasMoreElements()) {
+ final ZipEntry entry = (ZipEntry) entries.nextElement();
+
+ if (entry.isDirectory()) {
+ (new File(dest, entry.getName())).mkdirs();
+ continue;
+ }
+
+ copy(zipFile.getInputStream(entry),
+ new BufferedOutputStream(new FileOutputStream(new File(dest, entry.getName()))));
+ }
+ zipFile.close();
+ }
+
+ public static void copy(final InputStream in, final OutputStream out) throws IOException {
+ final byte[] buffer = new byte[1024];
+ int len;
+
+ while ((len = in.read(buffer)) >= 0) {
+ out.write(buffer, 0, len);
+ }
+
+ in.close();
+ out.close();
+ }
+}
View
53 grails-wrapper/src/main/java/org/grails/wrapper/RemoteFileHelper.java
@@ -0,0 +1,53 @@
+package org.grails.wrapper;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+
+
+public class RemoteFileHelper {
+ private static final int CHUNK_SIZE = 20000;
+ private static final int BUFFER_SIZE = 10000;
+
+ public void retrieve(final URI address, final File destination) throws Exception {
+ if (destination.exists()) {
+ return;
+ }
+ destination.getParentFile().mkdirs();
+
+ System.out.println("Downloading " + address + " to " + destination.getAbsolutePath());
+ OutputStream out = null;
+ InputStream in = null;
+ try {
+ final URL url = address.toURL();
+ out = new BufferedOutputStream(
+ new FileOutputStream(destination));
+ final URLConnection conn = url.openConnection();
+ in = conn.getInputStream();
+ final byte[] buffer = new byte[BUFFER_SIZE];
+ int numRead;
+ long progressCounter = 0;
+ while ((numRead = in.read(buffer)) != -1) {
+ progressCounter += numRead;
+ if (progressCounter / CHUNK_SIZE > 0) {
+ System.out.print(".");
+ progressCounter = progressCounter - CHUNK_SIZE;
+ }
+ out.write(buffer, 0, numRead);
+ }
+ } finally {
+ System.out.println("");
+ if (in != null) {
+ in.close();
+ }
+ if (out != null) {
+ out.close();
+ }
+ }
+ }
+}
View
2 grails-wrapper/src/main/resources/grails-wrapper.properties
@@ -0,0 +1,2 @@
+wrapper.version=@wrapperVersion@
+wrapper.dist.url=@distributationUrl@
View
80 scripts/Wrapper.groovy
@@ -0,0 +1,80 @@
+includeTargets << grailsScript("_GrailsInit")
+
+USAGE = """
+ wrapper [--wrapperVersion=version] [--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/
+
+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/'
+
+"""
+
+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'
+
+ targetDir = "${basedir}/${grailsWrapperDir}"
+
+ supportFiles = []
+ new File("${grailsHome}/dist/").eachFileMatch( groovy.io.FileType.FILES, { it ==~ /grails-wrapper-support.*/ }) {
+ supportFiles << it
+ }
+ if(supportFiles.size() != 1) {
+ if(supportFiles.size() == 0) {
+ event("StatusError", ["An error occurred locating the grails-wrapper-support jar file"])
+ } else {
+ event("StatusError", ["Multiple grails-wrapper-support jar files were found ${supportFiles.absolutePath}"])
+ }
+ exit 1
+ }
+ supportFile = supportFiles[0]
+ ant.unjar(dest: targetDir, src: supportFile.absolutePath, overwrite: true) {
+ patternset {
+ exclude(name: "META-INF/**")
+ }
+ }
+ ant.move(todir: basedir) {
+ fileset(dir: targetDir) {
+ 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')
+
+ springloadedFiles = []
+ new File("${grailsHome}/lib/com.springsource.springloaded/springloaded-core/jars/").eachFileMatch( groovy.io.FileType.FILES, { it ==~ /springloaded-core-.*/ }) {
+ springloadedFiles << it
+ }
+ if(springloadedFiles.size() != 1) {
+ if(springloadedFiles.size() == 0) {
+ event("StatusError", ["An error occurred locating the springloaded-core jar file"])
+ } else {
+ event("StatusError", ["Multiple springloaded-core jar files were found ${springloadedFiles.absolutePath}"])
+ }
+ exit 1
+ }
+
+ springloadedFile = springloadedFiles[0]
+
+ ant.copy(todir: targetDir, file: springloadedFile.absolutePath, overwrite: true)
+
+ event("StatusUpdate", [ "Wrapper installed successfully"])
+ event 'InstallWrapperEnd', [ 'Finished Installing Wrapper.' ]
+}
View
1 settings.gradle
@@ -10,6 +10,7 @@ include 'grails-bootstrap',
'grails-resources',
'grails-scripts',
'grails-logging',
+ 'grails-wrapper',
// Plugins
'grails-plugin-domain-class',

0 comments on commit 0c3fc90

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