From abfbd0d7325a094b657fe7374bb84e5178531a0e Mon Sep 17 00:00:00 2001 From: Christopher Tubbs Date: Tue, 9 May 2023 20:01:41 -0400 Subject: [PATCH] Bump versions, remove warnings Bump versions of plugins and dependencies. Remove warnings from unused maven plugin options, and fix modernizer-detected recommendations for Optional.get() to use the recommended Optional.orElseThrow() instead. --- pom.xml | 39 ++++++++----------- .../java/net/revelc/code/impsort/ImpSort.java | 34 ++++++++-------- 2 files changed, 34 insertions(+), 39 deletions(-) diff --git a/pom.xml b/pom.xml index 00517cb..ea0c493 100644 --- a/pom.xml +++ b/pom.xml @@ -86,14 +86,14 @@ 11 true - 3.8.7 - 3.7.1 + 3.9.1 + 3.8.2 11 3.5.0 2022-11-23T16:28:41Z UTF-8 UTF-8 - 3.4.2 + 3.4.3 source-release-tar 3.0.0-M5 @@ -128,17 +128,17 @@ org.apache.maven.skins maven-fluido-skin - 2.0.0-M2 + 2.0.0-M6 org.codehaus.plexus plexus-utils - 3.5.0 + 3.5.1 org.junit.jupiter junit-jupiter - 5.9.2 + 5.9.3 @@ -183,12 +183,12 @@ org.codehaus.mojo versions-maven-plugin - 2.14.2 + 2.15.0 org.gaul modernizer-maven-plugin - 2.5.0 + 2.6.0 ${maven.compiler.target} @@ -201,7 +201,7 @@ com.github.ekryd.sortpom sortpom-maven-plugin - 3.2.0 + 3.2.1 false false @@ -216,9 +216,8 @@ org.apache.maven.plugins maven-compiler-plugin - 3.10.1 + 3.11.0 - true true true @@ -232,12 +231,12 @@ org.apache.maven.plugins maven-enforcer-plugin - 3.1.0 + 3.3.0 org.apache.maven.plugins maven-javadoc-plugin - 3.4.1 + 3.5.0 true all,-missing @@ -246,7 +245,7 @@ org.apache.maven.plugins maven-release-plugin - 3.0.0-M7 + 3.0.0 false false @@ -256,13 +255,9 @@ net.revelc.code.formatter formatter-maven-plugin - 2.21.0 + 2.22.0 - ${maven.compiler.source} - ${maven.compiler.source} - ${maven.compiler.target} LF - true true true true @@ -282,19 +277,19 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.2.1 + 3.2.2 com.puppycrawl.tools checkstyle - 10.6.0 + 10.10.0 com.github.spotbugs spotbugs-maven-plugin - 4.7.3.0 + 4.7.3.4 true Max diff --git a/src/main/java/net/revelc/code/impsort/ImpSort.java b/src/main/java/net/revelc/code/impsort/ImpSort.java index 0b72c20..f2fa244 100644 --- a/src/main/java/net/revelc/code/impsort/ImpSort.java +++ b/src/main/java/net/revelc/code/impsort/ImpSort.java @@ -60,7 +60,8 @@ public class ImpSort { - private static final Comparator BY_POSITION = Comparator.comparing(a -> a.getBegin().get()); + private static final Comparator BY_POSITION = + Comparator.comparing(a -> a.getBegin().orElseThrow()); private final Charset sourceEncoding; private final Grouper grouper; @@ -134,8 +135,8 @@ public Result parseFile(final Path path, final byte[] buf) throws IOException { parseResult.getProblems().forEach(System.out::println); throw new ImpSortException(path, Reason.PARTIAL_PARSE); } - Position packagePosition = - unit.getPackageDeclaration().map(p -> p.getEnd().get()).orElse(unit.getBegin().get()); + Position packagePosition = unit.getPackageDeclaration().map(p -> p.getEnd().orElseThrow()) + .orElse(unit.getBegin().orElseThrow()); NodeList importDeclarations = unit.getImports(); if (importDeclarations.isEmpty()) { return new Result(path, sourceEncoding, fileLines, 0, fileLines.size(), "", "", @@ -144,9 +145,9 @@ public Result parseFile(final Path path, final byte[] buf) throws IOException { // find orphaned comments before between package and last import Position lastImportPosition = - importDeclarations.stream().max(BY_POSITION).get().getBegin().get(); + importDeclarations.stream().max(BY_POSITION).orElseThrow().getBegin().orElseThrow(); Stream orphanedComments = unit.getOrphanComments().parallelStream().filter(c -> { - Position p = c.getBegin().get(); + Position p = c.getBegin().orElseThrow(); return p.isAfter(packagePosition) && p.isBefore(lastImportPosition); }); @@ -156,9 +157,9 @@ public Result parseFile(final Path path, final byte[] buf) throws IOException { importSectionNodes.sort(BY_POSITION); // position line numbers start at 1, not 0 Node firstImport = importSectionNodes.get(0); - int start = firstImport.getComment().map(c -> c.getBegin().get()) - .orElse(firstImport.getBegin().get()).line - 1; - int stop = importSectionNodes.get(importSectionNodes.size() - 1).getEnd().get().line; + int start = firstImport.getComment().map(c -> c.getBegin().orElseThrow()) + .orElse(firstImport.getBegin().orElseThrow()).line - 1; + int stop = importSectionNodes.get(importSectionNodes.size() - 1).getEnd().orElseThrow().line; // get the original import section lines from the file // include surrounding whitespace while (start > 0 && fileLines.get(start - 1).trim().isEmpty()) { @@ -207,8 +208,8 @@ private static Set convertImportSection(List importSectionNodes, S Optional impComment = impDecl.getComment(); if (impComment.isPresent()) { - Comment c = impComment.get(); - if (c.getBegin().get().isBefore(impDecl.getBegin().get())) { + Comment c = impComment.orElseThrow(); + if (c.getBegin().orElseThrow().isBefore(impDecl.getBegin().orElseThrow())) { thisImport.add(c); thisImport.add(impDecl); } else { @@ -278,13 +279,12 @@ private static void convertAndAddImport(LinkedHashSet allImports, List tokensInUse(CompilationUnit unit) { // Extract tokens from the java code: - Stream packageDecl = - unit.getPackageDeclaration().isPresent() - ? Stream.of(unit.getPackageDeclaration().get()).map(PackageDeclaration::getAnnotations) - .flatMap(NodeList::stream) - : Stream.empty(); + Stream packageDecl = unit.getPackageDeclaration().isPresent() + ? Stream.of(unit.getPackageDeclaration().orElseThrow()) + .map(PackageDeclaration::getAnnotations).flatMap(NodeList::stream) + : Stream.empty(); Stream typesInCode = Stream.concat(packageDecl, unit.getTypes().stream()) - .map(Node::getTokenRange).filter(Optional::isPresent).map(Optional::get) + .map(Node::getTokenRange).filter(Optional::isPresent).map(Optional::orElseThrow) .filter(r -> r != TokenRange.INVALID).flatMap(r -> { // get all JavaTokens as strings from each range return StreamSupport.stream(r.spliterator(), false); @@ -311,7 +311,7 @@ private static Stream parseJavadoc(Javadoc javadoc) { EnumSet blockTagTypesWithImportableNames = EnumSet.of(THROWS, EXCEPTION); Stream importableTagNames = blockTagTypesWithImportableNames.contains(tag.getType()) - ? Stream.of(tag.getName()).filter(Optional::isPresent).map(Optional::get) + ? Stream.of(tag.getName()).filter(Optional::isPresent).map(Optional::orElseThrow) : Stream.empty(); Stream tagDescriptions = Stream.of(tag.getContent()).flatMap(ImpSort::parseJavadocDescription);