-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#84 Add PomChangeParentVersion that preserves file formatting
- Loading branch information
1 parent
19e7dd2
commit 4bde043
Showing
37 changed files
with
1,512 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
.../java/com/paypal/butterfly/utilities/operations/pom/AbstractStaxArtifactPomOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.paypal.butterfly.utilities.operations.pom; | ||
|
||
import com.paypal.butterfly.extensions.api.exception.TransformationDefinitionException; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Abstract Artifact POM operation. | ||
* | ||
* @author facarvalho | ||
*/ | ||
public abstract class AbstractStaxArtifactPomOperation<T extends AbstractStaxArtifactPomOperation> extends AbstractStaxPomOperation<T> { | ||
|
||
protected String groupId; | ||
protected String artifactId; | ||
|
||
public T setGroupId(String groupId) { | ||
checkForBlankString("GroupId", groupId); | ||
this.groupId = groupId; | ||
return (T) this; | ||
} | ||
|
||
public T setArtifactId(String artifactId) { | ||
checkForBlankString("ArtifactId",artifactId); | ||
this.artifactId = artifactId; | ||
return (T) this; | ||
} | ||
|
||
/** | ||
* Set dependency group id and artifact id based on a String | ||
* whose format is "groupId:artifactId". It throws a | ||
* {@link TransformationDefinitionException} if the specified | ||
* artifact String is invalid | ||
* | ||
* @param artifact the artifact formatted String | ||
* @return this operation instance | ||
*/ | ||
public T setArtifact(String artifact) { | ||
checkForBlankString("artifact", artifact); | ||
String[] split = artifact.split(":"); | ||
if (split.length != 2) { | ||
throw new TransformationDefinitionException("Invalid artifact " + artifact); | ||
} | ||
groupId = split[0]; | ||
artifactId = split[1]; | ||
return (T) this; | ||
} | ||
|
||
public String getGroupId() { | ||
return groupId; | ||
} | ||
|
||
public String getArtifactId() { | ||
return artifactId; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) return true; | ||
if (!(obj instanceof AbstractStaxArtifactPomOperation)) return false; | ||
|
||
AbstractStaxArtifactPomOperation tu = (AbstractStaxArtifactPomOperation) obj; | ||
if (!Objects.equals(tu.groupId, this.groupId)) return false; | ||
if (!Objects.equals(tu.artifactId, this.artifactId)) return false; | ||
|
||
return super.equals(obj); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return hashCode(super.hashCode(), groupId, artifactId); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...src/main/java/com/paypal/butterfly/utilities/operations/pom/AbstractStaxPomOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.paypal.butterfly.utilities.operations.pom; | ||
|
||
import com.paypal.butterfly.extensions.api.TOExecutionResult; | ||
import com.paypal.butterfly.extensions.api.TransformationContext; | ||
import com.paypal.butterfly.utilities.operations.pom.stax.AbstractStaxOperation; | ||
import org.apache.maven.model.Model; | ||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; | ||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; | ||
|
||
import javax.xml.stream.XMLStreamException; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Abstract POM operation. | ||
* | ||
* @author facarvalho | ||
*/ | ||
abstract class AbstractStaxPomOperation<T extends AbstractStaxPomOperation> extends AbstractStaxOperation<T> { | ||
|
||
/* | ||
* Read the Maven pom file and returns an in-memory model of it | ||
*/ | ||
protected Model getModel(File pomFile) throws IOException, XmlPullParserException { | ||
MavenXpp3Reader reader = new MavenXpp3Reader(); | ||
FileInputStream fileInputStream = new FileInputStream(pomFile); | ||
Model model = reader.read(fileInputStream); | ||
fileInputStream.close(); | ||
|
||
return model; | ||
} | ||
|
||
@Override | ||
protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { | ||
return super.execution(transformedAppFolder, transformationContext); | ||
} | ||
|
||
@Override | ||
protected TOExecutionResult xmlExecution(File transformedAppFolder, TransformationContext transformationContext) throws XmlPullParserException, XMLStreamException, IOException { | ||
return pomExecution(transformedAppFolder, transformationContext); | ||
} | ||
|
||
/* | ||
* This abstract method is supposed to be developed by the subclasses executing POM file operations | ||
*/ | ||
protected abstract TOExecutionResult pomExecution(File transformedAppFolder, TransformationContext transformationContext) throws XmlPullParserException, XMLStreamException, IOException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.