projectDependencies = effectiveModel.getDependencies();
- if ( flattenDependencyMode == null | flattenDependencyMode == FlattenDependencyMode.direct )
- {
- createFlattenedDependenciesDirect( projectDependencies, flattenedDependencies );
- }
- else if ( flattenDependencyMode == FlattenDependencyMode.all )
- {
- try
- {
- createFlattenedDependenciesAll( projectDependencies,
+ if (flattenDependencyMode == null | flattenDependencyMode == FlattenDependencyMode.direct) {
+ createFlattenedDependenciesDirect(projectDependencies, flattenedDependencies);
+ } else if (flattenDependencyMode == FlattenDependencyMode.all) {
+ try {
+ createFlattenedDependenciesAll(
+ projectDependencies,
effectiveModel.getDependencyManagement() != null
- ? effectiveModel.getDependencyManagement().getDependencies() : Collections.emptyList(),
- flattenedDependencies );
- }
- catch ( Exception e )
- {
- throw new MojoExecutionException( "caught exception when flattening dependencies", e );
+ ? effectiveModel.getDependencyManagement().getDependencies()
+ : Collections.emptyList(),
+ flattenedDependencies);
+ } catch (Exception e) {
+ throw new MojoExecutionException("caught exception when flattening dependencies", e);
}
}
}
@@ -1349,16 +1200,13 @@ else if ( flattenDependencyMode == FlattenDependencyMode.all )
* @return the flattened {@link Dependency} or null
if the given {@link Dependency} is NOT relevant for
* flattened POM.
*/
- protected Dependency createFlattenedDependency( Dependency projectDependency )
- {
- if ( JavaScopes.TEST.equals( projectDependency.getScope() ) )
- {
+ protected Dependency createFlattenedDependency(Dependency projectDependency) {
+ if (JavaScopes.TEST.equals(projectDependency.getScope())) {
return null;
}
- if ( omitExclusions )
- {
- projectDependency.setExclusions( Collections.emptyList() );
+ if (omitExclusions) {
+ projectDependency.setExclusions(Collections.emptyList());
}
return projectDependency;
@@ -1368,19 +1216,14 @@ protected Dependency createFlattenedDependency( Dependency projectDependency )
* @return true
if the generated flattened POM shall be {@link MavenProject#setFile(java.io.File) set}
* as POM artifact of the {@link MavenProject}, false
otherwise.
*/
- public boolean isUpdatePomFile()
- {
+ public boolean isUpdatePomFile() {
- if ( this.updatePomFile == null )
- {
- if ( this.flattenMode == FlattenMode.bom )
- {
+ if (this.updatePomFile == null) {
+ if (this.flattenMode == FlattenMode.bom) {
return true;
}
- return !this.project.getPackaging().equals( "pom" );
- }
- else
- {
+ return !this.project.getPackaging().equals("pom");
+ } else {
return this.updatePomFile.booleanValue();
}
}
@@ -1389,9 +1232,7 @@ public boolean isUpdatePomFile()
* This class is a simple SAX handler that extracts the first comment located before the root tag in an XML
* document.
*/
- private class SaxHeaderCommentHandler
- extends DefaultHandler2
- {
+ private class SaxHeaderCommentHandler extends DefaultHandler2 {
/**
* true
if root tag has already been visited, false
otherwise.
@@ -1406,8 +1247,7 @@ private class SaxHeaderCommentHandler
/**
* The constructor.
*/
- SaxHeaderCommentHandler()
- {
+ SaxHeaderCommentHandler() {
super();
this.rootTagSeen = false;
@@ -1416,8 +1256,7 @@ private class SaxHeaderCommentHandler
/**
* @return the XML comment from the header of the document or null
if not present.
*/
- public String getHeaderComment()
- {
+ public String getHeaderComment() {
return this.headerComment;
}
@@ -1426,19 +1265,13 @@ public String getHeaderComment()
* {@inheritDoc}
*/
@Override
- public void comment( char[] ch, int start, int length )
- throws SAXException
- {
-
- if ( !this.rootTagSeen )
- {
- if ( this.headerComment == null )
- {
- this.headerComment = new String( ch, start, length );
- }
- else
- {
- getLog().warn( "Ignoring multiple XML header comment!" );
+ public void comment(char[] ch, int start, int length) throws SAXException {
+
+ if (!this.rootTagSeen) {
+ if (this.headerComment == null) {
+ this.headerComment = new String(ch, start, length);
+ } else {
+ getLog().warn("Ignoring multiple XML header comment!");
}
}
}
@@ -1447,12 +1280,9 @@ public void comment( char[] ch, int start, int length )
* {@inheritDoc}
*/
@Override
- public void startElement( String uri, String localName, String qName, Attributes atts )
- throws SAXException
- {
+ public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
this.rootTagSeen = true;
}
}
-
}
diff --git a/src/main/java/org/codehaus/mojo/flatten/KeepCommentsInPom.java b/src/main/java/org/codehaus/mojo/flatten/KeepCommentsInPom.java
index e99b8877..1bfe6577 100644
--- a/src/main/java/org/codehaus/mojo/flatten/KeepCommentsInPom.java
+++ b/src/main/java/org/codehaus/mojo/flatten/KeepCommentsInPom.java
@@ -1,272 +1,241 @@
-package org.codehaus.mojo.flatten;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.BiConsumer;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.logging.Log;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.bootstrap.DOMImplementationRegistry;
-import org.w3c.dom.ls.DOMImplementationLS;
-import org.w3c.dom.ls.LSOutput;
-import org.w3c.dom.ls.LSSerializer;
-import org.xml.sax.SAXException;
-
-/**
- * Helper class to keep the comments how they have been in the original pom.xml While reading with
- * {@link org.apache.maven.model.io.xpp3.MavenXpp3Writer} the comments are not placed into the
- * {@link org.apache.maven.model.Model} and so {@link org.apache.maven.model.io.xpp3.MavenXpp3Writer} is not able to
- * re-write those comments.
- *
- * Workaround (maybe until core is fixed) is to remember all the comments and restore them after MavenXpp3Writer has
- * created the new flattened pom.xml.
- *
- * Current restriction on non-unique child nodes is that this class finds the node back due to the position in the file,
- * that may lead to mis-re-added comments e.g. on multiple added dependencies (but for e.g. resolveCiFriendliesOnly the
- * nodes keep stable)
- */
-class KeepCommentsInPom
-{
-
- /**
- * Create an instance with collected current comments of the passed pom.xml file.
- */
- static KeepCommentsInPom create( Log aLog, File aOriginalPomFile ) throws MojoExecutionException
- {
- KeepCommentsInPom tempKeepCommentsInPom = new KeepCommentsInPom();
- tempKeepCommentsInPom.setLog( aLog );
- tempKeepCommentsInPom.loadComments( aOriginalPomFile );
- return tempKeepCommentsInPom;
- }
-
- private Log log;
-
- /**
- * The unique path list for an original node (the comments are stored via the referenced previousSibling)
- */
- private Map commentsPaths;
-
- /**
- *
- */
- KeepCommentsInPom()
- {
- super();
- }
-
- /**
- * load all current comments and text fragments from xml file
- *
- * @param anOriginalPomFile the pom.xml
- */
- private void loadComments( File anOriginalPomFile ) throws MojoExecutionException
- {
- commentsPaths = new HashMap<>();
- DocumentBuilderFactory tempDBF = DocumentBuilderFactory.newInstance();
- DocumentBuilder tempDB;
- try
- {
- tempDB = tempDBF.newDocumentBuilder();
- Document tempPom = tempDB.parse( anOriginalPomFile );
- Node tempNode = tempPom.getDocumentElement();
- walkOverNodes( tempNode, ".", ( node, nodePath ) ->
- {
- // collectNodesByPathNames
- commentsPaths.put( nodePath, node );
- } );
- }
- catch ( ParserConfigurationException | SAXException | IOException e )
- {
- throw new MojoExecutionException( "Cannot load comments from " + anOriginalPomFile, e );
- }
- }
-
- /**
- * Walk over the pom hierarchy of the Document.
- *
- * @param Node the current Node
- * @param String the unique path in the parent
- * @param aConsumer Function to be called with the toBeCollected/found node.
- */
- private void walkOverNodes( Node aNode, String aParentPath, BiConsumer aConsumer )
- {
- String tempNodeName = aNode.getNodeName();
- if ( log.isDebugEnabled() )
- {
- log.debug( "walkOverNodes: aParentPath=" + aParentPath + " tempNodeName=" + tempNodeName );
- }
- String tempNodePath = aParentPath + "\t" + tempNodeName;
- aConsumer.accept( aNode, tempNodePath );
- NodeList tempChilds = aNode.getChildNodes();
- // Copy the childs as aConsumer may change the node sequence (add a comment)
- List tempCopiedChilds = new ArrayList<>();
- Map tempChildWithSameName = new HashMap<>();
- for ( int i = 0; i < tempChilds.getLength(); i++ )
- {
- Node tempItem = tempChilds.item( i );
- if ( tempItem.getNodeType() != Node.TEXT_NODE && tempItem.getNodeType() != Node.COMMENT_NODE )
- {
- // Take real nodes to find them back by number
- String tempChildNodeName = tempItem.getNodeName();
- Integer tempChildWithSameNameCount = tempChildWithSameName.get( tempChildNodeName );
- if ( tempChildWithSameNameCount == null )
- {
- tempChildWithSameNameCount = 1;
- }
- else
- {
- tempChildWithSameNameCount += 1;
- }
- tempChildWithSameName.put( tempChildNodeName, tempChildWithSameNameCount );
- tempCopiedChilds.add( tempItem );
- }
- }
- Map tempChildWithSameNameCounters = new HashMap<>();
- for ( Node tempCopiedChild : tempCopiedChilds )
- {
- String tempChildNodeName = tempCopiedChild.getNodeName();
- if ( tempChildWithSameName.get( tempChildNodeName ) > 1 )
- {
- Integer tempChildWithSameNameCounter = tempChildWithSameNameCounters.get( tempChildNodeName );
- if ( tempChildWithSameNameCounter == null )
- {
- tempChildWithSameNameCounter = 1;
- }
- else
- {
- tempChildWithSameNameCounter += 1;
- }
- tempChildWithSameNameCounters.put( tempChildNodeName, tempChildWithSameNameCounter );
- // add a counter to find back the correct node.
- walkOverNodes( tempCopiedChild, tempNodePath + "\t" + tempChildWithSameNameCounter, aConsumer );
- }
- else
- {
- // unique child names
- walkOverNodes( tempCopiedChild, tempNodePath, aConsumer );
- }
- }
- }
-
- /**
- * @param String the XML written by {@link org.apache.maven.model.io.xpp3.MavenXpp3Writer}
- */
- public String restoreOriginalComments( String anXml, String aModelEncoding ) throws MojoExecutionException
- {
- DocumentBuilderFactory tempDBF = DocumentBuilderFactory.newInstance();
- DocumentBuilder tempDB;
- try
- {
- tempDB = tempDBF.newDocumentBuilder();
- String tempEncoding = aModelEncoding == null ? "UTF-8" : aModelEncoding; // default encoding UTF-8 when
- // nothing in pom model.
- Document tempPom = tempDB.parse( new ByteArrayInputStream( anXml.getBytes( tempEncoding ) ) );
- Node tempNode = tempPom.getDocumentElement();
- walkOverNodes( tempNode, ".", ( newNode, nodePath ) ->
- {
- Node tempOriginalNode = commentsPaths.get( nodePath );
- if ( tempOriginalNode != null )
- {
- String tempOriginalNodeName = tempOriginalNode.getNodeName();
- if ( tempOriginalNodeName.equals( newNode.getNodeName() ) )
- {
- // found matching node
- Node tempRefChild = newNode;
- Node tempPotentialCommentOrText = tempOriginalNode.getPreviousSibling();
- while ( tempPotentialCommentOrText != null
- && tempPotentialCommentOrText.getNodeType() == Node.TEXT_NODE )
- {
- // skip text in the original xml node
- tempPotentialCommentOrText = tempPotentialCommentOrText.getPreviousSibling();
- }
- while ( tempPotentialCommentOrText != null
- && tempPotentialCommentOrText.getNodeType() == Node.COMMENT_NODE )
- {
- // copy the node to be able to call previoussibling for next element
- Node tempRefPrevious = tempRefChild.getPreviousSibling();
- String tempWhitespaceTextBeforeRefNode = null;
- if ( tempRefPrevious != null && tempRefPrevious.getNodeType() == Node.TEXT_NODE )
- {
- tempWhitespaceTextBeforeRefNode = tempRefPrevious.getNodeValue();
- }
- Node tempNewComment;
- tempNewComment = tempPom.createComment( tempPotentialCommentOrText.getNodeValue() );
- tempRefChild.getParentNode().insertBefore( tempNewComment, tempRefChild );
- // copy the whitespaces between comment and refNode
- if ( tempWhitespaceTextBeforeRefNode != null )
- {
- tempRefChild.getParentNode().insertBefore(
- tempPom.createTextNode( tempWhitespaceTextBeforeRefNode ), tempRefChild );
- }
-
- tempRefChild = tempNewComment;
-
- tempPotentialCommentOrText = tempPotentialCommentOrText.getPreviousSibling();
- while ( tempPotentialCommentOrText != null
- && tempPotentialCommentOrText.getNodeType() == Node.TEXT_NODE )
- {
- // skip text in the original xml node
- tempPotentialCommentOrText = tempPotentialCommentOrText.getPreviousSibling();
- }
- }
- }
- }
- } );
- return writeDocumentToString( tempPom );
- }
- catch ( ParserConfigurationException | SAXException | IOException | ClassNotFoundException
- | InstantiationException | IllegalAccessException | ClassCastException e )
- {
- throw new MojoExecutionException( "Cannot add comments", e );
- }
- }
-
- /**
- * Use an LSSerializer to keep whitespaces added by MavenXpp3Writer
- *
- * @param Document the pom to write to String.
- */
- private String writeDocumentToString( Document aPom )
- throws ClassNotFoundException, InstantiationException, IllegalAccessException
- {
- DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
- DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation( "LS" );
- LSOutput output = impl.createLSOutput();
- output.setEncoding( "UTF-8" );
- ByteArrayOutputStream outStream = new ByteArrayOutputStream();
- output.setByteStream( outStream );
- LSSerializer writer = impl.createLSSerializer();
- writer.write( aPom, output );
- return outStream.toString();
- }
-
- /**
- * @see #log
- */
- public Log getLog()
- {
- return log;
- }
-
- /**
- * @see #log
- */
- public void setLog( Log aLog )
- {
- log = aLog;
- }
-
-}
+package org.codehaus.mojo.flatten;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.BiConsumer;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.bootstrap.DOMImplementationRegistry;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSOutput;
+import org.w3c.dom.ls.LSSerializer;
+import org.xml.sax.SAXException;
+
+/**
+ * Helper class to keep the comments how they have been in the original pom.xml While reading with
+ * {@link org.apache.maven.model.io.xpp3.MavenXpp3Writer} the comments are not placed into the
+ * {@link org.apache.maven.model.Model} and so {@link org.apache.maven.model.io.xpp3.MavenXpp3Writer} is not able to
+ * re-write those comments.
+ *
+ * Workaround (maybe until core is fixed) is to remember all the comments and restore them after MavenXpp3Writer has
+ * created the new flattened pom.xml.
+ *
+ * Current restriction on non-unique child nodes is that this class finds the node back due to the position in the file,
+ * that may lead to mis-re-added comments e.g. on multiple added dependencies (but for e.g. resolveCiFriendliesOnly the
+ * nodes keep stable)
+ */
+class KeepCommentsInPom {
+
+ /**
+ * Create an instance with collected current comments of the passed pom.xml file.
+ */
+ static KeepCommentsInPom create(Log aLog, File aOriginalPomFile) throws MojoExecutionException {
+ KeepCommentsInPom tempKeepCommentsInPom = new KeepCommentsInPom();
+ tempKeepCommentsInPom.setLog(aLog);
+ tempKeepCommentsInPom.loadComments(aOriginalPomFile);
+ return tempKeepCommentsInPom;
+ }
+
+ private Log log;
+
+ /**
+ * The unique path list for an original node (the comments are stored via the referenced previousSibling)
+ */
+ private Map commentsPaths;
+
+ /**
+ *
+ */
+ KeepCommentsInPom() {
+ super();
+ }
+
+ /**
+ * load all current comments and text fragments from xml file
+ *
+ * @param anOriginalPomFile the pom.xml
+ */
+ private void loadComments(File anOriginalPomFile) throws MojoExecutionException {
+ commentsPaths = new HashMap<>();
+ DocumentBuilderFactory tempDBF = DocumentBuilderFactory.newInstance();
+ DocumentBuilder tempDB;
+ try {
+ tempDB = tempDBF.newDocumentBuilder();
+ Document tempPom = tempDB.parse(anOriginalPomFile);
+ Node tempNode = tempPom.getDocumentElement();
+ walkOverNodes(tempNode, ".", (node, nodePath) -> {
+ // collectNodesByPathNames
+ commentsPaths.put(nodePath, node);
+ });
+ } catch (ParserConfigurationException | SAXException | IOException e) {
+ throw new MojoExecutionException("Cannot load comments from " + anOriginalPomFile, e);
+ }
+ }
+
+ /**
+ * Walk over the pom hierarchy of the Document.
+ *
+ * @param Node the current Node
+ * @param String the unique path in the parent
+ * @param aConsumer Function to be called with the toBeCollected/found node.
+ */
+ private void walkOverNodes(Node aNode, String aParentPath, BiConsumer aConsumer) {
+ String tempNodeName = aNode.getNodeName();
+ if (log.isDebugEnabled()) {
+ log.debug("walkOverNodes: aParentPath=" + aParentPath + " tempNodeName=" + tempNodeName);
+ }
+ String tempNodePath = aParentPath + "\t" + tempNodeName;
+ aConsumer.accept(aNode, tempNodePath);
+ NodeList tempChilds = aNode.getChildNodes();
+ // Copy the childs as aConsumer may change the node sequence (add a comment)
+ List tempCopiedChilds = new ArrayList<>();
+ Map tempChildWithSameName = new HashMap<>();
+ for (int i = 0; i < tempChilds.getLength(); i++) {
+ Node tempItem = tempChilds.item(i);
+ if (tempItem.getNodeType() != Node.TEXT_NODE && tempItem.getNodeType() != Node.COMMENT_NODE) {
+ // Take real nodes to find them back by number
+ String tempChildNodeName = tempItem.getNodeName();
+ Integer tempChildWithSameNameCount = tempChildWithSameName.get(tempChildNodeName);
+ if (tempChildWithSameNameCount == null) {
+ tempChildWithSameNameCount = 1;
+ } else {
+ tempChildWithSameNameCount += 1;
+ }
+ tempChildWithSameName.put(tempChildNodeName, tempChildWithSameNameCount);
+ tempCopiedChilds.add(tempItem);
+ }
+ }
+ Map tempChildWithSameNameCounters = new HashMap<>();
+ for (Node tempCopiedChild : tempCopiedChilds) {
+ String tempChildNodeName = tempCopiedChild.getNodeName();
+ if (tempChildWithSameName.get(tempChildNodeName) > 1) {
+ Integer tempChildWithSameNameCounter = tempChildWithSameNameCounters.get(tempChildNodeName);
+ if (tempChildWithSameNameCounter == null) {
+ tempChildWithSameNameCounter = 1;
+ } else {
+ tempChildWithSameNameCounter += 1;
+ }
+ tempChildWithSameNameCounters.put(tempChildNodeName, tempChildWithSameNameCounter);
+ // add a counter to find back the correct node.
+ walkOverNodes(tempCopiedChild, tempNodePath + "\t" + tempChildWithSameNameCounter, aConsumer);
+ } else {
+ // unique child names
+ walkOverNodes(tempCopiedChild, tempNodePath, aConsumer);
+ }
+ }
+ }
+
+ /**
+ * @param String the XML written by {@link org.apache.maven.model.io.xpp3.MavenXpp3Writer}
+ */
+ public String restoreOriginalComments(String anXml, String aModelEncoding) throws MojoExecutionException {
+ DocumentBuilderFactory tempDBF = DocumentBuilderFactory.newInstance();
+ DocumentBuilder tempDB;
+ try {
+ tempDB = tempDBF.newDocumentBuilder();
+ String tempEncoding = aModelEncoding == null ? "UTF-8" : aModelEncoding; // default encoding UTF-8 when
+ // nothing in pom model.
+ Document tempPom = tempDB.parse(new ByteArrayInputStream(anXml.getBytes(tempEncoding)));
+ Node tempNode = tempPom.getDocumentElement();
+ walkOverNodes(tempNode, ".", (newNode, nodePath) -> {
+ Node tempOriginalNode = commentsPaths.get(nodePath);
+ if (tempOriginalNode != null) {
+ String tempOriginalNodeName = tempOriginalNode.getNodeName();
+ if (tempOriginalNodeName.equals(newNode.getNodeName())) {
+ // found matching node
+ Node tempRefChild = newNode;
+ Node tempPotentialCommentOrText = tempOriginalNode.getPreviousSibling();
+ while (tempPotentialCommentOrText != null
+ && tempPotentialCommentOrText.getNodeType() == Node.TEXT_NODE) {
+ // skip text in the original xml node
+ tempPotentialCommentOrText = tempPotentialCommentOrText.getPreviousSibling();
+ }
+ while (tempPotentialCommentOrText != null
+ && tempPotentialCommentOrText.getNodeType() == Node.COMMENT_NODE) {
+ // copy the node to be able to call previoussibling for next element
+ Node tempRefPrevious = tempRefChild.getPreviousSibling();
+ String tempWhitespaceTextBeforeRefNode = null;
+ if (tempRefPrevious != null && tempRefPrevious.getNodeType() == Node.TEXT_NODE) {
+ tempWhitespaceTextBeforeRefNode = tempRefPrevious.getNodeValue();
+ }
+ Node tempNewComment;
+ tempNewComment = tempPom.createComment(tempPotentialCommentOrText.getNodeValue());
+ tempRefChild.getParentNode().insertBefore(tempNewComment, tempRefChild);
+ // copy the whitespaces between comment and refNode
+ if (tempWhitespaceTextBeforeRefNode != null) {
+ tempRefChild
+ .getParentNode()
+ .insertBefore(
+ tempPom.createTextNode(tempWhitespaceTextBeforeRefNode), tempRefChild);
+ }
+
+ tempRefChild = tempNewComment;
+
+ tempPotentialCommentOrText = tempPotentialCommentOrText.getPreviousSibling();
+ while (tempPotentialCommentOrText != null
+ && tempPotentialCommentOrText.getNodeType() == Node.TEXT_NODE) {
+ // skip text in the original xml node
+ tempPotentialCommentOrText = tempPotentialCommentOrText.getPreviousSibling();
+ }
+ }
+ }
+ }
+ });
+ return writeDocumentToString(tempPom);
+ } catch (ParserConfigurationException
+ | SAXException
+ | IOException
+ | ClassNotFoundException
+ | InstantiationException
+ | IllegalAccessException
+ | ClassCastException e) {
+ throw new MojoExecutionException("Cannot add comments", e);
+ }
+ }
+
+ /**
+ * Use an LSSerializer to keep whitespaces added by MavenXpp3Writer
+ *
+ * @param Document the pom to write to String.
+ */
+ private String writeDocumentToString(Document aPom)
+ throws ClassNotFoundException, InstantiationException, IllegalAccessException {
+ DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
+ DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
+ LSOutput output = impl.createLSOutput();
+ output.setEncoding("UTF-8");
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ output.setByteStream(outStream);
+ LSSerializer writer = impl.createLSSerializer();
+ writer.write(aPom, output);
+ return outStream.toString();
+ }
+
+ /**
+ * @see #log
+ */
+ public Log getLog() {
+ return log;
+ }
+
+ /**
+ * @see #log
+ */
+ public void setLog(Log aLog) {
+ log = aLog;
+ }
+}
diff --git a/src/main/java/org/codehaus/mojo/flatten/LoggingModelProblemCollector.java b/src/main/java/org/codehaus/mojo/flatten/LoggingModelProblemCollector.java
index 5d7390d9..d250849a 100644
--- a/src/main/java/org/codehaus/mojo/flatten/LoggingModelProblemCollector.java
+++ b/src/main/java/org/codehaus/mojo/flatten/LoggingModelProblemCollector.java
@@ -1,57 +1,52 @@
-package org.codehaus.mojo.flatten;
-
-/*
- * 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.apache.maven.model.building.ModelProblemCollector;
-import org.apache.maven.model.building.ModelProblemCollectorRequest;
-import org.apache.maven.plugin.logging.Log;
-
-/**
- * This is an implementation of {@link ModelProblemCollector} that is logging all problems.
- *
- * @author Joerg Hohwiller (hohwille at users.sourceforge.net)
- * @since 1.0.0-beta-4
- */
-public class LoggingModelProblemCollector
- implements ModelProblemCollector
-{
-
- private final Log logger;
-
- /**
- * The constructor.
- *
- * @param logger is the {@link Log}.
- */
- public LoggingModelProblemCollector( Log logger )
- {
- super();
- this.logger = logger;
- }
-
- /**
- * {@inheritDoc}
- */
- public void add( ModelProblemCollectorRequest req )
- {
- this.logger.warn( req.getMessage(), req.getException() );
- }
-
-}
+package org.codehaus.mojo.flatten;
+
+/*
+ * 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.apache.maven.model.building.ModelProblemCollector;
+import org.apache.maven.model.building.ModelProblemCollectorRequest;
+import org.apache.maven.plugin.logging.Log;
+
+/**
+ * This is an implementation of {@link ModelProblemCollector} that is logging all problems.
+ *
+ * @author Joerg Hohwiller (hohwille at users.sourceforge.net)
+ * @since 1.0.0-beta-4
+ */
+public class LoggingModelProblemCollector implements ModelProblemCollector {
+
+ private final Log logger;
+
+ /**
+ * The constructor.
+ *
+ * @param logger is the {@link Log}.
+ */
+ public LoggingModelProblemCollector(Log logger) {
+ super();
+ this.logger = logger;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void add(ModelProblemCollectorRequest req) {
+ this.logger.warn(req.getMessage(), req.getException());
+ }
+}
diff --git a/src/main/java/org/codehaus/mojo/flatten/ModelBuilderThreadSafetyWorkaround.java b/src/main/java/org/codehaus/mojo/flatten/ModelBuilderThreadSafetyWorkaround.java
index 167135ad..d7f98242 100644
--- a/src/main/java/org/codehaus/mojo/flatten/ModelBuilderThreadSafetyWorkaround.java
+++ b/src/main/java/org/codehaus/mojo/flatten/ModelBuilderThreadSafetyWorkaround.java
@@ -57,8 +57,7 @@
* @since 1.2.3
*/
@Named
-public class ModelBuilderThreadSafetyWorkaround
-{
+public class ModelBuilderThreadSafetyWorkaround {
@Inject
private ModelProcessor modelProcessor;
@@ -106,30 +105,30 @@ public class ModelBuilderThreadSafetyWorkaround
@Inject
private ReportingConverter reportingConverter;
- public ModelBuildingResult build( ModelBuildingRequest buildingRequest, ProfileInjector customInjector,
- ProfileSelector customSelector )
- throws ModelBuildingException
- {
+ public ModelBuildingResult build(
+ ModelBuildingRequest buildingRequest, ProfileInjector customInjector, ProfileSelector customSelector)
+ throws ModelBuildingException {
// note: there is neither DefaultModelBuilder.get*(), nor DefaultModelBuilder.clone()
- return new DefaultModelBuilderFactory().newInstance()
- .setProfileInjector( customInjector )
- .setProfileSelector( customSelector )
- // apply currently active ModelProcessor etc. to support extensions like jgitver
- .setDependencyManagementImporter( dependencyManagementImporter )
- .setDependencyManagementInjector( dependencyManagementInjector )
- .setInheritanceAssembler( inheritanceAssembler )
- .setLifecycleBindingsInjector( lifecycleBindingsInjector )
- .setModelInterpolator( modelInterpolator )
- .setModelNormalizer( modelNormalizer )
- .setModelPathTranslator( modelPathTranslator )
- .setModelProcessor( modelProcessor )
- .setModelUrlNormalizer( modelUrlNormalizer )
- .setModelValidator( modelValidator )
- .setPluginConfigurationExpander( pluginConfigurationExpander )
- .setPluginManagementInjector( pluginManagementInjector )
- .setReportConfigurationExpander( reportConfigurationExpander )
- .setReportingConverter( reportingConverter )
- .setSuperPomProvider( superPomProvider )
- .build( buildingRequest );
+ return new DefaultModelBuilderFactory()
+ .newInstance()
+ .setProfileInjector(customInjector)
+ .setProfileSelector(customSelector)
+ // apply currently active ModelProcessor etc. to support extensions like jgitver
+ .setDependencyManagementImporter(dependencyManagementImporter)
+ .setDependencyManagementInjector(dependencyManagementInjector)
+ .setInheritanceAssembler(inheritanceAssembler)
+ .setLifecycleBindingsInjector(lifecycleBindingsInjector)
+ .setModelInterpolator(modelInterpolator)
+ .setModelNormalizer(modelNormalizer)
+ .setModelPathTranslator(modelPathTranslator)
+ .setModelProcessor(modelProcessor)
+ .setModelUrlNormalizer(modelUrlNormalizer)
+ .setModelValidator(modelValidator)
+ .setPluginConfigurationExpander(pluginConfigurationExpander)
+ .setPluginManagementInjector(pluginManagementInjector)
+ .setReportConfigurationExpander(reportConfigurationExpander)
+ .setReportingConverter(reportingConverter)
+ .setSuperPomProvider(superPomProvider)
+ .build(buildingRequest);
}
}
diff --git a/src/main/java/org/codehaus/mojo/flatten/PomProperty.java b/src/main/java/org/codehaus/mojo/flatten/PomProperty.java
index 96f39620..79e0d828 100644
--- a/src/main/java/org/codehaus/mojo/flatten/PomProperty.java
+++ b/src/main/java/org/codehaus/mojo/flatten/PomProperty.java
@@ -1,712 +1,632 @@
-package org.codehaus.mojo.flatten;
-
-/*
- * 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.io.File;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Properties;
-
-import org.apache.maven.model.Build;
-import org.apache.maven.model.CiManagement;
-import org.apache.maven.model.Contributor;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.model.DependencyManagement;
-import org.apache.maven.model.Developer;
-import org.apache.maven.model.DistributionManagement;
-import org.apache.maven.model.IssueManagement;
-import org.apache.maven.model.License;
-import org.apache.maven.model.MailingList;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Organization;
-import org.apache.maven.model.Parent;
-import org.apache.maven.model.PluginManagement;
-import org.apache.maven.model.Prerequisites;
-import org.apache.maven.model.Profile;
-import org.apache.maven.model.Reporting;
-import org.apache.maven.model.Repository;
-import org.apache.maven.model.Scm;
-
-/**
- * This class reflects a property of a {@link Model POM}. It contains {@link #getPomProperties() all available
- * properties} as constants and allows generic access to {@link #get(Model) read} and {@link #set(Model, Object) write}
- * the property via a {@link Model}.
- *
- * @param is the generic type of the {@link #get(Model) property value}.
- * @author Joerg Hohwiller (hohwille at users.sourceforge.net)
- * @since 1.0.0-beta-4
- */
-public abstract class PomProperty
-{
-
- /** @see Model#getArtifactId() */
- public static final PomProperty ARTIFACT_ID = new PomProperty( "artifactId", String.class )
- {
- @Override
- public String get( Model model )
- {
- return model.getArtifactId();
- }
-
- @Override
- public void set( Model model, String value )
- {
- model.setArtifactId( value );
- }
- };
-
- /** @see Model#getBuild() */
- public static final PomProperty BUILD = new PomProperty( "build", Build.class )
- {
- @Override
- public Build get( Model model )
- {
- return model.getBuild();
- }
-
- @Override
- public void set( Model model, Build value )
- {
- model.setBuild( value );
- }
- };
-
- /** @see Model#getCiManagement() */
- public static final PomProperty CI_MANAGEMENT =
- new PomProperty( "ciManagement", CiManagement.class )
- {
- @Override
- public CiManagement get( Model model )
- {
- return model.getCiManagement();
- }
-
- @Override
- public void set( Model model, CiManagement value )
- {
- model.setCiManagement( value );
- }
- };
-
- /** @see Model#getContributors() */
- @SuppressWarnings( { "rawtypes", "unchecked" } )
- public static final PomProperty> CONTRIBUTORS =
- new PomProperty>( "contributors", (Class) List.class )
- {
- @Override
- public List get( Model model )
- {
- return model.getContributors();
- }
-
- @Override
- public void set( Model model, List value )
- {
- model.setContributors( value );
- }
- };
-
- /** @see Model#getDependencies() */
- @SuppressWarnings( { "rawtypes", "unchecked" } )
- public static final PomProperty> DEPENDENCIES =
- new PomProperty>( "dependencies", (Class) List.class )
- {
- @Override
- public List get( Model model )
- {
- return model.getDependencies();
- }
-
- @Override
- public void set( Model model, List value )
- {
- model.setDependencies( value );
- }
- };
-
- /** @see Model#getDependencyManagement() */
- public static final PomProperty DEPENDENCY_MANAGEMENT =
- new PomProperty( "dependencyManagement", DependencyManagement.class )
- {
- @Override
- public DependencyManagement get( Model model )
- {
- return model.getDependencyManagement();
- }
-
- @Override
- public void set( Model model, DependencyManagement value )
- {
- model.setDependencyManagement( value );
- }
- };
-
- /** @see Model#getDescription() */
- public static final PomProperty DESCRIPTION = new PomProperty( "description", String.class )
- {
- @Override
- public String get( Model model )
- {
- return model.getDescription();
- }
-
- @Override
- public void set( Model model, String value )
- {
- model.setDescription( value );
- }
- };
-
- /** @see Model#getDevelopers() */
- @SuppressWarnings( { "rawtypes", "unchecked" } )
- public static final PomProperty> DEVELOPERS =
- new PomProperty>( "developers", (Class) List.class )
- {
- @Override
- public List get( Model model )
- {
- return model.getDevelopers();
- }
-
- @Override
- public void set( Model model, List value )
- {
- model.setDevelopers( value );
- }
- };
-
- /** @see Model#getDistributionManagement() */
- public static final PomProperty DISTRIBUTION_MANAGEMENT =
- new PomProperty( "distributionManagement", DistributionManagement.class )
- {
- @Override
- public DistributionManagement get( Model model )
- {
- return model.getDistributionManagement();
- }
-
- @Override
- public void set( Model model, DistributionManagement value )
- {
- model.setDistributionManagement( value );
- }
- };
-
- /** @see Model#getGroupId() */
- public static final PomProperty GROUP_ID = new PomProperty( "groupId", String.class )
- {
- @Override
- public String get( Model model )
- {
- return model.getGroupId();
- }
-
- @Override
- public void set( Model model, String value )
- {
- model.setGroupId( value );
- }
- };
-
- /** @see Model#getInceptionYear() */
- public static final PomProperty INCEPTION_YEAR = new PomProperty( "inceptionYear", String.class )
- {
- @Override
- public String get( Model model )
- {
- return model.getInceptionYear();
- }
-
- @Override
- public void set( Model model, String value )
- {
- model.setInceptionYear( value );
- }
- };
-
- /** @see Model#getIssueManagement() */
- public static final PomProperty ISSUE_MANAGEMENT =
- new PomProperty( "issueManagement", IssueManagement.class )
- {
- @Override
- public IssueManagement get( Model model )
- {
- return model.getIssueManagement();
- }
-
- @Override
- public void set( Model model, IssueManagement value )
- {
- model.setIssueManagement( value );
- }
- };
-
- /** @see Model#getLicenses() */
- @SuppressWarnings( { "rawtypes", "unchecked" } )
- public static final PomProperty> LICENSES =
- new PomProperty>( "licenses", (Class) List.class )
- {
- @Override
- public List get( Model model )
- {
- return model.getLicenses();
- }
-
- @Override
- public void set( Model model, List value )
- {
- model.setLicenses( value );
- }
- };
-
- /** @see Model#getMailingLists() */
- @SuppressWarnings( { "rawtypes", "unchecked" } )
- public static final PomProperty> MAILING_LISTS =
- new PomProperty>( "mailingLists", (Class) List.class )
- {
- @Override
- public List get( Model model )
- {
- return model.getMailingLists();
- }
-
- @Override
- public void set( Model model, List value )
- {
- model.setMailingLists( value );
- }
- };
-
- /** @see Model#getModelEncoding() */
- public static final PomProperty MODEL_ENCODING = new PomProperty( "modelEncoding", String.class )
- {
- @Override
- public String get( Model model )
- {
- return model.getModelEncoding();
- }
-
- @Override
- public void set( Model model, String value )
- {
- model.setModelEncoding( value );
- }
- };
-
- /** @see Model#getModelVersion() */
- public static final PomProperty MODEL_VERSION = new PomProperty( "modelVersion", String.class )
- {
- @Override
- public String get( Model model )
- {
- return model.getModelVersion();
- }
-
- @Override
- public void set( Model model, String value )
- {
- model.setModelVersion( value );
- }
- };
-
- /** @see Model#getModules() */
- @SuppressWarnings( { "rawtypes", "unchecked" } )
- public static final PomProperty> MODULES =
- new PomProperty>( "modules", (Class) List.class )
- {
- @Override
- public List get( Model model )
- {
- return model.getModules();
- }
-
- @Override
- public void set( Model model, List value )
- {
- model.setModules( value );
- }
- };
-
- /** @see Model#getName() */
- public static final PomProperty NAME = new PomProperty( "name", String.class )
- {
- @Override
- public String get( Model model )
- {
- return model.getName();
- }
-
- @Override
- public void set( Model model, String value )
- {
- model.setName( value );
- }
- };
-
- /** @see Model#getOrganization() */
- public static final PomProperty ORGANIZATION =
- new PomProperty( "organization", Organization.class )
- {
- @Override
- public Organization get( Model model )
- {
- return model.getOrganization();
- }
-
- @Override
- public void set( Model model, Organization value )
- {
- model.setOrganization( value );
- }
- };
-
- /** @see Model#getPackaging() */
- public static final PomProperty PACKAGING = new PomProperty( "packaging", String.class )
- {
- @Override
- public String get( Model model )
- {
- return model.getPackaging();
- }
-
- @Override
- public void set( Model model, String value )
- {
- model.setPackaging( value );
- }
- };
-
- /** @see Model#getParent() */
- public static final PomProperty PARENT = new PomProperty( "parent", Parent.class )
- {
- @Override
- public Parent get( Model model )
- {
- return model.getParent();
- }
-
- @Override
- public void set( Model model, Parent value )
- {
- model.setParent( value );
- }
- };
-
- /** @see Build#getPluginManagement() */
- public static final PomProperty PLUGIN_MANAGEMENT =
- new PomProperty( "pluginManagement", PluginManagement.class )
- {
- @Override
- public PluginManagement get( Model model )
- {
- if ( model.getBuild() == null )
- {
- return null;
- }
- return model.getBuild().getPluginManagement();
- }
-
- @Override
- public void set( Model model, PluginManagement value )
- {
- if ( model.getBuild() == null )
- {
- model.setBuild( new Build() );
- }
- model.getBuild().setPluginManagement( value );
- }
- };
-
- /** @see Model#getPluginRepositories() */
- @SuppressWarnings( { "rawtypes", "unchecked" } )
- public static final PomProperty> PLUGIN_REPOSITORIES =
- new PomProperty>( "pluginRepositories", (Class) List.class )
- {
- @Override
- public List get( Model model )
- {
- return model.getPluginRepositories();
- }
-
- @Override
- public void set( Model model, List value )
- {
- model.setPluginRepositories( value );
- }
- };
-
- /** @see Model#getPomFile() */
- public static final PomProperty POM_FILE = new PomProperty( "pomFile", File.class )
- {
- @Override
- public File get( Model model )
- {
- return model.getPomFile();
- }
-
- @Override
- public void set( Model model, File value )
- {
- model.setPomFile( value );
- }
- };
-
- /** @see Model#getPrerequisites() */
- public static final PomProperty PREREQUISITES =
- new PomProperty( "prerequisites", Prerequisites.class )
- {
- @Override
- public Prerequisites get( Model model )
- {
- return model.getPrerequisites();
- }
-
- @Override
- public void set( Model model, Prerequisites value )
- {
- model.setPrerequisites( value );
- }
- };
-
- /** @see Model#getProfiles() */
- @SuppressWarnings( { "rawtypes", "unchecked" } )
- public static final PomProperty> PROFILES =
- new PomProperty>( "profiles", (Class) List.class )
- {
- @Override
- public List get( Model model )
- {
- return model.getProfiles();
- }
-
- @Override
- public void set( Model model, List value )
- {
- model.setProfiles( value );
- }
- };
-
- /** @see Model#getProperties() */
- public static final PomProperty PROPERTIES =
- new PomProperty( "properties", Properties.class )
- {
- @Override
- public Properties get( Model model )
- {
- return model.getProperties();
- }
-
- @Override
- public void set( Model model, Properties value )
- {
- model.setProperties( value );
- }
- };
-
- /** @see Model#getReporting() */
- public static final PomProperty REPORTING = new PomProperty( "reporting", Reporting.class )
- {
- @Override
- public Reporting get( Model model )
- {
- return model.getReporting();
- }
-
- @Override
- public void set( Model model, Reporting value )
- {
- model.setReporting( value );
- }
- };
-
- /** @see Model#getPluginRepositories() */
- @SuppressWarnings( { "rawtypes", "unchecked" } )
- public static final PomProperty> REPOSITORIES =
- new PomProperty>( "repositories", (Class) List.class )
- {
- @Override
- public List get( Model model )
- {
- return model.getRepositories();
- }
-
- @Override
- public void set( Model model, List value )
- {
- model.setRepositories( value );
- }
- };
-
- /** @see Model#getScm() */
- public static final PomProperty SCM = new PomProperty( "scm", Scm.class )
- {
- @Override
- public Scm get( Model model )
- {
- return model.getScm();
- }
-
- @Override
- public void set( Model model, Scm value )
- {
- model.setScm( value );
- }
- };
-
- /** @see Model#getUrl() */
- public static final PomProperty URL = new PomProperty( "url", String.class )
- {
- @Override
- public String get( Model model )
- {
- return model.getUrl();
- }
-
- @Override
- public void set( Model model, String value )
- {
- model.setUrl( value );
- }
- };
-
- /** @see Model#getVersion() */
- public static final PomProperty VERSION = new PomProperty( "version", String.class )
- {
- @Override
- public String get( Model model )
- {
- return model.getVersion();
- }
-
- @Override
- public void set( Model model, String value )
- {
- model.setVersion( value );
- }
- };
-
- private static final PomProperty>[] POM_PROPERTIES_ARRAY = new PomProperty>[] { ARTIFACT_ID, BUILD,
- CI_MANAGEMENT, CONTRIBUTORS, DEPENDENCIES, DEPENDENCY_MANAGEMENT, DESCRIPTION, DEVELOPERS,
- DISTRIBUTION_MANAGEMENT, GROUP_ID, INCEPTION_YEAR, ISSUE_MANAGEMENT, LICENSES, MAILING_LISTS, MODEL_ENCODING,
- MODEL_VERSION, MODULES, NAME, ORGANIZATION, PACKAGING, PARENT, PLUGIN_MANAGEMENT, PLUGIN_REPOSITORIES, POM_FILE,
- PREREQUISITES, PROFILES, PROPERTIES, REPORTING, REPOSITORIES, SCM, URL, VERSION };
-
- private static final List> POM_PROPERTIES =
- Collections.unmodifiableList( Arrays.asList( POM_PROPERTIES_ARRAY ) );
-
- private final String name;
-
- private final Class valueType;
-
- /**
- * The constructor.
- *
- * @param name - see {@link #getName()}.
- * @param valueType - see {@link #getValueType()}.
- */
- public PomProperty( String name, Class valueType )
- {
- super();
- this.name = name;
- this.valueType = valueType;
- }
-
- /**
- * @return name
- */
- public String getName()
- {
- return this.name;
- }
-
- /**
- * @return {@link Class} reflecting the type of the {@link #get(Model) property value}.
- */
- public Class getValueType()
- {
- return this.valueType;
- }
-
- /**
- * @return true
if required for flattened POM, false
otherwise.
- */
- public boolean isRequired()
- {
- return this == GROUP_ID || this == ARTIFACT_ID || this == VERSION;
- }
-
- /**
- * @return true
if this property represents an XML element of the POM representation,
- * false
otherwise (if an internal property such as {@link Model#getPomFile()}).
- */
- public boolean isElement()
- {
-
- if ( this == POM_FILE )
- {
- return false;
- }
- return this != MODEL_ENCODING;
- }
-
- /**
- * Generic getter for reading a {@link PomProperty} from a {@link Model}.
- *
- * @param model is the {@link Model} to read from.
- * @return the value of the property to read identified by this {@link PomProperty}.
- */
- public abstract V get( Model model );
-
- /**
- * Generic setter for writing a {@link PomProperty} in a {@link Model}.
- *
- * @param model is the {@link Model} to write to.
- * @param value is the value of the property to write identified by this {@link PomProperty}.
- */
- public abstract void set( Model model, V value );
-
- /**
- * Copies the value identified by this {@link PomProperty} from the given source
{@link Model} to the
- * given target
{@link Model}.
- *
- * @param source is the {@link Model} to copy from (read).
- * @param target is the {@link Model} to copy to (write).
- */
- public void copy( Model source, Model target )
- {
-
- V value = get( source );
- if ( value != null )
- {
- set( target, value );
- }
- }
-
- /**
- * @return an {@link Collections#unmodifiableList(List) unmodifiable} {@link List} with all {@link PomProperty
- * properties}.
- */
- public static List> getPomProperties()
- {
- return POM_PROPERTIES;
- }
-
-}
+package org.codehaus.mojo.flatten;
+
+/*
+ * 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.io.File;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.maven.model.Build;
+import org.apache.maven.model.CiManagement;
+import org.apache.maven.model.Contributor;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Developer;
+import org.apache.maven.model.DistributionManagement;
+import org.apache.maven.model.IssueManagement;
+import org.apache.maven.model.License;
+import org.apache.maven.model.MailingList;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Organization;
+import org.apache.maven.model.Parent;
+import org.apache.maven.model.PluginManagement;
+import org.apache.maven.model.Prerequisites;
+import org.apache.maven.model.Profile;
+import org.apache.maven.model.Reporting;
+import org.apache.maven.model.Repository;
+import org.apache.maven.model.Scm;
+
+/**
+ * This class reflects a property of a {@link Model POM}. It contains {@link #getPomProperties() all available
+ * properties} as constants and allows generic access to {@link #get(Model) read} and {@link #set(Model, Object) write}
+ * the property via a {@link Model}.
+ *
+ * @param is the generic type of the {@link #get(Model) property value}.
+ * @author Joerg Hohwiller (hohwille at users.sourceforge.net)
+ * @since 1.0.0-beta-4
+ */
+public abstract class PomProperty {
+
+ /** @see Model#getArtifactId() */
+ public static final PomProperty ARTIFACT_ID = new PomProperty("artifactId", String.class) {
+ @Override
+ public String get(Model model) {
+ return model.getArtifactId();
+ }
+
+ @Override
+ public void set(Model model, String value) {
+ model.setArtifactId(value);
+ }
+ };
+
+ /** @see Model#getBuild() */
+ public static final PomProperty BUILD = new PomProperty("build", Build.class) {
+ @Override
+ public Build get(Model model) {
+ return model.getBuild();
+ }
+
+ @Override
+ public void set(Model model, Build value) {
+ model.setBuild(value);
+ }
+ };
+
+ /** @see Model#getCiManagement() */
+ public static final PomProperty CI_MANAGEMENT =
+ new PomProperty("ciManagement", CiManagement.class) {
+ @Override
+ public CiManagement get(Model model) {
+ return model.getCiManagement();
+ }
+
+ @Override
+ public void set(Model model, CiManagement value) {
+ model.setCiManagement(value);
+ }
+ };
+
+ /** @see Model#getContributors() */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public static final PomProperty> CONTRIBUTORS =
+ new PomProperty>("contributors", (Class) List.class) {
+ @Override
+ public List get(Model model) {
+ return model.getContributors();
+ }
+
+ @Override
+ public void set(Model model, List value) {
+ model.setContributors(value);
+ }
+ };
+
+ /** @see Model#getDependencies() */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public static final PomProperty> DEPENDENCIES =
+ new PomProperty>("dependencies", (Class) List.class) {
+ @Override
+ public List get(Model model) {
+ return model.getDependencies();
+ }
+
+ @Override
+ public void set(Model model, List value) {
+ model.setDependencies(value);
+ }
+ };
+
+ /** @see Model#getDependencyManagement() */
+ public static final PomProperty DEPENDENCY_MANAGEMENT =
+ new PomProperty("dependencyManagement", DependencyManagement.class) {
+ @Override
+ public DependencyManagement get(Model model) {
+ return model.getDependencyManagement();
+ }
+
+ @Override
+ public void set(Model model, DependencyManagement value) {
+ model.setDependencyManagement(value);
+ }
+ };
+
+ /** @see Model#getDescription() */
+ public static final PomProperty DESCRIPTION = new PomProperty("description", String.class) {
+ @Override
+ public String get(Model model) {
+ return model.getDescription();
+ }
+
+ @Override
+ public void set(Model model, String value) {
+ model.setDescription(value);
+ }
+ };
+
+ /** @see Model#getDevelopers() */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public static final PomProperty> DEVELOPERS =
+ new PomProperty>("developers", (Class) List.class) {
+ @Override
+ public List get(Model model) {
+ return model.getDevelopers();
+ }
+
+ @Override
+ public void set(Model model, List value) {
+ model.setDevelopers(value);
+ }
+ };
+
+ /** @see Model#getDistributionManagement() */
+ public static final PomProperty DISTRIBUTION_MANAGEMENT =
+ new PomProperty("distributionManagement", DistributionManagement.class) {
+ @Override
+ public DistributionManagement get(Model model) {
+ return model.getDistributionManagement();
+ }
+
+ @Override
+ public void set(Model model, DistributionManagement value) {
+ model.setDistributionManagement(value);
+ }
+ };
+
+ /** @see Model#getGroupId() */
+ public static final PomProperty GROUP_ID = new PomProperty("groupId", String.class) {
+ @Override
+ public String get(Model model) {
+ return model.getGroupId();
+ }
+
+ @Override
+ public void set(Model model, String value) {
+ model.setGroupId(value);
+ }
+ };
+
+ /** @see Model#getInceptionYear() */
+ public static final PomProperty INCEPTION_YEAR = new PomProperty("inceptionYear", String.class) {
+ @Override
+ public String get(Model model) {
+ return model.getInceptionYear();
+ }
+
+ @Override
+ public void set(Model model, String value) {
+ model.setInceptionYear(value);
+ }
+ };
+
+ /** @see Model#getIssueManagement() */
+ public static final PomProperty ISSUE_MANAGEMENT =
+ new PomProperty("issueManagement", IssueManagement.class) {
+ @Override
+ public IssueManagement get(Model model) {
+ return model.getIssueManagement();
+ }
+
+ @Override
+ public void set(Model model, IssueManagement value) {
+ model.setIssueManagement(value);
+ }
+ };
+
+ /** @see Model#getLicenses() */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public static final PomProperty> LICENSES =
+ new PomProperty>("licenses", (Class) List.class) {
+ @Override
+ public List get(Model model) {
+ return model.getLicenses();
+ }
+
+ @Override
+ public void set(Model model, List value) {
+ model.setLicenses(value);
+ }
+ };
+
+ /** @see Model#getMailingLists() */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public static final PomProperty> MAILING_LISTS =
+ new PomProperty>("mailingLists", (Class) List.class) {
+ @Override
+ public List get(Model model) {
+ return model.getMailingLists();
+ }
+
+ @Override
+ public void set(Model model, List value) {
+ model.setMailingLists(value);
+ }
+ };
+
+ /** @see Model#getModelEncoding() */
+ public static final PomProperty MODEL_ENCODING = new PomProperty("modelEncoding", String.class) {
+ @Override
+ public String get(Model model) {
+ return model.getModelEncoding();
+ }
+
+ @Override
+ public void set(Model model, String value) {
+ model.setModelEncoding(value);
+ }
+ };
+
+ /** @see Model#getModelVersion() */
+ public static final PomProperty MODEL_VERSION = new PomProperty("modelVersion", String.class) {
+ @Override
+ public String get(Model model) {
+ return model.getModelVersion();
+ }
+
+ @Override
+ public void set(Model model, String value) {
+ model.setModelVersion(value);
+ }
+ };
+
+ /** @see Model#getModules() */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public static final PomProperty> MODULES =
+ new PomProperty>("modules", (Class) List.class) {
+ @Override
+ public List get(Model model) {
+ return model.getModules();
+ }
+
+ @Override
+ public void set(Model model, List value) {
+ model.setModules(value);
+ }
+ };
+
+ /** @see Model#getName() */
+ public static final PomProperty NAME = new PomProperty("name", String.class) {
+ @Override
+ public String get(Model model) {
+ return model.getName();
+ }
+
+ @Override
+ public void set(Model model, String value) {
+ model.setName(value);
+ }
+ };
+
+ /** @see Model#getOrganization() */
+ public static final PomProperty ORGANIZATION =
+ new PomProperty("organization", Organization.class) {
+ @Override
+ public Organization get(Model model) {
+ return model.getOrganization();
+ }
+
+ @Override
+ public void set(Model model, Organization value) {
+ model.setOrganization(value);
+ }
+ };
+
+ /** @see Model#getPackaging() */
+ public static final PomProperty PACKAGING = new PomProperty("packaging", String.class) {
+ @Override
+ public String get(Model model) {
+ return model.getPackaging();
+ }
+
+ @Override
+ public void set(Model model, String value) {
+ model.setPackaging(value);
+ }
+ };
+
+ /** @see Model#getParent() */
+ public static final PomProperty PARENT = new PomProperty("parent", Parent.class) {
+ @Override
+ public Parent get(Model model) {
+ return model.getParent();
+ }
+
+ @Override
+ public void set(Model model, Parent value) {
+ model.setParent(value);
+ }
+ };
+
+ /** @see Build#getPluginManagement() */
+ public static final PomProperty PLUGIN_MANAGEMENT =
+ new PomProperty("pluginManagement", PluginManagement.class) {
+ @Override
+ public PluginManagement get(Model model) {
+ if (model.getBuild() == null) {
+ return null;
+ }
+ return model.getBuild().getPluginManagement();
+ }
+
+ @Override
+ public void set(Model model, PluginManagement value) {
+ if (model.getBuild() == null) {
+ model.setBuild(new Build());
+ }
+ model.getBuild().setPluginManagement(value);
+ }
+ };
+
+ /** @see Model#getPluginRepositories() */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public static final PomProperty> PLUGIN_REPOSITORIES =
+ new PomProperty>("pluginRepositories", (Class) List.class) {
+ @Override
+ public List get(Model model) {
+ return model.getPluginRepositories();
+ }
+
+ @Override
+ public void set(Model model, List value) {
+ model.setPluginRepositories(value);
+ }
+ };
+
+ /** @see Model#getPomFile() */
+ public static final PomProperty POM_FILE = new PomProperty("pomFile", File.class) {
+ @Override
+ public File get(Model model) {
+ return model.getPomFile();
+ }
+
+ @Override
+ public void set(Model model, File value) {
+ model.setPomFile(value);
+ }
+ };
+
+ /** @see Model#getPrerequisites() */
+ public static final PomProperty PREREQUISITES =
+ new PomProperty("prerequisites", Prerequisites.class) {
+ @Override
+ public Prerequisites get(Model model) {
+ return model.getPrerequisites();
+ }
+
+ @Override
+ public void set(Model model, Prerequisites value) {
+ model.setPrerequisites(value);
+ }
+ };
+
+ /** @see Model#getProfiles() */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public static final PomProperty> PROFILES =
+ new PomProperty>("profiles", (Class) List.class) {
+ @Override
+ public List get(Model model) {
+ return model.getProfiles();
+ }
+
+ @Override
+ public void set(Model model, List value) {
+ model.setProfiles(value);
+ }
+ };
+
+ /** @see Model#getProperties() */
+ public static final PomProperty PROPERTIES =
+ new PomProperty("properties", Properties.class) {
+ @Override
+ public Properties get(Model model) {
+ return model.getProperties();
+ }
+
+ @Override
+ public void set(Model model, Properties value) {
+ model.setProperties(value);
+ }
+ };
+
+ /** @see Model#getReporting() */
+ public static final PomProperty REPORTING = new PomProperty("reporting", Reporting.class) {
+ @Override
+ public Reporting get(Model model) {
+ return model.getReporting();
+ }
+
+ @Override
+ public void set(Model model, Reporting value) {
+ model.setReporting(value);
+ }
+ };
+
+ /** @see Model#getPluginRepositories() */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public static final PomProperty> REPOSITORIES =
+ new PomProperty>("repositories", (Class) List.class) {
+ @Override
+ public List get(Model model) {
+ return model.getRepositories();
+ }
+
+ @Override
+ public void set(Model model, List value) {
+ model.setRepositories(value);
+ }
+ };
+
+ /** @see Model#getScm() */
+ public static final PomProperty SCM = new PomProperty("scm", Scm.class) {
+ @Override
+ public Scm get(Model model) {
+ return model.getScm();
+ }
+
+ @Override
+ public void set(Model model, Scm value) {
+ model.setScm(value);
+ }
+ };
+
+ /** @see Model#getUrl() */
+ public static final PomProperty URL = new PomProperty("url", String.class) {
+ @Override
+ public String get(Model model) {
+ return model.getUrl();
+ }
+
+ @Override
+ public void set(Model model, String value) {
+ model.setUrl(value);
+ }
+ };
+
+ /** @see Model#getVersion() */
+ public static final PomProperty VERSION = new PomProperty("version", String.class) {
+ @Override
+ public String get(Model model) {
+ return model.getVersion();
+ }
+
+ @Override
+ public void set(Model model, String value) {
+ model.setVersion(value);
+ }
+ };
+
+ private static final PomProperty>[] POM_PROPERTIES_ARRAY = new PomProperty>[] {
+ ARTIFACT_ID,
+ BUILD,
+ CI_MANAGEMENT,
+ CONTRIBUTORS,
+ DEPENDENCIES,
+ DEPENDENCY_MANAGEMENT,
+ DESCRIPTION,
+ DEVELOPERS,
+ DISTRIBUTION_MANAGEMENT,
+ GROUP_ID,
+ INCEPTION_YEAR,
+ ISSUE_MANAGEMENT,
+ LICENSES,
+ MAILING_LISTS,
+ MODEL_ENCODING,
+ MODEL_VERSION,
+ MODULES,
+ NAME,
+ ORGANIZATION,
+ PACKAGING,
+ PARENT,
+ PLUGIN_MANAGEMENT,
+ PLUGIN_REPOSITORIES,
+ POM_FILE,
+ PREREQUISITES,
+ PROFILES,
+ PROPERTIES,
+ REPORTING,
+ REPOSITORIES,
+ SCM,
+ URL,
+ VERSION
+ };
+
+ private static final List> POM_PROPERTIES =
+ Collections.unmodifiableList(Arrays.asList(POM_PROPERTIES_ARRAY));
+
+ private final String name;
+
+ private final Class valueType;
+
+ /**
+ * The constructor.
+ *
+ * @param name - see {@link #getName()}.
+ * @param valueType - see {@link #getValueType()}.
+ */
+ public PomProperty(String name, Class valueType) {
+ super();
+ this.name = name;
+ this.valueType = valueType;
+ }
+
+ /**
+ * @return name
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * @return {@link Class} reflecting the type of the {@link #get(Model) property value}.
+ */
+ public Class getValueType() {
+ return this.valueType;
+ }
+
+ /**
+ * @return true
if required for flattened POM, false
otherwise.
+ */
+ public boolean isRequired() {
+ return this == GROUP_ID || this == ARTIFACT_ID || this == VERSION;
+ }
+
+ /**
+ * @return true
if this property represents an XML element of the POM representation,
+ * false
otherwise (if an internal property such as {@link Model#getPomFile()}).
+ */
+ public boolean isElement() {
+
+ if (this == POM_FILE) {
+ return false;
+ }
+ return this != MODEL_ENCODING;
+ }
+
+ /**
+ * Generic getter for reading a {@link PomProperty} from a {@link Model}.
+ *
+ * @param model is the {@link Model} to read from.
+ * @return the value of the property to read identified by this {@link PomProperty}.
+ */
+ public abstract V get(Model model);
+
+ /**
+ * Generic setter for writing a {@link PomProperty} in a {@link Model}.
+ *
+ * @param model is the {@link Model} to write to.
+ * @param value is the value of the property to write identified by this {@link PomProperty}.
+ */
+ public abstract void set(Model model, V value);
+
+ /**
+ * Copies the value identified by this {@link PomProperty} from the given source
{@link Model} to the
+ * given target
{@link Model}.
+ *
+ * @param source is the {@link Model} to copy from (read).
+ * @param target is the {@link Model} to copy to (write).
+ */
+ public void copy(Model source, Model target) {
+
+ V value = get(source);
+ if (value != null) {
+ set(target, value);
+ }
+ }
+
+ /**
+ * @return an {@link Collections#unmodifiableList(List) unmodifiable} {@link List} with all {@link PomProperty
+ * properties}.
+ */
+ public static List> getPomProperties() {
+ return POM_PROPERTIES;
+ }
+}
diff --git a/src/main/java/org/codehaus/mojo/flatten/cifriendly/CiInterpolator.java b/src/main/java/org/codehaus/mojo/flatten/cifriendly/CiInterpolator.java
index 7ec0b5b7..dd8d13ba 100644
--- a/src/main/java/org/codehaus/mojo/flatten/cifriendly/CiInterpolator.java
+++ b/src/main/java/org/codehaus/mojo/flatten/cifriendly/CiInterpolator.java
@@ -26,25 +26,22 @@
import org.apache.maven.model.building.ModelProblemCollector;
/**
-* A shameless replacement of ModelInterpolator from maven-model-builder.
-* Made because of class loading issues that ensued when using ModelInterpolator interface.
-*/
-public interface CiInterpolator
-{
-
- /**
- * Interpolates expressions in the specified model. Note that implementations are free to either interpolate the
- * provided model directly or to create a clone of the model and interpolate the clone. Callers should always use
- * the returned model and must not rely on the input model being updated.
- *
- * @param model The model to interpolate, must not be {@code null}.
- * @param projectDir The project directory, may be {@code null} if the model does not belong to a local project but
- * to some artifact's metadata.
- * @param request The model building request that holds further settings, must not be {@code null}.
- * @param problems The container used to collect problems that were encountered, must not be {@code null}.
- * @return The interpolated model, never {@code null}.
- */
- Model interpolateModel( Model model, File projectDir, ModelBuildingRequest request,
- ModelProblemCollector problems );
+ * A shameless replacement of ModelInterpolator from maven-model-builder.
+ * Made because of class loading issues that ensued when using ModelInterpolator interface.
+ */
+public interface CiInterpolator {
+ /**
+ * Interpolates expressions in the specified model. Note that implementations are free to either interpolate the
+ * provided model directly or to create a clone of the model and interpolate the clone. Callers should always use
+ * the returned model and must not rely on the input model being updated.
+ *
+ * @param model The model to interpolate, must not be {@code null}.
+ * @param projectDir The project directory, may be {@code null} if the model does not belong to a local project but
+ * to some artifact's metadata.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ * @return The interpolated model, never {@code null}.
+ */
+ Model interpolateModel(Model model, File projectDir, ModelBuildingRequest request, ModelProblemCollector problems);
}
diff --git a/src/main/java/org/codehaus/mojo/flatten/cifriendly/CiInterpolatorImpl.java b/src/main/java/org/codehaus/mojo/flatten/cifriendly/CiInterpolatorImpl.java
index 098dd136..c943de07 100644
--- a/src/main/java/org/codehaus/mojo/flatten/cifriendly/CiInterpolatorImpl.java
+++ b/src/main/java/org/codehaus/mojo/flatten/cifriendly/CiInterpolatorImpl.java
@@ -39,8 +39,7 @@
* see {@link org.codehaus.plexus.interpolation.StringSearchInterpolator}.
* This interpolates only the Maven CI Friendly variables revision, sha1 and changelist.
*/
-public class CiInterpolatorImpl implements Interpolator
-{
+public class CiInterpolatorImpl implements Interpolator {
private final Map existingAnswers = new HashMap();
@@ -58,74 +57,62 @@ public class CiInterpolatorImpl implements Interpolator
private final String endExpr;
- public CiInterpolatorImpl()
- {
+ public CiInterpolatorImpl() {
this.startExpr = DEFAULT_START_EXPR;
this.endExpr = DEFAULT_END_EXPR;
}
- public CiInterpolatorImpl( String startExpr, String endExpr )
- {
+ public CiInterpolatorImpl(String startExpr, String endExpr) {
this.startExpr = startExpr;
this.endExpr = endExpr;
}
-
/**
* {@inheritDoc}
*/
@Override
- public void addValueSource( ValueSource valueSource )
- {
- valueSources.add( valueSource );
+ public void addValueSource(ValueSource valueSource) {
+ valueSources.add(valueSource);
}
/**
* {@inheritDoc}
*/
@Override
- public void removeValuesSource( ValueSource valueSource )
- {
- valueSources.remove( valueSource );
+ public void removeValuesSource(ValueSource valueSource) {
+ valueSources.remove(valueSource);
}
/**
* {@inheritDoc}
*/
@Override
- public void addPostProcessor( InterpolationPostProcessor postProcessor )
- {
- postProcessors.add( postProcessor );
+ public void addPostProcessor(InterpolationPostProcessor postProcessor) {
+ postProcessors.add(postProcessor);
}
/**
* {@inheritDoc}
*/
@Override
- public void removePostProcessor( InterpolationPostProcessor postProcessor )
- {
- postProcessors.remove( postProcessor );
+ public void removePostProcessor(InterpolationPostProcessor postProcessor) {
+ postProcessors.remove(postProcessor);
}
@Override
- public String interpolate( String input, String thisPrefixPattern )
- throws InterpolationException
- {
- return interpolate( input, new SimpleRecursionInterceptor() );
+ public String interpolate(String input, String thisPrefixPattern) throws InterpolationException {
+ return interpolate(input, new SimpleRecursionInterceptor());
}
@Override
- public String interpolate( String input, String thisPrefixPattern, RecursionInterceptor recursionInterceptor )
- throws InterpolationException
- {
- return interpolate( input, recursionInterceptor );
+ public String interpolate(String input, String thisPrefixPattern, RecursionInterceptor recursionInterceptor)
+ throws InterpolationException {
+ return interpolate(input, recursionInterceptor);
}
@Override
- public String interpolate( String input )
- throws InterpolationException
- {
- return interpolate( input, new SimpleRecursionInterceptor() );
+ public String interpolate(String input) throws InterpolationException {
+ return interpolate(input, new SimpleRecursionInterceptor());
}
/**
@@ -133,82 +120,64 @@ public String interpolate( String input )
* nested expressions.
*/
@Override
- public String interpolate( String input, RecursionInterceptor recursionInterceptor )
- throws InterpolationException
- {
- try
- {
- return interpolate( input, recursionInterceptor, new HashSet<>() );
- }
- finally
- {
- if ( !cacheAnswers )
- {
+ public String interpolate(String input, RecursionInterceptor recursionInterceptor) throws InterpolationException {
+ try {
+ return interpolate(input, recursionInterceptor, new HashSet<>());
+ } finally {
+ if (!cacheAnswers) {
existingAnswers.clear();
}
}
}
- private String interpolate( String input, RecursionInterceptor recursionInterceptor, Set unresolvable )
- throws InterpolationException
- {
- if ( input == null )
- {
+ private String interpolate(String input, RecursionInterceptor recursionInterceptor, Set unresolvable)
+ throws InterpolationException {
+ if (input == null) {
// return empty String to prevent NPE too
return "";
}
- StringBuilder result = new StringBuilder( input.length() * 2 );
+ StringBuilder result = new StringBuilder(input.length() * 2);
int startIdx;
int endIdx = -1;
- while ( ( startIdx = input.indexOf( startExpr, endIdx + 1 ) ) > -1 )
- {
- result.append( input, endIdx + 1, startIdx );
+ while ((startIdx = input.indexOf(startExpr, endIdx + 1)) > -1) {
+ result.append(input, endIdx + 1, startIdx);
- endIdx = input.indexOf( endExpr, startIdx + 1 );
- if ( endIdx < 0 )
- {
+ endIdx = input.indexOf(endExpr, startIdx + 1);
+ if (endIdx < 0) {
break;
}
- final String wholeExpr = input.substring( startIdx, endIdx + endExpr.length() );
- String realExpr = wholeExpr.substring( startExpr.length(), wholeExpr.length() - endExpr.length() );
+ final String wholeExpr = input.substring(startIdx, endIdx + endExpr.length());
+ String realExpr = wholeExpr.substring(startExpr.length(), wholeExpr.length() - endExpr.length());
boolean resolved = false;
- if ( !unresolvable.contains( wholeExpr ) )
- {
- if ( realExpr.startsWith( "." ) )
- {
- realExpr = realExpr.substring( 1 );
+ if (!unresolvable.contains(wholeExpr)) {
+ if (realExpr.startsWith(".")) {
+ realExpr = realExpr.substring(1);
}
- if ( recursionInterceptor.hasRecursiveExpression( realExpr ) )
- {
- throw new InterpolationCycleException( recursionInterceptor, realExpr, wholeExpr );
+ if (recursionInterceptor.hasRecursiveExpression(realExpr)) {
+ throw new InterpolationCycleException(recursionInterceptor, realExpr, wholeExpr);
}
- recursionInterceptor.expressionResolutionStarted( realExpr );
- try
- {
- Object value = existingAnswers.get( realExpr );
- if ( !wholeExpr.equals( "${revision}" )
- && !wholeExpr.contains( "${sha1}" )
- && !wholeExpr.contains( "${changelist}" ) )
- {
+ recursionInterceptor.expressionResolutionStarted(realExpr);
+ try {
+ Object value = existingAnswers.get(realExpr);
+ if (!wholeExpr.equals("${revision}")
+ && !wholeExpr.contains("${sha1}")
+ && !wholeExpr.contains("${changelist}")) {
value = realExpr;
}
Object bestAnswer = null;
- for ( ValueSource valueSource : valueSources )
- {
- if ( value != null )
- {
+ for (ValueSource valueSource : valueSources) {
+ if (value != null) {
break;
}
- value = valueSource.getValue( realExpr );
+ value = valueSource.getValue(realExpr);
- if ( value != null && value.toString().contains( wholeExpr ) )
- {
+ if (value != null && value.toString().contains(wholeExpr)) {
bestAnswer = value;
value = null;
}
@@ -217,22 +186,17 @@ private String interpolate( String input, RecursionInterceptor recursionIntercep
// this is the simplest recursion check to catch exact recursion
// (non synonym), and avoid the extra effort of more string
// searching.
- if ( value == null && bestAnswer != null )
- {
- throw new InterpolationCycleException( recursionInterceptor, realExpr, wholeExpr );
+ if (value == null && bestAnswer != null) {
+ throw new InterpolationCycleException(recursionInterceptor, realExpr, wholeExpr);
}
- if ( value != null )
- {
- value = interpolate( String.valueOf( value ), recursionInterceptor, unresolvable );
-
- if ( !postProcessors.isEmpty() )
- {
- for ( InterpolationPostProcessor postProcessor : postProcessors )
- {
- Object newVal = postProcessor.execute( realExpr, value );
- if ( newVal != null )
- {
+ if (value != null) {
+ value = interpolate(String.valueOf(value), recursionInterceptor, unresolvable);
+
+ if (!postProcessors.isEmpty()) {
+ for (InterpolationPostProcessor postProcessor : postProcessors) {
+ Object newVal = postProcessor.execute(realExpr, value);
+ if (newVal != null) {
value = newVal;
break;
}
@@ -243,35 +207,27 @@ private String interpolate( String input, RecursionInterceptor recursionIntercep
// result = matcher.replaceFirst( stringValue );
// but this could result in multiple lookups of stringValue, and replaceAll is not correct
// behaviour
- result.append( value );
+ result.append(value);
resolved = true;
+ } else {
+ unresolvable.add(wholeExpr);
}
- else
- {
- unresolvable.add( wholeExpr );
- }
- }
- finally
- {
- recursionInterceptor.expressionResolutionFinished( realExpr );
+ } finally {
+ recursionInterceptor.expressionResolutionFinished(realExpr);
}
}
- if ( !resolved )
- {
- result.append( wholeExpr );
+ if (!resolved) {
+ result.append(wholeExpr);
}
endIdx += endExpr.length() - 1;
}
- if ( endIdx == -1 && startIdx > -1 )
- {
- result.append( input, startIdx, input.length() );
- }
- else if ( endIdx < input.length() )
- {
- result.append( input, endIdx + 1, input.length() );
+ if (endIdx == -1 && startIdx > -1) {
+ result.append(input, startIdx, input.length());
+ } else if (endIdx < input.length()) {
+ result.append(input, endIdx + 1, input.length());
}
return result.toString();
@@ -287,15 +243,12 @@ else if ( endIdx < input.length() )
* {@link Throwable} instances.
*/
@Override
- public List getFeedback()
- {
+ public List getFeedback() {
List> messages = new ArrayList();
- for ( ValueSource vs : valueSources )
- {
+ for (ValueSource vs : valueSources) {
List feedback = vs.getFeedback();
- if ( feedback != null && !feedback.isEmpty() )
- {
- messages.addAll( feedback );
+ if (feedback != null && !feedback.isEmpty()) {
+ messages.addAll(feedback);
}
}
@@ -306,31 +259,24 @@ public List getFeedback()
* Clear the feedback messages from previous interpolate(..) calls.
*/
@Override
- public void clearFeedback()
- {
- for ( ValueSource vs : valueSources )
- {
+ public void clearFeedback() {
+ for (ValueSource vs : valueSources) {
vs.clearFeedback();
}
}
@Override
- public boolean isCacheAnswers()
- {
+ public boolean isCacheAnswers() {
return cacheAnswers;
}
@Override
- public void setCacheAnswers( boolean cacheAnswers )
- {
+ public void setCacheAnswers(boolean cacheAnswers) {
this.cacheAnswers = cacheAnswers;
}
@Override
- public void clearAnswers()
- {
+ public void clearAnswers() {
existingAnswers.clear();
}
-
}
-
diff --git a/src/main/java/org/codehaus/mojo/flatten/cifriendly/CiModelInterpolator.java b/src/main/java/org/codehaus/mojo/flatten/cifriendly/CiModelInterpolator.java
index f8e13425..51086420 100644
--- a/src/main/java/org/codehaus/mojo/flatten/cifriendly/CiModelInterpolator.java
+++ b/src/main/java/org/codehaus/mojo/flatten/cifriendly/CiModelInterpolator.java
@@ -63,19 +63,17 @@
*
* IMPORTANT: this is a legacy Plexus component, with manually authored descriptor in src/main/resources!
*/
-public class CiModelInterpolator implements CiInterpolator, ModelInterpolator
-{
+public class CiModelInterpolator implements CiInterpolator, ModelInterpolator {
- private static final List PROJECT_PREFIXES = Arrays.asList( "pom.", "project." );
+ private static final List PROJECT_PREFIXES = Arrays.asList("pom.", "project.");
private static final Collection