Skip to content
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

Remove usage of plexus util internals (no included in maven 4) #288

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Changes from 1 commit
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
29 changes: 16 additions & 13 deletions src/test/java/io/kokuwa/maven/k3s/test/MojoExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.io.StringReader;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;

import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.apache.maven.plugin.logging.Log;
import org.codehaus.plexus.util.InterpolationFilterReader;
import org.codehaus.plexus.util.ReflectionUtils;
import org.codehaus.plexus.util.xml.XmlStreamReader;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolutionException;
import org.junit.jupiter.api.extension.ParameterResolver;
import org.opentest4j.AssertionFailedError;

import io.kokuwa.maven.k3s.mojo.K3sMojo;
import io.kokuwa.maven.k3s.util.Docker;
Expand All @@ -39,13 +38,14 @@ public class MojoExtension implements ParameterResolver, BeforeAllCallback {
@Override
public void beforeAll(ExtensionContext context) throws Exception {
if (mojos.isEmpty()) {
var inputStream = K3sMojo.class.getResourceAsStream("/META-INF/maven/plugin.xml");
assertNotNull(inputStream, "Plugin descriptor for not found, run 'mvn plugin:descriptor'.");
new PluginDescriptorBuilder()
.build(new InterpolationFilterReader(new XmlStreamReader(inputStream),
Map.of("project.build.directory", "target", "project.basedir", ".")))
.getMojos()
.forEach(mojos::add);
try (var inputStream = K3sMojo.class.getResourceAsStream("/META-INF/maven/plugin.xml");) {
assertNotNull(inputStream, "Plugin descriptor for not found, run 'mvn plugin:descriptor'.");
new PluginDescriptorBuilder()
.build(new StringReader( new String(inputStream.readAllBytes())
.replaceAll("\\$\\{project.build.directory}", "target")
.replaceAll("\\$\\{project.basedir}", ".")))
.getMojos().forEach(mojos::add);
}
}
}

Expand Down Expand Up @@ -74,8 +74,11 @@ public Object resolveParameter(ParameterContext parameterContext, ExtensionConte
var mojo = (K3sMojo) type.getDeclaredConstructor().newInstance();
for (var parameter : descriptor.getParameters()) {
if (parameter.getDefaultValue() != null) {
var setter = ReflectionUtils.getSetter(parameter.getName(), mojo.getClass());
var parameterType = ReflectionUtils.getSetterType(setter);
var setter = Stream.of(type.getMethods())
.filter(m -> m.getName().toLowerCase().equals("set" + parameter.getName().toLowerCase()))
.findFirst()
.orElseThrow(() -> new AssertionFailedError("Setter not found: set" + parameter.getName()));
var parameterType = setter.getParameters()[0].getType();
if (String.class.equals(parameterType)) {
setter.invoke(mojo, parameter.getDefaultValue());
} else if (File.class.equals(parameterType)) {
Expand Down