Skip to content

More improvements #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 0.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@

/**
* Specify which properties should be defined as parameters.
* Parameters will be configured with {@code @Property(parameter = )} in Maven.
* Parameters will be configured with {@code @Property(parameter = )} in Maven. All the
* parameters will be prefixed with {@link #parameterPrefix()};<br />
*
* To specify an alternative parameter name, provide it by an equals sign,
* like {@code "myProperty=my-property"}.
*
* @return The parameters list
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ private void addParameter(MavenTaskConfig taskConfig, ParameterConfig parameter,
if (parameter.required()) {
ann.addMember("required", true);
}
if (taskConfig.globalParameters().contains(parameter.source().getName())) {
if (taskConfig.globalParameters().containsKey(parameter.source().getName())) {
ann.addMember("property", taskConfig.parameterPrefix()
+ "." + MavenPluginUtils.toDotSeparated(parameter.source().getName()));
+ "." + taskConfig.globalParameters().get(parameter.source().getName()));
}
FieldDef field = FieldDef.builder(parameter.source().getName())
.ofType(parameter.type())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.micronaut.core.annotation.Internal;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.core.type.Argument;
import io.micronaut.inject.ast.ClassElement;
import io.micronaut.inject.ast.PropertyElement;
import io.micronaut.inject.processing.ProcessingException;
Expand All @@ -35,7 +34,9 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Utils class for Maven plugin generation.
Expand Down Expand Up @@ -117,14 +118,30 @@ public static String toDotSeparated(String camelCase) {
namePrefix,
annotation.booleanValue("micronautPlugin").orElse(true),
parameterPrefix,
annotation.get("globalParameters", Argument.listOf(String.class)).orElse(Collections.emptyList()),
createGlobalParameters(annotation.get("globalParameters", String[].class).orElse(null)),
annotation.stringValue("enabledPropertyName").orElse(parameterPrefix + ".enabled"),
javadoc.javadoc().orElse(namePrefix + " Maven Mojo."),
methodJavadoc,
generatedModels
);
}

private static Map<String, String> createGlobalParameters(@Nullable String[] values) {
if (values == null || values.length == 0) {
return Collections.emptyMap();
}
Map<String, String> globalParameters = new HashMap<>();
for (String value : values) {
int index = value.indexOf('=');
if (index > -1) {
globalParameters.put(value.substring(0, index), value.substring(index + 1));
} else {
globalParameters.put(value, value);
}
}
return globalParameters;
}

/**
* Configuration for a gradle task type.
*
Expand All @@ -149,7 +166,7 @@ public record MavenTaskConfig(
@NonNull String namePrefix,
boolean micronautPlugin,
@Nullable String parameterPrefix,
@NonNull List<String> globalParameters,
@NonNull Map<String, String> globalParameters,
@Nullable String enabledPropertyName,
@NonNull String taskJavadoc,
@NonNull String methodJavadoc,
Expand Down
Loading