Skip to content

Commit

Permalink
Require Maven 3.5.4+ and updates
Browse files Browse the repository at this point in the history
- update plexus-resources from 1.0.1 to 1.2.0
- update maven-plugin-testing-harness from 2.1 to 3.3.0
  • Loading branch information
slawekjaranowski committed Jun 19, 2023
1 parent 75d0bb9 commit 9ae4e72
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 118 deletions.
34 changes: 25 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,27 @@
</ciManagement>

<properties>
<mavenVersion>3.0</mavenVersion>
<mavenVersion>3.5.4</mavenVersion>
<!-- Override version set in parent -->
<mojo.java.target>8</mojo.java.target>
</properties>

<dependencyManagement>
<!-- mange transitive dependencies -->
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>4.7.1</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
Expand All @@ -138,7 +154,7 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-resources</artifactId>
<version>1.0.1</version>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>xml-resolver</groupId>
Expand All @@ -153,7 +169,7 @@
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>2.1</version>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -162,12 +178,6 @@
<version>${mavenVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>saxon</artifactId>
<version>8.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
Expand All @@ -186,6 +196,12 @@
<version>0.9.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
Expand Down
109 changes: 5 additions & 104 deletions src/test/java/org/codehaus/mojo/xml/test/AbstractXmlMojoTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,20 @@
*/
package org.codehaus.mojo.xml.test;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;

import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.PluginParameterExpressionEvaluator;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.plugin.testing.SilentLog;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingRequest;
import org.codehaus.mojo.xml.AbstractXmlMojo;
import org.codehaus.mojo.xml.TransformMojo;
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.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.resource.DefaultResourceManager;
import org.codehaus.plexus.resource.loader.FileResourceLoader;
import org.codehaus.plexus.resource.loader.JarResourceLoader;
import org.codehaus.plexus.resource.loader.ResourceLoader;
import org.codehaus.plexus.resource.loader.ThreadContextClasspathResourceLoader;
import org.codehaus.plexus.resource.loader.URLResourceLoader;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

Expand All @@ -68,35 +45,12 @@ protected AbstractXmlMojo newMojo( String pDir )

MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
buildingRequest.setRepositorySession(new DefaultRepositorySystemSession());
ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
MavenProject project = projectBuilder.build(testPom, buildingRequest).getProject();
// final Build build = new Build();
// build.setDirectory( "target" );
// project.setBuild(build);
project.getBuild().setDirectory("target");
AbstractXmlMojo vm = (AbstractXmlMojo) lookupConfiguredMojo(project, getGoal());
setVariableValueToObject( vm, "basedir", new File( getBasedir(), pDir ) );
final Log log = new SilentLog();
DefaultResourceManager rm = new DefaultResourceManager();
setVariableValueToObject( rm, "logger", log );
setVariableValueToObject( vm, "locator", rm );
final Map<String, ResourceLoader> resourceLoaders = new HashMap<String, ResourceLoader>();
resourceLoaders.put( "file", new FileResourceLoader() );
resourceLoaders.put( "jar", new JarResourceLoader() );
resourceLoaders.put( "classloader", new ThreadContextClasspathResourceLoader() );
URLResourceLoader url = new URLResourceLoader();
setVariableValueToObject( url, "logger", log );
resourceLoaders.put( "url", url );
setVariableValueToObject( rm, "resourceLoaders", resourceLoaders );

// MavenProjectStub project = new MavenProjectStub()
// {
// public Build getBuild()
// {
// return build;
// }
// };
// setVariableValueToObject( vm, "project", project );
return vm;
}

Expand All @@ -114,57 +68,4 @@ protected Document parse( File pFile )
dbf.setNamespaceAware( true );
return dbf.newDocumentBuilder().parse( pFile );
}

protected boolean java1_6_Aware()
throws IllegalAccessException, InvocationTargetException
{
try
{
TransformMojo.newTransformerFactory( "net.sf.saxon.TransformerFactoryImpl",
Thread.currentThread().getContextClassLoader() );
return true;
}
catch ( NoSuchMethodException e )
{
return false;
}
}



@Override //In maven-plugin-testing-harnes 2.1, this method had a simple error in it which resulted in
//the configuration being incorrectly generated. In later versions, the error has been corrected.
//The error is annotated in the comments below. This method should be removed when upgrading to later
//versions.
protected Mojo lookupConfiguredMojo( MavenSession session, MojoExecution execution )
throws Exception, ComponentConfigurationException
{
MavenProject project = session.getCurrentProject();
MojoDescriptor mojoDescriptor = execution.getMojoDescriptor();

Mojo mojo = (Mojo) lookup( mojoDescriptor.getRole(), mojoDescriptor.getRoleHint() );

ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator( session, execution );

Xpp3Dom configuration = null;
Plugin plugin = project.getPlugin( mojoDescriptor.getPluginDescriptor().getPluginLookupKey() );
if ( plugin != null )
{
configuration = (Xpp3Dom) plugin.getConfiguration();
}
if ( configuration == null )
{
configuration = new Xpp3Dom( "configuration" );
}
//FIX: the parameters were in the wrong order on this call - they have been reversed
configuration = Xpp3Dom.mergeXpp3Dom( configuration ,execution.getConfiguration());
//END FIX
PlexusConfiguration pluginConfiguration = new XmlPlexusConfiguration( configuration );

getContainer().lookup( ComponentConfigurator.class, "basic" ).configureComponent( mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm() );

return mojo;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,6 @@ private String eval( Node contextNode, String str )
public void testIt8()
throws Exception
{
if ( !java1_6_Aware() )
{
System.out.println( " skip test due to non compliance jvm version need 1.6" );
return;
}
final String dir = "src/test/it8";
runTest( dir );
Document doc1 = parse( new File( dir, "target/generated-resources/xml/xslt/doc1.xml" ) );
Expand Down

0 comments on commit 9ae4e72

Please sign in to comment.