From 0075bb8c540e7cce70bcca5e23fa15426f3aec22 Mon Sep 17 00:00:00 2001 From: Keegan Witt Date: Fri, 6 Oct 2023 10:49:58 -0400 Subject: [PATCH] Handle different Grapes cache directory --- test/grape.groovy | 50 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/test/grape.groovy b/test/grape.groovy index 4b51639..100c7a8 100644 --- a/test/grape.groovy +++ b/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') }