dev.jbang.Cache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbang-cli Show documentation
Show all versions of jbang-cli Show documentation
JBang Command Line Interface
package dev.jbang;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import dev.jbang.cli.ExitException;
import dev.jbang.net.JdkManager;
import dev.jbang.net.JdkProvider;
import dev.jbang.util.Util;
public class Cache {
public enum CacheClass {
urls, jars, jdks, kotlincs, groovycs, projects, scripts, stdins, deps
}
static void setupCache(Path dir) {
// create cache dir if it does not yet exist
dir.toFile().mkdirs();
}
public static void clearCache(CacheClass... classes) {
for (CacheClass cc : classes) {
Util.infoMsg("Clearing cache for " + cc.name());
if (cc == CacheClass.jdks && Util.isWindows() && JdkManager.isCurrentJdkManaged()) {
// We're running using a managed JDK on Windows so we can't just delete the
// entire folder!
for (JdkProvider.Jdk jdk : JdkManager.listInstalledJdks()) {
JdkManager.uninstallJdk(jdk);
}
}
if (cc == CacheClass.deps) {
try {
if (Settings.getCacheDependencyFile().toFile().exists()) {
Util.verboseMsg("Deleting file " + Settings.getCacheDependencyFile());
Files.deleteIfExists(Settings.getCacheDependencyFile().toAbsolutePath());
}
} catch (IOException io) {
throw new ExitException(-1,
"Could not delete dependency cache " + Settings.getCacheDependencyFile().toString(), io);
}
} else {
Util.deletePath(Settings.getCacheDir(cc), true);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy