diff --git a/.idea/artifacts/SpaceTrimmer_jar.xml b/.idea/artifacts/SpaceTrimmer_jar.xml new file mode 100644 index 0000000..d32f5a6 --- /dev/null +++ b/.idea/artifacts/SpaceTrimmer_jar.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/output/artifacts/SpaceTrimmer_jar + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 8296b21..749a333 100644 --- a/README.md +++ b/README.md @@ -6,27 +6,32 @@ It's able to get rid of all trailing spaces for all code files in a directory an All programming languages are supported, you can input a comma-separated list of code-file extensions into the app's GUI, so that all matching files are included in the operation. Definition of GUI option 1 ("Remove trailing spaces/tabs"): -- empty whitespaces at the end of a line consisting of characters (only the very end of it, no loss of indent) +- remove whitespaces at the end of a line consisting of empty character spaces (no loss of indent or style) - actual tabs/spaces content in empty lines (it won't delete the empty lines itself, only bring it back to 0 bytes) [Example] See below image for the effects of this option: -[img] https://i.imgur.com/i35spWx.png +[img] https://i.imgur.com/7jLMMlk.png -Definition of GUI option 2 ("Remove empty lines"): -- delete empty lines by completely removing them. This will most often be separator lines between blocks of code, added by the developer's preference over the lifespan of a project. +Definition of GUI option 2 ("Remove excessive empty lines"): +- Particular locations with more than 3 empty lines, will be brought back to 2 lines. Such lines are often separator spaces between code/function blocks, and grow inconsistent over the lifespan of a project. [Example] See below image for the effects of this option: -[img] https://i.imgur.com/KGGnhz8.png +[img] https://i.imgur.com/cu46f7E.png The stable, multi-threaded approach and progress bar, should allow you to work on an high amount of files simultaneously and large repositories. -This is freeware and free to use, distribute, compilate and modify on private and corporate level. No further updates will be commited by myself, although you're free to submit Pull requests. +This is freeware and free to use for private and commercial purposes, change the license of, (re)distribute, compile and modify on private and corporate level. There are no restrictions. GUI interface: -https://i.imgur.com/N5dEWo3.png +https://i.imgur.com/QL6asxH.png -Processing the 1100 files in above example GUI image, costed just under 3 seconds. \ No newline at end of file +Processing the 1100 files in above example GUI image, took just under 3 seconds of execution time. + + + +It should speak for itself, but if you have any specific demands, you can simply edit the source and recompile the app. +Also feel free to submit pull requests! \ No newline at end of file diff --git a/src/nl/dutchman/spacetrimmer/ui/MainWindow.form b/src/nl/dutchman/spacetrimmer/ui/MainWindow.form index eecae88..2fac57d 100644 --- a/src/nl/dutchman/spacetrimmer/ui/MainWindow.form +++ b/src/nl/dutchman/spacetrimmer/ui/MainWindow.form @@ -100,7 +100,7 @@ - + diff --git a/src/nl/dutchman/spacetrimmer/ui/WindowController.java b/src/nl/dutchman/spacetrimmer/ui/WindowController.java index c9eeb75..316bff6 100644 --- a/src/nl/dutchman/spacetrimmer/ui/WindowController.java +++ b/src/nl/dutchman/spacetrimmer/ui/WindowController.java @@ -85,11 +85,9 @@ private void initializeProcess(String directory, String extensionStr, boolean tr boolean noExtensions = extensionStr == null || extensionStr.trim().isEmpty(); List extensions; if (noExtensions) - extensions = new ArrayList(); // empty list, just in case, to avoid nullptr + extensions = new ArrayList<>(); else - { extensions = Arrays.asList(extensionStr.split(",")); - } ExecutorService processService = Executors.newSingleThreadExecutor(); processService.submit(() -> { @@ -97,12 +95,14 @@ private void initializeProcess(String directory, String extensionStr, boolean tr { BiFunction, Boolean> endsWithAny = (dirName, exts) -> { - for (String ext : exts) + try { - if (dirName.endsWith(ext)) - return true; + return exts.contains(dirName.substring(dirName.lastIndexOf('.') + 1)); + } + catch (IndexOutOfBoundsException e) + { + return false; } - return false; }; System.out.println("Step 0 --> Gathering files to modify"); stepInformation[0] = new ProcessInformation(); @@ -111,7 +111,7 @@ private void initializeProcess(String directory, String extensionStr, boolean tr List processableFiles = Files.walk(Paths.get(directory)). map(p -> new ProcessableFile(p.toFile(), p.toFile().length())). filter(p -> !p.getFile().isDirectory()). - filter(noExtensions ? p -> true : p -> endsWithAny.apply(p.getFile().getAbsolutePath(), extensions)). + filter(noExtensions ? p -> true : p -> endsWithAny.apply(p.getFile().getAbsolutePath(), extensions)). collect(Collectors.toList()); stepInformation[0].end(); @@ -136,13 +136,25 @@ private void initializeProcess(String directory, String extensionStr, boolean tr try { List lineFiles = new ArrayList<>(); - for (String line : Files.readAllLines(file.getFile().toPath(), StandardCharsets.ISO_8859_1)) + for (String line : Files.readAllLines(file.getFile().toPath(), StandardCharsets.UTF_8)) { if (trimSpaces) line = line.replaceAll("\\s+$", ""); - if (!trimLines || (trimLines && line != null && !line.trim().isEmpty())) - lineFiles.add(line); + + lineFiles.add(line); } + + if (trimLines) + { + for (int i = lineFiles.size() - 3; i >= 0; i--) + { + if (lineFiles.get(i).trim().isEmpty() && + lineFiles.get(i+1).trim().isEmpty() && + lineFiles.get(i+2).trim().isEmpty()) + lineFiles.remove(i); + } + } + Files.write(file.getFile().toPath(), lineFiles); } catch (IOException e)