Skip to content

Commit

Permalink
Use Java 11 language features where possible (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Nov 30, 2022
1 parent 47d8584 commit 2695cfb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/jenkinsci/maven/plugins/hpi/RunMojo.java
Expand Up @@ -62,11 +62,11 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -457,7 +457,7 @@ private void copyPlugin(File src, File pluginsDir, String shortName) throws IOEx
// TODO skip .pinned file creation if Jenkins version is >= 2.0
// pin the dependency plugin, so that even if a different version of the same plugin is bundled to Jenkins,
// we still use the plugin as specified by the POM of the plugin.
FileUtils.writeStringToFile(new File(dst + ".pinned"), "pinned");
Files.writeString(pluginsDir.toPath().resolve(shortName + ".jpi.pinned"), "pinned", StandardCharsets.US_ASCII);
Files.deleteIfExists(new File(pluginsDir, shortName + ".jpl").toPath()); // in case we used to have a snapshot dependency
}
private VersionNumber versionOfPlugin(File p) throws IOException {
Expand Down Expand Up @@ -489,7 +489,7 @@ private void copyHpl(File src, File pluginsDir, String shortName) throws IOExcep
File dst = new File(pluginsDir, shortName + ".jpl");
getLog().info("Copying snapshot dependency Jenkins plugin " + src);
FileUtils.copyFile(src, dst);
FileUtils.writeStringToFile(new File(pluginsDir, shortName + ".jpi.pinned"), "pinned");
Files.writeString(pluginsDir.toPath().resolve(shortName + ".jpi.pinned"), "pinned", StandardCharsets.US_ASCII);
}

/**
Expand Down Expand Up @@ -788,7 +788,7 @@ protected Set<Artifact> resolveDependencies(String scope) throws MojoExecutionEx
RepositoryUtils.toArtifacts(
artifacts,
result.getDependencyGraph().getChildren(),
Collections.singletonList(getProject().getArtifact().getId()),
List.of(getProject().getArtifact().getId()),
request.getResolutionFilter());
}
return artifacts;
Expand Down
Expand Up @@ -132,15 +132,15 @@ public class TestDependencyMojo extends AbstractHpiMojo {

@Override
public void execute() throws MojoExecutionException {
Map<String, String> overrides = overrideVersions != null ? parseOverrides(overrideVersions) : Collections.emptyMap();
Map<String, String> overrides = overrideVersions != null ? parseOverrides(overrideVersions) : Map.of();
if (!overrides.isEmpty()) {
getLog().info(String.format("Applying %d overrides.", overrides.size()));
}
if (overrides.containsKey(String.format("%s:%s", project.getGroupId(), project.getArtifactId()))) {
throw new MojoExecutionException("Cannot override self");
}

Map<String, String> bundledPlugins = overrideWar != null ? scanWar(overrideWar, session, project) : Collections.emptyMap();
Map<String, String> bundledPlugins = overrideWar != null ? scanWar(overrideWar, session, project) : Map.of();
if (!bundledPlugins.isEmpty()) {
getLog().info(String.format("Scanned contents of %s with %d bundled plugins", overrideWar, bundledPlugins.size()));
}
Expand Down Expand Up @@ -235,7 +235,7 @@ public void execute() throws MojoExecutionException {
Set<Artifact> resolved = resolveDependencies(shadow);
shadow.setArtifacts(resolved);

applyOverrides(upperBounds, Collections.emptyMap(), true, overrideWarAdditions, shadow, getLog());
applyOverrides(upperBounds, Map.of(), true, overrideWarAdditions, shadow, getLog());
}
}
} else if (!upperBoundsExcludes.isEmpty()) {
Expand Down Expand Up @@ -661,7 +661,7 @@ private Set<Artifact> resolveDependencies(MavenProject project) throws MojoExecu
RepositoryUtils.toArtifacts(
artifacts,
result.getDependencyGraph().getChildren(),
Collections.singletonList(project.getArtifact().getId()),
List.of(project.getArtifact().getId()),
request.getResolutionFilter());
}
return artifacts;
Expand All @@ -678,11 +678,7 @@ private class RequireUpperBoundDepsVisitor implements DependencyNodeVisitor {
public boolean visit(DependencyNode node) {
DependencyNodeHopCountPair pair = new DependencyNodeHopCountPair(node);
String key = pair.constructKey();
List<DependencyNodeHopCountPair> pairs = keyToPairsMap.get(key);
if (pairs == null) {
pairs = new ArrayList<>();
keyToPairsMap.put(key, pairs);
}
List<DependencyNodeHopCountPair> pairs = keyToPairsMap.computeIfAbsent(key, unused -> new ArrayList<>());
pairs.add(pair);
Collections.sort(pairs);
return true;
Expand Down Expand Up @@ -820,9 +816,7 @@ private static StringBuilder buildTreeString(DependencyNode node) {
Collections.reverse(loc);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < loc.size(); i++) {
for (int j = 0; j < i; j++) {
builder.append(" ");
}
builder.append(" ".repeat(i));
builder.append("+-").append(loc.get(i));
builder.append(System.lineSeparator());
}
Expand Down

0 comments on commit 2695cfb

Please sign in to comment.