From a39d0b6656e763d42b66e0ad80636d9c7969f3ff Mon Sep 17 00:00:00 2001 From: Adrian Siekierka Date: Sat, 22 Dec 2018 15:35:36 +0100 Subject: [PATCH] add cleanLoomMappings, close #36 --- .../net/fabricmc/loom/LoomGradlePlugin.java | 1 + .../fabricmc/loom/task/CleanLoomMappings.java | 51 +++++++++++++++++++ .../loom/util/DeletingFileVisitor.java | 46 +++++++++++++++++ .../fabricmc/loom/util/SourceRemapper.java | 14 +---- 4 files changed, 99 insertions(+), 13 deletions(-) create mode 100644 src/main/java/net/fabricmc/loom/task/CleanLoomMappings.java create mode 100644 src/main/java/net/fabricmc/loom/util/DeletingFileVisitor.java diff --git a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java index ee3da8a..36f4ca3 100644 --- a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java +++ b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java @@ -33,6 +33,7 @@ public class LoomGradlePlugin extends AbstractPlugin { super.apply(target); makeTask("cleanLoomBinaries", CleanLoomBinaries.class); + makeTask("cleanLoomMappings", CleanLoomMappings.class); makeTask("remapJar", RemapJar.class); diff --git a/src/main/java/net/fabricmc/loom/task/CleanLoomMappings.java b/src/main/java/net/fabricmc/loom/task/CleanLoomMappings.java new file mode 100644 index 0000000..54eb50f --- /dev/null +++ b/src/main/java/net/fabricmc/loom/task/CleanLoomMappings.java @@ -0,0 +1,51 @@ +/* + * This file is part of fabric-loom, licensed under the MIT License (MIT). + * + * Copyright (c) 2016, 2017, 2018 FabricMC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package net.fabricmc.loom.task; + +import net.fabricmc.loom.LoomGradleExtension; +import net.fabricmc.loom.util.DeletingFileVisitor; +import org.gradle.api.DefaultTask; +import org.gradle.api.Project; +import org.gradle.api.tasks.TaskAction; + +import java.io.IOException; +import java.nio.file.Files; + +public class CleanLoomMappings extends DefaultTask { + @TaskAction + public void run() { + Project project = this.getProject(); + LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); + extension.getMappingsProvider().MAPPINGS_TINY.delete(); + extension.getMappingsProvider().MAPPINGS_TINY_BASE.delete(); + extension.getMinecraftMappedProvider().getIntermediaryJar().delete(); + extension.getMinecraftMappedProvider().getMappedJar().delete(); + try { + Files.walkFileTree(extension.getProjectCache().toPath(), new DeletingFileVisitor()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/net/fabricmc/loom/util/DeletingFileVisitor.java b/src/main/java/net/fabricmc/loom/util/DeletingFileVisitor.java new file mode 100644 index 0000000..491ab18 --- /dev/null +++ b/src/main/java/net/fabricmc/loom/util/DeletingFileVisitor.java @@ -0,0 +1,46 @@ +/* + * This file is part of fabric-loom, licensed under the MIT License (MIT). + * + * Copyright (c) 2016, 2017, 2018 FabricMC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package net.fabricmc.loom.util; + +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; + +public class DeletingFileVisitor extends SimpleFileVisitor { + @Override + public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException { + Files.delete(path); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path path, IOException e) throws IOException { + Files.delete(path); + return FileVisitResult.CONTINUE; + } +} diff --git a/src/main/java/net/fabricmc/loom/util/SourceRemapper.java b/src/main/java/net/fabricmc/loom/util/SourceRemapper.java index 36e1048..d8724f7 100644 --- a/src/main/java/net/fabricmc/loom/util/SourceRemapper.java +++ b/src/main/java/net/fabricmc/loom/util/SourceRemapper.java @@ -125,19 +125,7 @@ public class SourceRemapper { } if (isSrcTmp) { - Files.walkFileTree(srcPath, new SimpleFileVisitor() { - @Override - public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException { - Files.delete(path); - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult postVisitDirectory(Path path, IOException e) throws IOException { - Files.delete(path); - return FileVisitResult.CONTINUE; - } - }); + Files.walkFileTree(srcPath, new DeletingFileVisitor()); } }