private String getHome() {
return System.getProperty("bees.home");
}
private void initialize(boolean force) throws Exception {
LocalRepository localRepository = new LocalRepository();
String beesRepoPath = localRepository.getRepositoryPath();
File lastCheckFile = new File(beesRepoPath, CHECK_FILE);
boolean checkVersion = true;
Properties p = new Properties();
if (!force && Helper.loadProperties(lastCheckFile, p)) {
String str = p.getProperty("last");
if (str != null) {
long interval = System.currentTimeMillis() - Long.parseLong(str);
if (interval < CHECK_INTERVAL)
checkVersion = false;
}
}
if (checkVersion) {
// Check SDK version
File sdkConfig = getURLAsFile(localRepository, app_template_xml_url + app_template_xml_name,
app_template_xml_name, app_template_xml_desc);
Document doc = XmlHelper.readXMLFromFile(sdkConfig.getCanonicalPath());
Element e = doc.getDocumentElement();
String availVersion = e.getAttribute("version");
String minVersion = e.getAttribute("min-version");
VersionNumber currentVersion = version;
VersionNumber availableVersion = new VersionNumber(availVersion);
VersionNumber minimunVersion = new VersionNumber(minVersion);
if (currentVersion.compareTo(availableVersion) < 0) {
System.out.println();
if (currentVersion.compareTo(minimunVersion) < 0) {
throw new AbortException("ERROR - This version of the CloudBees SDK is no longer supported," + "" +
" please install the latest version (" + availVersion + ").");
} else if (currentVersion.compareTo(availableVersion) < 0) {
System.out.println("WARNING - A new version of the CloudBees SDK is available, please install the latest version (" + availVersion + ").");
}
String hRef = e.getAttribute("href");
String homeRef = "www.cloudbees.com";
NodeList nodeList = e.getElementsByTagName("link");
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
NamedNodeMap nodeMap = node.getAttributes();
Node rel = nodeMap.getNamedItem("rel");
Node href = nodeMap.getNamedItem("href");
if (rel != null && rel.getTextContent().trim().equalsIgnoreCase("alternate") && href != null) {
homeRef = href.getTextContent();
}
}
NodeList libsNL = e.getElementsByTagName("libraries");
Node libsNode = null;
if (libsNL.getLength() > 0) {
libsNode = libsNL.item(0);
}
if (libsNode != null) {
NodeList libNL = e.getElementsByTagName("library");
for (int i = 0; i < libNL.getLength(); i++) {
Node node = libNL.item(i);
NamedNodeMap nodeMap = node.getAttributes();
Node nameNode = nodeMap.getNamedItem("name");
Node refNode = nodeMap.getNamedItem("href");
if (nameNode != null && refNode != null) {
String libName = nameNode.getTextContent();
String libUrlString = refNode.getTextContent().trim();
int idx = libUrlString.lastIndexOf('/');
String libFileName = libUrlString.substring(idx);
localRepository.getURLAsFile(libUrlString, "lib1" + libFileName, libName);
}
}
}
System.out.println(" SDK home: " + homeRef);