Skip to content

Commit

Permalink
Bump versions, remove warnings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ctubbsii committed May 10, 2023
1 parent be632ae commit abfbd0d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 39 deletions.
39 changes: 17 additions & 22 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@
<maven.compiler.target>11</maven.compiler.target>
<!-- skip standard site deployment, because site is deployed using github plugin instead -->
<maven.site.deploy.skip>true</maven.site.deploy.skip>
<maven.tools-version>3.8.7</maven.tools-version>
<mavenPluginToolsVersion>3.7.1</mavenPluginToolsVersion>
<maven.tools-version>3.9.1</maven.tools-version>
<mavenPluginToolsVersion>3.8.2</mavenPluginToolsVersion>
<minimalJavaBuildVersion>11</minimalJavaBuildVersion>
<minimalMavenBuildVersion>3.5.0</minimalMavenBuildVersion>
<project.build.outputTimestamp>2022-11-23T16:28:41Z</project.build.outputTimestamp>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<projectInfoReportsVersion>3.4.2</projectInfoReportsVersion>
<projectInfoReportsVersion>3.4.3</projectInfoReportsVersion>
<sourceReleaseAssemblyDescriptor>source-release-tar</sourceReleaseAssemblyDescriptor>
<surefire.version>3.0.0-M5</surefire.version>
</properties>
Expand Down Expand Up @@ -128,17 +128,17 @@
<!-- Fluido is listed here for version update checking only -->
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>2.0.0-M2</version>
<version>2.0.0-M6</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.5.0</version>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.2</version>
<version>5.9.3</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down Expand Up @@ -183,12 +183,12 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.14.2</version>
<version>2.15.0</version>
</plugin>
<plugin>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-plugin</artifactId>
<version>2.5.0</version>
<version>2.6.0</version>
<configuration>
<javaVersion>${maven.compiler.target}</javaVersion>
</configuration>
Expand All @@ -201,7 +201,7 @@
<plugin>
<groupId>com.github.ekryd.sortpom</groupId>
<artifactId>sortpom-maven-plugin</artifactId>
<version>3.2.0</version>
<version>3.2.1</version>
<configuration>
<createBackupFile>false</createBackupFile>
<expandEmptyElements>false</expandEmptyElements>
Expand All @@ -216,9 +216,8 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.11.0</version>
<configuration>
<optimize>true</optimize>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<compilerArgs>
Expand All @@ -232,12 +231,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.1.0</version>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
<version>3.5.0</version>
<configuration>
<quiet>true</quiet>
<doclint>all,-missing</doclint>
Expand All @@ -246,7 +245,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M7</version>
<version>3.0.0</version>
<configuration>
<useReleaseProfile>false</useReleaseProfile>
<pushChanges>false</pushChanges>
Expand All @@ -256,13 +255,9 @@
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.21.0</version>
<version>2.22.0</version>
<configuration>
<compilerCompliance>${maven.compiler.source}</compilerCompliance>
<compilerSource>${maven.compiler.source}</compilerSource>
<compilerTargetPlatform>${maven.compiler.target}</compilerTargetPlatform>
<lineEnding>LF</lineEnding>
<overrideConfigCompilerVersion>true</overrideConfigCompilerVersion>
<skipJsFormatting>true</skipJsFormatting>
<skipHtmlFormatting>true</skipHtmlFormatting>
<skipXmlFormatting>true</skipXmlFormatting>
Expand All @@ -282,19 +277,19 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.2.1</version>
<version>3.2.2</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.6.0</version>
<version>10.10.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.7.3.0</version>
<version>4.7.3.4</version>
<configuration>
<xmlOutput>true</xmlOutput>
<effort>Max</effort>
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/net/revelc/code/impsort/ImpSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@

public class ImpSort {

private static final Comparator<Node> BY_POSITION = Comparator.comparing(a -> a.getBegin().get());
private static final Comparator<Node> BY_POSITION =
Comparator.comparing(a -> a.getBegin().orElseThrow());

private final Charset sourceEncoding;
private final Grouper grouper;
Expand Down Expand Up @@ -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<ImportDeclaration> importDeclarations = unit.getImports();
if (importDeclarations.isEmpty()) {
return new Result(path, sourceEncoding, fileLines, 0, fileLines.size(), "", "",
Expand All @@ -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<Comment> orphanedComments = unit.getOrphanComments().parallelStream().filter(c -> {
Position p = c.getBegin().get();
Position p = c.getBegin().orElseThrow();
return p.isAfter(packagePosition) && p.isBefore(lastImportPosition);
});

Expand All @@ -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()) {
Expand Down Expand Up @@ -207,8 +208,8 @@ private static Set<Import> convertImportSection(List<Node> importSectionNodes, S

Optional<Comment> 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 {
Expand Down Expand Up @@ -278,13 +279,12 @@ private static void convertAndAddImport(LinkedHashSet<Import> allImports, List<N
private static Set<String> tokensInUse(CompilationUnit unit) {

// Extract tokens from the java code:
Stream<Node> packageDecl =
unit.getPackageDeclaration().isPresent()
? Stream.of(unit.getPackageDeclaration().get()).map(PackageDeclaration::getAnnotations)
.flatMap(NodeList::stream)
: Stream.empty();
Stream<Node> packageDecl = unit.getPackageDeclaration().isPresent()
? Stream.of(unit.getPackageDeclaration().orElseThrow())
.map(PackageDeclaration::getAnnotations).flatMap(NodeList::stream)
: Stream.empty();
Stream<String> 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);
Expand All @@ -311,7 +311,7 @@ private static Stream<String> parseJavadoc(Javadoc javadoc) {
EnumSet<JavadocBlockTag.Type> blockTagTypesWithImportableNames =
EnumSet.of(THROWS, EXCEPTION);
Stream<String> 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<String> tagDescriptions =
Stream.of(tag.getContent()).flatMap(ImpSort::parseJavadocDescription);
Expand Down

0 comments on commit abfbd0d

Please sign in to comment.