Lines 74-79
Link Here
|
74 |
import org.apache.tools.ant.Task; |
74 |
import org.apache.tools.ant.Task; |
75 |
import org.apache.tools.ant.taskdefs.Get; |
75 |
import org.apache.tools.ant.taskdefs.Get; |
76 |
import org.apache.tools.ant.types.FileSet; |
76 |
import org.apache.tools.ant.types.FileSet; |
|
|
77 |
import org.apache.tools.ant.util.FileUtils; |
77 |
import org.netbeans.nbbuild.AutoUpdateCatalogParser.ModuleItem; |
78 |
import org.netbeans.nbbuild.AutoUpdateCatalogParser.ModuleItem; |
78 |
import org.w3c.dom.Document; |
79 |
import org.w3c.dom.Document; |
79 |
import org.w3c.dom.Element; |
80 |
import org.w3c.dom.Element; |
Lines 94-99
Link Here
|
94 |
private File cluster; |
95 |
private File cluster; |
95 |
private URL catalog; |
96 |
private URL catalog; |
96 |
private boolean force; |
97 |
private boolean force; |
|
|
98 |
private File cache; |
99 |
boolean optimizeForLocal; // for test |
97 |
|
100 |
|
98 |
public void setUpdateCenter(URL u) { |
101 |
public void setUpdateCenter(URL u) { |
99 |
catalog = u; |
102 |
catalog = u; |
Lines 130-135
Link Here
|
130 |
return m; |
133 |
return m; |
131 |
} |
134 |
} |
132 |
|
135 |
|
|
|
136 |
/** |
137 |
* Location of per-user cache of already downloaded binaries. |
138 |
* Optional; no cache will be used if unset. |
139 |
* The directory will be created if it does not yet exist. |
140 |
*/ |
141 |
public void setCache(File cache) { |
142 |
if (cache.getAbsolutePath().contains("${")) { |
143 |
log("Ignoring unevaluated cache dir: " + cache, Project.MSG_INFO); |
144 |
} else { |
145 |
this.cache = cache; |
146 |
} |
147 |
} |
148 |
|
133 |
@Override |
149 |
@Override |
134 |
public void execute() throws BuildException { |
150 |
public void execute() throws BuildException { |
135 |
boolean downloadOnly = false; |
151 |
boolean downloadOnly = false; |
Lines 183-189
Link Here
|
183 |
} |
199 |
} |
184 |
|
200 |
|
185 |
|
201 |
|
186 |
for (ModuleItem uu : units.values()) { |
202 |
for (Map.Entry<String,ModuleItem> entry : units.entrySet()) { |
|
|
203 |
String id = entry.getKey(); |
204 |
ModuleItem uu = entry.getValue(); |
187 |
if (!matches(uu.getCodeName(), uu.targetcluster)) { |
205 |
if (!matches(uu.getCodeName(), uu.targetcluster)) { |
188 |
continue; |
206 |
continue; |
189 |
} |
207 |
} |
Lines 201-207
Link Here
|
201 |
boolean delete = false; |
219 |
boolean delete = false; |
202 |
File lastM = null; |
220 |
File lastM = null; |
203 |
try { |
221 |
try { |
204 |
if (download == null && uu.getURL().getProtocol().equals("file")) { |
222 |
if (download == null && uu.getURL().getProtocol().equals("file") && !optimizeForLocal) { |
205 |
try { |
223 |
try { |
206 |
tmp = new File(uu.getURL().toURI()); |
224 |
tmp = new File(uu.getURL().toURI()); |
207 |
} catch (URISyntaxException ex) { |
225 |
} catch (URISyntaxException ex) { |
Lines 232-244
Link Here
|
232 |
} else { |
250 |
} else { |
233 |
log("Version " + info.get(0) + " of " + uu.getCodeName() + " needs update to " + uu.getSpecVersion(), Project.MSG_INFO); |
251 |
log("Version " + info.get(0) + " of " + uu.getCodeName() + " needs update to " + uu.getSpecVersion(), Project.MSG_INFO); |
234 |
} |
252 |
} |
235 |
Get get = new Get(); |
253 |
if (cache == null) { |
236 |
get.setProject(getProject()); |
254 |
download(uu, tmp); |
237 |
get.setTaskName("get:" + uu.getCodeName()); |
255 |
} else { |
238 |
get.setSrc(uu.getURL()); |
256 |
File cacheLoc = new File(cache, id + ".nbm"); |
239 |
get.setDest(tmp); |
257 |
if (cacheLoc.isFile()) { |
240 |
get.setVerbose(true); |
258 |
log("Cache hit: " + cacheLoc, Project.MSG_INFO); |
241 |
get.execute(); |
259 |
} else { |
|
|
260 |
cache.mkdirs(); |
261 |
File momentary = new File(cacheLoc.getParentFile(), cacheLoc.getName() + ".tmp"); |
262 |
momentary.delete(); |
263 |
download(uu, momentary); |
264 |
if (!momentary.renameTo(cacheLoc)) { |
265 |
throw new IOException("rename " + momentary + " to " + cacheLoc); |
266 |
} |
267 |
} |
268 |
FileUtils.getFileUtils().copyFile(cacheLoc, tmp, null, true); |
269 |
} |
242 |
} |
270 |
} |
243 |
if (downloadOnly) { |
271 |
if (downloadOnly) { |
244 |
continue; |
272 |
continue; |
Lines 346-352
Link Here
|
346 |
config.close(); |
374 |
config.close(); |
347 |
} |
375 |
} |
348 |
} catch (IOException ex) { |
376 |
} catch (IOException ex) { |
349 |
throw new BuildException(ex); |
377 |
throw new BuildException("Failed to unpack " + tmp, ex); |
350 |
} finally { |
378 |
} finally { |
351 |
if (delete && tmp != null) { |
379 |
if (delete && tmp != null) { |
352 |
tmp.delete(); |
380 |
tmp.delete(); |
Lines 357-362
Link Here
|
357 |
} |
385 |
} |
358 |
} |
386 |
} |
359 |
} |
387 |
} |
|
|
388 |
|
389 |
private void download(ModuleItem uu, File f) throws BuildException { |
390 |
Get get = new Get(); |
391 |
get.setProject(getProject()); |
392 |
get.setTaskName("get:" + uu.getCodeName()); |
393 |
get.setSrc(uu.getURL()); |
394 |
get.setDest(f); |
395 |
get.setVerbose(true); |
396 |
get.execute(); |
397 |
} |
360 |
|
398 |
|
361 |
private InputStream externalDownload(InputStream is, AtomicLong crc) throws IOException { |
399 |
private InputStream externalDownload(InputStream is, AtomicLong crc) throws IOException { |
362 |
BufferedReader br = new BufferedReader(new InputStreamReader(is)); |
400 |
BufferedReader br = new BufferedReader(new InputStreamReader(is)); |