Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Objects;
import java.util.Properties;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -127,7 +127,7 @@ public FormatterStep build() {
var roundtrippableState = new EquoStep(formatterVersion, settingProperties, settingXml, FileSignature.promise(settingsFiles), JarState.promise(() -> {
P2QueryResult query;
try {
if (null != cacheDirectory) {
if (cacheDirectory != null) {
CacheLocations.override_p2data = cacheDirectory.toPath().resolve("dev/equo/p2-data").toFile();
}
query = createModelWithMirrors().query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW);
Expand Down Expand Up @@ -190,8 +190,8 @@ static class EquoStep implements Serializable {
ImmutableMap<String, String> stepProperties) {

this.semanticVersion = semanticVersion;
this.settingProperties = Optional.ofNullable(settingProperties).orElse(new ArrayList<>());
this.settingXml = Optional.ofNullable(settingXml).orElse(new ArrayList<>());
this.settingProperties = Objects.requireNonNullElse(settingProperties, new ArrayList<>());
this.settingXml = Objects.requireNonNullElse(settingXml, new ArrayList<>());
this.settingsPromise = settingsPromise;
this.jarPromise = jarPromise;
this.stepProperties = stepProperties;
Expand All @@ -218,8 +218,8 @@ public static class State implements Serializable {
public State(String semanticVersion, JarState jarState, List<String> settingProperties, List<String> settingXml, FileSignature settingsFiles, ImmutableMap<String, String> stepProperties) {
this.semanticVersion = semanticVersion;
this.jarState = jarState;
this.settingProperties = Optional.ofNullable(settingProperties).orElse(new ArrayList<>());
this.settingXml = Optional.ofNullable(settingXml).orElse(new ArrayList<>());
this.settingProperties = Objects.requireNonNullElse(settingProperties, new ArrayList<>());
this.settingXml = Objects.requireNonNullElse(settingXml, new ArrayList<>());
this.settingsFiles = settingsFiles;
this.stepProperties = stepProperties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static FormatterFunc apply(EquoBasedStepBuilder.State state) throws Exce
} catch (InvocationTargetException exceptionWrapper) {
Throwable throwable = exceptionWrapper.getTargetException();
Exception exception = throwable instanceof Exception e ? e : null;
throw null == exception ? exceptionWrapper : exception;
throw exception == null ? exceptionWrapper : exception;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static FormatterFunc apply(EquoBasedStepBuilder.State state) throws Exce
} catch (InvocationTargetException exceptionWrapper) {
Throwable throwable = exceptionWrapper.getTargetException();
Exception exception = throwable instanceof Exception e ? e : null;
throw null == exception ? exceptionWrapper : exception;
throw exception == null ? exceptionWrapper : exception;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static FormatterFunc applyWithoutFile(String className, EclipseBasedStep
} catch (InvocationTargetException exceptionWrapper) {
Throwable throwable = exceptionWrapper.getTargetException();
Exception exception = throwable instanceof Exception e ? e : null;
throw null == exception ? exceptionWrapper : exception;
throw exception == null ? exceptionWrapper : exception;
}
};
}
Expand All @@ -86,7 +86,7 @@ public String applyWithFile(String unix, File file) throws Exception {
} catch (InvocationTargetException exceptionWrapper) {
Throwable throwable = exceptionWrapper.getTargetException();
Exception exception = throwable instanceof Exception e ? e : null;
throw null == exception ? exceptionWrapper : exception;
throw exception == null ? exceptionWrapper : exception;
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public boolean equals(Object o) {
}
FilterByContentPatternFormatterStep that = (FilterByContentPatternFormatterStep) o;
return Objects.equals(delegateStep, that.delegateStep)
&& Objects.equals(onMatch, that.onMatch)
&& onMatch == that.onMatch
&& Objects.equals(contentPattern.pattern(), that.contentPattern.pattern());
}

Expand Down
3 changes: 1 addition & 2 deletions lib/src/main/java/com/diffplug/spotless/JarState.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -132,7 +131,7 @@ private static JarState provisionWithTransitives(boolean withTransitives, Collec
Objects.requireNonNull(provisioner, "provisioner");
Set<File> jars = provisioner.provisionWithTransitives(withTransitives, mavenCoordinates);
if (jars.isEmpty()) {
throw new NoSuchElementException("Resolved to an empty result: " + mavenCoordinates.stream().collect(Collectors.joining(", ")));
throw new NoSuchElementException("Resolved to an empty result: " + String.join(", ", mavenCoordinates));
}
FileSignature fileSignature = FileSignature.signAsSet(jars);
return new JarState(fileSignature);
Expand Down
32 changes: 16 additions & 16 deletions lib/src/main/java/com/diffplug/spotless/Jvm.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ private Support(String formatterName, Comparator<? super V> formatterVersionComp
*/
public Support<V> add(int minimumJvmVersion, V maxFormatterVersion) {
Objects.requireNonNull(maxFormatterVersion);
if (null != jvm2fmtMaxVersion.put(minimumJvmVersion, maxFormatterVersion)) {
if (jvm2fmtMaxVersion.put(minimumJvmVersion, maxFormatterVersion) != null) {
throw new IllegalArgumentException("Added duplicate entry for JVM %d+.".formatted(minimumJvmVersion));
}
if (null != fmtMaxVersion2jvmVersion.put(maxFormatterVersion, minimumJvmVersion)) {
if (fmtMaxVersion2jvmVersion.put(maxFormatterVersion, minimumJvmVersion) != null) {
throw new IllegalArgumentException("Added duplicate entry for formatter version %s.".formatted(maxFormatterVersion));
}
verifyVersionRangesDoNotIntersect(jvm2fmtMaxVersion, minimumJvmVersion, maxFormatterVersion);
Expand All @@ -101,7 +101,7 @@ public Support<V> add(int minimumJvmVersion, V maxFormatterVersion) {

public Support<V> addMin(int minimumJvmVersion, V minFormatterVersion) {
Objects.requireNonNull(minFormatterVersion);
if (null != jvm2fmtMinVersion.put(minimumJvmVersion, minFormatterVersion)) {
if (jvm2fmtMinVersion.put(minimumJvmVersion, minFormatterVersion) != null) {
throw new IllegalArgumentException("Added duplicate entry for JVM %d+.".formatted(minimumJvmVersion));
}
verifyVersionRangesDoNotIntersect(jvm2fmtMinVersion, minimumJvmVersion, minFormatterVersion);
Expand All @@ -110,24 +110,24 @@ public Support<V> addMin(int minimumJvmVersion, V minFormatterVersion) {

private void verifyVersionRangesDoNotIntersect(NavigableMap<Integer, V> jvm2fmtVersion, int minimumJvmVersion, V formatterVersion) {
Map.Entry<Integer, V> lower = jvm2fmtVersion.lowerEntry(minimumJvmVersion);
if ((null != lower) && (fmtVersionComparator.compare(formatterVersion, lower.getValue()) <= 0)) {
if ((lower != null) && (fmtVersionComparator.compare(formatterVersion, lower.getValue()) <= 0)) {
throw new IllegalArgumentException("%d/%s should be lower than %d/%s".formatted(minimumJvmVersion, formatterVersion, lower.getKey(), lower.getValue()));
}
Map.Entry<Integer, V> higher = jvm2fmtVersion.higherEntry(minimumJvmVersion);
if ((null != higher) && (fmtVersionComparator.compare(formatterVersion, higher.getValue()) >= 0)) {
if ((higher != null) && (fmtVersionComparator.compare(formatterVersion, higher.getValue()) >= 0)) {
throw new IllegalArgumentException("%d/%s should be higher than %d/%s".formatted(minimumJvmVersion, formatterVersion, higher.getKey(), higher.getValue()));
}
}

/** @return Highest formatter version recommended for this JVM (null, if JVM not supported) */
@Nullable public V getRecommendedFormatterVersion() {
Integer configuredJvmVersionOrNull = jvm2fmtMaxVersion.floorKey(Jvm.version());
return null == configuredJvmVersionOrNull ? null : jvm2fmtMaxVersion.get(configuredJvmVersionOrNull);
return configuredJvmVersionOrNull == null ? null : jvm2fmtMaxVersion.get(configuredJvmVersionOrNull);
}

@Nullable public V getMinimumRequiredFormatterVersion() {
Integer configuredJvmVersionOrNull = jvm2fmtMinVersion.floorKey(Jvm.version());
return null == configuredJvmVersionOrNull ? null : jvm2fmtMinVersion.get(configuredJvmVersionOrNull);
return configuredJvmVersionOrNull == null ? null : jvm2fmtMinVersion.get(configuredJvmVersionOrNull);
}

/**
Expand All @@ -151,7 +151,7 @@ private String buildUnsupportedFormatterMessage(V fmtVersion) {
}
// check if the formatter version is too low for the jvm version
V minimumFormatterVersion = getMinimumRequiredFormatterVersion();
if ((null != minimumFormatterVersion) && (fmtVersionComparator.compare(fmtVersion, minimumFormatterVersion) < 0)) {
if ((minimumFormatterVersion != null) && (fmtVersionComparator.compare(fmtVersion, minimumFormatterVersion) < 0)) {
return "You are running Spotless on JVM %d. This requires %s of at least %s (you are using %s).%n".formatted(Jvm.version(), fmtName, minimumFormatterVersion, fmtVersion);
}
// otherwise all is well
Expand All @@ -162,11 +162,11 @@ private String buildUpgradeJvmMessage(V fmtVersion) {
StringBuilder builder = new StringBuilder();
builder.append("You are running Spotless on JVM %d".formatted(Jvm.version()));
V recommendedFmtVersionOrNull = getRecommendedFormatterVersion();
if (null != recommendedFmtVersionOrNull) {
if (recommendedFmtVersionOrNull != null) {
builder.append(", which limits you to %s %s.%n".formatted(fmtName, recommendedFmtVersionOrNull));
} else {
Entry<V, Integer> nextFmtVersionOrNull = fmtMaxVersion2jvmVersion.ceilingEntry(fmtVersion);
if (null != nextFmtVersionOrNull) {
if (nextFmtVersionOrNull != null) {
builder.append(". %s %s requires JVM %d+".formatted(fmtName, fmtVersion, nextFmtVersionOrNull.getValue()));
}
builder.append(".%n".formatted());
Expand All @@ -176,10 +176,10 @@ private String buildUpgradeJvmMessage(V fmtVersion) {

private int getRequiredJvmVersion(V fmtVersion) {
Entry<V, Integer> entry = fmtMaxVersion2jvmVersion.ceilingEntry(fmtVersion);
if (null == entry) {
if (entry == null) {
entry = fmtMaxVersion2jvmVersion.lastEntry();
}
if (null != entry) {
if (entry != null) {
V maxKnownFmtVersion = jvm2fmtMaxVersion.get(entry.getValue());
if (fmtVersionComparator.compare(fmtVersion, maxKnownFmtVersion) <= 0) {
return entry.getValue();
Expand Down Expand Up @@ -227,20 +227,20 @@ private String buildUpgradeFormatterMessage(V fmtVersion) {
// check if the formatter is not supported on this jvm
V minimumFormatterVersion = getMinimumRequiredFormatterVersion();
V recommendedFmtVersionOrNull = getRecommendedFormatterVersion();
if ((null != minimumFormatterVersion) && (fmtVersionComparator.compare(fmtVersion, minimumFormatterVersion) < 0)) {
if ((minimumFormatterVersion != null) && (fmtVersionComparator.compare(fmtVersion, minimumFormatterVersion) < 0)) {
builder.append("You are running Spotless on JVM %d. This requires %s of at least %s.%n".formatted(Jvm.version(), fmtName, minimumFormatterVersion));
builder.append("You are using %s %s.%n".formatted(fmtName, fmtVersion));
if (null != recommendedFmtVersionOrNull) {
if (recommendedFmtVersionOrNull != null) {
builder.append("%s %s is the recommended version, which may have fixed this problem.%n".formatted(fmtName, recommendedFmtVersionOrNull));
}
// check if the formatter is outdated on this jvm
} else if (null != recommendedFmtVersionOrNull && (fmtVersionComparator.compare(fmtVersion, recommendedFmtVersionOrNull) < 0)) {
} else if (recommendedFmtVersionOrNull != null && (fmtVersionComparator.compare(fmtVersion, recommendedFmtVersionOrNull) < 0)) {
builder.append("%s %s is currently being used, but outdated.%n".formatted(fmtName, fmtVersion));
builder.append("%s %s is the recommended version, which may have fixed this problem.%n".formatted(fmtName, recommendedFmtVersionOrNull));
builder.append("%s %s requires JVM %d+.".formatted(fmtName, recommendedFmtVersionOrNull, getRequiredJvmVersion(recommendedFmtVersionOrNull)));
} else {
V higherFormatterVersionOrNull = fmtMaxVersion2jvmVersion.higherKey(fmtVersion);
if (null != higherFormatterVersionOrNull) {
if (higherFormatterVersionOrNull != null) {
builder.append(buildUpgradeJvmMessage(fmtVersion));
Integer higherJvmVersion = fmtMaxVersion2jvmVersion.get(higherFormatterVersionOrNull);
builder.append("If you upgrade your JVM to %d+, then you can use %s %s, which may have fixed this problem.".formatted(higherJvmVersion, fmtName, higherFormatterVersionOrNull));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ public Path ensureDownloaded(String version) throws IOException, InterruptedExce
logger.debug("Ensuring that Biome for platform '{}' is downloaded", platform);
var existing = findDownloaded(version);
if (existing.isPresent()) {
logger.debug("Biome was already downloaded, using executable at '{}'", existing.get());
return existing.get();
logger.debug("Biome was already downloaded, using executable at '{}'", existing.orElseThrow());
return existing.orElseThrow();
} else {
logger.debug("Biome was not yet downloaded, attempting to download executable");
return download(version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ private Runtime(String licenseHeader, String delimiter, String yearSeparator, bo
Optional<String> yearToken = getYearToken(licenseHeader);
if (yearToken.isPresent()) {
this.yearToday = String.valueOf(YearMonth.now().getYear());
int yearTokenIndex = licenseHeader.indexOf(yearToken.get());
int yearTokenIndex = licenseHeader.indexOf(yearToken.orElseThrow());
this.beforeYear = licenseHeader.substring(0, yearTokenIndex);
this.afterYear = licenseHeader.substring(yearTokenIndex + yearToken.get().length());
this.afterYear = licenseHeader.substring(yearTokenIndex + yearToken.orElseThrow().length());
this.yearSepOrFull = yearSeparator;
this.updateYearWithLatest = updateYearWithLatest;

Expand Down
Loading
Loading