View Javadoc
1   package org.apache.maven.model.transform;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.nio.file.Path;
23  import java.util.Optional;
24  import java.util.function.BiFunction;
25  import java.util.function.Function;
26  
27  import org.codehaus.plexus.util.xml.pull.XmlPullParser;
28  
29  /**
30   * Base implementation for providing the BuildToRawPomXML.
31   *
32   * @author Robert Scholte
33   * @since 4.0.0
34   */
35  public class BuildToRawPomXMLFilterFactory
36  {
37      private final boolean consume;
38  
39      public BuildToRawPomXMLFilterFactory()
40      {
41          this( false );
42      }
43  
44      public BuildToRawPomXMLFilterFactory( boolean consume )
45      {
46          this.consume = consume;
47      }
48  
49      /**
50       *
51       * @param projectFile will be used by ConsumerPomXMLFilter to get the right filter
52       */
53      public final XmlPullParser get( XmlPullParser orgParser, Path projectFile )
54  
55      {
56          // Ensure that xs:any elements aren't touched by next filters
57          XmlPullParser parser = orgParser instanceof FastForwardFilter
58                  ? orgParser : new FastForwardFilter( orgParser );
59  
60          if ( getDependencyKeyToVersionMapper() != null )
61          {
62              parser = new ReactorDependencyXMLFilter( parser, getDependencyKeyToVersionMapper() );
63          }
64  
65          if ( getRelativePathMapper() != null )
66          {
67              parser = new ParentXMLFilter( parser, getRelativePathMapper(), projectFile.getParent() );
68          }
69  
70          CiFriendlyXMLFilter ciFriendlyFilter = new CiFriendlyXMLFilter( parser, consume );
71          getChangelist().ifPresent( ciFriendlyFilter::setChangelist  );
72          getRevision().ifPresent( ciFriendlyFilter::setRevision );
73          getSha1().ifPresent( ciFriendlyFilter::setSha1 );
74          parser = ciFriendlyFilter;
75  
76          return parser;
77      }
78  
79      /**
80       * @return the mapper or {@code null} if relativePaths don't need to be mapped
81       */
82      protected Function<Path, Optional<RelativeProject>> getRelativePathMapper()
83      {
84          return null;
85      }
86  
87      protected BiFunction<String, String, String> getDependencyKeyToVersionMapper()
88      {
89          return null;
90      }
91  
92      // getters for the 3 magic properties of CIFriendly versions ( https://maven.apache.org/maven-ci-friendly.html )
93  
94      protected Optional<String> getChangelist()
95      {
96          return Optional.empty();
97      }
98  
99      protected Optional<String> getRevision()
100     {
101         return Optional.empty();
102     }
103 
104     protected Optional<String> getSha1()
105     {
106         return Optional.empty();
107     }
108 
109 }