Skip to content

Commit

Permalink
Upgrade to Maven 4.0.0-alpha-13
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed May 23, 2024
1 parent 41caf07 commit 98db829
Show file tree
Hide file tree
Showing 17 changed files with 1,139 additions and 273 deletions.
27 changes: 26 additions & 1 deletion 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 All @@ -62,18 +62,33 @@ under the License.
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model-builder</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-xml-impl</artifactId>
<version>${mavenVersion}</version>
</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 @@ -99,6 +114,16 @@ under the License.
<artifactId>plexus-testing</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.6</version>
</dependency>
<dependency>
<!-- newer version is required by plexus-testing -->
<groupId>com.google.guava</groupId>
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:[email protected]">Trygve Laugst&oslash;l</a>
* @author <a href="mailto:[email protected]">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
@@ -0,0 +1,34 @@
/*
* 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.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.extension.ExtendWith;

/**
* Plexus test
*/
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(MavenDIExtension.class)
@Target(ElementType.TYPE)
public @interface MavenDITest {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.plugin.testing;

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

/**
* Mojo parameters container
*/
@Retention(RetentionPolicy.RUNTIME)
@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

0 comments on commit 98db829

Please sign in to comment.