Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Java 11 language features where possible #402

Merged
merged 2 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/org/jenkinsci/maven/plugins/hpi/RunMojo.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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