Skip to content

Commit 7d0a5bc

Browse files
jen20normen662
authored andcommitted
Fix deprecated Gradle syntax and configuration features (FoundationDB#3358)
When running `./gradlew shadowJar compileTestJava --warning-mode=all` on the current HEAD of `main` (68f805a), a number of warnings are produced for deprecated usages of Gradle configuration features. Upon fixing the trivial deprecations produced in the first pass, a second round of issues is also produced. This pull request fixes all of those, such that the command executes cleanly, without generating a Gradle problem report. Each class of issue is addressed in a separate commit (which contains links to the Gradle documentation showing the fix mechanism to be the recommended approach), but broadly speaking there are five categories: 1. Use of `destination` instead of `outputLocation` when configuring JUnit report output location ([docs](https://docs.gradle.org/8.13/dsl/org.gradle.api.reporting.Report.html#org.gradle.api.reporting.Report:destination)) 2. Consistent use of `key = value` assignment rather than "space assignment" or `propertyName(value)` assignment ([docs](https://docs.gradle.org/8.13/userguide/upgrading_version_8.html#groovy_space_assignment_syntax)) 3. Use of plugin blocks instead of conventions for the `Java` plugin ([docs](https://docs.gradle.org/8.13/userguide/upgrading_version_8.html#java_convention_deprecation)) 4. Use of plugin blocks instead of conventions for the `Application` plugin ([docs](https://docs.gradle.org/8.13/userguide/upgrading_version_8.html#application_convention_deprecation)) and applying the ensuing required cleanup from the Gradle 7 migration ([docs](https://docs.gradle.org/current/userguide/upgrading_version_7.html#javaapplication_api_cleanup)) 5. Stopping the use of `Task.project` in Task actions ([docs](https://docs.gradle.org/8.13/userguide/upgrading_version_7.html#task_project)). Other tasks which are not dependents of `shadowJar` or `compileTestJava` likely still use deprecated syntax or conventions - I will follow up with a second pull request to address those in future.
1 parent 6b181b8 commit 7d0a5bc

File tree

9 files changed

+283
-16
lines changed

9 files changed

+283
-16
lines changed

build.gradle

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,22 @@ allprojects {
100100

101101
// Configure JUnit tests
102102
tasks.withType(Test) {
103-
reports.junitXml.destination = project.file("${->project.buildDir}/test-results")
103+
reports.junitXml.outputLocation = project.file("${->project.buildDir}/test-results")
104104
}
105105

106+
def projectName = it.name
107+
def projectVersion = it.version
108+
106109
// Configure JAR generation
107110
tasks.jar.configure {
108111
description = "Produces a Jar with the main classes in .out/."
109112
manifest {
110113
attributes "Built-JDK": System.getProperty("java.version"),
111-
"Specification-Title": project.name,
112-
"Specification-Version": "${-> project.version}",
114+
"Specification-Title": projectName,
115+
"Specification-Version": "${-> projectVersion}",
113116
"Specification-Vendor": "Apple Inc.",
114-
"Implementation-Title": project.name,
115-
"Implementation-Version": "${-> project.version}",
117+
"Implementation-Title": projectName,
118+
"Implementation-Version": "${-> projectVersion}",
116119
"Implementation-Vendor": "Apple Inc."
117120
}
118121
doFirst {
@@ -182,8 +185,10 @@ allprojects {
182185
subprojects {
183186
apply from: rootProject.file('gradle/testing.gradle')
184187

185-
sourceCompatibility = JavaVersion.VERSION_11
186-
targetCompatibility = JavaVersion.VERSION_11
188+
java {
189+
sourceCompatibility = JavaVersion.VERSION_11
190+
targetCompatibility = JavaVersion.VERSION_11
191+
}
187192

188193
def publishBuild = Boolean.parseBoolean(findProperty('publishBuild') ?: 'false')
189194
def autoServiceVersion = publishBuild ? libs.versions.autoService.asProvider().get() : libs.versions.autoService.development.get()

examples/examples.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ dependencies {
3030
runtimeOnly(libs.log4j.core) // library
3131
}
3232

33-
mainClassName = 'com.apple.foundationdb.record.sample.Main'
34-
applicationDefaultJvmArgs = ["-Dlog4j.configurationFile=${projectDir}/src/main/resources/log4j2.properties"]
33+
application {
34+
mainClass = 'com.apple.foundationdb.record.sample.Main'
35+
applicationDefaultJvmArgs = ["-Dlog4j.configurationFile=${projectDir}/src/main/resources/log4j2.properties"]
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
/*
2+
* TranslationMap.java
3+
*
4+
* This source file is part of the FoundationDB open source project
5+
*
6+
* Copyright 2015-2024 Apple Inc. and the FoundationDB project authors
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
package com.apple.foundationdb.record.query.plan.cascades.values.translation;
22+
23+
import com.apple.foundationdb.record.query.plan.cascades.AliasMap;
24+
import com.apple.foundationdb.record.query.plan.cascades.CorrelationIdentifier;
25+
import com.apple.foundationdb.record.query.plan.cascades.typing.Type;
26+
import com.apple.foundationdb.record.query.plan.cascades.values.LeafValue;
27+
import com.apple.foundationdb.record.query.plan.cascades.values.QuantifiedObjectValue;
28+
import com.apple.foundationdb.record.query.plan.cascades.values.QuantifiedValue;
29+
import com.apple.foundationdb.record.query.plan.cascades.values.Value;
30+
import com.google.common.base.Preconditions;
31+
import com.google.common.base.Verify;
32+
import com.google.common.collect.ImmutableMap;
33+
import com.google.common.collect.ImmutableSet;
34+
import com.google.common.collect.Maps;
35+
36+
import javax.annotation.Nonnull;
37+
import javax.annotation.Nullable;
38+
import java.util.Map;
39+
import java.util.Optional;
40+
import java.util.Set;
41+
42+
/**
43+
* Map used to specify translations.
44+
*/
45+
public class TranslationMap {
46+
@Nonnull
47+
private static final TranslationMap EMPTY = new TranslationMap(ImmutableMap.of());
48+
49+
@Nonnull
50+
private final Map<CorrelationIdentifier, TranslationTarget> aliasToTargetMap;
51+
52+
private TranslationMap(@Nonnull final Map<CorrelationIdentifier, TranslationTarget> aliasToTargetMap) {
53+
this.aliasToTargetMap = ImmutableMap.copyOf(aliasToTargetMap);
54+
}
55+
56+
@Nonnull
57+
public Optional<AliasMap> getAliasMapMaybe() {
58+
return Optional.empty();
59+
}
60+
61+
public boolean definesOnlyIdentities() {
62+
return getAliasMapMaybe().map(AliasMap::definesOnlyIdentities)
63+
.orElseGet(aliasToTargetMap::isEmpty);
64+
}
65+
66+
public boolean containsSourceAlias(@Nullable CorrelationIdentifier sourceAlias) {
67+
return aliasToTargetMap.containsKey(sourceAlias);
68+
}
69+
70+
@Nonnull
71+
public Value applyTranslationFunction(@Nonnull final CorrelationIdentifier sourceAlias,
72+
@Nonnull final LeafValue leafValue) {
73+
final var translationTarget = Preconditions.checkNotNull(aliasToTargetMap.get(sourceAlias));
74+
return translationTarget.translate(sourceAlias, leafValue);
75+
}
76+
77+
@Nonnull
78+
public Builder toBuilder() {
79+
return new Builder(aliasToTargetMap);
80+
}
81+
82+
@Nonnull
83+
public static Builder builder() {
84+
return new Builder();
85+
}
86+
87+
@Nonnull
88+
public static TranslationMap empty() {
89+
return EMPTY;
90+
}
91+
92+
@Nonnull
93+
public static TranslationMap rebaseWithAliasMap(@Nonnull final AliasMap aliasMap) {
94+
final var translationMapBuilder = ImmutableMap.<CorrelationIdentifier, TranslationTarget>builder();
95+
for (final var entry : aliasMap.entrySet()) {
96+
translationMapBuilder.put(entry.getKey(),
97+
new TranslationTarget(((sourceAlias, leafValue) -> leafValue.rebaseLeaf(entry.getValue()))));
98+
}
99+
return new AliasMapBasedTranslationMap(translationMapBuilder.build(), aliasMap);
100+
}
101+
102+
@Nonnull
103+
public static TranslationMap ofAliases(@Nonnull final CorrelationIdentifier source,
104+
@Nonnull final CorrelationIdentifier target) {
105+
return rebaseWithAliasMap(AliasMap.ofAliases(source, target));
106+
}
107+
108+
@Nonnull
109+
public static TranslationMap compose(@Nonnull final Iterable<TranslationMap> translationMaps) {
110+
final var builder = TranslationMap.builder();
111+
for (final var translationMap : translationMaps) {
112+
builder.compose(translationMap);
113+
}
114+
return builder.build();
115+
}
116+
117+
private static class AliasMapBasedTranslationMap extends TranslationMap {
118+
@Nonnull
119+
private final AliasMap aliasMap;
120+
121+
public AliasMapBasedTranslationMap(@Nonnull final Map<CorrelationIdentifier, TranslationTarget> aliasToTargetMap,
122+
@Nonnull final AliasMap aliasMap) {
123+
super(aliasToTargetMap);
124+
this.aliasMap = aliasMap;
125+
}
126+
127+
@Nonnull
128+
@Override
129+
public Optional<AliasMap> getAliasMapMaybe() {
130+
return Optional.of(aliasMap);
131+
}
132+
}
133+
134+
private static class TranslationTarget {
135+
@Nonnull
136+
private final TranslationFunction translationFunction;
137+
138+
public TranslationTarget(@Nonnull final TranslationFunction translationFunction) {
139+
this.translationFunction = translationFunction;
140+
}
141+
142+
@Nonnull
143+
public Value translate(@Nonnull final CorrelationIdentifier sourceAlias,
144+
@Nonnull final LeafValue leafValue) {
145+
return translationFunction.apply(sourceAlias, leafValue);
146+
}
147+
}
148+
149+
/**
150+
* Functional interface to specify the translation to take place when a {@link QuantifiedValue} is encountered.
151+
*/
152+
@FunctionalInterface
153+
public interface TranslationFunction {
154+
@Nonnull
155+
Value apply(@Nonnull CorrelationIdentifier sourceAlias,
156+
@Nonnull LeafValue leafValue);
157+
158+
@Nonnull
159+
static TranslationFunction adjustValueType(@Nonnull final Value translationTargetValue) {
160+
final var translationTargetType = translationTargetValue.getResultType();
161+
if (translationTargetValue instanceof QuantifiedObjectValue) {
162+
if (translationTargetType instanceof Type.Erasable &&
163+
((Type.Erasable)translationTargetType).isErased()) {
164+
return (source, quantifiedValue) -> QuantifiedObjectValue.of(((QuantifiedObjectValue)translationTargetValue).getAlias(),
165+
quantifiedValue.getResultType());
166+
}
167+
}
168+
Verify.verify(!(translationTargetType instanceof Type.Erasable) ||
169+
!((Type.Erasable)translationTargetType).isErased());
170+
return (ignored, ignored2) -> translationTargetValue;
171+
}
172+
}
173+
174+
/**
175+
* Builder class for a translation map.
176+
*/
177+
public static class Builder {
178+
@Nonnull
179+
private final Map<CorrelationIdentifier, TranslationTarget> aliasToTargetMap;
180+
181+
public Builder() {
182+
this.aliasToTargetMap = Maps.newLinkedHashMap();
183+
}
184+
185+
private Builder(@Nonnull final Map<CorrelationIdentifier, TranslationTarget> aliasToTargetMap) {
186+
this.aliasToTargetMap = Maps.newLinkedHashMap(aliasToTargetMap);
187+
}
188+
189+
@Nonnull
190+
public TranslationMap build() {
191+
if (aliasToTargetMap.isEmpty()) {
192+
return TranslationMap.empty();
193+
}
194+
return new TranslationMap(aliasToTargetMap);
195+
}
196+
197+
@Nonnull
198+
public Builder.When when(@Nonnull final CorrelationIdentifier sourceAlias) {
199+
return new When(sourceAlias);
200+
}
201+
202+
@Nonnull
203+
public Builder.WhenAny whenAny(@Nonnull final Iterable<CorrelationIdentifier> sourceAliases) {
204+
return new WhenAny(sourceAliases);
205+
}
206+
207+
@Nonnull
208+
public Builder compose(@Nonnull final TranslationMap other) {
209+
other.aliasToTargetMap
210+
.forEach((key, value) -> {
211+
Verify.verify(!aliasToTargetMap.containsKey(key));
212+
aliasToTargetMap.put(key, value);
213+
});
214+
return this;
215+
}
216+
217+
/**
218+
* Class to provide fluent API, e.g. {@code .when(...).then(...)}
219+
*/
220+
public class When {
221+
@Nonnull
222+
private final CorrelationIdentifier sourceAlias;
223+
224+
public When(@Nonnull final CorrelationIdentifier sourceAlias) {
225+
this.sourceAlias = sourceAlias;
226+
}
227+
228+
@Nonnull
229+
public Builder then(@Nonnull final TranslationFunction translationFunction) {
230+
aliasToTargetMap.put(sourceAlias, new TranslationTarget(translationFunction));
231+
return Builder.this;
232+
}
233+
}
234+
235+
/**
236+
* Class to provide fluent API, e.g. {@code .when(...).then(...)}
237+
*/
238+
public class WhenAny {
239+
@Nonnull
240+
private final Set<CorrelationIdentifier> sourceAliases;
241+
242+
public WhenAny(@Nonnull final Iterable<CorrelationIdentifier> sourceAliases) {
243+
this.sourceAliases = ImmutableSet.copyOf(sourceAliases);
244+
}
245+
246+
@Nonnull
247+
public Builder then(@Nonnull TranslationFunction translationFunction) {
248+
for (final CorrelationIdentifier sourceAlias : sourceAliases) {
249+
aliasToTargetMap.put(sourceAlias, new TranslationTarget(translationFunction));
250+
}
251+
return Builder.this;
252+
}
253+
}
254+
}
255+
}

fdb-relational-api/fdb-relational-api.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ task createVersionPropertiesFile() {
3030
// Write a file of version and build info for the java processes to read
3131
// from their classpaths.
3232
def versionsFile = new File(projectDir, "src/gen/main/resources/version.properties")
33+
def projectVersion = project.version
34+
def rootProjectName = rootProject.name
3335
def gitDetails = versionDetails()
36+
3437
outputs.file versionsFile
3538
doLast {
3639
println "Writing ${versionsFile}"
3740
versionsFile.text = """# Generated by fdb-relational-api build.
3841
# Returned by RelationalDatabaseMetaData#getDatabaseProductName()
39-
name=${rootProject.name}
42+
name=${rootProjectName}
4043
# Returned by RelationalDatabaseMetaData#getDatabaseProductVersion()
4144
# and by RelationalDatabaseMetaData#getDriverVersion()
42-
version=${project.version}
45+
version=${projectVersion}
4346
gitHash=${gitDetails.gitHashFull}
4447
branch=${gitDetails.branchName}
4548
# Returned as RelationalDatabaseMetaData#getUrl()

fdb-relational-cli/fdb-relational-cli.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ dependencies {
7474
}
7575

7676
jar {
77-
duplicatesStrategy "exclude"
77+
duplicatesStrategy = "exclude"
7878
manifest {
7979
attributes(
8080
'Main-Class': 'com.apple.foundationdb.relational.cli.sqlline.RelationalSQLLine',

fdb-relational-jdbc/fdb-relational-jdbc.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ serviceLoader {
5252
}
5353

5454
jar {
55-
duplicatesStrategy "exclude"
55+
duplicatesStrategy = "exclude"
5656
}
5757

5858
// Task to build a fat jar, one w/ all dependencies; good for handing out as the 'jdbc' jar.

fdb-relational-server/fdb-relational-server.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ jar {
5656

5757
// Task to build a fat jar, one w/ all dependencies
5858
shadowJar {
59-
mainClassName = mainServerClass
59+
application {
60+
mainClass = mainServerClass
61+
}
6062
mergeServiceFiles()
6163
}
6264

gradle/testing.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ task destructiveTest(type: Test) {
4040
maxParallelForks = 1
4141
}
4242
reports {
43-
junitXml.destination = file("${buildDir}/test-results/destructive")
43+
junitXml.outputLocation = file("${buildDir}/test-results/destructive")
4444
}
4545
}
4646

yaml-tests/yaml-tests.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ project.tasks.named("processTestResources") {
3333
}
3434

3535
tasks.named("sourcesJar") {
36-
duplicatesStrategy('include')
36+
duplicatesStrategy = 'include'
3737
// classifier('sources')
3838
from sourceSets.main.allSource
3939
}

0 commit comments

Comments
 (0)