Skip to content

Commit f4b5d31

Browse files
#18 Update current README and javadocs
1 parent 4064bbf commit f4b5d31

File tree

3 files changed

+69
-16
lines changed

3 files changed

+69
-16
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public class FooToBarMigration extends AbstractMigration {
5252
The following Java classes in `org.technologybrewery.baton.util` can be leveraged to easily implement common migration logic into your extension:
5353
* `CommonUtils`
5454
* `FileUtils`
55+
* `pom.PomHelper`
56+
* `pom.PomModifications`
57+
* `pom.LocationAwareMavenReader`
5558

5659
### Configure Baton to use the migration
5760
With a migration to apply, we both configure and tailor that use through a simple json file. This file can live anywhere

baton-maven-plugin/src/main/java/org/technologybrewery/baton/util/pom/PomHelper.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717
import java.nio.file.Paths;
1818
import java.nio.file.StandardCopyOption;
1919

20+
/**
21+
* Generalized static utilities for assisting with altering Maven POM files.
22+
*/
2023
public final class PomHelper {
2124

2225
private PomHelper(){
2326
}
2427

2528
/**
2629
* Helper function to construct a Model of a pom file.
30+
*
2731
* @param file File object representing a pom file.
2832
* @return the constructed Model.
2933
*/
@@ -40,6 +44,7 @@ public static Model getLocationAnnotatedModel(File file) {
4044

4145
/**
4246
* Writes a finalized set of modifications back to a pom file.
47+
*
4348
* @param file The original pom file.
4449
* @param modifications Finalized set of modifications.
4550
* @return true iff the write operation completes successfully.
@@ -68,7 +73,15 @@ public static boolean writeModifications(File file, PomModifications.Final modif
6873
return true;
6974
}
7075

71-
public static InputLocation incrementColumn(InputLocation location, int i) {
76+
/**
77+
* Shifts the given column index for a given InputLocation type by a given amount.
78+
*
79+
* @param location the initial location to be updated with a new column index as a InputLocation.
80+
* @param columnIndexShift number of column indexes to move by represented as a signed integer.
81+
* @return a new InputLocation type with an updated column index.
82+
* @see org.apache.maven.model.InputLocation
83+
*/
84+
public static InputLocation incrementColumn(InputLocation location, int columnIndexShift) {
7285
return new InputLocation(location.getLineNumber(), location.getColumnNumber() + i, location.getSource());
7386
}
7487
}

baton-maven-plugin/src/main/java/org/technologybrewery/baton/util/pom/PomModifications.java

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,31 @@
1717
*/
1818
public final class PomModifications extends TreeSet<PomModifications.Modification> {
1919

20+
/**
21+
* Returns an instance of the Final class configure with an iterable of all loaded POM file modifications.
22+
*
23+
* @see org.technologybrewery.baton.util.pom.PomModifications.Final
24+
*/
2025
public Final finalizeMods() {
2126
return new Final(iterator());
2227
}
2328

29+
/**
30+
* A class to iteratively apply a series of POM file modifications.
31+
*
32+
* @see org.technologybrewery.baton.util.pom.PomModifications.Modification
33+
*/
2434
public static class Final {
2535
private Iterator<Modification> iterator;
2636
private Modification next;
2737

38+
/**
39+
* Constructor that initializes a series of POM file modifications passed in as an Iterator of the
40+
* internally defined Modification class.
41+
*
42+
* @param iterator A given Iterator of the type Modification.
43+
* @see org.technologybrewery.baton.util.pom.PomModifications.Modification
44+
*/
2845
private Final(Iterator<Modification> iterator) {
2946
this.iterator = iterator;
3047
next = iterator.next();
@@ -38,11 +55,11 @@ public boolean appliesTo(int lineNumber) {
3855
/**
3956
* Applies the next modification to the input reader, writing the result to the output writer.
4057
*
41-
* @param in the input reader
42-
* @param out the output writer
43-
* @param line the current line of the input reader
44-
* @return the line number of `in` after the modification has been applied (changes iff the input reader was advanced)
45-
* @throws IOException if an I/O error occurs
58+
* @param in the input reader.
59+
* @param out the output writer.
60+
* @param line the current line of the input reader.
61+
* @return the line number of `in` after the modification has been applied (changes iff the input reader was advanced).
62+
* @throws IOException if an I/O error occurs.
4663
*/
4764
public int apply(BufferedReader in, Writer out, String line) throws IOException {
4865
int newInputLine = next.apply(in, out, line);
@@ -55,9 +72,19 @@ public int apply(BufferedReader in, Writer out, String line) throws IOException
5572
}
5673
}
5774

75+
/**
76+
* The abstract class by which all POM file modifications inherit from.
77+
*/
5878
public static abstract class Modification implements Comparable<Modification> {
5979
private final InputLocation start;
6080

81+
/**
82+
* The constructor accepts an InputLocation type representing the line and column of the file
83+
* where modifications will start being applied.
84+
*
85+
* @param start the location to begin modifying the content.
86+
* @see org.apache.maven.model.InputLocation
87+
*/
6188
public Modification(InputLocation start) {
6289
this.start = start;
6390
}
@@ -85,6 +112,13 @@ public int compareTo(Modification o) {
85112
public static class Deletion extends Modification {
86113
private final InputLocation end;
87114

115+
/**
116+
* Constructor to delete content between the given start and end parameters.
117+
*
118+
* @param start the location to begin deleting POM file content (inclusive).
119+
* @param end the location to stop deleting POM file content (exclusive).
120+
* @see org.apache.maven.model.InputLocation
121+
*/
88122
public Deletion(InputLocation start, InputLocation end) {
89123
super(start);
90124
this.end = end;
@@ -125,9 +159,12 @@ public static class Insertion extends Modification {
125159
private final int currentIndent;
126160

127161
/**
128-
* @param start the location to insert the content (will insert before the existing content on that line)
129-
* @param currentIndent the indent level of the current content on the line
130-
* @param contentProducer a function that produces the content to insert, given a one-level indent string
162+
* Constructor to insert content before the given start existing content on the given start index.
163+
*
164+
* @param start the location to insert the content (before the existing content on that line).
165+
* @param currentIndent the indent level of the current content on the line.
166+
* @param contentProducer a function that produces the content to insert, given a one-level indent string.
167+
* @see org.apache.maven.model.InputLocation
131168
*/
132169
public Insertion(InputLocation start, int currentIndent, Function<String,String> contentProducer) {
133170
super(start);
@@ -156,9 +193,9 @@ public static class Replacement extends Modification {
156193
/**
157194
* Constructor for replacing content within a single line.
158195
*
159-
* @param start the location to insert the new content
160-
* @param end the location to skip to, existing content between start and end will be deleted
161-
* @param content the new content
196+
* @param start the location to insert the new content.
197+
* @param end the location to skip to, existing content between start and end will be deleted.
198+
* @param content the new content.
162199
*/
163200
public Replacement(InputLocation start, InputLocation end, String content) {
164201
this(start, end, 0, l -> content);
@@ -167,10 +204,10 @@ public Replacement(InputLocation start, InputLocation end, String content) {
167204
/**
168205
* Constructor for multi-line replacements.
169206
*
170-
* @param start the location to insert the new content
171-
* @param end the location to skip to, existing content between start and end will be deleted
172-
* @param indentLvl the indent level of the current content on the line
173-
* @param contentProducer a function that produces the content to insert, given a one-level indent string
207+
* @param start the location to insert the new content.
208+
* @param end the location to skip to, existing content between start and end will be deleted.
209+
* @param indentLvl the indent level of the current content on the line.
210+
* @param contentProducer a function that produces the content to insert, given a one-level indent string.
174211
*/
175212
public Replacement(InputLocation start, InputLocation end, int indentLvl, Function<String,String> contentProducer) {
176213
super(start);

0 commit comments

Comments
 (0)