Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust script compilation to use jsr305 strict mode
This is what we already do for Kotlin plugins. This change makes the Gradle DSL more consistent.
- Loading branch information
Showing
11 changed files
with
111 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
subprojects/base-services/src/main/java/org/gradle/api/internal/NullableTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.gradle.api.internal; | ||
|
||
import org.gradle.api.Transformer; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* <p>{@code Transformer} extension that explicitly allows {@code null} return values</p> | ||
* | ||
* @param <OUT> The type the value is transformed to. | ||
* @param <IN> The type of the value to be transformed. | ||
*/ | ||
public abstract class NullableTransformer<OUT, IN> implements Transformer<OUT, IN> { | ||
|
||
@Nullable | ||
@Override | ||
public abstract OUT transform(IN in); | ||
|
||
public Transformer<OUT, IN> asTransformer() { | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...src/integTest/kotlin/org/gradle/kotlin/dsl/support/KotlinScriptCompilerIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.gradle.kotlin.dsl.support | ||
|
||
import org.gradle.kotlin.dsl.fixtures.AbstractKotlinIntegrationTest | ||
import org.junit.Test | ||
import spock.lang.Issue | ||
|
||
|
||
class KotlinScriptCompilerIntegrationTest : AbstractKotlinIntegrationTest() { | ||
|
||
@Test | ||
@Issue("https://github.com/gradle/gradle/issues/18714") | ||
fun `Build scripts are compiled with jsr305 strict mode`() { | ||
|
||
// given: | ||
withFile( | ||
"buildSrc/src/main/java/StringTransformer.java", | ||
""" | ||
@org.gradle.api.NonNullApi | ||
public interface StringTransformer { | ||
String transform(String input); | ||
} | ||
""" | ||
) | ||
|
||
withBuildScript("StringTransformer { input -> null }") | ||
|
||
// when: | ||
val result = buildAndFail("help") | ||
|
||
// then: | ||
result.assertHasDescription("Script compilation error") | ||
result.hasErrorOutput("Null can not be a value of a non-null type String") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters