-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVersionIncrementer.xml
169 lines (146 loc) · 11.5 KB
/
VersionIncrementer.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<project name="VersionIncrementer" default="increment-version">
<property file="ModInfo.java"/>
<target name="increment-version">
<loadfile property="fileContentModInfo" srcFile="src/main/java/com/SwingTheVine/QSAND/ModInfo.java"/>
<script language="javascript">
<![CDATA[
var fileContent = project.getProperty("fileContentModInfo"); // Gets the content of the ModInfo file
var lines = fileContent.split("\n"); // All file content is in a string. This splits the string into multiple lines (a multi-line string if you will) at the delimiter of a new line character
var newContent = []; // Will store each line as it comes across them (and potentially modifies them)
var versionPattern = /version\s*=\s*\"(\d+)\.(\d+)\.(\d+)\"/; // A RegEx to match the three numbers in the version
var versionPatternPatch = /totalPatches\s*=\s*\"(\d+)\"/; // A RegEx to match the total patches
// For every line...
for (var i = 0; i < lines.length; i++) {
var currentLine = lines[i]; // Sets the current line to its own variable
var match = versionPattern.exec(currentLine); // (boolean) Does the line match the RegEx?
var matchPatch = versionPatternPatch.exec(currentLine); // (boolean) Does the line match the RegEx?
// If the RegEx matches this line...
if (match) {
var major = parseInt(match[1]); // Stores the major number as the first RegEx number matched
var minor = parseInt(match[2]); // Stores the minor number as the second RegEx number matched
var patch = parseInt(match[3]) + 1; // Stores the patch number as the third RegEx number matched and adds one
var newVersion = major + '.' + minor + '.' + patch; // Reforms the version string with the new version number
newContent.push('\tpublic static final String version = "' + newVersion + '";'); // Reforms the entire line using the new version string
// Else If total patches RegEx matches this line...
} else if (matchPatch) {
var patchPatch = parseInt(matchPatch[1]) + 1; // Increment the total patches
newContent.push('\tpublic static final String totalPatches = "' + patchPatch + '";'); // Reform the entire line
} else {
newContent.push(currentLine); // This line is not the version. Add it to the new file without modifying
}
}
var newFileContent = newContent.join("\n"); // Converts the Array into a string. Adds back the line delimiter of a new line character (except for on the last line)
project.setProperty("newFileContent", newFileContent); // Sets the new file content as a variable in the Ant instance
]]>
</script>
<echo message="New content:"/>
<echo message="${newFileContent}"/>
<echo file="src/main/java/com/SwingTheVine/QSAND/ModInfo.java" message="${newFileContent}"/>
</target>
<target name="increment-mcmod">
<loadfile property="fileContentMCMod" srcFile="src/main/resources/mcmod.info"/>
<loadfile property="fileContentModInfo2" srcFile="src/main/java/com/SwingTheVine/QSAND/ModInfo.java"/>
<script language="javascript">
<![CDATA[
var fileContent2 = project.getProperty("fileContentModInfo2"); // Obtains the ModInfo file contents
var lines2 = fileContent2.split("\n"); // Splits the file contents at the delimiter of a new line character
var versionPattern2 = /version\s*=\s*\"(\d+)\.(\d+)\.(\d+)\"/; // Matches the version variable
var major2 = 0; // Major version of version in ModInfo
var minor2 = 0; // Minor version of version in ModInfo
var patch2 = 0; // Patch version of version in ModInfo
// For every line...
for (var i = 0; i < lines2.length; i++) {
var currentLine2 = lines2[i]; // Sets the current line
var match2 = versionPattern2.exec(currentLine2); // Does it match the version RegEx?
// If the RegEx matches...
if (match2) {
major2 = parseInt(match2[1]); // Store the major version
minor2 = parseInt(match2[2]); // Store the minor version
patch2 = parseInt(match2[3]); // Store the patch version
}
}
var fileContent = project.getProperty("fileContentMCMod"); // Gets the content of the Ant's target file
var lines = fileContent.split("\n"); // All file content is in a string. This splits the string into multiple lines (a multi-line string if you will) at the delimiter of a new line character
var newContent = []; // Will store each line as it comes across them (and potentially modifies them)
var versionPattern = /\"version\"\:\s*\"(\d+)\.(\d+)\.(\d+)\",/; // A RegEx to match the three numbers in the version
// For every line...
for (var i = 0; i < lines.length; i++) {
var currentLine = lines[i]; // Sets the current line to its own variable
var match = versionPattern.exec(currentLine); // (boolean) Does the line match the RegEx?
// If the RegEx matches this line...
if (match) {
var newVersion = major2 + '.' + minor2 + '.' + patch2; // Reforms the version string with the new version number
newContent.push(' "version": "' + newVersion + '",'); // Reforms the entire line using the new version string
} else {
newContent.push(currentLine); // This line is not the version. Add it to the new file without modifying
}
}
var newFileContent = newContent.join("\n"); // Converts the Array into a string. Adds back the line delimiter of a new line character (except for on the last line)
project.setProperty("newFileContent", newFileContent); // Sets the new file content as a variable in the Ant instance
]]>
</script>
<echo message="New content:"/>
<echo message="${newFileContent}"/>
<echo file="src/main/resources/mcmod.info" message="${newFileContent}"/>
</target>
<target name="increment-readme">
<loadfile property="fileContentREADME" srcFile="docs/README.md"/>
<loadfile property="fileContentModInfo" srcFile="src/main/java/com/SwingTheVine/QSAND/ModInfo.java"/>
<script language="javascript">
<![CDATA[
var fileContentRead = project.getProperty("fileContentModInfo"); // Obtains the contents of the ModInfo file
var linesRead = fileContentRead.split("\n"); // Splits the file at the delimiter of a new line character
var versionPatternRead = /version\s*=\s*\"(\d+)\.(\d+)\.(\d+)\"/; // A RegEx to match the three numbers in the version
var versionPatternReadPatch = /totalPatches\s*=\s*\"(\d+)\"/; // The RegEx for total patches variable
var majorRead = 0; // Stores the major version from ModInfo
var minorRead = 0; // Stores the minor version from ModInfo
var patchRead = 0; // Stores the patch version from ModInfo
var patchReadPatch = 0; // Stores the total patch variable from ModInfo
// For every line...
for (var i = 0; i < linesRead.length; i++) {
var currentLineRead = linesRead[i]; // Sets the current line
var matchRead = versionPatternRead.exec(currentLineRead); // Does the RegEx version match this line?
var matchReadPatch = versionPatternReadPatch.exec(currentLineRead); // Does the RegEx total patches match this line?
// If version is a match...
if (matchRead) {
majorRead = parseInt(matchRead[1]); // Store major version
minorRead = parseInt(matchRead[2]); // Store minor version
patchRead = parseInt(matchRead[3]) + 1; // Store and increment patch version
// Else If the total patch is a match...
} else if (matchReadPatch) {
patchReadPatch = parseInt(matchReadPatch[1]) + 1; // Store and increment total patches
}
}
var fileContent = project.getProperty("fileContentREADME"); // Gets the content of the Ant's target file
var lines = fileContent.split("\n"); // All file content is in a string. This splits the string into multiple lines (a multi-line string if you will) at the delimiter of a new line character
var newContent = []; // Will store each line as it comes across them (and potentially modifies them)
var versionPattern = /Latest_Version-(\d+)\.(\d+)\.(\d+)--(\d+)\.(\d+)\.(\d+)-lightblue/; // A RegEx to match the three numbers in the version
var versionPatternPatch = /Total_Patches-(\d+)-black/;
project.setProperty("lineLength", lines.length);
// For every line...
for (var i = 0; i < lines.length; i++) {
var currentLine = lines[i]; // Sets the current line to its own variable
var match = versionPattern.exec(currentLine); // (boolean) Does the line match the RegEx?
var matchPatch = versionPatternPatch.exec(currentLine);
// If the RegEx matches this line...
if (match) {
var newVersion = parseInt(match[1]) + '.' + parseInt(match[2]) + '.' + parseInt(match[3]) + '--' + majorRead + '.' + minorRead + '.' + patchRead; // Reforms the version string with the new version number
newContent.push('<a href=\"\" target=\"_blank\"><img alt=\"Latest Version\" src=\"https://img.shields.io/badge/Latest_Version-' + newVersion + '-lightblue?style=flat\"></a>'); // Reforms the entire line using the new version string
// If the total patched RegEx matches...
} else if (matchPatch) {
newContent.push('<a href=\"\" target=\"_blank\"><img alt=\"Total Patches\" src=\"https://img.shields.io/badge/Total_Patches-' + patchReadPatch + '-black?style=flat"></a>');
} else {
newContent.push(currentLine); // This line is not the version. Add it to the new file without modifying
}
}
var newFileContent = newContent.join("\n"); // Converts the Array into a string. Adds back the line delimiter of a new line character (except for on the last line)
project.setProperty("newFileContent", newFileContent); // Sets the new file content as a variable in the Ant instance
]]>
</script>
<echo message="Line Count:"/>
<echo message="${lineLength}"/>
<echo message="New content:"/>
<echo message="${newFileContent}"/>
<echo file="docs/README.md" message="${newFileContent}"/>
</target>
</project>