diff --git a/.gitignore b/.gitignore index d7c9f291..f8b56fb7 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,4 @@ .run/XeresApplication.run.xml /scripts/bot/config.json /scripts/bot/avatar.png - +/cache/ \ No newline at end of file diff --git a/app/src/main/java/io/xeres/app/configuration/CacheDirConfiguration.java b/app/src/main/java/io/xeres/app/configuration/CacheDirConfiguration.java index 62d0f3f8..10dbd12f 100644 --- a/app/src/main/java/io/xeres/app/configuration/CacheDirConfiguration.java +++ b/app/src/main/java/io/xeres/app/configuration/CacheDirConfiguration.java @@ -19,11 +19,13 @@ package io.xeres.app.configuration; +import io.xeres.app.util.DevUtils; import io.xeres.common.AppName; import net.harawata.appdirs.AppDirsFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; +import org.springframework.core.env.Profiles; import java.io.IOException; import java.nio.file.Files; @@ -61,7 +63,16 @@ public String getCacheDir() return null; } - cacheDir = getCacheDirFromPortableFileLocation(); + if (environment.acceptsProfiles(Profiles.of("dev"))) + { + cacheDir = DevUtils.getDirFromDevelopmentSetup("cache"); + } + + if (cacheDir == null) + { + cacheDir = getCacheDirFromPortableFileLocation(); + } + if (cacheDir == null) { cacheDir = getCacheDirFromNativePlatform(); diff --git a/app/src/main/java/io/xeres/app/configuration/DataDirConfiguration.java b/app/src/main/java/io/xeres/app/configuration/DataDirConfiguration.java index 1e4fb5db..af40df8d 100644 --- a/app/src/main/java/io/xeres/app/configuration/DataDirConfiguration.java +++ b/app/src/main/java/io/xeres/app/configuration/DataDirConfiguration.java @@ -19,6 +19,7 @@ package io.xeres.app.configuration; +import io.xeres.app.util.DevUtils; import io.xeres.common.AppName; import io.xeres.common.properties.StartupProperties; import net.harawata.appdirs.AppDirsFactory; @@ -30,7 +31,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Objects; import static io.xeres.common.properties.StartupProperties.Property.DATA_DIR; @@ -74,7 +74,7 @@ public String getDataDir() dataDir = getDataDirFromArgs(); if (dataDir == null && environment.acceptsProfiles(Profiles.of("dev"))) { - dataDir = getDataDirFromDevelopmentSetup(); + dataDir = DevUtils.getDirFromDevelopmentSetup(LOCAL_DATA); } if (dataDir == null) @@ -123,23 +123,4 @@ private static String getDataDirFromNativePlatform() var appDirs = AppDirsFactory.getInstance(); return appDirs.getUserDataDir(AppName.NAME, null, null, true); } - - private static String getDataDirFromDevelopmentSetup() - { - // Find out if we're running from rootProject, which means - // we have an 'app' folder in there. - // We use a relative directory because currentDir is not supposed - // to change, and it looks clearer. - var appDir = Path.of("app"); - if (Files.exists(appDir)) - { - return Path.of(".", LOCAL_DATA).toString(); - } - appDir = Path.of("..", "app"); - if (Files.exists(appDir)) - { - return Path.of("..", LOCAL_DATA).toString(); - } - throw new IllegalStateException("Unable to find/create data directory. Current directory must be the project's root directory or 'app'. It is " + Paths.get("").toAbsolutePath()); - } } diff --git a/app/src/main/java/io/xeres/app/util/DevUtils.java b/app/src/main/java/io/xeres/app/util/DevUtils.java new file mode 100644 index 00000000..d277e46a --- /dev/null +++ b/app/src/main/java/io/xeres/app/util/DevUtils.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 by David Gerber - https://zapek.com + * + * This file is part of Xeres. + * + * Xeres is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Xeres is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Xeres. If not, see . + */ + +package io.xeres.app.util; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public final class DevUtils +{ + private DevUtils() + { + throw new UnsupportedOperationException("Utility class"); + } + + public static String getDirFromDevelopmentSetup(String directory) + { + // Find out if we're running from rootProject, which means + // we have an 'app' folder in there. + // We use a relative directory because currentDir is not supposed + // to change, and it looks clearer. + var appDir = Path.of("app"); + if (Files.exists(appDir)) + { + return Path.of(".", directory).toString(); + } + appDir = Path.of("..", "app"); + if (Files.exists(appDir)) + { + return Path.of("..", directory).toString(); + } + throw new IllegalStateException("Unable to find/create directory. Current directory must be the project's root directory or 'app'. It is " + Paths.get("").toAbsolutePath()); + } +}