Skip to content

Commit

Permalink
Use assign operator for Kotlin DSL generated with BuildInit
Browse files Browse the repository at this point in the history
  • Loading branch information
alllex committed Dec 4, 2023
1 parent f59fdfd commit ddfc157
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ ${TextUtil.indent(configLines.join("\n"), " ")}
}
'''.stripIndent().trim())) || rootBuildFile.text.contains(TextUtil.toPlatformLineSeparators('''
val testsJar by tasks.registering(Jar::class) {
archiveClassifier.set("tests")
archiveClassifier = "tests"
from(sourceSets["test"].output)
}
'''.stripIndent().trim()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public BuildScriptBuilder javaToolchainFor(JavaLanguageVersion languageVersion)
t.block(null, "toolchain", t1 -> {
t1.propertyAssignment(null, "languageVersion",
new MethodInvocationExpression(null, "JavaLanguageVersion.of", singletonList(new LiteralValue(languageVersion.asInt()))),
false);
true);
});
});
}
Expand Down Expand Up @@ -1036,13 +1036,13 @@ private static class PropertyAssignment extends AbstractStatement {

final String propertyName;
final ExpressionValue propertyValue;
final boolean legacyProperty;
final boolean assignOperator;

private PropertyAssignment(String comment, String propertyName, ExpressionValue propertyValue, boolean legacyProperty) {
private PropertyAssignment(String comment, String propertyName, ExpressionValue propertyValue, boolean assignOperator) {
super(comment);
this.propertyName = propertyName;
this.propertyValue = propertyValue;
this.legacyProperty = legacyProperty;
this.assignOperator = assignOperator;
}

@Override
Expand Down Expand Up @@ -1558,8 +1558,8 @@ public void writeBodyTo(PrettyPrinter printer) {
}

@Override
public void propertyAssignment(String comment, String propertyName, Object propertyValue, boolean legacyProperty) {
statements.add(new PropertyAssignment(comment, propertyName, expressionValue(propertyValue), legacyProperty));
public void propertyAssignment(String comment, String propertyName, Object propertyValue, boolean assignOperator) {
statements.add(new PropertyAssignment(comment, propertyName, expressionValue(propertyValue), assignOperator));
}

@Override
Expand Down Expand Up @@ -2095,12 +2095,11 @@ public String dependencySpec(String config, String notation) {
return config + "(" + notation + ")";
}


@Override
public String propertyAssignment(PropertyAssignment expression) {
String propertyName = expression.propertyName;
ExpressionValue propertyValue = expression.propertyValue;
if (expression.legacyProperty) {
if (expression.assignOperator) {
if (propertyValue.isBooleanType()) {
return booleanPropertyNameFor(propertyName) + " = " + propertyValue.with(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void generateProjectBuildScript(String projectName, InitSettings settings
if (!isSingleProject(settings)) {
mainClass = "app." + mainClass;
}
b.propertyAssignment("Define the main class for the application.", "mainClass", withPackage(settings, mainClass), false);
b.propertyAssignment("Define the main class for the application.", "mainClass", withPackage(settings, mainClass), true);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface ScriptBlockBuilder {
/**
* Adds a property assignment statement to this block
*/
void propertyAssignment(@Nullable String comment, String propertyName, Object propertyValue, boolean legacyProperty);
void propertyAssignment(@Nullable String comment, String propertyName, Object propertyValue, boolean assignOperator);

/**
* Adds a method invocation statement to this block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ boolean packageTests(MavenProject project, BuildScriptBuilder builder) {
Plugin jarPlugin = plugin("maven-jar-plugin", project);
if (pluginGoal("test-jar", jarPlugin) != null) {
builder.taskRegistration(null, "testsJar", "Jar", task -> {
task.propertyAssignment(null, "archiveClassifier", "tests", false);
task.propertyAssignment(null, "archiveClassifier", "tests", true);
task.methodInvocation(null, "from", builder.propertyExpression(builder.containerElementExpression("sourceSets", "test"), "output"));
});
return true;
Expand Down

0 comments on commit ddfc157

Please sign in to comment.