Permalink
Browse files

refactor wrapper setup code

  • Loading branch information...
1 parent ce96104 commit fcc6ee4bf977618be9f4e6062a58bd80b885d415 @jeffbrown jeffbrown committed May 10, 2012
Showing with 25 additions and 13 deletions.
  1. +25 −13 grails-wrapper/src/main/java/org/grails/wrapper/GrailsWrapper.java
@@ -25,26 +25,15 @@ public static void main(final String[] args) throws Exception{
final ResourceBundle applicationBundle = ResourceBundle.getBundle("application");
final ResourceBundle wrapperBundle = ResourceBundle.getBundle("grails-wrapper");
final String grailsVersion = applicationBundle.getString("app.grails.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 = 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());
@@ -79,6 +68,29 @@ public boolean accept(final File dir, final String name) {
mainMethod.invoke(null, new Object[]{newArgsArray});
}
+
+ /**
+ *
+ * @param distUrl URL to directory where 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());

0 comments on commit fcc6ee4

Please sign in to comment.