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

[MPLUGINTESTING-84] Support Junit 5 + Maven 3 #31

Merged
merged 3 commits into from
Oct 18, 2023
Merged
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
11 changes: 8 additions & 3 deletions maven-plugin-testing-harness/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ under the License.
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${mavenVersion}</version>
<scope>test</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand All @@ -71,9 +71,14 @@ under the License.

<!-- plexus -->
<dependency>
<groupId>org.apache.maven</groupId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>${mavenVersion}</version>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@
import org.slf4j.LoggerFactory;

/**
* JUnit extension to help testing Mojos. The extension should be automatically registered
* by adding the {@link MojoTest} annotation on the test class.
*
* @see MojoTest
* @see InjectMojo
* @see MojoParameter
*/
public class MojoExtension extends PlexusExtension implements ParameterResolver {

Expand Down Expand Up @@ -134,15 +139,6 @@ public void beforeEach(ExtensionContext context) throws Exception {

PluginDescriptor pluginDescriptor = new PluginDescriptorBuilder().build(interpolationReader);

// Artifact artifact =
// lookup( RepositorySystem.class ).createArtifact( pluginDescriptor.getGroupId(),
// pluginDescriptor.getArtifactId(),
// pluginDescriptor.getVersion(), ".jar" );
//
// artifact.setFile( getPluginArtifactFile() );
// pluginDescriptor.setPluginArtifact( artifact );
// pluginDescriptor.setArtifacts( Collections.singletonList( artifact ) );

context.getStore(ExtensionContext.Namespace.GLOBAL).put(PluginDescriptor.class, pluginDescriptor);

for (ComponentDescriptor<?> desc : pluginDescriptor.getComponents()) {
Expand Down Expand Up @@ -203,7 +199,7 @@ protected String[] mojoCoordinates(String goal) throws Exception {
}

/**
* lookup the mojo while we have all of the relavent information
* lookup the mojo while we have all the relevent information
*/
protected Mojo lookupMojo(String[] coord, XmlNode pluginConfiguration, PluginDescriptor descriptor)
throws Exception {
Expand Down Expand Up @@ -319,13 +315,8 @@ private static String resolveFromRootThenParent(Xpp3Dom pluginPomDom, String ele

/**
* Convenience method to obtain the value of a variable on a mojo that might not have a getter.
*
* NOTE: the caller is responsible for casting to to what the desired type is.
*
* @param object
* @param variable
* @return object value of variable
* @throws IllegalArgumentException
* <br>
* NOTE: the caller is responsible for casting to what the desired type is.
*/
public static Object getVariableValueFromObject(Object object, String variable) throws IllegalAccessException {
Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses(variable, object.getClass());
Expand All @@ -335,23 +326,18 @@ public static Object getVariableValueFromObject(Object object, String variable)

/**
* Convenience method to obtain all variables and values from the mojo (including its superclasses)
*
* <br>
* Note: the values in the map are of type Object so the caller is responsible for casting to desired types.
*
* @param object
* @return map of variable names and values
*/
public static Map<String, Object> getVariablesAndValuesFromObject(Object object) throws IllegalAccessException {
return getVariablesAndValuesFromObject(object.getClass(), object);
}

/**
* Convenience method to obtain all variables and values from the mojo (including its superclasses)
*
* <br>
* Note: the values in the map are of type Object so the caller is responsible for casting to desired types.
*
* @param clazz
* @param object
* @return map of variable names and values
*/
public static Map<String, Object> getVariablesAndValuesFromObject(Class<?> clazz, Object object)
Expand All @@ -371,11 +357,6 @@ public static Map<String, Object> getVariablesAndValuesFromObject(Class<?> clazz

/**
* Convenience method to set values to variables in objects that don't have setters
*
* @param object
* @param variable
* @param value
* @throws IllegalAccessException
*/
public static void setVariableValueToObject(Object object, String variable, Object value)
throws IllegalAccessException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.Properties;

import com.google.inject.Module;
import org.apache.commons.io.input.XmlStreamReader;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
Expand Down Expand Up @@ -75,6 +74,7 @@
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.ReflectionUtils;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.XmlStreamReader;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.maven.plugin.testing.junit5;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
*
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface InjectMojo {

String goal();

String pom();

boolean empty() default false;
}
Loading