Skip to content

Commit 4ad8b74

Browse files
Aleksandar Gradinacgradinac
Aleksandar Gradinac
authored andcommitted
Warn about deprecated agent DSL
1 parent 5e702c3 commit 4ad8b74

File tree

5 files changed

+95
-2
lines changed

5 files changed

+95
-2
lines changed

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/NativeImagePlugin.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,15 @@ public void apply(Project project) {
176176

177177
project.getPlugins().withType(JavaLibraryPlugin.class, javaLibraryPlugin -> graalExtension.getAgent().getDefaultMode().convention("conditional"));
178178

179-
project.afterEvaluate(p -> instrumentTasksWithAgent(project, graalExtension));
179+
project.afterEvaluate(p -> {
180+
instrumentTasksWithAgent(project, graalExtension);
181+
for (NativeImageOptions options : graalExtension.getBinaries()) {
182+
if (options.getAgent().getOptions().get().size() > 0 || options.getAgent().getEnabled().isPresent()) {
183+
logger.warn("The agent block in binary configuration '" + options.getName() + "' is deprecated.");
184+
logger.warn("Such agent configuration has no effect and will become an error in the future.");
185+
}
186+
}
187+
});
180188
}
181189

182190
private void instrumentTasksWithAgent(Project project, DefaultGraalVmExtension graalExtension) {

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/dsl/NativeImageOptions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
package org.graalvm.buildtools.gradle.dsl;
4343

44+
import org.graalvm.buildtools.gradle.dsl.agent.DeprecatedAgentOptions;
4445
import org.gradle.api.Action;
4546
import org.gradle.api.Named;
4647
import org.gradle.api.file.ConfigurableFileCollection;
@@ -267,4 +268,9 @@ public interface NativeImageOptions extends Named {
267268
*/
268269
@Input
269270
Property<Boolean> getUseFatJar();
271+
272+
@Nested
273+
DeprecatedAgentOptions getAgent();
274+
275+
void agent(Action<? super DeprecatedAgentOptions> spec);
270276
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2022, 2022 Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package org.graalvm.buildtools.gradle.dsl.agent;
42+
43+
import org.gradle.api.provider.ListProperty;
44+
import org.gradle.api.provider.Property;
45+
import org.gradle.api.tasks.Input;
46+
import org.gradle.api.tasks.Optional;
47+
48+
public interface DeprecatedAgentOptions {
49+
50+
@Input
51+
@Optional
52+
Property<Boolean> getEnabled();
53+
54+
@Input
55+
@Optional
56+
ListProperty<String> getOptions();
57+
58+
}

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/internal/BaseNativeImageOptions.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
import org.graalvm.buildtools.gradle.dsl.NativeImageOptions;
4545
import org.graalvm.buildtools.gradle.dsl.NativeResourcesOptions;
46+
import org.graalvm.buildtools.gradle.dsl.agent.DeprecatedAgentOptions;
4647
import org.gradle.api.Action;
4748
import org.gradle.api.file.ConfigurableFileCollection;
4849
import org.gradle.api.model.ObjectFactory;
@@ -340,4 +341,13 @@ public BaseNativeImageOptions runtimeArgs(Iterable<?> arguments) {
340341
);
341342
return this;
342343
}
344+
345+
@Override
346+
@Nested
347+
public abstract DeprecatedAgentOptions getAgent();
348+
349+
@Override
350+
public void agent(Action<? super DeprecatedAgentOptions> spec) {
351+
spec.execute(getAgent());
352+
}
343353
}

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/internal/DeprecatedNativeImageOptions.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import org.graalvm.buildtools.gradle.dsl.NativeImageOptions;
4444
import org.graalvm.buildtools.gradle.dsl.NativeResourcesOptions;
45+
import org.graalvm.buildtools.gradle.dsl.agent.DeprecatedAgentOptions;
4546
import org.gradle.api.Action;
4647
import org.gradle.api.file.ConfigurableFileCollection;
4748
import org.gradle.api.provider.ListProperty;
@@ -236,6 +237,16 @@ public NativeImageOptions runtimeArgs(Object... arguments) {
236237

237238
@Override
238239
public NativeImageOptions runtimeArgs(Iterable<?> arguments) {
239-
return warnAboutDeprecation(() ->delegate.runtimeArgs(arguments));
240+
return warnAboutDeprecation(() -> delegate.runtimeArgs(arguments));
241+
}
242+
243+
@Override
244+
public DeprecatedAgentOptions getAgent() {
245+
return warnAboutDeprecation(delegate::getAgent);
246+
}
247+
248+
@Override
249+
public void agent(Action<? super DeprecatedAgentOptions> spec) {
250+
warnAboutDeprecation(() -> delegate.agent(spec));
240251
}
241252
}

0 commit comments

Comments
 (0)