.iceignore to exclude files from exports

This commit is contained in:
Johannes Frohnmeyer 2022-09-16 16:30:12 +02:00
parent cdf81fcb57
commit da621e0eba
Signed by: Johannes
GPG Key ID: E76429612C2929F4
4 changed files with 36 additions and 42 deletions

View File

@ -54,7 +54,7 @@ public class InceptumConfig {
case "authorName" -> authorName = jr.nextString();
default -> {
Utils.LOGGER.error("Unexpected entry name: " + name);
skipValue(jr);
jr.skipValue();
}
}
} catch (Throwable t) {
@ -66,28 +66,6 @@ public class InceptumConfig {
}
}
private static void skipValue(JsonReader jr) throws IOException {
switch (jr.peek()) {
case BEGIN_ARRAY -> {
jr.beginArray();
while (jr.peek() != JsonToken.END_ARRAY) skipValue(jr);
jr.endArray();
}
case BEGIN_OBJECT -> {
jr.beginObject();
while (jr.peek() != JsonToken.END_OBJECT) {
jr.nextName();
skipValue(jr);
}
jr.endObject();
}
case STRING -> jr.nextString();
case NUMBER -> jr.nextDouble();
case BOOLEAN -> jr.nextBoolean();
case NULL -> jr.nextNull();
}
}
public static void saveConfig() {
try (Writer writer = Files.newBufferedWriter(MetaHolder.CONFIG_PATH);
JsonWriter jw = GsonHolder.getGson().newJsonWriter(writer)) {

View File

@ -12,7 +12,20 @@ public class MetaHolder {
Path runDir = Path.of(".").resolve("run").toAbsolutePath();
if (!BuildMetadata.IS_RELEASE) BASE_PATH = runDir;
else if (Files.exists(runDir)) BASE_PATH = runDir;
else BASE_PATH = getConfigPath().resolve("Inceptum");
else {
Path configsDir = switch (OSUtils.TYPE) {
case WINDOWS -> getPath(System.getenv("APPDATA"));
case MAC_OS -> getPath(System.getProperty("user.home")).resolve("Library").resolve("Application Support");
case LINUX -> {
String s = System.getenv().get("XDG_CONFIG_HOME");
if (s == null)
yield getPath(System.getProperty("user.home")).resolve(".config");
else
yield getPath(s);
}
};
BASE_PATH = configsDir.resolve("Inceptum");
}
} else {
BASE_PATH = getPath(System.getProperty("inceptum.base"));
}
@ -29,20 +42,6 @@ public class MetaHolder {
public static final Path CACHE_DIR = BASE_PATH.resolve("cache");
private static boolean isWrapper = false;
private static Path getConfigPath() {
return switch (OSUtils.TYPE) {
case WINDOWS -> getPath(System.getenv("APPDATA"));
case MAC_OS -> getPath(System.getProperty("user.home")).resolve("Library").resolve("Application Support");
case LINUX -> {
String s = System.getenv().get("XDG_CONFIG_HOME");
if (s == null)
yield getPath(System.getProperty("user.home")).resolve(".config");
else
yield getPath(s);
}
};
}
private static Path getPath(String text) {
return Paths.get(text).toAbsolutePath();
}

View File

@ -30,11 +30,18 @@ public class WriteMetadataStep implements Step {
saves/
screenshots/
logs/
fabricloader.log
.mixin.out/
.fabric/
*.lock
eula.txt
world/""");
world/
usercache.json
realms_persistence.json""");
}
if (!Files.exists(instance.resolve(".iceignore"))) {
Files.writeString(instance.resolve(".iceignore"), """
instance.json""");
}
}
}

View File

@ -14,6 +14,7 @@ public class IgnoringWalk implements Iterator<Path> {
}
private static final String GITIGNORE = ".gitignore";
private static final String ICEIGNORE = ".iceignore";
private static final String GIT = ".git";
private final Path ref;
@ -50,14 +51,23 @@ public class IgnoringWalk implements Iterator<Path> {
}
private void enqueueContent(Path directory) throws IOException {
Path ignorePath = directory.resolve(GITIGNORE);
if (Files.exists(ignorePath)) {
ignores.put(directory, new Ignore().add(Files.readAllLines(ignorePath)));
Path gitignorePath = directory.resolve(GITIGNORE);
Path iceignorePath = directory.resolve(ICEIGNORE);
Ignore ignore = null;
if (Files.exists(gitignorePath)) {
if (ignore == null) ignore = new Ignore();
ignore.add(Files.readAllLines(gitignorePath));
}
if (Files.exists(iceignorePath)) {
if (ignore == null) ignore = new Ignore();
ignore.add(Files.readAllLines(iceignorePath));
}
if (ignore != null) ignores.put(directory, ignore);
try (Stream<Path> files = Files.list(directory)) {
for (Path path : files.toList()) {
String fileName = path.getFileName().toString();
if (!fileName.equals(GITIGNORE)
&& !fileName.equals(ICEIGNORE)
&& !fileName.equals(GIT)
&& !isIgnored(ref.relativize(path))) {
toScan.add(path);