You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2019/08/24 16:25:35 UTC
[maven] 11/12: Move Filters to maven-xml filter,
so it can be picked up by maven-model-builder and maven-core
Provide BuildPomXMlFilter to set CI Friendly properties
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch MNG-6656
in repository https://gitbox.apache.org/repos/asf/maven.git
commit 5065aecb27fdc1d825d9d53c71e72f422b0d4c70
Author: rfscholte <rf...@apache.org>
AuthorDate: Sat Aug 24 18:10:31 2019 +0200
Move Filters to maven-xml filter, so it can be picked up by maven-model-builder and maven-core
Provide BuildPomXMlFilter to set CI Friendly properties
---
.../DefaultRepositorySystemSessionFactory.java | 32 ++++---
.../maven/model/building/DefaultModelBuilder.java | 40 ++++----
maven-xml/pom.xml | 5 +
.../apache/maven/xml/filter/BuildPomXMLFilter.java | 13 ++-
.../maven/xml/filter/ConsumerPomXMLFilter.java | 19 ++++
.../apache/maven/xml/filter/FastForwardFilter.java | 2 +-
.../maven/xml/filter/RelativePathXMLFilter.java | 1 +
.../maven/xml/filter/AbstractXMLFilterTests.java | 33 ++++---
.../maven/xml/filter/ConsumerPomXMLFilterTest.java | 103 +++++++++++++++++++--
.../maven/xml/filter/ModulesXMLFilterTest.java | 22 ++++-
.../xml/filter/RelativePathXMLFilterTest.java | 75 +++++++++++++--
11 files changed, 264 insertions(+), 81 deletions(-)
diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
index a291c4d..20bd449 100644
--- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
+++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
@@ -34,6 +34,7 @@ import java.util.Properties;
import javax.inject.Inject;
import javax.inject.Named;
+import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXSource;
@@ -52,9 +53,7 @@ import org.apache.maven.settings.building.SettingsProblem;
import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
import org.apache.maven.settings.crypto.SettingsDecrypter;
import org.apache.maven.settings.crypto.SettingsDecryptionResult;
-import org.apache.maven.xml.filter.BuildPomXMLFilter;
-import org.apache.maven.xml.filter.BuildPomXMLFilterFactory;
-import org.apache.maven.xml.filter.ConsumerPomXMLFilter;
+import org.apache.maven.xml.filter.ConsumerPomXMLFilterFactory;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.xml.Xpp3Dom;
@@ -79,8 +78,6 @@ import org.eclipse.aether.util.repository.SimpleResolutionErrorPolicy;
import org.eclipse.sisu.Nullable;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
/**
* @since 3.3.0
@@ -116,6 +113,9 @@ public class DefaultRepositorySystemSessionFactory
@Inject
MavenRepositorySystem mavenRepositorySystem;
+ @Inject
+ private ConsumerPomXMLFilterFactory consumerPomXMLFilterFactory;
+
public DefaultRepositorySystemSession newRepositorySession( MavenExecutionRequest request )
{
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
@@ -273,7 +273,7 @@ public class DefaultRepositorySystemSessionFactory
return new FileTransformerManager()
{
@Override
- public Collection<FileTransformer> getTransformersForArtifact( Artifact artifact )
+ public Collection<FileTransformer> getTransformersForArtifact( final Artifact artifact )
{
Collection<FileTransformer> transformers = new ArrayList<>();
if ( "pom".equals( artifact.getExtension() ) )
@@ -286,23 +286,24 @@ public class DefaultRepositorySystemSessionFactory
public InputStream transformData( File file )
throws IOException, TransformException
{
+ System.out.println( "transforming " + file.getAbsolutePath() );
final PipedOutputStream pipedOutputStream = new PipedOutputStream();
final PipedInputStream pipedInputStream = new PipedInputStream( pipedOutputStream );
- XMLReader parent;
+ final SAXSource transformSource;
try
{
- parent = XMLReaderFactory.createXMLReader();
+ transformSource =
+ new SAXSource( consumerPomXMLFilterFactory.get( artifact.getGroupId(),
+ artifact.getArtifactId() ),
+ new InputSource( new FileReader( file ) ) );
}
- catch ( SAXException e )
- {
- throw new TransformException( "Failed to create XMLReader", e );
+ catch ( SAXException | ParserConfigurationException e )
+ {
+ e.printStackTrace();
+ throw new TransformException( "Failed to create a consumerPomXMLFilter", e );
}
- final SAXSource transformSource =
- new SAXSource( new ConsumerPomXMLFilter( new B ),
- new InputSource( new FileReader( file ) ) );
-
final StreamResult result = new StreamResult( pipedOutputStream );
final Runnable runnable = new Runnable()
@@ -316,6 +317,7 @@ public class DefaultRepositorySystemSessionFactory
}
catch ( TransformerException | IOException e )
{
+ e.printStackTrace();
throw new RuntimeException( e );
}
}
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 50f8773..1fea6dd 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -39,10 +39,10 @@ import java.util.Properties;
import javax.inject.Inject;
import javax.inject.Named;
+import javax.inject.Provider;
import javax.inject.Singleton;
import javax.xml.crypto.dsig.TransformException;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXSource;
@@ -87,12 +87,11 @@ import org.apache.maven.model.resolution.UnresolvableModelException;
import org.apache.maven.model.resolution.WorkspaceModelResolver;
import org.apache.maven.model.superpom.SuperPomProvider;
import org.apache.maven.model.validation.ModelValidator;
-import org.apache.maven.xml.filter.BuildPomXMLFilter;
+import org.apache.maven.xml.filter.BuildPomXMLFilterFactory;
import org.codehaus.plexus.interpolation.MapBasedValueSource;
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
import org.eclipse.sisu.Nullable;
import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
/**
* @author Benjamin Bentmann
@@ -153,6 +152,9 @@ public class DefaultModelBuilder
@Inject
private ReportingConverter reportingConverter;
+
+ @Inject
+ private Provider<BuildPomXMLFilterFactory> buildPomXMLFilterFactory;
public DefaultModelBuilder setModelProcessor( ModelProcessor modelProcessor )
{
@@ -561,7 +563,6 @@ public class DefaultModelBuilder
try
{
- // RFS adjust inputstream
model = modelProcessor.read( modelSource.getInputStream(), options );
}
catch ( ModelParseException e )
@@ -760,14 +761,19 @@ public class DefaultModelBuilder
{
// TODO: parent might be part of reactor... better read all lineage items like this?
Model parent = lineage.get( 1 ).getModel();
- Model child = lineage.get( 0 ).getModel();
- // modelProcessor.read( lineage.get( 0 ).getSource().getInputStream(), null );
+
+ Model child = modelProcessor.read( transformData( lineage.get( 0 ) ), null );
inheritanceAssembler.assembleModelInheritance( child, parent, request, problems );
+
+ // sync pomfile, is transient
+ child.setPomFile( lineage.get( 0 ).getModel().getPomFile() );
+ // overwrite child
+ lineage.get( 0 ).setModel( child );
}
- finally
-// catch ( IOException e )
+ catch ( IOException | TransformException | SAXException | ParserConfigurationException e )
{
// this is second read, should not happen
+ e.printStackTrace();
}
}
else
@@ -778,27 +784,17 @@ public class DefaultModelBuilder
}
}
- private InputStream transformData( InputStream inputStream )
- throws IOException, TransformException
+ private InputStream transformData( ModelData modelData )
+ throws IOException, TransformException, SAXException, ParserConfigurationException
{
final TransformerFactory transformerFactory = TransformerFactory.newInstance();
final PipedOutputStream pipedOutputStream = new PipedOutputStream();
final PipedInputStream pipedInputStream = new PipedInputStream( pipedOutputStream );
- XMLReader parent;
- try
- {
- parent = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
- }
- catch ( SAXException | ParserConfigurationException e )
- {
- throw new TransformException( "Failed to create XMLReader", e );
- }
-
final SAXSource transformSource =
- new SAXSource( new BuildPomXMLFilter( parent ),
- new org.xml.sax.InputSource( inputStream ) );
+ new SAXSource( buildPomXMLFilterFactory.get().get( modelData.getGroupId(), modelData.getArtifactId() ),
+ new org.xml.sax.InputSource( modelData.getSource().getInputStream() ) );
final StreamResult result = new StreamResult( pipedOutputStream );
diff --git a/maven-xml/pom.xml b/maven-xml/pom.xml
index aeef99e..1c57690 100644
--- a/maven-xml/pom.xml
+++ b/maven-xml/pom.xml
@@ -54,6 +54,11 @@ under the License.
<dependencies>
<dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-assertj</artifactId>
<scope>test</scope>
diff --git a/maven-xml/src/main/java/org/apache/maven/xml/filter/BuildPomXMLFilter.java b/maven-xml/src/main/java/org/apache/maven/xml/filter/BuildPomXMLFilter.java
index 9e8d261..ab846a0 100644
--- a/maven-xml/src/main/java/org/apache/maven/xml/filter/BuildPomXMLFilter.java
+++ b/maven-xml/src/main/java/org/apache/maven/xml/filter/BuildPomXMLFilter.java
@@ -1,7 +1,5 @@
package org.apache.maven.xml.filter;
-import org.xml.sax.XMLFilter;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -36,8 +34,6 @@ import org.xml.sax.helpers.XMLFilterImpl;
*/
public class BuildPomXMLFilter extends XMLFilterImpl
{
- private XMLFilter rootFilter;
-
BuildPomXMLFilter()
{
super();
@@ -47,4 +43,13 @@ public class BuildPomXMLFilter extends XMLFilterImpl
{
super( parent );
}
+
+ @Override
+ public final void setParent( XMLReader parent )
+ {
+ if ( getParent() == null )
+ {
+ super.setParent( parent );
+ }
+ }
}
diff --git a/maven-xml/src/main/java/org/apache/maven/xml/filter/ConsumerPomXMLFilter.java b/maven-xml/src/main/java/org/apache/maven/xml/filter/ConsumerPomXMLFilter.java
index 6c2ea9f..9975c22 100644
--- a/maven-xml/src/main/java/org/apache/maven/xml/filter/ConsumerPomXMLFilter.java
+++ b/maven-xml/src/main/java/org/apache/maven/xml/filter/ConsumerPomXMLFilter.java
@@ -1,5 +1,24 @@
package org.apache.maven.xml.filter;
+/*
+ * 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.
+ */
+
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLFilterImpl;
diff --git a/maven-xml/src/main/java/org/apache/maven/xml/filter/FastForwardFilter.java b/maven-xml/src/main/java/org/apache/maven/xml/filter/FastForwardFilter.java
index df68167..6e03a34 100644
--- a/maven-xml/src/main/java/org/apache/maven/xml/filter/FastForwardFilter.java
+++ b/maven-xml/src/main/java/org/apache/maven/xml/filter/FastForwardFilter.java
@@ -34,7 +34,7 @@ import org.xml.sax.helpers.XMLFilterImpl;
* Should be used in case of a DOM that should not be effected by other filters, even though the elements match
*
* @author Robert Scholte
- * @since 4.0.0
+ * @since 3.7.0
*/
class FastForwardFilter extends XMLFilterImpl
{
diff --git a/maven-xml/src/main/java/org/apache/maven/xml/filter/RelativePathXMLFilter.java b/maven-xml/src/main/java/org/apache/maven/xml/filter/RelativePathXMLFilter.java
index 8548ddd..5dc367f 100644
--- a/maven-xml/src/main/java/org/apache/maven/xml/filter/RelativePathXMLFilter.java
+++ b/maven-xml/src/main/java/org/apache/maven/xml/filter/RelativePathXMLFilter.java
@@ -57,6 +57,7 @@ class RelativePathXMLFilter
public void startElement( String uri, String localName, String qName, Attributes atts )
throws SAXException
{
+
if ( relativePathStatus == -1 && "relativePath".equals( localName ) )
{
relativePathStatus = 1;
diff --git a/maven-xml/src/test/java/org/apache/maven/xml/filter/AbstractXMLFilterTests.java b/maven-xml/src/test/java/org/apache/maven/xml/filter/AbstractXMLFilterTests.java
index 69fc33b..4ee0e31 100644
--- a/maven-xml/src/test/java/org/apache/maven/xml/filter/AbstractXMLFilterTests.java
+++ b/maven-xml/src/test/java/org/apache/maven/xml/filter/AbstractXMLFilterTests.java
@@ -1,7 +1,5 @@
package org.apache.maven.xml.filter;
-import java.io.Reader;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -21,10 +19,13 @@ import java.io.Reader;
* under the License.
*/
+import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
@@ -35,34 +36,32 @@ import javax.xml.transform.stream.StreamResult;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLFilter;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
-public class AbstractXMLFilterTests
+public abstract class AbstractXMLFilterTests
{
-
public AbstractXMLFilterTests()
{
super();
}
+
+ protected abstract XMLFilter getFilter() throws TransformerException, SAXException, ParserConfigurationException;
+
- protected String transform( String input, XMLFilter filter )
- throws TransformerException, SAXException
+ protected String transform( String input )
+ throws TransformerException, SAXException, ParserConfigurationException
{
- return transform( new StringReader( input ), filter );
+ return transform( new StringReader( input ) );
}
- protected String transform( Reader input, XMLFilter filter )
- throws TransformerException, SAXException
+ protected String transform( Reader input )
+ throws TransformerException, SAXException, ParserConfigurationException
{
- XMLReader reader = XMLReaderFactory.createXMLReader();
-
- XMLFilter parent = filter;
- while ( parent.getParent() instanceof XMLFilter )
+ XMLFilter filter = getFilter();
+ if( filter.getParent() == null )
{
- parent = (XMLFilter) parent.getParent();
+ filter.setParent( SAXParserFactory.newInstance().newSAXParser().getXMLReader() );
+ filter.setFeature( "http://xml.org/sax/features/namespaces", true );
}
- parent.setParent( reader );
Writer writer = new StringWriter();
StreamResult result = new StreamResult( writer );
diff --git a/maven-xml/src/test/java/org/apache/maven/xml/filter/ConsumerPomXMLFilterTest.java b/maven-xml/src/test/java/org/apache/maven/xml/filter/ConsumerPomXMLFilterTest.java
index a169b13..8fe2d67 100644
--- a/maven-xml/src/test/java/org/apache/maven/xml/filter/ConsumerPomXMLFilterTest.java
+++ b/maven-xml/src/test/java/org/apache/maven/xml/filter/ConsumerPomXMLFilterTest.java
@@ -21,18 +21,56 @@ package org.apache.maven.xml.filter;
import static org.xmlunit.assertj.XmlAssert.assertThat;
-import javax.xml.parsers.SAXParserFactory;
+import java.util.Optional;
+
+import javax.inject.Provider;
+import javax.xml.parsers.ParserConfigurationException;
-import org.junit.Before;
import org.junit.Test;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLFilter;
public class ConsumerPomXMLFilterTest extends AbstractXMLFilterTests
{
- private ConsumerPomXMLFilter filter;
-
- @Before
- public void setup() throws Exception {
- filter = new ConsumerPomXMLFilterFactory(){}.get( new BuildPomXMLFilter( SAXParserFactory.newInstance().newSAXParser().getXMLReader() ) );
+ @Override
+ protected XMLFilter getFilter() throws SAXException, ParserConfigurationException
+ {
+ final BuildPomXMLFilterFactory buildPomXMLFilterFactory = new BuildPomXMLFilterFactory()
+ {
+ @Override
+ protected Optional<String> getSha1()
+ {
+ return Optional.empty();
+ }
+
+ @Override
+ protected Optional<String> getRevision()
+ {
+ return Optional.empty();
+ }
+
+ @Override
+ protected Optional<String> getChangelist()
+ {
+ return Optional.of( "CL" );
+ }
+ };
+
+ Provider<BuildPomXMLFilterFactory> provider = new Provider<BuildPomXMLFilterFactory>()
+ {
+
+ @Override
+ public BuildPomXMLFilterFactory get()
+ {
+ return buildPomXMLFilterFactory;
+ }
+ };
+
+ XMLFilter filter = new ConsumerPomXMLFilterFactory( provider )
+ {
+ }.get( "G", "A" );
+ filter.setFeature( "http://xml.org/sax/features/namespaces", true );
+ return filter;
}
@Test
@@ -59,8 +97,57 @@ public class ConsumerPomXMLFilterTest extends AbstractXMLFilterTests
+ " </parent>\n"
+ " <artifactId>PROJECT</artifactId>\n"
+ "</project>";
- String actual = transform( input, filter );
+ String actual = transform( input );
assertThat( actual ).and( expected ).ignoreWhitespace().areIdentical();
}
+
+ @Test
+ public void testMe() throws Exception {
+ String input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" +
+ "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" \r\n" +
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" +
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 \r\n" +
+ " http://maven.apache.org/maven-v4_0_0.xsd\">\r\n" +
+ " <modelVersion>4.0.0</modelVersion>\r\n" +
+ " <groupId>org.sonatype.mavenbook.multispring</groupId>\r\n" +
+ " <artifactId>parent</artifactId>\r\n" +
+ " <version>0.9-${changelist}-SNAPSHOT</version>\r\n" +
+ " <packaging>pom</packaging>\r\n" +
+ " <name>Multi-Spring Chapter Parent Project</name>\r\n" +
+ " <modules>\r\n" +
+ " <module>simple-parent</module>\r\n" +
+ " </modules>\r\n" +
+ " \r\n" +
+ " <pluginRepositories>\r\n" +
+ " <pluginRepository>\r\n" +
+ " <id>apache.snapshots</id>\r\n" +
+ " <url>http://repository.apache.org/snapshots/</url>\r\n" +
+ " </pluginRepository>\r\n" +
+ " </pluginRepositories>\r\n" +
+ "</project>";
+ String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" +
+ "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" \r\n" +
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" +
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 \r\n" +
+ " http://maven.apache.org/maven-v4_0_0.xsd\">\r\n" +
+ " <modelVersion>4.0.0</modelVersion>\r\n" +
+ " <groupId>org.sonatype.mavenbook.multispring</groupId>\r\n" +
+ " <artifactId>parent</artifactId>\r\n" +
+ " <version>0.9-CL-SNAPSHOT</version>\r\n" +
+ " <packaging>pom</packaging>\r\n" +
+ " <name>Multi-Spring Chapter Parent Project</name>\r\n" +
+ " \r\n" +
+ " <pluginRepositories>\r\n" +
+ " <pluginRepository>\r\n" +
+ " <id>apache.snapshots</id>\r\n" +
+ " <url>http://repository.apache.org/snapshots/</url>\r\n" +
+ " </pluginRepository>\r\n" +
+ " </pluginRepositories>\r\n" +
+ "</project>";
+ String actual = transform( input );
+ assertThat( actual ).and( expected ).ignoreWhitespace().areIdentical();
+ }
+
+
}
diff --git a/maven-xml/src/test/java/org/apache/maven/xml/filter/ModulesXMLFilterTest.java b/maven-xml/src/test/java/org/apache/maven/xml/filter/ModulesXMLFilterTest.java
index 353f174..63880ed 100644
--- a/maven-xml/src/test/java/org/apache/maven/xml/filter/ModulesXMLFilterTest.java
+++ b/maven-xml/src/test/java/org/apache/maven/xml/filter/ModulesXMLFilterTest.java
@@ -21,23 +21,35 @@ package org.apache.maven.xml.filter;
import static org.xmlunit.assertj.XmlAssert.assertThat;
+import javax.xml.parsers.SAXParserFactory;
+
import org.junit.Before;
import org.junit.Test;
+import org.xml.sax.XMLFilter;
+import org.xml.sax.XMLReader;
public class ModulesXMLFilterTest extends AbstractXMLFilterTests {
private ModulesXMLFilter filter;
+
+ @Override
+ protected XMLFilter getFilter()
+ {
+ return new ModulesXMLFilter();
+ }
@Before
- public void setup() {
- filter = new ModulesXMLFilter();
+ public void setup() throws Exception {
+ XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
+ filter = new ModulesXMLFilter( xmlReader );
+ filter.setFeature( "http://xml.org/sax/features/namespaces", true );
}
@Test
public void testEmptyModules() throws Exception {
String input = "<project><modules/></project>";
String expected = "<project/>";
- String actual = transform( input, filter );
+ String actual = transform( input );
assertThat( actual ).and( expected ).areIdentical();
}
@@ -48,7 +60,7 @@ public class ModulesXMLFilterTest extends AbstractXMLFilterTests {
+ "<module>../cd</module>"
+ "</modules></project>";
String expected = "<project/>";
- String actual = transform( input, filter );
+ String actual = transform( input );
assertThat( actual ).and( expected ).areIdentical();
}
@@ -56,7 +68,7 @@ public class ModulesXMLFilterTest extends AbstractXMLFilterTests {
public void testNoModules() throws Exception {
String input = "<project><name>NAME</name></project>";
String expected = input;
- String actual = transform( input, filter );
+ String actual = transform( input );
assertThat( actual ).and( expected ).areIdentical();
}
}
diff --git a/maven-xml/src/test/java/org/apache/maven/xml/filter/RelativePathXMLFilterTest.java b/maven-xml/src/test/java/org/apache/maven/xml/filter/RelativePathXMLFilterTest.java
index 298197d..1fed1ca 100644
--- a/maven-xml/src/test/java/org/apache/maven/xml/filter/RelativePathXMLFilterTest.java
+++ b/maven-xml/src/test/java/org/apache/maven/xml/filter/RelativePathXMLFilterTest.java
@@ -1,7 +1,5 @@
package org.apache.maven.xml.filter;
-import static org.xmlunit.assertj.XmlAssert.assertThat;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -21,16 +19,17 @@ import static org.xmlunit.assertj.XmlAssert.assertThat;
* under the License.
*/
-import org.junit.Before;
+import static org.xmlunit.assertj.XmlAssert.assertThat;
+
import org.junit.Test;
+import org.xml.sax.XMLFilter;
public class RelativePathXMLFilterTest extends AbstractXMLFilterTests
{
- private RelativePathXMLFilter filter;
-
- @Before
- public void setup() {
- filter = new RelativePathXMLFilter();
+ @Override
+ protected XMLFilter getFilter()
+ {
+ return new RelativePathXMLFilter();
}
@Test
@@ -54,7 +53,65 @@ public class RelativePathXMLFilterTest extends AbstractXMLFilterTests
+ " </parent>\n"
+ " <artifactId>PROJECT</artifactId>\n"
+ "</project>";
- String actual = transform( input, filter );
+ String actual = transform( input );
+ assertThat( actual ).and( expected ).areIdentical();
+ }
+
+ @Test
+ public void testRelativePathNS() throws Exception
+ {
+ String input = "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" +
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n"
+ + " <parent>\n"
+ + " <groupId>GROUPID</groupId>\n"
+ + " <artifactId>PARENT</artifactId>\n"
+ + " <version>VERSION</version>\n"
+ + " <relativePath>../pom.xml</relativePath>\n"
+ + " </parent>\n"
+ + " <artifactId>PROJECT</artifactId>\n"
+ + "</project>";
+ String expected = "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" +
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n"
+ + " <parent>\n"
+ + " <groupId>GROUPID</groupId>\n"
+ + " <artifactId>PARENT</artifactId>\n"
+ + " <version>VERSION</version>\n"
+ + " <relativePath/>\n"
+ + " </parent>\n"
+ + " <artifactId>PROJECT</artifactId>\n"
+ + "</project>";
+ String actual = transform( input );
+ assertThat( actual ).and( expected ).areIdentical();
+ }
+
+ @Test
+ public void testRelativePathPasNS() throws Exception
+ {
+ String input = "<p:project xmlns:p=\"http://maven.apache.org/POM/4.0.0\"\n" +
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n"
+ + " <p:parent>\n"
+ + " <p:groupId>GROUPID</p:groupId>\n"
+ + " <p:artifactId>PARENT</p:artifactId>\n"
+ + " <p:version>VERSION</p:version>\n"
+ + " <p:relativePath>../pom.xml</p:relativePath>\n"
+ + " </p:parent>\n"
+ + " <p:artifactId>PROJECT</p:artifactId>\n"
+ + "</p:project>";
+ String expected = "<p:project xmlns:p=\"http://maven.apache.org/POM/4.0.0\"\n" +
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n"
+ + " <p:parent>\n"
+ + " <p:groupId>GROUPID</p:groupId>\n"
+ + " <p:artifactId>PARENT</p:artifactId>\n"
+ + " <p:version>VERSION</p:version>\n"
+ + " <p:relativePath/>\n"
+ + " </p:parent>\n"
+ + " <p:artifactId>PROJECT</p:artifactId>\n"
+ + "</p:project>";
+ String actual = transform( input );
assertThat( actual ).and( expected ).areIdentical();
}