-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from groovy/handle-other-grapes-cache-directories
Handle different Grapes cache directory
- Loading branch information
Showing
1 changed file
with
44 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,46 @@ | ||
@Grab(group='org.apache.commons', module='commons-lang3', version='3.7') | ||
import org.apache.commons.lang3.StringUtils | ||
@Grab(group='org.apache.commons', module='commons-lang3', version='3.13.0') | ||
import org.apache.commons.lang3.* | ||
|
||
if (new File('/home/groovy/.groovy/grapes').listFiles().size() == 0) { | ||
System.exit 1 | ||
} else { | ||
System.exit 0 | ||
File getGroovyRoot() { | ||
String root = System.getProperty('groovy.root') | ||
def groovyRoot | ||
if (root == null) { | ||
groovyRoot = new File(System.getProperty('user.home'), '.groovy') | ||
} else { | ||
groovyRoot = new File(root) | ||
} | ||
try { | ||
groovyRoot = groovyRoot.getCanonicalFile() | ||
} catch (IOException ignore) { | ||
// skip canonicalization then, it may not exist yet | ||
} | ||
groovyRoot | ||
} | ||
|
||
File getGrapeDir() { | ||
String root = System.getProperty('grape.root') | ||
if (root == null) { | ||
return getGroovyRoot() | ||
} | ||
File grapeRoot = new File(root) | ||
try { | ||
grapeRoot = grapeRoot.getCanonicalFile() | ||
} catch (IOException ignore) { | ||
// skip canonicalization then, it may not exist yet | ||
} | ||
grapeRoot | ||
} | ||
|
||
File getGrapeCacheDir() { | ||
File cache = new File(getGrapeDir(), 'grapes') | ||
if (!cache.exists()) { | ||
cache.mkdirs() | ||
} else if (!cache.isDirectory()) { | ||
throw new RuntimeException("The grape cache dir $cache is not a directory") | ||
} | ||
cache | ||
} | ||
|
||
if (getGrapeCacheDir().listFiles().size() == 0) { | ||
throw new RuntimeException('No Grapes files') | ||
} |