Skip to content

Commit

Permalink
Merge pull request #350 from hazendaz/master
Browse files Browse the repository at this point in the history
Copy more maven testing module to support maven 3 still with junit 5
  • Loading branch information
hazendaz authored Aug 4, 2024
2 parents 662a338 + 61c7a02 commit c54e715
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
matrix:
cache: [maven]
distribution: [temurin]
java: [11, 17, 21, 22, 23-ea]
java: [11, 17, 21, 22, 23-ea, 24-ea]
os: [ubuntu-latest, macos-latest, windows-latest]
fail-fast: false
max-parallel: 4
Expand Down
16 changes: 9 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<groupId>org.mybatis</groupId>
<artifactId>mybatis-parent</artifactId>
<version>44</version>
<relativePath/>
<relativePath />
</parent>

<groupId>org.mybatis.maven</groupId>
Expand All @@ -32,11 +32,9 @@
<packaging>maven-plugin</packaging>

<name>MyBatis Migrations Maven plugin</name>
<description>
Migration-plugin is a Apache Maven 3 plugin that aims to integrate into the maven life cycle,
<description>Migration-plugin is a Apache Maven 3 plugin that aims to integrate into the maven life cycle,
the myBatis 3 Migration tool. MyBatis 3 Migration Schema is a tool that helps you to manage database
schema changes.
</description>
schema changes.</description>
<url>https://www.mybatis.org/migrations-maven-plugin/</url>

<scm>
Expand All @@ -62,6 +60,10 @@
</distributionManagement>

<properties>
<!-- Java Usage -->
<java.version>8</java.version>
<java.release.version>8</java.release.version>

<findbugs.onlyAnalyze>org.mybatis.maven.mvnmigrate.*</findbugs.onlyAnalyze>
<module.name>org.mybatis.maven.migrations</module.name>

Expand Down Expand Up @@ -347,7 +349,7 @@
</goals>
</pluginExecutionFilter>
<action>
<ignore/>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
Expand All @@ -360,7 +362,7 @@
</goals>
</pluginExecutionFilter>
<action>
<ignore/>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,7 +46,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
init();

if (getCommand() instanceof StatusCommand) {
StatusCommand command = (StatusCommand) getCommand();
StatusCommand command = getCommand();
command.execute();
StatusOperation operation = command.getOperation();
List<Change> changes = operation.getCurrentStatus();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,9 +25,6 @@
@Mojo(name = "pending")
public final class PendingCommandMojo extends AbstractCommandMojo<PendingCommand> {

/**
* {@inheritDoc}
*/
@Override
protected PendingCommand createCommandClass(SelectedOptions options) {
return new PendingCommand(options);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -133,11 +133,11 @@ protected void executeReport(Locale locale) throws MavenReportException {
return;
}

Map<MavenProject, List<Change>> aggregateReport = new HashMap<MavenProject, List<Change>>();
Map<MavenProject, List<Change>> aggregateReport = new HashMap<>();

for (MavenProject mavenProject : reactorProjects) {

Map<String, ReportPlugin> reportPluginMap = mavenProject.getReporting().getReportPluginsAsMap();
Map<String, ReportPlugin> reportPluginMap = mavenProject.getModel().getReporting().getReportPluginsAsMap();
ReportPlugin plug = reportPluginMap.get(getBundle(locale).getString("migration.plugin.key"));

Xpp3Dom configurationDom = (Xpp3Dom) plug.getConfiguration();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,7 +55,7 @@ public MavenOutputStream(final Log log) {
@Override
public void write(byte[] b, int off, int len) throws IOException {
for (int i = off; i < len; i++) {
write((int) b[i]);
write(b[i]);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mybatis.maven.testing.AbstractMojoTestCase;

@ExtendWith(MojoExtension.class)
public abstract class AbstractMigrateTestCase {
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/mybatis/maven/mvnmigrate/MojoExtension.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,14 +20,15 @@
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.mybatis.maven.testing.AbstractMojoTestCase;

public class MojoExtension implements AfterEachCallback, BeforeEachCallback {

// Make AbstractMojoTestCase concrete
protected AbstractMojoTestCase testCase = new AbstractMojoTestCase() {
};

protected void cleanup() throws Exception {
protected void cleanup() {
File initMigrationDbFolder;
initMigrationDbFolder = new File("target/init");
if (initMigrationDbFolder.exists()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2023 the original author or authors.
* Copyright 2010-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.mybatis.maven.mvnmigrate;
package org.mybatis.maven.testing;

import com.google.inject.Module;

Expand Down Expand Up @@ -70,8 +70,6 @@
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.apache.maven.plugin.testing.ConfigurationException;
import org.apache.maven.plugin.testing.ResolverExpressionEvaluatorStub;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.codehaus.plexus.ContainerConfiguration;
Expand All @@ -82,7 +80,6 @@
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.ComponentConfigurator;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
Expand All @@ -99,7 +96,8 @@

/**
* Mybatis: Borrowed from 'https://github.com/apache/maven-plugin-testing/blob/master/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java'
* Reason: Too restrictive to use directly for junit 5. Only changes were to add imports after inclusion from maven's test harness.
* Reason: Too restrictive to use directly for junit 5.
* Changes: Imports added, method access expanded, removed some left over junk code
* Git: From release 4.0.0-alpha-2
*/

Expand Down Expand Up @@ -146,9 +144,8 @@ public abstract class AbstractMojoTestCase extends PlexusTestCase {
* we are going to try and make an instance of the localrespository and assign that to either the project stub or into
* the mojo directly with injection...not sure yet though.
*/
// private MavenProjectBuilder projectBuilder;
@Override
protected void setUp() throws Exception {
public void setUp() throws Exception {
assertTrue("Maven 3.2.4 or better is required",
MAVEN_VERSION == null || new DefaultArtifactVersion("3.2.3").compareTo(MAVEN_VERSION) < 0);

Expand Down Expand Up @@ -311,7 +308,7 @@ protected <T extends Mojo> T lookupEmptyMojo(String goal, String pluginPom) thro
*
* @throws Exception
*/
protected <T extends Mojo> T lookupMojo(String goal, File pom) throws Exception {
public <T extends Mojo> T lookupMojo(String goal, File pom) throws Exception {
File pluginPom = new File(getBasedir(), "pom.xml");

Xpp3Dom pluginPomDom = Xpp3DomBuilder.build(ReaderFactory.newXmlReader(pluginPom));
Expand Down Expand Up @@ -351,11 +348,6 @@ protected <T extends Mojo> T lookupEmptyMojo(String goal, File pom) throws Excep
return lookupMojo(groupId, artifactId, version, goal, null);
}

/*
* protected Mojo lookupMojo( String groupId, String artifactId, String version, String goal, File pom ) throws
* Exception { PlexusConfiguration pluginConfiguration = extractPluginConfiguration( artifactId, pom ); return
* lookupMojo( groupId, artifactId, version, goal, pluginConfiguration ); }
*/
/**
* lookup the mojo while we have all of the relavent information
*
Expand All @@ -378,10 +370,6 @@ protected <T extends Mojo> T lookupMojo(String groupId, String artifactId, Strin
T mojo = (T) lookup(Mojo.class, groupId + ":" + artifactId + ":" + version + ":" + goal);

if (pluginConfiguration != null) {
/*
* requires v10 of plexus container for lookup on expression evaluator ExpressionEvaluator evaluator =
* (ExpressionEvaluator) getContainer().lookup( ExpressionEvaluator.ROLE, "stub-evaluator" );
*/
ExpressionEvaluator evaluator = new ResolverExpressionEvaluatorStub();

configurator.configureComponent(mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm());
Expand Down Expand Up @@ -411,12 +399,10 @@ protected <T extends Mojo> T lookupConfiguredMojo(MavenProject project, String g
* @return
*
* @throws Exception
* @throws ComponentConfigurationException
*
* @since 2.0
*/
protected <T extends Mojo> T lookupConfiguredMojo(MavenSession session, MojoExecution execution)
throws Exception, ComponentConfigurationException {
protected <T extends Mojo> T lookupConfiguredMojo(MavenSession session, MojoExecution execution) throws Exception {
MavenProject project = session.getCurrentProject();
MojoDescriptor mojoDescriptor = execution.getMojoDescriptor();

Expand Down Expand Up @@ -690,7 +676,7 @@ protected Map<String, Object> getVariablesAndValuesFromObject(Class<?> clazz, Ob
*
* @throws IllegalAccessException
*/
protected <T> void setVariableValueToObject(Object object, String variable, T value) throws IllegalAccessException {
public <T> void setVariableValueToObject(Object object, String variable, T value) throws IllegalAccessException {
Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses(variable, object.getClass());

field.setAccessible(true);
Expand All @@ -699,8 +685,9 @@ protected <T> void setVariableValueToObject(Object object, String variable, T va
}

/**
* sometimes the parent element might contain the correct value so generalize that access TODO find out where this is
* probably done elsewhere
* Sometimes the parent element might contain the correct value so generalize that access.
* <p>
* TODO find out where this is probably done elsewhere
*
* @param pluginPomDom
* @param element
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2010-2024 the original author or authors.
*
* Licensed 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
*
* https://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.
*/
/*
* 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.mybatis.maven.testing;

/**
* Mybatis: Borrowed from 'https://github.com/apache/maven-plugin-testing/blob/master/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ConfiguationException.java'
* Reason: Removed from release 4.0.0-beta-1 and we need to have junit 5 support. Maven dropped maven 3 support here!
* Git: From release 4.0.0-alpha-2
*/

/**
* ConfigurationException
*
* @author jesse
*/
public class ConfigurationException extends Exception {
/** serialVersionUID */
static final long serialVersionUID = -6180939638742159065L;

/**
* @param message
* The detailed message.
*/
public ConfigurationException(String message) {
super(message);
}

/**
* @param cause
* The detailed cause.
*/
public ConfigurationException(Throwable cause) {
super(cause);
}

/**
* @param message
* The detailed message.
* @param cause
* The detailed cause.
*/
public ConfigurationException(String message, Throwable cause) {
super(message, cause);
}
}
Loading

0 comments on commit c54e715

Please sign in to comment.