My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#include "Builders.h"

String AdjustLines(const String& file)
{
String out;
const char *p = file;
while(*p)
{
const char *b = p;
while(*p && (byte)*p <= ' ' && *p != '\r' && *p != '\n')
p++;
if(*p == '#')
{
out.Cat("//");
b = p;
while(*p && *p != '\n' && *p != '\"')
p++;
out.Cat(b, (int)(p - b));
b = p;
if(*p == '\"')
{
out.Cat('\"');
b = ++p;
while(*p && *p++ != '\n')
;
const char *e = p;
while(e > b && (byte)e[-1] <= ' ')
e--;
if(e[-1] == '\"')
e--;
out.Cat(UnixPath(String(b, e)));
out.Cat("\"\r\n");
b = p;
continue;
}
}
out.Cat(b, (int)(p - b));
while(*p && *p != '\n')
{
b = p;
while(*p && *p != '\n' && *p != '\r')
p++;
out.Cat(b, (int)(p - b));
while(*p == '\r')
p++;
}
if(*p == '\n')
{
p++;
out.Cat("\r\n");
}
}
return out;
}

String JavaBuilder::JavaLine()
{
return "javac";
}

String JavaBuilder::JarLine()
{
return "jar";
}

enum { MAINCLASS, MAINDIR, MANIFEST, ITEMCOUNT };

bool JavaBuilder::BuildPackage(const String& package, Vector<String>& linkfile, String& linkoptions,
const Vector<String>& all_uses, const Vector<String>& all_libraries, int)
{
int time = msecs();
int i;
int manifest = -1;
String packagepath = PackagePath(package);
Package pkg;
pkg.Load(packagepath);
String packagedir = GetFileFolder(packagepath);
ChDir(packagedir);
PutVerbose("cd " + packagedir);
Vector<String> pkgsfile;
Vector<String> sfile;
Vector<String> sobjfile;
Vector<String> soptions;
bool error = false;
bool main = HasFlag("MAIN");

for(i = 0; i < pkg.GetCount(); i++) {
if(!IdeIsBuilding())
return false;
if(!pkg[i].separator) {
String gop = Gather(pkg[i].option, config.GetKeys());
Vector<String> srcfile = CustomStep(pkg[i], package, error);
if(srcfile.GetCount() == 0)
error = true;
for(int j = 0; j < srcfile.GetCount(); j++)
{
String fn = srcfile[j];
String ext = ToLower(GetFileExt(fn));
bool ismf = false;
if(ext == ".java" || main && ext == ".mf")
{
if(ext == ".mf")
{
ismf = true;
if(manifest >= 0)
{
PutConsole(NFormat("%s(1): duplicate manifest file", GetHostPath(fn)));
PutConsole(NFormat("%s(1): (previous manifest file)", GetHostPath(sfile[manifest])));
}
manifest = sfile.GetCount();
}
String pkgfile = AppendFileName(package, pkg[i]);
pkgsfile.Add(pkgfile);
sfile.Add(fn);
soptions.Add(gop);
String objfile = NativePath(CatAnyPath(outdir, ismf ? String("manifest.mf") : pkgfile));
sobjfile.Add(objfile);
}
}
}
}

Vector<Host::FileInfo> sobjinfo = host->GetFileInfo(sobjfile);
int ccount = 0;
for(i = 0; i < sfile.GetCount(); i++) {
if(!IdeIsBuilding())
return false;
if(HdependFileTime(sfile[i]) > sobjinfo[i]) {
ccount++;
if(!PreprocessJava(sfile[i], sobjfile[i], soptions[i], package, pkg))
error = true;
}
}
linkfile.Add(outdir);
if(ccount > 0)
PutConsole(String().Cat() << ccount << " file(s) preprocessed in " << GetPrintTime(time) <<
" " << int(GetTickCount() - time) / ccount << " msec/file");
linkoptions << ' ' << Gather(pkg.link, config.GetKeys());

if(!error && HasFlag("MAIN") && !sfile.IsEmpty())
{
String mainfile = sfile.Top();
String mainobj = sobjfile.Top();
String maincls = ForceExt(mainobj, ".class");
String libs;
int i;
for(i = 0; i < libpath.GetCount(); i++)
libs << (i ? ";" : " -classpath ") << '\"' << libpath[i] << '\"';
String linkcmd;
linkcmd << "javac";
linkcmd << (HasFlag("DEBUG") ? " -g" : " -g:none");
if(!HasFlag("DEBUG"))
if(!IsNull(release_options))
linkcmd << ' ' << release_options;
else
linkcmd << " -O";
linkcmd << " -deprecation" << linkoptions << " -sourcepath ";
bool win32 = HasFlag("WIN32");
for(i = 0; i < linkfile.GetCount(); i++) {
linkcmd << (i ? (win32 ? ";" : ":") : "");
if(linkfile[i].Find(' ') >= 0)
linkcmd << '\"' << linkfile[i] << '\"';
else
linkcmd << linkfile[i];
}
linkfile.InsertN(0, ITEMCOUNT);
linkfile[MAINCLASS] = maincls;
linkfile[MAINDIR] = outdir;
linkfile[MANIFEST] = (manifest >= 0 ? sobjfile[manifest] : String());
linkcmd << ' ' << mainobj;
linkoptions = linkcmd;
}
return !error;
}

bool JavaBuilder::Preprocess(const String& package, const String& file, const String& target, bool)
{
return Preprocess(file, target, Null, false);
}

bool JavaBuilder::PreprocessJava(String file, String target, String options,
String package, const Package& pkg)
{
String mscpp = GetVar("MSCPP_JDK");
String cc;
if(!IsNull(mscpp))
cc = mscpp + " /C /TP /P /nologo ";
else
cc = "cpp -C ";
cc << IncludesDefinesTargetTime(package, pkg);
int time = GetTickCount();
RealizePath(target);
String execpath;
execpath << cc << ' ' << options << ' ';
String prepfile;
bool error = false;
if(!IsNull(mscpp))
{
prepfile = ForceExt(file, ".i");
host->ChDir(GetFileFolder(prepfile));
execpath << GetHostPath(file);
}
else
{
PutConsole(file);
execpath << GetHostPath(file) << " " << GetHostPath(target);
prepfile = target;
}
if(Execute(execpath) != 0)
{
DeleteFile(target);
error = true;
}
String prep = LoadFile(prepfile);
if(prep.IsEmpty())
{
PutConsole(NFormat("Error loading preprocessed file %s", prepfile));
error = true;
}
DeleteFile(prepfile);
if(!prep.IsEmpty() && !::SaveFile(target, AdjustLines(prep)))
{
DeleteFile(target);
error = true;
PutConsole(NFormat("%s: error saving file.", target));
}
PutVerbose("preprocessed in " + GetPrintTime(time));
return !error;
}

Time JavaBuilder::AddClassDeep(String& link, String dir, String reldir)
{
Time time = Time::Low();
Vector<String> folders;
for(FindFile ff(AppendFileName(dir, AppendFileName(reldir, "*"))); ff; ff.Next()) {
if(ff.IsFolder())
folders.Add(ff.GetName());
else if(!stricmp(GetFileExtPos(ff.GetName()), ".class"))
{
link << " -C \"" << dir << "\" \"" << UnixPath(CatAnyPath(reldir, ff.GetName())) << '\"';
time = max(time, Time(ff.GetLastWriteTime()));
}
}
for(int f = 0; f < folders.GetCount(); f++)
time = max(time, AddClassDeep(link, dir, AppendFileName(reldir, folders[f])));
return time;
}

bool JavaBuilder::Link(const Vector<String>& linkfile, const String& linkoptions, bool)
{
if(linkfile.GetCount() < ITEMCOUNT)
return false;
int time = GetTickCount();
String mainclass = linkfile[MAINCLASS];
String maindir = linkfile[MAINDIR];
String manifest = linkfile[MANIFEST];
PutConsole("Compiling...");
if(Execute(linkoptions) != 0) {
DeleteFile(mainclass);
return false;
}
PutVerbose("compiled in " + GetPrintTime(time));
host->ChDir(maindir);

PutConsole("Archiving...");
String cmdline;
cmdline << "cf";
if(!manifest.IsEmpty())
cmdline << 'm';
cmdline << ' ' << GetHostPath(target);
if(!manifest.IsEmpty())
cmdline << ' ' << GetHostPath(manifest);
Time tm = Time::Low();
for(int i = ITEMCOUNT; i < linkfile.GetCount(); i++)
tm = max(tm, AddClassDeep(cmdline, linkfile[i], Null));
bool error = false;
if(tm > targettime) {
CustomStep(".pre-link", Null, error);
String link, response;
link << "jar ";
if(cmdline.GetLength() < 32000)
link << cmdline;
else {
response = GetTempFileName("jar");
link << '@' << response;
if(!UPP::SaveFile(response, cmdline)) {
PutConsole(String().Cat() << "Error writing JAR response file '" << response << "'");
return false;
}
}
bool ok = (Execute(link) == 0);
if(!IsNull(response))
FileDelete(response);
if(!ok) {
DeleteFile(target);
return false;
}
CustomStep(".post-link", Null, error);
PutConsole(String().Cat() << target << " (" << GetFileInfo(target).length
<< " B) archived in " << GetPrintTime(time));
}
else
PutConsole(String().Cat() << GetHostPath(target) << " (" << GetFileInfo(target).length
<< " B) is up to date.");
return true;
}

static Builder *CreateJavaBuilder()
{
return new JavaBuilder;
}

INITBLOCK
{
RegisterBuilder("JDK", &CreateJavaBuilder);
}

Change log

r4203 by cxl on Nov 25, 2011   Diff
ide: Custom build steps refresh
Go to: 
Project members, sign in to write a code review

Older revisions

r3717 by cxl on Jul 30, 2011   Diff
.devloping umake
All revisions of this file

File info

Size: 8435 bytes, 316 lines
Powered by Google Project Hosting