Skip to content

Commit c46d7ac

Browse files
committed
Format code
1 parent 66107f5 commit c46d7ac

17 files changed

+258
-404
lines changed
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
1-
/*
2-
* Copyright 2022 the GradleX team.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
1+
// SPDX-License-Identifier: Apache-2.0
172
package org.gradlex.buildparameters;
183

194
import javax.inject.Inject;
@@ -24,5 +9,4 @@ public abstract class BooleanBuildParameter extends BuildParameter<Boolean> {
249
public BooleanBuildParameter(Identifier identifier) {
2510
super(identifier);
2611
}
27-
2812
}

src/main/java/org/gradlex/buildparameters/BuildParameter.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
1-
/*
2-
* Copyright 2022 the GradleX team.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
1+
// SPDX-License-Identifier: Apache-2.0
172
package org.gradlex.buildparameters;
183

194
import org.gradle.api.provider.Property;

src/main/java/org/gradlex/buildparameters/BuildParameterGroup.java

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1-
/*
2-
* Copyright 2022 the GradleX team.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
1+
// SPDX-License-Identifier: Apache-2.0
172
package org.gradlex.buildparameters;
183

4+
import java.util.stream.Stream;
5+
import javax.inject.Inject;
196
import org.gradle.api.Action;
207
import org.gradle.api.model.ObjectFactory;
218
import org.gradle.api.provider.ListProperty;
@@ -24,9 +11,6 @@
2411
import org.gradle.api.tasks.Nested;
2512
import org.gradle.api.tasks.Optional;
2613

27-
import javax.inject.Inject;
28-
import java.util.stream.Stream;
29-
3014
public abstract class BuildParameterGroup {
3115

3216
private static final Action<Object> NO_OP = o -> {};
@@ -82,7 +66,8 @@ public void enumeration(String name, Action<EnumBuildParameter> configure) {
8266
configureParameter(name, EnumBuildParameter.class, configure);
8367
}
8468

85-
private <T extends BuildParameter<?>> void configureParameter(String name, Class<T> paramType, Action<? super T> configure) {
69+
private <T extends BuildParameter<?>> void configureParameter(
70+
String name, Class<T> paramType, Action<? super T> configure) {
8671
T parameter = getObjects().newInstance(paramType, id.append(name));
8772
parameter.getMandatory().convention(false);
8873
configure.execute(parameter);
@@ -110,12 +95,15 @@ public String getPropertyPath() {
11095
}
11196

11297
java.util.Optional<BuildParameter<?>> findParameter(String propertyPath) {
113-
java.util.Optional<BuildParameter<?>> match =
114-
getParameters().get().stream().filter(p -> p.getPropertyPath().equals(propertyPath)).findFirst();
98+
java.util.Optional<BuildParameter<?>> match = getParameters().get().stream()
99+
.filter(p -> p.getPropertyPath().equals(propertyPath))
100+
.findFirst();
115101
if (match.isPresent()) {
116102
return match;
117103
} else {
118-
return getGroups().get().stream().flatMap(g -> stream(g.findParameter(propertyPath))).findFirst();
104+
return getGroups().get().stream()
105+
.flatMap(g -> stream(g.findParameter(propertyPath)))
106+
.findFirst();
119107
}
120108
}
121109

src/main/java/org/gradlex/buildparameters/BuildParametersExtension.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,15 @@
1-
/*
2-
* Copyright 2022 the GradleX team.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
1+
// SPDX-License-Identifier: Apache-2.0
172
package org.gradlex.buildparameters;
183

4+
import static org.gradlex.buildparameters.Constants.PACKAGE_NAME;
5+
import static org.gradlex.buildparameters.Constants.PLUGIN_CLASS_NAME;
6+
7+
import javax.inject.Inject;
198
import org.gradle.api.provider.Property;
209
import org.gradle.api.tasks.Input;
2110
import org.gradle.plugin.devel.GradlePluginDevelopmentExtension;
2211
import org.gradle.plugin.devel.PluginDeclaration;
2312

24-
import javax.inject.Inject;
25-
26-
import static org.gradlex.buildparameters.Constants.PACKAGE_NAME;
27-
import static org.gradlex.buildparameters.Constants.PLUGIN_CLASS_NAME;
28-
2913
public abstract class BuildParametersExtension extends BuildParameterGroup {
3014

3115
private final PluginDeclaration pluginDeclaration;

src/main/java/org/gradlex/buildparameters/BuildParametersPlugin.java

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
1-
/*
2-
* Copyright 2022 the GradleX team.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
1+
// SPDX-License-Identifier: Apache-2.0
172
package org.gradlex.buildparameters;
183

194
import org.gradle.api.Plugin;
@@ -44,11 +29,15 @@ public void apply(Project project) {
4429
BuildParametersExtension extension =
4530
project.getExtensions().create("buildParameters", BuildParametersExtension.class, gradlePlugins);
4631

47-
TaskProvider<PluginCodeGeneration> task = project.getTasks().register("generatePluginCode", PluginCodeGeneration.class, t -> {
48-
t.setDescription("Generates code for compile-safe access to build parameters.");
49-
t.getBaseGroup().convention(extension);
50-
t.getOutputDirectory().convention(project.getLayout().getBuildDirectory().dir("generated/sources/build-parameters-plugin/java/main"));
51-
});
32+
TaskProvider<PluginCodeGeneration> task = project.getTasks()
33+
.register("generatePluginCode", PluginCodeGeneration.class, t -> {
34+
t.setDescription("Generates code for compile-safe access to build parameters.");
35+
t.getBaseGroup().convention(extension);
36+
t.getOutputDirectory()
37+
.convention(project.getLayout()
38+
.getBuildDirectory()
39+
.dir("generated/sources/build-parameters-plugin/java/main"));
40+
});
5241
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
5342
SourceSet main = sourceSets.getByName("main");
5443
main.getJava().srcDir(task.flatMap(PluginCodeGeneration::getOutputDirectory));
@@ -65,7 +54,8 @@ private static String getBuildPath(Gradle gradle, String acc) {
6554
if (gradle.getParent() == null) {
6655
return acc;
6756
} else {
68-
return getBuildPath(gradle.getParent(), ":" + gradle.getRootProject().getName() + acc);
57+
return getBuildPath(
58+
gradle.getParent(), ":" + gradle.getRootProject().getName() + acc);
6959
}
7060
}
7161
}

src/main/java/org/gradlex/buildparameters/CodeGeneratingBuildParameter.java

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
1-
/*
2-
* Copyright 2022 the GradleX team.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
1+
// SPDX-License-Identifier: Apache-2.0
172
package org.gradlex.buildparameters;
183

19-
import org.gradle.api.provider.Property;
4+
import static org.gradlex.buildparameters.PluginCodeGeneration.escapeEnumValue;
205

216
import java.util.function.Function;
22-
23-
import static org.gradlex.buildparameters.PluginCodeGeneration.escapeEnumValue;
7+
import org.gradle.api.provider.Property;
248

259
interface CodeGeneratingBuildParameter {
2610

@@ -37,10 +21,15 @@ static CodeGeneratingBuildParameter from(BuildParameter<?> parameter, BuildParam
3721
if (parameter instanceof IntegerBuildParameter) {
3822
type = new ParameterType("int", "Integer", ".map(Integer::parseInt)", Function.identity());
3923
} else if (parameter instanceof BooleanBuildParameter) {
40-
type = new ParameterType("boolean", "Boolean", ".map(" + containingGroup.id.toSimpleTypeName() + "::parse" + parameter.id.toSimpleTypeName() + ")", Function.identity());
24+
type = new ParameterType(
25+
"boolean",
26+
"Boolean",
27+
".map(" + containingGroup.id.toSimpleTypeName() + "::parse" + parameter.id.toSimpleTypeName() + ")",
28+
Function.identity());
4129
} else if (parameter instanceof EnumBuildParameter) {
4230
String typeName = parameter.id.toFullQualifiedTypeName();
43-
type = new ParameterType(typeName, typeName, ".map(" + typeName + "::parse)", s -> typeName + "." + escapeEnumValue(s));
31+
type = new ParameterType(
32+
typeName, typeName, ".map(" + typeName + "::parse)", s -> typeName + "." + escapeEnumValue(s));
4433
} else {
4534
type = new ParameterType("String", "String", "", s -> "\"" + s + "\"");
4635
}
@@ -70,13 +59,17 @@ public String getType() {
7059
public String getValue() {
7160
if (parameter.getEnvironmentVariableName().isPresent()) {
7261
String envName = parameter.getEnvironmentVariableName().get();
73-
return "providers.gradleProperty(\"" + parameter.id.toPropertyPath() + "\").orElse(providers.environmentVariable(\"" + envName + "\"))" + type.transformation + ".getOrElse(" + getDefaultValue() + ")";
62+
return "providers.gradleProperty(\"" + parameter.id.toPropertyPath()
63+
+ "\").orElse(providers.environmentVariable(\"" + envName + "\"))" + type.transformation
64+
+ ".getOrElse(" + getDefaultValue() + ")";
7465
}
75-
return "providers.gradleProperty(\"" + parameter.id.toPropertyPath() + "\")" + type.transformation + ".getOrElse(" + getDefaultValue() + ")";
66+
return "providers.gradleProperty(\"" + parameter.id.toPropertyPath() + "\")" + type.transformation
67+
+ ".getOrElse(" + getDefaultValue() + ")";
7668
}
7769

7870
private String getDefaultValue() {
79-
return type.defaultValueTransformation.apply(parameter.getDefaultValue().get().toString());
71+
return type.defaultValueTransformation.apply(
72+
parameter.getDefaultValue().get().toString());
8073
}
8174

8275
@Override
@@ -108,9 +101,12 @@ public String getType() {
108101
public String getValue() {
109102
if (parameter.getEnvironmentVariableName().isPresent()) {
110103
String envName = parameter.getEnvironmentVariableName().get();
111-
return "providers.gradleProperty(\"" + parameter.id.toPropertyPath() + "\").orElse(providers.environmentVariable(\"" + envName + "\"))" + errorIfMandatory() + type.transformation;
104+
return "providers.gradleProperty(\"" + parameter.id.toPropertyPath()
105+
+ "\").orElse(providers.environmentVariable(\"" + envName + "\"))" + errorIfMandatory()
106+
+ type.transformation;
112107
} else {
113-
return "providers.gradleProperty(\"" + parameter.id.toPropertyPath() + "\")" + errorIfMandatory() + type.transformation;
108+
return "providers.gradleProperty(\"" + parameter.id.toPropertyPath() + "\")" + errorIfMandatory()
109+
+ type.transformation;
114110
}
115111
}
116112

@@ -130,16 +126,17 @@ private String errorIfMandatory() {
130126
}
131127

132128
String description = parameter.getDescription().isPresent()
133-
? " (" + parameter.getDescription().get() + ")" : "";
129+
? " (" + parameter.getDescription().get() + ")"
130+
: "";
134131
String envVariable = parameter.getEnvironmentVariableName().isPresent()
135-
? " " + parameter.getEnvironmentVariableName().get() + "=value (environment variable)\\n" : "";
136-
137-
return ".orElse(providers.provider(() -> { throw new RuntimeException(\"" +
138-
"Build parameter " + parameter.id.toPropertyPath() + description + " not set. Use one of the following:\\n" +
139-
" -P" + parameter.id.toPropertyPath() + "=value (command line)\\n" +
140-
" " + parameter.id.toPropertyPath() + "=value (in 'gradle.properties' file)\\n" +
141-
envVariable +
142-
"\"); }))";
132+
? " " + parameter.getEnvironmentVariableName().get() + "=value (environment variable)\\n"
133+
: "";
134+
135+
return ".orElse(providers.provider(() -> { throw new RuntimeException(\"" + "Build parameter "
136+
+ parameter.id.toPropertyPath() + description + " not set. Use one of the following:\\n" + " -P"
137+
+ parameter.id.toPropertyPath() + "=value (command line)\\n" + " "
138+
+ parameter.id.toPropertyPath() + "=value (in 'gradle.properties' file)\\n" + envVariable
139+
+ "\"); }))";
143140
}
144141
}
145142

@@ -150,7 +147,11 @@ class ParameterType {
150147
final String transformation;
151148
final Function<String, String> defaultValueTransformation;
152149

153-
ParameterType(String name, String typeParameter, String transformation, Function<String, String> defaultValueTransformation) {
150+
ParameterType(
151+
String name,
152+
String typeParameter,
153+
String transformation,
154+
Function<String, String> defaultValueTransformation) {
154155
this.name = name;
155156
this.typeParameter = typeParameter;
156157
this.transformation = transformation;

0 commit comments

Comments
 (0)