From 9ae4e72844780e18cc49bf2a63df5f8fea94f857 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Mon, 19 Jun 2023 23:30:10 +0200 Subject: [PATCH] Require Maven 3.5.4+ and updates - update plexus-resources from 1.0.1 to 1.2.0 - update maven-plugin-testing-harness from 2.1 to 3.3.0 --- pom.xml | 34 ++++-- .../xml/test/AbstractXmlMojoTestCase.java | 109 +----------------- .../mojo/xml/test/TransformMojoTest.java | 5 - 3 files changed, 30 insertions(+), 118 deletions(-) diff --git a/pom.xml b/pom.xml index a165c84..3088549 100644 --- a/pom.xml +++ b/pom.xml @@ -112,11 +112,27 @@ - 3.0 + 3.5.4 8 + + + + + commons-io + commons-io + 2.13.0 + + + org.codehaus.plexus + plexus-archiver + 4.7.1 + + + + org.apache.maven @@ -138,7 +154,7 @@ org.codehaus.plexus plexus-resources - 1.0.1 + 1.2.0 xml-resolver @@ -153,7 +169,7 @@ org.apache.maven.plugin-testing maven-plugin-testing-harness - 2.1 + 3.3.0 test @@ -162,12 +178,6 @@ ${mavenVersion} test - - net.sf.saxon - saxon - 8.7 - test - xalan xalan @@ -186,6 +196,12 @@ 0.9.4 test + + junit + junit + 4.13.2 + test + org.apache.maven.plugin-tools maven-plugin-annotations diff --git a/src/test/java/org/codehaus/mojo/xml/test/AbstractXmlMojoTestCase.java b/src/test/java/org/codehaus/mojo/xml/test/AbstractXmlMojoTestCase.java index 73ed544..b9c7edf 100644 --- a/src/test/java/org/codehaus/mojo/xml/test/AbstractXmlMojoTestCase.java +++ b/src/test/java/org/codehaus/mojo/xml/test/AbstractXmlMojoTestCase.java @@ -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; @@ -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 resourceLoaders = new HashMap(); - 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; } @@ -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; - } - - } diff --git a/src/test/java/org/codehaus/mojo/xml/test/TransformMojoTest.java b/src/test/java/org/codehaus/mojo/xml/test/TransformMojoTest.java index 6ca8456..58ad29a 100644 --- a/src/test/java/org/codehaus/mojo/xml/test/TransformMojoTest.java +++ b/src/test/java/org/codehaus/mojo/xml/test/TransformMojoTest.java @@ -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" ) );