Skip to content

Commit d7d3339

Browse files
committed
Use new Java features
1 parent 4f53a43 commit d7d3339

File tree

13 files changed

+33
-49
lines changed

13 files changed

+33
-49
lines changed

subprojects/downloader-jdk-http/src/main/java/org/spongepowered/gradle/vanilla/resolver/jdk11/ValidatingBodySubscriber.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ public void onSubscribe(final Flow.Subscription subscription) {
6060

6161
@Override
6262
public void onNext(final List<ByteBuffer> item) {
63-
for (int i = 0, size = item.size(); i < size; i++) {
64-
final ByteBuffer buf = item.get(i);
63+
for (final ByteBuffer buf : item) {
6564
final int pos = buf.position();
6665
this.md.update(buf);
6766
buf.position(pos);

subprojects/gradle-plugin/src/main/java/org/spongepowered/gradle/vanilla/internal/Constants.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@
3535
import java.nio.file.Paths;
3636
import java.time.Instant;
3737
import java.time.format.DateTimeFormatter;
38-
import java.util.Arrays;
3938
import java.util.Collections;
40-
import java.util.HashSet;
4139
import java.util.List;
4240
import java.util.Set;
4341
import java.util.stream.Collectors;
@@ -160,22 +158,22 @@ private Configurations() {
160158
/**
161159
* Group IDs of dependencies that should not be added to a server-only environment
162160
*/
163-
public static final Set<String> CLIENT_ONLY_DEPENDENCY_GROUPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
161+
public static final Set<String> CLIENT_ONLY_DEPENDENCY_GROUPS = Set.of(
164162
"oshi-project",
165163
"net.java.dev.jna",
166164
"com.ibm.icu",
167165
"net.java.jinput",
168166
"net.java.jutils",
169167
"org.lwjgl"
170-
)));
168+
);
171169

172170
/**
173171
* Extra dependencies that are injected into the project.
174172
*/
175-
public static final Set<GroupArtifactVersion> INJECTED_DEPENDENCIES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
173+
public static final Set<GroupArtifactVersion> INJECTED_DEPENDENCIES = Set.of(
176174
GroupArtifactVersion.of("com.google.code.findbugs", "jsr305", "3.0.2"),
177175
GroupArtifactVersion.of("org.jetbrains", "annotations", "23.0.0") // 1.18+ only technically
178-
)));
176+
);
179177

180178
private Constants() {
181179
}

subprojects/gradle-plugin/src/main/java/org/spongepowered/gradle/vanilla/internal/ProvideMinecraftPlugin.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ public void apply(final Project target) {
100100
.create(MinecraftExtension.class, "minecraft", MinecraftExtensionImpl.class, target, minecraftProvider);
101101

102102
final NamedDomainObjectProvider<Configuration> minecraftConfig = target.getConfigurations().register(Constants.Configurations.MINECRAFT, config -> {
103-
config.setVisible(false);
104103
config.setCanBeConsumed(false);
105104
config.setCanBeResolved(true);
106105

@@ -249,7 +248,6 @@ private TaskProvider<DecompileJarTask> createJarDecompile(
249248
private TaskProvider<DownloadAssetsTask> createAssetsDownload(final MinecraftExtensionImpl minecraft, final Provider<MinecraftProviderService> minecraftProvider, final TaskContainer tasks) {
250249

251250
final NamedDomainObjectProvider<Configuration> natives = this.project.getConfigurations().register(Constants.Configurations.MINECRAFT_NATIVES, config -> {
252-
config.setVisible(false);
253251
config.setCanBeResolved(true);
254252
config.setCanBeConsumed(false);
255253
config.setTransitive(false);

subprojects/gradle-plugin/src/main/java/org/spongepowered/gradle/vanilla/internal/model/rule/RuleDeclaration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public <T> Builder rule(final Rule<T> rule, final T value) {
100100
}
101101

102102
public Builder nextEntry() {
103-
this.entries.add(new Entry(this.action, Collections.unmodifiableMap(new HashMap<>(this.rules))));
103+
this.entries.add(new Entry(this.action, Map.copyOf(this.rules)));
104104
this.action = RuleAction.ALLOW;
105105
this.rules.clear();
106106
return this;

subprojects/gradle-plugin/src/main/java/org/spongepowered/gradle/vanilla/internal/repository/MinecraftRepositoryPlugin.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.gradle.api.Project;
3333
import org.gradle.api.ProjectEvaluationListener;
3434
import org.gradle.api.ProjectState;
35-
import org.gradle.api.Task;
3635
import org.gradle.api.artifacts.ModuleVersionSelector;
3736
import org.gradle.api.artifacts.ResolutionStrategy;
3837
import org.gradle.api.artifacts.ResolvableDependencies;
@@ -96,14 +95,13 @@ public MinecraftRepositoryPlugin(final BuildEventsListenerRegistry registry) {
9695

9796
@Override
9897
public void apply(final Object target) {
99-
if (target instanceof Project) {
100-
this.applyToProject((Project) target);
101-
} else if (target instanceof Settings) {
102-
this.applyToSettings((Settings) target);
103-
} else if (target instanceof Gradle) {
104-
// no-op marker left by our settings plugin
105-
} else {
106-
throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
98+
switch (target) {
99+
case Project project -> this.applyToProject(project);
100+
case Settings settings -> this.applyToSettings(settings);
101+
case Gradle _ -> {
102+
// no-op marker left by our settings plugin
103+
}
104+
default -> throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
107105
}
108106
}
109107

@@ -292,12 +290,9 @@ public void beforeEvaluate(final @NotNull Project project) {}
292290
public void afterEvaluate(final Project project, final ProjectState state) {
293291
if (state.getFailure() != null) return;
294292
project.getTasks().configureEach(task -> {
295-
task.doLast(new Action<Task>() {
296-
@Override
297-
public void execute(final Task task) {
298-
task.getLogger().info("Dropping VG resolver state on thread '{}' (task doLast action)", Thread.currentThread().getName());
299-
service.get().dropState();
300-
}
293+
task.doLast(t -> {
294+
t.getLogger().info("Dropping VG resolver state on thread '{}' (task doLast action)", Thread.currentThread().getName());
295+
service.get().dropState();
301296
});
302297
});
303298
}

subprojects/gradle-plugin/src/main/java/org/spongepowered/gradle/vanilla/internal/repository/rule/JoinedProvidesClientAndServerRule.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,10 @@ public static void configureResolution(final CapabilitiesResolution resolution)
7878

7979
private static void selectJoined(final CapabilityResolutionDetails details) {
8080
final List<ComponentVariantIdentifier> candidates = details.getCandidates();
81-
for (int i = 0; i < candidates.size(); i++) {
82-
final ComponentVariantIdentifier id = candidates.get(i);
81+
for (final ComponentVariantIdentifier id : candidates) {
8382
// TODO: is this the right logic if the joined artifact is at a lower version than the single-sided artifact?
84-
if (id.getId() instanceof ModuleComponentIdentifier
85-
&& ((ModuleComponentIdentifier) id.getId()).getModule().equals(MinecraftPlatform.JOINED.artifactId())) {
86-
details.select(id).because("Selecting joined artifact version "
87-
+ ((ModuleComponentIdentifier) id.getId()).getVersion() + " because it contains both client and server");
83+
if (id.getId() instanceof ModuleComponentIdentifier moduleId && moduleId.getModule().equals(MinecraftPlatform.JOINED.artifactId())) {
84+
details.select(id).because("Selecting joined artifact version " + moduleId.getVersion() + " because it contains both client and server");
8885
}
8986
}
9087
}

subprojects/gradle-plugin/src/main/java/org/spongepowered/gradle/vanilla/internal/util/FunctionalUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ private FunctionalUtils() {
3434

3535
public static <T> Supplier<T> memoizeSupplier(final Supplier<T> in) {
3636
Objects.requireNonNull(in, "in");
37-
return new Supplier<T>() {
37+
return new Supplier<>() {
3838
private volatile boolean initialized;
3939
private T value;
40+
4041
@Override
4142
public T get() {
4243
if (!this.initialized) {

subprojects/gradle-plugin/src/main/java/org/spongepowered/gradle/vanilla/internal/util/SelfPreferringClassLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected Class<?> loadClass(final String name, final boolean resolve) throws Cl
8282

8383
@Override
8484
public Enumeration<URL> getResources(final String name) throws IOException {
85-
return new Enumeration<URL>() {
85+
return new Enumeration<>() {
8686

8787
@Nullable Enumeration<URL> active = SelfPreferringClassLoader.this.findResources(name);
8888
@Nullable Enumeration<URL> staged = SelfPreferringClassLoader.this.parent == null

subprojects/gradle-plugin/src/main/java/org/spongepowered/gradle/vanilla/runs/ManifestDerivedArgumentProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ final class ManifestDerivedArgumentProvider implements CommandLineArgumentProvid
6060
@Override
6161
public Iterable<String> asArguments() {
6262
final List<String> outputArgs = new ArrayList<>();
63-
final StringBuffer builder = new StringBuffer();
63+
final StringBuilder builder = new StringBuilder();
6464
for (final Argument arg : this.arguments.get()) {
6565
if (arg.rules().test(this.rules)) {
6666
arg: for (final String argument : arg.value()) {
@@ -74,8 +74,8 @@ public Iterable<String> asArguments() {
7474
final String value = this.environmentTokens.get().get(matcher.group(1));
7575
if (value == null) {
7676
// If we are the value to a command line argument and we're not present, delete the previous argument.
77-
if (!outputArgs.isEmpty() && outputArgs.get(outputArgs.size() - 1).startsWith("-")) {
78-
outputArgs.remove(outputArgs.size() - 1);
77+
if (!outputArgs.isEmpty() && outputArgs.getLast().startsWith("-")) {
78+
outputArgs.removeLast();
7979
}
8080
// Either way, skip this whole argument
8181
continue arg;

subprojects/gradle-plugin/src/main/java/org/spongepowered/gradle/vanilla/task/DecompileJarTask.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,12 @@ public void execute() {
146146
flags,
147147
(env, output) -> {
148148
final long totalSystemMemoryBytes =
149-
((OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize() / (1024L * 1024L);
149+
((OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalMemorySize() / (1024L * 1024L);
150150
return CompletableFuture.runAsync(() -> {
151151
// Determine which parts of the configuration are MC, and which are its dependencies
152152
final Set<File> dependencies = new HashSet<>();
153153
for (final ResolvedArtifactResult artifact : this.getInputArtifacts().get()) {
154-
if (artifact.getId() instanceof ModuleComponentArtifactIdentifier) {
155-
final ModuleComponentArtifactIdentifier id = (ModuleComponentArtifactIdentifier) artifact.getId();
154+
if (artifact.getId() instanceof ModuleComponentArtifactIdentifier id) {
156155
if (id.getComponentIdentifier().getGroup().equals(MinecraftPlatform.GROUP)) {
157156
if (env.decoratedArtifactId().equals(id.getComponentIdentifier().getModule())) {
158157
continue;

0 commit comments

Comments
 (0)