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:36:10 UTC

[maven] branch MNG-6656 updated: Add missing classes

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


The following commit(s) were added to refs/heads/MNG-6656 by this push:
     new 82d8693  Add missing classes
82d8693 is described below

commit 82d8693fad39cbe5217bcf1a9518f548a2444eb1
Author: rfscholte <rf...@apache.org>
AuthorDate: Sat Aug 24 18:36:02 2019 +0200

    Add missing classes
---
 .../internal/DefaultBuildPomXMLFilterFactory.java  | 69 ++++++++++++++++++
 .../DefaultConsumerPomXMLFilterFactory.java        | 37 ++++++++++
 .../maven/xml/filter/BuildPomXMLFilterFactory.java | 70 ++++++++++++++++++
 .../maven/xml/filter/CiFriendlyXMLFilter.java      | 84 ++++++++++++++++++++++
 .../xml/filter/ConsumerPomXMLFilterFactory.java    | 65 +++++++++++++++++
 5 files changed, 325 insertions(+)

diff --git a/maven-core/src/main/java/org/apache/maven/xml/internal/DefaultBuildPomXMLFilterFactory.java b/maven-core/src/main/java/org/apache/maven/xml/internal/DefaultBuildPomXMLFilterFactory.java
new file mode 100644
index 0000000..0b51da2
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/xml/internal/DefaultBuildPomXMLFilterFactory.java
@@ -0,0 +1,69 @@
+package org.apache.maven.xml.internal;
+
+/*
+ * 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 java.util.Optional;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+//import javax.inject.Provider;
+import javax.inject.Singleton;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.xml.filter.BuildPomXMLFilterFactory;
+import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
+
+/**
+ * 
+ * @author Robert Scholte
+ * @since 3.7.0
+ */
+@Named
+@Singleton
+@IgnoreJRERequirement( )
+public class DefaultBuildPomXMLFilterFactory extends BuildPomXMLFilterFactory
+{
+    private MavenSession session;
+    
+    @Inject
+    public DefaultBuildPomXMLFilterFactory( MavenSession session )
+    {
+        this.session = session;
+    }
+
+    @Override
+    protected Optional<String> getChangelist()
+    {
+        return Optional.ofNullable( session.getUserProperties().getProperty( "changelist" ) );
+    }
+
+    @Override
+    protected Optional<String> getRevision()
+    {
+        return Optional.ofNullable( session.getUserProperties().getProperty( "revision" ) );
+    }
+
+    @Override
+    protected Optional<String> getSha1()
+    {
+        return Optional.ofNullable( session.getUserProperties().getProperty( "sha1" ) );
+    }
+
+}
diff --git a/maven-core/src/main/java/org/apache/maven/xml/internal/DefaultConsumerPomXMLFilterFactory.java b/maven-core/src/main/java/org/apache/maven/xml/internal/DefaultConsumerPomXMLFilterFactory.java
new file mode 100644
index 0000000..af05bc3
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/xml/internal/DefaultConsumerPomXMLFilterFactory.java
@@ -0,0 +1,37 @@
+package org.apache.maven.xml.internal;
+
+/*
+ * 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.inject.Named;
+import javax.inject.Singleton;
+
+import org.apache.maven.xml.filter.ConsumerPomXMLFilterFactory;
+
+/**
+ * 
+ * @author Robert Scholte
+ * @since 3.7.0
+ */
+@Named
+@Singleton
+public class DefaultConsumerPomXMLFilterFactory extends ConsumerPomXMLFilterFactory
+{
+
+}
diff --git a/maven-xml/src/main/java/org/apache/maven/xml/filter/BuildPomXMLFilterFactory.java b/maven-xml/src/main/java/org/apache/maven/xml/filter/BuildPomXMLFilterFactory.java
new file mode 100644
index 0000000..03cad01
--- /dev/null
+++ b/maven-xml/src/main/java/org/apache/maven/xml/filter/BuildPomXMLFilterFactory.java
@@ -0,0 +1,70 @@
+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 java.util.Optional;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
+/**
+ * 
+ * @author Robert Scholte
+ * 
+ * @since 3.7.0
+ */
+public abstract class BuildPomXMLFilterFactory
+{
+    public final BuildPomXMLFilter get( String groupId, String artifactId )
+        throws SAXException, ParserConfigurationException
+    {
+        CiFriendlyXMLFilter filter = new CiFriendlyXMLFilter();
+        getChangelist().ifPresent( filter::setChangelist  );
+        getRevision().ifPresent( filter::setRevision );
+        getSha1().ifPresent( filter::setSha1 );
+        
+        if ( filter.isSet() )
+        {
+            filter.setParent( getParent() );
+            return new BuildPomXMLFilter( filter );
+        }
+        else
+        {
+            return new BuildPomXMLFilter( getParent() );
+        }
+    }
+    
+    protected XMLReader getParent() throws SAXException, ParserConfigurationException 
+    {
+        XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
+        xmlReader.setFeature( "http://xml.org/sax/features/namespaces", true );
+        return xmlReader;
+    }
+    
+    // For CIFriendly
+    protected abstract Optional<String> getChangelist();
+        
+    protected abstract Optional<String> getRevision();
+    
+    protected abstract Optional<String> getSha1();
+}
diff --git a/maven-xml/src/main/java/org/apache/maven/xml/filter/CiFriendlyXMLFilter.java b/maven-xml/src/main/java/org/apache/maven/xml/filter/CiFriendlyXMLFilter.java
new file mode 100644
index 0000000..7f8c206
--- /dev/null
+++ b/maven-xml/src/main/java/org/apache/maven/xml/filter/CiFriendlyXMLFilter.java
@@ -0,0 +1,84 @@
+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 java.util.function.Function;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.XMLFilterImpl;
+
+/**
+ * Resolves all ci-friendly properties occurrences
+ * 
+ * @author Robert Scholte
+ * @since 3.7.0
+ */
+class CiFriendlyXMLFilter
+    extends XMLFilterImpl
+{
+    private Function<String, String> replaceChain = Function.identity();
+    
+    public CiFriendlyXMLFilter setChangelist( String changelist )
+    {
+        replaceChain = replaceChain.andThen( t -> t.replace( "${changelist}", changelist ) );
+        return this;
+    }
+    
+    public CiFriendlyXMLFilter setRevision( String revision )
+    {
+        replaceChain = replaceChain.andThen( t -> t.replace( "${revision}", revision ) );
+        return this;
+    }
+
+    public CiFriendlyXMLFilter setSha1( String sha1 )
+    {
+        replaceChain = replaceChain.andThen( t -> t.replace( "${sha1}", sha1 ) );
+        return this;
+    }
+    
+    /**
+     * @return {@code true} is any of the ci properties is set, otherwise {@code false}
+     */
+    public boolean isSet()
+    {
+        return !replaceChain.equals( Function.identity() );
+    }
+    
+    @Override
+    public void characters( char[] ch, int start, int length )
+        throws SAXException
+    {
+        String text = new String( ch, start, length );
+
+        // assuming this has the best performance
+        if ( text.contains( "${" ) )
+        {
+            String newText = replaceChain.apply( text );
+            
+            super.characters( newText.toCharArray(), 0, newText.length() );
+        }
+        else
+        {
+            super.characters( ch, start, length );
+        }
+    }
+    
+    
+}
\ No newline at end of file
diff --git a/maven-xml/src/main/java/org/apache/maven/xml/filter/ConsumerPomXMLFilterFactory.java b/maven-xml/src/main/java/org/apache/maven/xml/filter/ConsumerPomXMLFilterFactory.java
new file mode 100644
index 0000000..c185fdf
--- /dev/null
+++ b/maven-xml/src/main/java/org/apache/maven/xml/filter/ConsumerPomXMLFilterFactory.java
@@ -0,0 +1,65 @@
+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.inject.Inject;
+import javax.inject.Provider;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLFilter;
+import org.xml.sax.XMLReader;
+
+/**
+ * 
+ * @author Robert Scholte
+ * @since 3.7.0
+ */
+public abstract class ConsumerPomXMLFilterFactory
+{
+    @Inject
+    private Provider<BuildPomXMLFilterFactory> buildPomXMLFilterFactory;
+    
+    public ConsumerPomXMLFilterFactory()
+    {
+    }
+
+    // For testing purpose
+    ConsumerPomXMLFilterFactory( Provider<BuildPomXMLFilterFactory> buildPomXMLFilterFactory )
+    {
+        this.buildPomXMLFilterFactory = buildPomXMLFilterFactory;
+    }
+    
+    public final ConsumerPomXMLFilter get( String groupId, String artifactId )
+        throws SAXException, ParserConfigurationException
+    {
+        XMLFilter parent = buildPomXMLFilterFactory.get().get( groupId, artifactId );
+        
+        // Ensure that xs:any elements aren't touched by next filters
+        XMLReader filter = new FastForwardFilter( parent );
+        
+        // Strip modules
+        filter = new ModulesXMLFilter( filter );
+        // Adjust relativePath
+        filter = new RelativePathXMLFilter( filter );
+        
+        return new ConsumerPomXMLFilter( filter );
+    }
+}