diff --git a/build.sbt b/build.sbt index deb4666..3e7b66a 100644 --- a/build.sbt +++ b/build.sbt @@ -1,47 +1,64 @@ -lazy val root = (project in file(".")) +lazy val sharedSettings = Def.settings( + organization := "dev.dirs", + managedScalaInstance := false, + crossPaths := false, + version := "20", + homepage := Some(url("https://github.com/dirs-dev/directories-jvm")), + licenses := Seq("Mozilla Public License 2.0" -> url("https://opensource.org/licenses/MPL-2.0")), + fork := true, + // The javaHome setting can be removed if building against the latest installed version of Java is acceptable. + // Running the tests requires removing the setting. + // It can also be changed to point to a different Java version. + // javaHome := Some(file("/home/soc/apps/zulu6.19.0.1-jdk6.0.103-linux_x64/")), + /* + publishTo := { + val nexus = "https://oss.sonatype.org/" + if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots") + else Some("releases" at nexus + "service/local/staging/deploy/maven2") + }, + */ + pomIncludeRepository := { _ => false }, + pomExtra := + + git@github.com:dirs-dev/directories-jvm.git + scm:git:git@github.com:dirs-dev/directories-jvm.git + + + + soc + Simon Ochsenreither + https://github.com/soc + + Project Lead + + + +) + +def automaticModuleName(name: String) = Def.settings( + packageOptions in (Compile, packageBin) += { + import java.util.jar.{Attributes, Manifest} + val manifest = new Manifest + manifest.getMainAttributes.put(new Attributes.Name("Automatic-Module-Name"), name) + Package.JarManifest(manifest) + } +) + +lazy val core = project .settings( + sharedSettings, name := "directories", - organization := "dev.dirs", - managedScalaInstance := false, - crossPaths := false, - version := "20", - homepage := Some(url("https://github.com/dirs-dev/directories-jvm")), - licenses := Seq("Mozilla Public License 2.0" -> url("https://opensource.org/licenses/MPL-2.0")), - fork := true, - // The javaHome setting can be removed if building against the latest installed version of Java is acceptable. - // Running the tests requires removing the setting. - // It can also be changed to point to a different Java version. - // javaHome := Some(file("/home/soc/apps/zulu6.19.0.1-jdk6.0.103-linux_x64/")), libraryDependencies += "junit" % "junit" % "4.13" % Test, libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % Test, testOptions in Test := Seq(Tests.Argument(TestFrameworks.JUnit, "-a")), - /* - publishTo := { - val nexus = "https://oss.sonatype.org/" - if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots") - else Some("releases" at nexus + "service/local/staging/deploy/maven2") - }, - */ - packageOptions in (Compile, packageBin) += { - import java.util.jar.{Attributes, Manifest} - val manifest = new Manifest - manifest.getMainAttributes.put(new Attributes.Name("Automatic-Module-Name"), "dev.dirs") - Package.JarManifest(manifest) - }, - pomIncludeRepository := { _ => false }, - pomExtra := - - git@github.com:dirs-dev/directories-jvm.git - scm:git:git@github.com:dirs-dev/directories-jvm.git - - - - soc - Simon Ochsenreither - https://github.com/soc - - Project Lead - - - + automaticModuleName("dev.dirs") + ) + +lazy val cli = project + .dependsOn(core) + .settings( + sharedSettings, + name := "directories-cli", + libraryDependencies += "info.picocli" % "picocli" % "4.4.0", + automaticModuleName("dev.dirs.cli") ) diff --git a/cli/src/main/java/dev/dirs/cli/DirectoriesCli.java b/cli/src/main/java/dev/dirs/cli/DirectoriesCli.java new file mode 100644 index 0000000..b2873ec --- /dev/null +++ b/cli/src/main/java/dev/dirs/cli/DirectoriesCli.java @@ -0,0 +1,71 @@ +package dev.dirs.cli; + +import dev.dirs.ProjectDirectories; +import picocli.CommandLine; +import picocli.CommandLine.*; + +@Command(name = "directories", mixinStandardHelpOptions = true, version = "20") +public class DirectoriesCli implements Runnable { + @Option(names = {"--cache"}, description = "Prints cache directory") + boolean cache; + @Option(names = {"--config"}, description = "Prints config directory") + boolean config; + @Option(names = {"--data"}, description = "Prints data directory") + boolean data; + @Option(names = {"--data-local"}, description = "Prints local data directory") + boolean dataLocal; + @Option(names = {"--preferences"}, description = "Prints preferences directory") + boolean preferences; + @Option(names = {"--runtime"}, description = "Prints runtime directory") + boolean runtime; + + @Parameters(index = "0") + String project; + + @Override + public void run() { + int dirCount = 0; + if (cache) dirCount += 1; + if (config) dirCount += 1; + if (data) dirCount += 1; + if (dataLocal) dirCount += 1; + if (preferences) dirCount += 1; + if (runtime) dirCount += 1; + + boolean all = dirCount == 0; + + ProjectDirectories projDirs = ProjectDirectories.from(null, null, project); + + if (dirCount == 1) { + if (cache) + System.out.println(projDirs.cacheDir); + if (config) + System.out.println(projDirs.configDir); + if (data) + System.out.println(projDirs.dataDir); + if (dataLocal) + System.out.println(projDirs.dataLocalDir); + if (preferences) + System.out.println(projDirs.preferenceDir); + if (runtime) + System.out.println(projDirs.runtimeDir); + } else { + if (all || cache) + System.out.println("cache: " + projDirs.cacheDir); + if (all || config) + System.out.println("config: " + projDirs.configDir); + if (all || data) + System.out.println("data: " + projDirs.dataDir); + if (all || dataLocal) + System.out.println("local data: " + projDirs.dataLocalDir); + if (all || preferences) + System.out.println("preference: " + projDirs.preferenceDir); + if (all || runtime) + System.out.println("runtime: " + projDirs.runtimeDir); + } + } + + public static void main(String... args) { + System.exit(new CommandLine(new DirectoriesCli()).execute(args)); + } +} diff --git a/src/main/java/dev/dirs/BaseDirectories.java b/core/src/main/java/dev/dirs/BaseDirectories.java similarity index 100% rename from src/main/java/dev/dirs/BaseDirectories.java rename to core/src/main/java/dev/dirs/BaseDirectories.java diff --git a/src/main/java/dev/dirs/ProjectDirectories.java b/core/src/main/java/dev/dirs/ProjectDirectories.java similarity index 100% rename from src/main/java/dev/dirs/ProjectDirectories.java rename to core/src/main/java/dev/dirs/ProjectDirectories.java diff --git a/src/main/java/dev/dirs/UnsupportedOperatingSystemException.java b/core/src/main/java/dev/dirs/UnsupportedOperatingSystemException.java similarity index 100% rename from src/main/java/dev/dirs/UnsupportedOperatingSystemException.java rename to core/src/main/java/dev/dirs/UnsupportedOperatingSystemException.java diff --git a/src/main/java/dev/dirs/UserDirectories.java b/core/src/main/java/dev/dirs/UserDirectories.java similarity index 100% rename from src/main/java/dev/dirs/UserDirectories.java rename to core/src/main/java/dev/dirs/UserDirectories.java diff --git a/src/main/java/dev/dirs/Util.java b/core/src/main/java/dev/dirs/Util.java similarity index 100% rename from src/main/java/dev/dirs/Util.java rename to core/src/main/java/dev/dirs/Util.java diff --git a/src/main/resources/META-INF/native-image/dev.dirs/reflect-config.json b/core/src/main/resources/META-INF/native-image/dev.dirs/reflect-config.json similarity index 100% rename from src/main/resources/META-INF/native-image/dev.dirs/reflect-config.json rename to core/src/main/resources/META-INF/native-image/dev.dirs/reflect-config.json diff --git a/src/test/java/dev/dirs/DirectoriesTest.java b/core/src/test/java/dev/dirs/DirectoriesTest.java similarity index 100% rename from src/test/java/dev/dirs/DirectoriesTest.java rename to core/src/test/java/dev/dirs/DirectoriesTest.java diff --git a/src/test/java/dev/dirs/UtilTest.java b/core/src/test/java/dev/dirs/UtilTest.java similarity index 100% rename from src/test/java/dev/dirs/UtilTest.java rename to core/src/test/java/dev/dirs/UtilTest.java