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:34 UTC

[maven] 10/12: Merge remote-tracking branch 'remotes/origin/master' into MNG-6656

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 6e624f0f3733ac711084551bb0aa9a9870f90199
Merge: e6240d5 b65e846
Author: rfscholte <rf...@apache.org>
AuthorDate: Tue Aug 20 21:08:08 2019 +0200

    Merge remote-tracking branch 'remotes/origin/master' into MNG-6656

 maven-core/pom.xml                                 |  13 +++
 .../DefaultRepositorySystemSessionFactory.java     |  19 +++-
 .../maven/project/DefaultProjectBuilder.java       |   2 +-
 .../apache/maven/project/ProjectBuilderTest.java   |  16 +++
 .../project-builder/MNG-6716/project/pom.xml       |  22 +++++
 maven-model-builder/pom.xml                        |   5 +
 .../maven/model/building/DefaultModelBuilder.java  | 109 ++++++++++++++++----
 .../StringSearchModelInterpolator.java             | 102 ++++++++-----------
 .../StringSearchModelInterpolatorTest.java         | 110 +++++++++++++++++++++
 .../apache/maven/xml/filter/BuildPomXMLFilter.java |  19 +++-
 .../maven/xml/filter/ConsumerPomXMLFilter.java     |  72 ++------------
 .../maven/xml/filter/ConsumerPomXMLFilterTest.java |   4 +-
 pom.xml                                            |   8 +-
 13 files changed, 353 insertions(+), 148 deletions(-)

diff --cc maven-core/pom.xml
index 79dc86e,be31a3e..2861a94
--- a/maven-core/pom.xml
+++ b/maven-core/pom.xml
@@@ -256,6 -247,6 +256,19 @@@ under the License
            </execution>
          </executions>
        </plugin>
++      <plugin>
++        <groupId>org.apache.maven.plugins</groupId>
++        <artifactId>maven-failsafe-plugin</artifactId>
++        <executions>
++          <execution>
++            <!--  <phase></phase> -->
++            <goals>
++              <goal>integration-test</goal>
++              <goal>verify</goal>
++            </goals>
++          </execution>
++        </executions>
++      </plugin>
      </plugins>
    </build>
  </project>
diff --cc maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
index 5ee5525,248a3b6..a291c4d
--- 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
@@@ -52,7 -32,6 +52,9 @@@ import org.apache.maven.settings.buildi
  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.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
  import org.codehaus.plexus.logging.Logger;
  import org.codehaus.plexus.util.xml.Xpp3Dom;
@@@ -75,7 -50,14 +77,10 @@@ import org.eclipse.aether.util.reposito
  import org.eclipse.aether.util.repository.DefaultProxySelector;
  import org.eclipse.aether.util.repository.SimpleResolutionErrorPolicy;
  import org.eclipse.sisu.Nullable;
 -
 -import javax.inject.Inject;
 -import javax.inject.Named;
 -import java.io.IOException;
 -import java.io.InputStream;
 -import java.util.LinkedHashMap;
 -import java.util.Map;
 -import java.util.Properties;
 +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
@@@ -110,7 -92,7 +115,7 @@@ public class DefaultRepositorySystemSes
  
      @Inject
      MavenRepositorySystem mavenRepositorySystem;
--
++    
      public DefaultRepositorySystemSession newRepositorySession( MavenExecutionRequest request )
      {
          DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
@@@ -263,66 -241,6 +268,76 @@@
          return session;
      }
  
 +    private FileTransformerManager newFileTransformerManager()
 +    {
 +        return new FileTransformerManager()
 +        {
 +            @Override
 +            public Collection<FileTransformer> getTransformersForArtifact( Artifact artifact )
 +            {
 +                Collection<FileTransformer> transformers = new ArrayList<>();
 +                if ( "pom".equals( artifact.getExtension() ) )
 +                {
 +                    final TransformerFactory transformerFactory = TransformerFactory.newInstance();
 +
 +                    transformers.add( new FileTransformer()
 +                    {
 +                        @Override
 +                        public InputStream transformData( File file )
 +                            throws IOException, TransformException
 +                        {
 +                            final PipedOutputStream pipedOutputStream  = new PipedOutputStream();
 +                            final PipedInputStream pipedInputStream  = new PipedInputStream( pipedOutputStream );
 +                            
++                            XMLReader parent;
++                            try
++                            {
++                                parent = XMLReaderFactory.createXMLReader();
++                            }
++                            catch ( SAXException e )
++                            {
++                                throw new TransformException( "Failed to create XMLReader", e );
++                            }
++                            
 +                            final SAXSource transformSource =
-                                             new SAXSource( new ConsumerPomXMLFilter( null /* @TODO bass BuildPomXMLFilter */ ), 
++                                            new SAXSource( new ConsumerPomXMLFilter( new B ), 
 +                                                           new InputSource( new FileReader( file ) ) );
 +                            
 +                            final StreamResult result = new StreamResult( pipedOutputStream );
 +                            
 +                            final Runnable runnable = new Runnable()
 +                            {
 +                                @Override
 +                                public void run()
 +                                {
 +                                    try ( PipedOutputStream out = pipedOutputStream )
 +                                    {
 +                                        transformerFactory.newTransformer().transform( transformSource, result );
 +                                    }
 +                                    catch ( TransformerException | IOException e )
 +                                    {
 +                                        throw new RuntimeException( e );
 +                                    }
 +                                }
 +                            };
 +
 +                            new Thread( runnable ).start();
 +
 +                            return pipedInputStream;
 +                        }
 +
 +                        @Override
 +                        public Artifact transformArtifact( Artifact artifact )
 +                        {
 +                            return artifact;
 +                        }
 +                    } );
 +                }
 +                return Collections.unmodifiableCollection( transformers );
 +            }
 +        };
 +    }
 +    
      private String getUserAgent()
      {
          return "Apache-Maven/" + getMavenVersion() + " (Java " + System.getProperty( "java.version" ) + "; "
diff --cc maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 7022781,f981944..50f8773
--- 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
@@@ -19,6 -19,6 +19,34 @@@ package org.apache.maven.model.building
   * under the License.
   */
  
++import static org.apache.maven.model.building.Result.error;
++import static org.apache.maven.model.building.Result.newResult;
++
++import java.io.File;
++import java.io.IOException;
++import java.io.InputStream;
++import java.io.PipedInputStream;
++import java.io.PipedOutputStream;
++import java.util.ArrayList;
++import java.util.Collection;
++import java.util.HashMap;
++import java.util.Iterator;
++import java.util.LinkedHashSet;
++import java.util.List;
++import java.util.Map;
++import java.util.Objects;
++import java.util.Properties;
++
++import javax.inject.Inject;
++import javax.inject.Named;
++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;
++import javax.xml.transform.stream.StreamResult;
  
  import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
  import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
@@@ -59,28 -59,28 +87,12 @@@ import org.apache.maven.model.resolutio
  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.codehaus.plexus.interpolation.MapBasedValueSource;
  import org.codehaus.plexus.interpolation.StringSearchInterpolator;
  import org.eclipse.sisu.Nullable;
--
--import java.io.File;
--import java.io.IOException;
--import java.util.ArrayList;
--import java.util.Collection;
--import java.util.HashMap;
--import java.util.Iterator;
--import java.util.LinkedHashSet;
--import java.util.List;
--import java.util.Map;
--import java.util.Objects;
--import java.util.Properties;
--
--import javax.inject.Inject;
--import javax.inject.Named;
--import javax.inject.Singleton;
--
--import static org.apache.maven.model.building.Result.error;
--import static org.apache.maven.model.building.Result.newResult;
++import org.xml.sax.SAXException;
++import org.xml.sax.XMLReader;
  
  /**
   * @author Benjamin Bentmann
@@@ -740,19 -739,7 +752,76 @@@ public class DefaultModelBuilde
              Model child = lineage.get( i ).getModel();
              inheritanceAssembler.assembleModelInheritance( child, parent, request, problems );
          }
 +        
 +        // re-read model from file
 +        if ( Boolean.getBoolean( "maven.experimental.buildconsumer" ) )
 +        {
-             throw new UnsupportedOperationException();
++            try
++            {
++                // 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 );
++                inheritanceAssembler.assembleModelInheritance( child, parent, request, problems );
++            }
++            finally
++//            catch ( IOException e )
++            {
++                // this is second read, should not happen
++            }
 +        }
 +        else
 +        {
 +            Model parent = lineage.get( 1 ).getModel();
 +            Model child = lineage.get( 0 ).getModel();
 +            inheritanceAssembler.assembleModelInheritance( child, parent, request, problems );
 +        }
 +    }
++    
++    private InputStream transformData( InputStream inputStream )
++                    throws IOException, TransformException
++    {
++        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 ) );
++        
++        final StreamResult result = new StreamResult( pipedOutputStream );
++        
++        final Runnable runnable = new Runnable()
++        {
++            @Override
++            public void run()
++            {
++                try ( PipedOutputStream out = pipedOutputStream )
++                {
++                    transformerFactory.newTransformer().transform( transformSource, result );
++                }
++                catch ( TransformerException | IOException e )
++                {
++                    throw new RuntimeException( e );
++                }
++            }
++        };
++
++        new Thread( runnable ).start();
++
++        return pipedInputStream;
+     }
  
      private Map<String, Activation> getProfileActivations( Model model, boolean clone )
      {
diff --cc maven-xml/src/main/java/org/apache/maven/xml/filter/BuildPomXMLFilter.java
index 58d219b,0000000..9e8d261
mode 100644,000000..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,35 -1,0 +1,50 @@@
 +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
 + * 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;
 +
 +/**
 + * Filter to adjust pom on filesystem before being processed for effective pom.
++ * There should only be 1 BuildPomXMLFilter, so the same is being used by both
++ * org.apache.maven.model.building.DefaultModelBuilder.transformData(InputStream) and
++ * org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory.newFileTransformerManager()
++ * 
 + * 
 + * @author Robert Scholte
 + * @since 3.7.0
 + */
- public class BuildPomXMLFilter extends XMLFilterImpl
++public class BuildPomXMLFilter extends XMLFilterImpl 
 +{
++    private XMLFilter rootFilter;
 +    
++    BuildPomXMLFilter()
++    {
++        super();
++    }
 +
-     
++    BuildPomXMLFilter( XMLReader parent )
++    {
++        super( parent );
++    }
 +}
diff --cc maven-xml/src/main/java/org/apache/maven/xml/filter/ConsumerPomXMLFilter.java
index a367419,0000000..6c2ea9f
mode 100644,000000..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,88 -1,0 +1,36 @@@
 +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 javax.xml.parsers.ParserConfigurationException;
- import javax.xml.parsers.SAXParserFactory;
- 
- import org.xml.sax.SAXException;
- import org.xml.sax.XMLFilter;
 +import org.xml.sax.XMLReader;
- 
 +import org.xml.sax.helpers.XMLFilterImpl;
 +
 +/**
 + * XML Filter to transform pom.xml to consumer pom.
 + * This often means stripping of build-specific information.
 + * When extra information is required during filtering it is probably a member of the BuildPomXMLFilter
 + * 
 + * This filter is used at 2 locations:
 + * - {@link org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory} when publishing pom files.
 + * - TODO ???Class when a reactor module is used as dependency. This ensures consistency of dependency handling
 + * 
 + * @author Robert Scholte
 + * @since 3.7.0
 + */
 +public class ConsumerPomXMLFilter extends XMLFilterImpl
 +{
-     private final XMLFilter rootFilter;
- 
-     // only for testing purpose
-     ConsumerPomXMLFilter() throws SAXException, ParserConfigurationException
-     {
-         this( SAXParserFactory.newInstance().newSAXParser().getXMLReader() );
-     }
-     
-     // only for testing purpose
-     ConsumerPomXMLFilter( XMLReader parent )
-     {
-         this.rootFilter = new XMLFilterImpl( parent );
-         
-         applyFilters();
-     }
-     
-     public ConsumerPomXMLFilter( BuildPomXMLFilter buildPomXMLFilter )
-     {
-         this.rootFilter = buildPomXMLFilter;
-         
-         applyFilters();
-     }
-     
-     private void applyFilters()
++    ConsumerPomXMLFilter( XMLReader filter )
 +    {
-         // Ensure that xs:any elements aren't touched by next filters
-         XMLFilter filter = new FastForwardFilter( rootFilter );
-         
-         // Strip modules
-         filter = new ModulesXMLFilter( filter );
-         // Adjust relativePath
-         filter = new RelativePathXMLFilter( filter );
-         
-         // maybe more to follow
-         
-         super.setParent( filter );
++        super( filter );
 +    }
 +    
++    /**
++     * Don't allow overwriting parent
++     */
 +    @Override
-     public void setParent( XMLReader parent )
++    public final void setParent( XMLReader parent )
 +    {
-         rootFilter.setParent( parent );
++        if ( getParent() == null )
++        {
++            super.setParent( parent );
++        }
 +    }
 +}
diff --cc maven-xml/src/test/java/org/apache/maven/xml/filter/ConsumerPomXMLFilterTest.java
index b3d44db,0000000..a169b13
mode 100644,000000..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
@@@ -1,64 -1,0 +1,66 @@@
 +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 static org.xmlunit.assertj.XmlAssert.assertThat;
 +
++import javax.xml.parsers.SAXParserFactory;
++
 +import org.junit.Before;
 +import org.junit.Test;
 +
 +public class ConsumerPomXMLFilterTest extends AbstractXMLFilterTests
 +{
 +    private ConsumerPomXMLFilter filter;
 +    
 +    @Before
 +    public void setup() throws Exception {
-         filter = new ConsumerPomXMLFilter();
++        filter = new ConsumerPomXMLFilterFactory(){}.get( new BuildPomXMLFilter( SAXParserFactory.newInstance().newSAXParser().getXMLReader()  ) );
 +    }
 +    
 +    @Test
 +    public void testAllFilters() throws Exception {
 +        String input = "<project>\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"
 +                     + "  <modules>\n"
 +                     + "    <module>ab</module>\n"
 +                     + "    <module>../cd</module>\n"
 +                     + "  </modules>\n"
 +                     + "</project>";
 +        String expected = "<project>\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, filter );
 +        assertThat( actual ).and( expected ).ignoreWhitespace().areIdentical();
 +    }
 +
 +}
diff --cc pom.xml
index da0b9de,7b59454..bed2633
--- a/pom.xml
+++ b/pom.xml
@@@ -64,9 -64,10 +64,10 @@@ under the License
      <cipherVersion>1.7</cipherVersion>
      <modelloVersion>1.11</modelloVersion>
      <jxpathVersion>1.3</jxpathVersion>
-     <resolverVersion>1.3.3</resolverVersion>
+     <resolverVersion>1.4.1</resolverVersion>
      <slf4jVersion>1.7.25</slf4jVersion>
 -    <xmlunitVersion>2.2.1</xmlunitVersion>
 +    <xmlunitVersion>2.6.2</xmlunitVersion>
+     <powermockVersion>1.7.4</powermockVersion>
      <maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
      <!-- Control the name of the distribution and information output by mvn -->
      <distributionId>apache-maven</distributionId>