diff --git a/.idea/runConfigurations/Delete_Finished_Icons.xml b/.idea/runConfigurations/Delete_Finished_Icons.xml new file mode 100644 index 0000000..f397231 --- /dev/null +++ b/.idea/runConfigurations/Delete_Finished_Icons.xml @@ -0,0 +1,24 @@ +<component name="ProjectRunConfigurationManager"> + <configuration default="false" name="Delete Finished Icons" type="GradleRunConfiguration" factoryName="Gradle"> + <ExternalSystemSettings> + <option name="executionName" /> + <option name="externalProjectPath" value="$PROJECT_DIR$" /> + <option name="externalSystemIdString" value="GRADLE" /> + <option name="scriptParameters" value="" /> + <option name="taskDescriptions"> + <list /> + </option> + <option name="taskNames"> + <list> + <option value="deleteFinishedIcons" /> + </list> + </option> + <option name="vmOptions" /> + </ExternalSystemSettings> + <ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess> + <ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess> + <DebugAllEnabled>false</DebugAllEnabled> + <RunAsTest>false</RunAsTest> + <method v="2" /> + </configuration> +</component> \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index de64c2b..fdec054 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -81,6 +81,7 @@ fun getClassPathFolders(configuration: Configuration): List<String> { } createHelperTask("fixSVGs", main = "FixSVGs") +createHelperTask("deleteFinishedIcons", main = "DeleteFinishedIcons") createHelperTask("grabIconsFromInstalledIDEs", main = "GrabIcons\$FromInstalledIDEs") createHelperTask("grabIconsFromGradle", main = "GrabIcons\$FromArgumentPaths") { task -> val ideLibraries = getClassPathFolders(project.configurations.getByName("ides")) diff --git a/helpers/com/chylex/intellij/coloredicons/DeleteFinishedIcons.java b/helpers/com/chylex/intellij/coloredicons/DeleteFinishedIcons.java new file mode 100644 index 0000000..5902445 --- /dev/null +++ b/helpers/com/chylex/intellij/coloredicons/DeleteFinishedIcons.java @@ -0,0 +1,50 @@ +package com.chylex.intellij.coloredicons; + +import org.apache.commons.io.FileUtils; +import java.io.File; +import java.nio.file.Path; +import java.util.Collection; +import java.util.Set; +import static java.util.stream.Collectors.toSet; + +public final class DeleteFinishedIcons { + @SuppressWarnings("ResultOfMethodCallIgnored") + public static void main(final String[] args) { + final Path extractedRootPath = Path.of("./extracted"); + final Path finishedRootPath = Path.of("./resources/icons"); + + final Collection<File> extractedFiles = FileUtils.listFiles(extractedRootPath.toFile(), null, true); + final Collection<File> finishedFiles = FileUtils.listFiles(finishedRootPath.toFile(), null, true); + + System.out.println("Extracted files: " + extractedFiles.size()); + System.out.println("Finished files: " + finishedFiles.size()); + + final Set<String> finishedRelativePaths = finishedFiles.stream() + .map(file -> relativize(finishedRootPath, file)) + .collect(toSet()); + + int deleted = 0; + + for (final File extractedFile : extractedFiles) { + if (finishedRelativePaths.remove(relativize(extractedRootPath, extractedFile))) { + ++deleted; + extractedFile.delete(); + } + } + + System.out.println("Deleted files: " + deleted); + + if (!finishedRelativePaths.isEmpty()) { + System.out.println("Undeleted files: " + finishedRelativePaths.size()); + System.out.println(); + + finishedRelativePaths.stream() + .sorted() + .forEachOrdered(undeletedPath -> System.out.println("Undeleted file: " + undeletedPath)); + } + } + + private static String relativize(final Path basePath, final File file) { + return basePath.relativize(file.toPath()).toString(); + } +}