Skip to content

Commit

Permalink
Merge pull request #97 from groovy/handle-other-grapes-cache-directories
Browse files Browse the repository at this point in the history
Handle different Grapes cache directory
  • Loading branch information
keeganwitt committed Oct 6, 2023
2 parents 66c1c41 + 0075bb8 commit ce5e447
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions test/grape.groovy
@@ -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')
}

0 comments on commit ce5e447

Please sign in to comment.