Lines 52-57
Link Here
|
52 |
import java.io.InputStream; |
52 |
import java.io.InputStream; |
53 |
import java.io.InputStreamReader; |
53 |
import java.io.InputStreamReader; |
54 |
import java.io.OutputStream; |
54 |
import java.io.OutputStream; |
|
|
55 |
import java.net.MalformedURLException; |
55 |
import java.net.URISyntaxException; |
56 |
import java.net.URISyntaxException; |
56 |
import java.net.URL; |
57 |
import java.net.URL; |
57 |
import java.net.URLConnection; |
58 |
import java.net.URLConnection; |
Lines 67-72
Link Here
|
67 |
import java.util.zip.ZipFile; |
68 |
import java.util.zip.ZipFile; |
68 |
import javax.xml.parsers.SAXParser; |
69 |
import javax.xml.parsers.SAXParser; |
69 |
import javax.xml.parsers.SAXParserFactory; |
70 |
import javax.xml.parsers.SAXParserFactory; |
|
|
71 |
import javax.xml.xpath.XPathExpressionException; |
72 |
import javax.xml.xpath.XPathFactory; |
70 |
import org.apache.tools.ant.BuildException; |
73 |
import org.apache.tools.ant.BuildException; |
71 |
import org.apache.tools.ant.DirectoryScanner; |
74 |
import org.apache.tools.ant.DirectoryScanner; |
72 |
import org.apache.tools.ant.Project; |
75 |
import org.apache.tools.ant.Project; |
Lines 88-93
Link Here
|
88 |
public class AutoUpdate extends Task { |
91 |
public class AutoUpdate extends Task { |
89 |
private List<Modules> modules = new ArrayList<Modules>(); |
92 |
private List<Modules> modules = new ArrayList<Modules>(); |
90 |
private FileSet nbmSet; |
93 |
private FileSet nbmSet; |
|
|
94 |
private File download; |
91 |
private File dir; |
95 |
private File dir; |
92 |
private File cluster; |
96 |
private File cluster; |
93 |
private URL catalog; |
97 |
private URL catalog; |
Lines 112-117
Link Here
|
112 |
public void setToDir(File dir) { |
116 |
public void setToDir(File dir) { |
113 |
this.cluster = dir; |
117 |
this.cluster = dir; |
114 |
} |
118 |
} |
|
|
119 |
|
120 |
public void setDownloadDir(File dir) { |
121 |
this.download = dir; |
122 |
} |
115 |
|
123 |
|
116 |
/** Forces rewrite even the version of a module is not newer */ |
124 |
/** Forces rewrite even the version of a module is not newer */ |
117 |
public void setForce(boolean force) { |
125 |
public void setForce(boolean force) { |
Lines 126-133
Link Here
|
126 |
|
134 |
|
127 |
@Override |
135 |
@Override |
128 |
public void execute() throws BuildException { |
136 |
public void execute() throws BuildException { |
|
|
137 |
boolean downloadOnly = false; |
129 |
if ((dir != null) == (cluster != null)) { |
138 |
if ((dir != null) == (cluster != null)) { |
130 |
throw new BuildException("Specify either todir or installdir"); |
139 |
if (dir == null && cluster == null && download != null) { |
|
|
140 |
log("Going to download NBMs only to " + download); |
141 |
downloadOnly = true; |
142 |
} else { |
143 |
throw new BuildException("Specify either todir or installdir"); |
144 |
} |
131 |
} |
145 |
} |
132 |
Map<String, ModuleItem> units; |
146 |
Map<String, ModuleItem> units; |
133 |
if (catalog != null) { |
147 |
if (catalog != null) { |
Lines 194-200
Link Here
|
194 |
boolean delete = false; |
208 |
boolean delete = false; |
195 |
File lastM = null; |
209 |
File lastM = null; |
196 |
try { |
210 |
try { |
197 |
if (uu.getURL().getProtocol().equals("file")) { |
211 |
if (download == null && uu.getURL().getProtocol().equals("file")) { |
198 |
try { |
212 |
try { |
199 |
tmp = new File(uu.getURL().toURI()); |
213 |
tmp = new File(uu.getURL().toURI()); |
200 |
} catch (URISyntaxException ex) { |
214 |
} catch (URISyntaxException ex) { |
Lines 206-214
Link Here
|
206 |
} |
220 |
} |
207 |
final String dash = uu.getCodeName().replace('.', '-'); |
221 |
final String dash = uu.getCodeName().replace('.', '-'); |
208 |
if (tmp == null) { |
222 |
if (tmp == null) { |
209 |
tmp = File.createTempFile(dash, ".nbm"); |
223 |
if (download != null) { |
210 |
tmp.deleteOnExit(); |
224 |
tmp = new File(download, dash + ".nbm"); |
211 |
delete = true; |
225 |
String v = readVersion(tmp); |
|
|
226 |
if (v != null && !uu.isNewerThan(v)) { |
227 |
log("Version " + v + " of " + tmp + " is up to date", Project.MSG_VERBOSE); |
228 |
if (!force) { |
229 |
continue; |
230 |
} |
231 |
} |
232 |
} else { |
233 |
tmp = File.createTempFile(dash, ".nbm"); |
234 |
tmp.deleteOnExit(); |
235 |
delete = true; |
236 |
} |
212 |
Get get = new Get(); |
237 |
Get get = new Get(); |
213 |
get.setProject(getProject()); |
238 |
get.setProject(getProject()); |
214 |
get.setTaskName("get:" + uu.getCodeName()); |
239 |
get.setTaskName("get:" + uu.getCodeName()); |
Lines 217-222
Link Here
|
217 |
get.setVerbose(true); |
242 |
get.setVerbose(true); |
218 |
get.execute(); |
243 |
get.execute(); |
219 |
} |
244 |
} |
|
|
245 |
if (downloadOnly) { |
246 |
continue; |
247 |
} |
220 |
|
248 |
|
221 |
File whereTo = dir != null ? new File(dir, uu.targetcluster) : cluster; |
249 |
File whereTo = dir != null ? new File(dir, uu.targetcluster) : cluster; |
222 |
whereTo.mkdirs(); |
250 |
whereTo.mkdirs(); |
Lines 447-452
Link Here
|
447 |
} |
475 |
} |
448 |
return all; |
476 |
return all; |
449 |
} |
477 |
} |
|
|
478 |
|
479 |
private String readVersion(File nbm) { |
480 |
try { |
481 |
URL u = new URL("jar:" + nbm.toURI() + "!/Info/info.xml"); |
482 |
XPathFactory f = XPathFactory.newInstance(); |
483 |
final InputStream s = u.openStream(); |
484 |
InputSource is = new InputSource(s); |
485 |
String res = f.newXPath().evaluate("module/manifest/@OpenIDE-Module-Specification-Version", is); |
486 |
if (res.length() == 0) { |
487 |
throw new IOException("Not found tag OpenIDE-Module-Specification-Version!"); |
488 |
} |
489 |
s.close(); |
490 |
return res; |
491 |
} catch (Exception ex) { |
492 |
log("Cannot parse Info/info.xml from " + nbm, ex, Project.MSG_INFO); |
493 |
return null; |
494 |
} |
495 |
} |
450 |
|
496 |
|
451 |
private void parseVersion(final File config, final Map<String,List<String>> toAdd) throws Exception { |
497 |
private void parseVersion(final File config, final Map<String,List<String>> toAdd) throws Exception { |
452 |
class P extends DefaultHandler { |
498 |
class P extends DefaultHandler { |