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-94] Switch to Maven 4.0.0-beta-3 #39

Merged
merged 4 commits into from
Jun 21, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/maven-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
name: Verify
uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v4
with:
jdk-matrix: '[ "8", "11", "17" ]'
jdk-matrix: '[ "17", "21" ]'
50 changes: 15 additions & 35 deletions maven-plugin-testing-harness/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ under the License.
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.0</version>
<version>5.10.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -64,16 +64,19 @@ under the License.
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<artifactId>maven-xml-impl</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-resolver-provider</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
</dependency>

<!-- plexus -->
<dependency>
Expand All @@ -85,39 +88,10 @@ under the License.
<!-- correct version must be provided by project depends on Maven version -->
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
<version>4.0.0</version>
<version>4.0.3</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>4.8.0</version>
</dependency>

<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-testing</artifactId>
<version>1.1.0</version>
<exclusions>
<exclusion>
<!-- we need as optional dependencies -->
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<!-- newer version is required by plexus-testing -->
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.0.1-jre</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -130,8 +104,14 @@ under the License.
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
<artifactId>slf4j-api</artifactId>
<version>2.0.13</version>
</dependency>

<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>6.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* 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.api.di.testing;

import java.io.*;

import org.apache.maven.di.Injector;
import org.apache.maven.di.Key;
import org.apache.maven.di.impl.DIException;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

/**
* This is a slightly modified version of the original plexus class
* available at https://raw.githubusercontent.com/codehaus-plexus/plexus-containers/master/plexus-container-default/
* src/main/java/org/codehaus/plexus/PlexusTestCase.java
* in order to migrate the tests to JUnit 4.
*
* @author Jason van Zyl
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @author <a href="mailto:michal@codehaus.org">Michal Maczka</a>
* @author Guillaume Nodet
*/
public class MavenDIExtension implements BeforeEachCallback, AfterEachCallback {
protected static ExtensionContext context;
protected Injector injector;
protected static String basedir;

@Override
public void beforeEach(ExtensionContext context) throws Exception {
basedir = getBasedir();

setContext(context);

getInjector().bindInstance((Class<Object>) context.getRequiredTestClass(), context.getRequiredTestInstance());
getInjector().injectInstance(context.getRequiredTestInstance());
}

protected void setContext(ExtensionContext context) {
this.context = context;
}

@SuppressWarnings("unchecked")
protected void setupContainer() {
try {
injector = Injector.create();
injector.bindInstance(ExtensionContext.class, this.context);
injector.discover(this.context.getRequiredTestClass().getClassLoader());
injector.bindInstance(Injector.class, injector);
injector.bindInstance((Class) this.context.getRequiredTestClass(), this.context.getRequiredTestInstance());
} catch (Exception e) {
throw new IllegalArgumentException("Failed to create DI injector.", e);
}
}

@Override
public void afterEach(ExtensionContext context) throws Exception {
if (injector != null) {
// TODO: implement
// injector.dispose();
injector = null;
}
}

public Injector getInjector() {
if (injector == null) {
setupContainer();
}

return injector;
}

// ----------------------------------------------------------------------
// Container access
// ----------------------------------------------------------------------

protected <T> T lookup(Class<T> componentClass) throws DIException {
return getInjector().getInstance(componentClass);
}

protected <T> T lookup(Class<T> componentClass, String roleHint) throws DIException {
return getInjector().getInstance(Key.ofType(componentClass, roleHint));
}

protected <T> T lookup(Class<T> componentClass, Object qualifier) throws DIException {
return getInjector().getInstance(Key.ofType(componentClass, qualifier));
}

protected void release(Object component) throws DIException {
// TODO: implement
// getInjector().release(component);
}

// ----------------------------------------------------------------------
// Helper methods for sub classes
// ----------------------------------------------------------------------

public static File getTestFile(String path) {
return new File(getBasedir(), path);
}

public static File getTestFile(String basedir, String path) {
File basedirFile = new File(basedir);

if (!basedirFile.isAbsolute()) {
basedirFile = getTestFile(basedir);
}

return new File(basedirFile, path);
}

public static String getTestPath(String path) {
return getTestFile(path).getAbsolutePath();
}

public static String getTestPath(String basedir, String path) {
return getTestFile(basedir, path).getAbsolutePath();
}

public static String getBasedir() {
if (basedir != null) {
return basedir;
}

basedir = System.getProperty("basedir");

if (basedir == null) {
basedir = new File("").getAbsolutePath();
}

return basedir;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.plugin.testing.junit5;
package org.apache.maven.api.di.testing;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand All @@ -26,9 +26,9 @@
import org.junit.jupiter.api.extension.ExtendWith;

/**
*
* Plexus test
*/
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(MojoExtension.class)
@ExtendWith(MavenDIExtension.class)
@Target(ElementType.TYPE)
public @interface MojoTest {}
public @interface MavenDITest {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.plugin.testing.junit5;
package org.apache.maven.api.plugin.testing;

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

/**
* Mojo parameters container
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface MojoParameters {
MojoParameter[] value();
@Inherited
public @interface Basedir {
String value() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
*/
package org.apache.maven.api.plugin.testing;

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

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

String goal();

String pom();

boolean empty() default false;
String pom() default "";
}
Loading