-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon-methods.gradle
More file actions
127 lines (94 loc) · 2.75 KB
/
common-methods.gradle
File metadata and controls
127 lines (94 loc) · 2.75 KB
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
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.xml.sax.SAXException;
def getVersion(path) {
//check nuspec version
File f = new File(path);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
try {
Document doc = dBuilder.parse(f);
doc.getDocumentElement().normalize();
def value = doc.getElementsByTagName("version").item(0).getTextContent();
return value.replaceAll("(\\r|\\n|\\r\\n)+", "").trim();
} catch(IOException| SAXException | IllegalArgumentException e) {
return null
}
}
def getAssemblyVersion(path) {
// check c# assembly version
File f = new File(path);
def line
def version = "0.0.0"
f.withReader { reader ->
while ((line = reader.readLine())!=null) {
if( (line =~ /AssemblyVersion\("(\d\.\d\.\d)/) ) {
version = (line =~ /AssemblyVersion\("(\d\.\d\.\d)/)[0][1]
break;
}
}
}
return version
}
def getVersionNupkg(path) {
FileTree tree = fileTree(dir: path, include: '*.nupkg')
Set<File> nupkgFiles = tree.getFiles()
if(nupkgFiles.size() == 1) {
File f = null
nupkgFiles.each { file -> f = file }
def version = (f.name =~ /.*(\d\.\d\.\d)/)[0][1]
if(version != null) {
return version
} else {
println "Invalide .nupkg version number."
}
} else {
println nupkgFiles.size()
println "Incorrect number of .nupkg files."
}
return "0.0.0"
}
def parseVersion(versionStr) {
return versionStr.replaceAll('\\.', '')
}
def getCurrentDir() {
return file()
}
def isUpdatedVersion(nupkgVersion, nuspecVersion) {
return !nupkgVersion.equals(nuspecVersion)
}
def isUpdatedVersionTwo(assemblyVersion, nupkgVersion) {
println 'c# : ' + assemblyVersion
println 'nupkg : ' + nupkgVersion
return parseVersion(assemblyVersion) > parseVersion(nupkgVersion)
}
def getIntAssemblyVersion(path) {
def strVersion = getAssemblyVersion(path)
return parseVersion(strVersion)
}
def getIntVersionNupkg(path) {
def strVersion = getVersionNupkg(path)
return parseVersion(strVersion)
}
ext {
getVersion = this.&getVersion
getVersionNupkg = this.&getVersionNupkg
getCurrentDir = this.&getCurrentDir
isUpdatedVersion = this.&isUpdatedVersion
getAssemblyVersion = this.&getAssemblyVersion
getIntAssemblyVersion = this.&getIntAssemblyVersion
getIntVersionNupkg = this.&getIntVersionNupkg
isUpdatedVersionTwo = this.&isUpdatedVersionTwo
}