-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeData.py
More file actions
188 lines (130 loc) · 5.82 KB
/
makeData.py
File metadata and controls
188 lines (130 loc) · 5.82 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import os
import compositor, utils
class MakeData:
def __init__(self):
self.projectPath = ""
self.jarName = "app"
self.outDirs = ["release"]
self.mainClass = ""
self.srcDirs = ["src"]
self.imports = []
self.dynImports = []
self.dynImportsExt = []
self.extLibDir = "lib"
self.packFiles = []
self.copyFiles = []
self.targets = ["jar"]
self.runScripts = []
self.javacOptions = []
self.runOptions = []
self.compiledDependency = False
def loadFromData(self, projectPath, jsonData):
data = utils.CaseInsensitiveDict(jsonData)
self.projectPath = projectPath.replace("\\", "/")
self.jarName = data["jarName"] if "jarName" in data else self.jarName
self.outDirs = data["outDir"] if "outDir" in data else self.outDirs
self.outDirs = data["outDirs"] if "outDirs" in data else self.outDirs
self.mainClass = data["main"] if "main" in data else self.mainClass
self.mainClass = data["mainClass"] if "mainClass" in data else self.mainClass
self.srcDirs = data["sourceDirs"] if "sourceDirs" in data else self.srcDirs
self.imports = data["imports"] if "imports" in data else self.imports
self.dynImports = data["dynImports"] if "dynImports" in data else self.dynImports
self.dynImportsExt = data["dynImportsExt"] if "dynImportsExt" in data else self.dynImportsExt
self.extLibDir = data["extLibDir"] if "extLibDir" in data else self.extLibDir
self.packFiles = data["packFiles"] if "packFiles" in data else self.packFiles
self.copyFiles = data["copyFiles"] if "copyFiles" in data else self.copyFiles
self.targets = data["target"] if "target" in data else self.targets
self.targets = data["targets"] if "targets" in data else self.targets
self.runScripts = data["runScripts"] if "runScripts" in data else self.runScripts
self.runScripts = data["scripts"] if "scripts" in data else self.runScripts
self.javacOptions = data["javacOptions"] if "javacOptions" in data else self.javacOptions
self.runOptions = data["runOptions"] if "runOptions" in data else self.runOptions
self.srcDirs = ensureList(self.srcDirs)
self.imports = ensureList(self.imports)
self.dynImports = ensureList(self.dynImports)
self.dynImportsExt = ensureList(self.dynImportsExt)
self.packFiles = ensureList(self.packFiles)
self.copyFiles = ensureList(self.copyFiles)
self.targets = ensureList(self.targets)
self.runScripts = ensureList(self.runScripts)
self.outDirs = ensureList(self.outDirs)
self.runOptions = ensureList(self.runOptions)
self.javacOptions = ensureList(self.javacOptions)
self.targets = [t.lower().strip() for t in self.targets]
self.runScripts = [s.lower().strip() for s in self.runScripts]
if not self.jarName.lower().endswith(".jar"):
self.jarName = self.jarName+".jar"
if ("bin" in self.targets or self.javacOptions) and self.mainClass and not self.runScripts:
self.runScripts = ["py"]
compositor.completePaths(self.srcDirs, projectPath)
compositor.completePaths(self.imports, projectPath)
compositor.completePaths(self.dynImports, projectPath)
compositor.completePaths(self.dynImportsExt, projectPath)
self.extLibDir = compositor.completePath(self.extLibDir, projectPath)
compositor.completePaths(self.packFiles, projectPath)
compositor.completePaths(self.outDirs, projectPath)
self._collectCopyFiles()
expandWildcards(self.imports, self.dynImports, self.dynImportsExt, self.packFiles)
def _collectCopyFiles(self):
files = []
for entry in self.copyFiles:
if not (isinstance(entry, str) or isinstance(entry, list)):
print("Warning: invalid entry in copyFiles: \""+str(entry)+"\".")
continue
if isinstance(entry, str) or len(entry) == 1 or not entry[1]:
src = entry if isinstance(entry, str) else entry[0]
src = src.replace("\\", "/")
if utils.is_absolute(src) and not src.startswith(self.projectPath):
print("Warning: Src-only entries in copyFiles must be" \
" inside the project's directory. \""+src+"\"")
continue
if not utils.is_absolute(src):
src = self.projectPath+"/"+src
dst = src[len(self.projectPath)+1:]
self._addEntryToCopyFiles(files, src, dst)
elif isinstance(entry, list) and len(entry) == 2:
src = compositor.completePath(entry[0], self.projectPath)
dst = entry[1].replace("\\", "/")
if not dst or utils.is_absolute(dst):
if dst.startswith(self.projectPath):
dst = dst[len(self.projectPath)+1:]
else:
print("Warning: Absolute filepath as dst in copyFiles \""+str(dst)+"\".")
continue
self._addEntryToCopyFiles(files, src, dst)
self.copyFiles = files
def _addEntryToCopyFiles(self, files, source, dest):
if os.path.isdir(source):
for directory, subdirList, fileList in os.walk(source):
for file in fileList:
src = directory.replace("\\", "/")+"/"+file
dst = dest+src[len(source):]
files.append(src)
files.append(dst)
else:
if os.path.exists(source):
files.append(source)
files.append(dest)
else:
print("Warning: File \""+source+"\" not found but listed in copyFiles.")
def expandWildcards(*paths):
for pths in paths:
i = 0
while i < len(pths):
p = pths[i]
name = p[p.rfind("/")+1:]
dir = p[:p.rfind("/")]
ind = name.find("*")
if ind < 0 or not os.path.isdir(dir):
i += 1
continue
prefix = name[:ind]
suffix = name[ind+1:]
for file in os.listdir(dir):
if file.startswith(prefix) and file.endswith(suffix):
pths.append(dir+"/"+file)
del pths[i]
def ensureList(lst):
if not isinstance(lst, list):
return [lst]
return lst