Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:grails/grails-core
- Loading branch information
Showing
13 changed files
with
323 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
102 changes: 102 additions & 0 deletions
102
grails-wrapper/src/main/java/org/grails/wrapper/GrailsWrapper.java
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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(); | |||
} | |||
} |
53 changes: 53 additions & 0 deletions
53
grails-wrapper/src/main/java/org/grails/wrapper/RemoteFileHelper.java
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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(); | |||
} | |||
} | |||
} | |||
} |
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
wrapper.version=@wrapperVersion@ | |||
wrapper.dist.url=@distributationUrl@ |
Oops, something went wrong.