List of usage examples for org.dom4j.io SAXReader read
public Document read(InputSource in) throws DocumentException
Reads a Document from the given InputSource
using SAX
From source file:com.nokia.ant.BuildStatusDef.java
License:Open Source License
public ArrayList getCustomerProperties(Project project) { ArrayList props = new ArrayList(); Database db = new Database(null, null, null); try {//w w w . j av a 2s. com String heliumpath = new File(project.getProperty("helium.dir")).getCanonicalPath(); for (Object o : db.getAntFiles(project)) { String antFile = (String) o; antFile = new File(antFile).getCanonicalPath(); if (!antFile.contains(heliumpath)) { SAXReader xmlReader = new SAXReader(); Document antDoc = xmlReader.read(new File(antFile)); List propertyNodes = antDoc.selectNodes("//property | //param"); for (Iterator iterator = propertyNodes.iterator(); iterator.hasNext();) { Element propertyNode = (Element) iterator.next(); String propertyName = propertyNode.attributeValue("name"); props.add(propertyName); } } } } catch (Exception e) { // We are Ignoring the errors as no need to fail the build. log("Not able read the Customer Properties " + e.getMessage(), Project.MSG_WARN); } return props; }
From source file:com.nokia.ant.conditions.AtsCondition.java
License:Open Source License
/** Read from diamonds and signal if ats failed */ public boolean eval() { String bid = getProject().getProperty("diamonds.build.id"); if (bid == null) { log("Diamonds not enabled"); } else {//from w w w .j a v a 2 s. c o m boolean testsfound = false; log("Looking for tests in diamonds"); SAXReader xmlReader = new SAXReader(); while (!testsfound) { Document antDoc = null; try { URL url = new URL("http://" + getProject().getProperty("diamonds.host") + bid + "?fmt=xml"); antDoc = xmlReader.read(url); } catch (MalformedURLException e) { // We are Ignoring the errors as no need to fail the build. log("Not able to read the Diamonds URL http://" + getProject().getProperty("diamonds.host") + bid + "?fmt=xml: " + e.getMessage(), Project.MSG_ERR); } catch (DocumentException e) { log("Not able to read the Diamonds URL http://" + getProject().getProperty("diamonds.host") + bid + "?fmt=xml: " + e.getMessage(), Project.MSG_ERR); } for (Iterator iterator = antDoc.selectNodes("//test/failed").iterator(); iterator.hasNext();) { testsfound = true; Element element = (Element) iterator.next(); String failed = element.getText(); if (!failed.equals("0")) { log("ATS tests failed", Project.MSG_ERR); for (Iterator iterator2 = antDoc.selectNodes("//actual_result").iterator(); iterator2 .hasNext();) { Element resultElement = (Element) iterator2.next(); log(resultElement.getText(), Project.MSG_ERR); } return false; } } int noofdrops = Integer.parseInt(getProject().getProperty("drop.file.counter")); if (noofdrops > 0) { int testsrun = antDoc.selectNodes("//test").size(); if (testsrun < noofdrops) { log(testsrun + " test completed, " + noofdrops + " total"); testsfound = false; } } if (!testsfound) { log("Tests not found sleeping for " + sleeptimesecs + " seconds"); try { Thread.sleep(sleeptimesecs * 1000); } catch (InterruptedException e) { // This will not affect the build process so ignoring. log("Interrupted while reading ATS build status " + e.getMessage(), Project.MSG_DEBUG); } } } } return true; }
From source file:com.nokia.ant.Database.java
License:Open Source License
private void readSignals(Element root, String antFile) throws DocumentException, IOException { SAXReader xmlReader = new SAXReader(); Document antDoc = xmlReader.read(new File(antFile)); XPath xpath = DocumentHelper.createXPath("//hlm:signalListenerConfig"); xpath.setNamespaceURIs(map);//from ww w. jav a2 s.c om List signalNodes = xpath.selectNodes(antDoc); for (Iterator iterator = signalNodes.iterator(); iterator.hasNext();) { signaldoc = antDoc; Element propertyNode = (Element) iterator.next(); String signalid = propertyNode.attributeValue("id"); String signaltarget = propertyNode.attributeValue("target"); List existinglist = globalSignalList.get(signaltarget); String failbuild = signalType(signalid, signaldoc); if (existinglist == null) existinglist = new ArrayList<String>(); existinglist.add(signalid + "," + failbuild); globalSignalList.put(signaltarget, existinglist); } }
From source file:com.nokia.ant.Database.java
License:Open Source License
/** * @param root//from w w w.jav a 2s .c om * @param antFile * @throws DocumentException * @throws IOException */ private void parseAntFile(Element root, String antFile) throws DocumentException, IOException { log("Processing Ant file: " + antFile, Project.MSG_DEBUG); SAXReader xmlReader = new SAXReader(); Document antDoc = xmlReader.read(new File(antFile)); // Element targetElement = // DocumentHelper.createElement("target"); Element projectElement = root.addElement("project"); Element nameElement = projectElement.addElement("name"); String projectName = antDoc.valueOf("/project/@name"); nameElement.setText(projectName); // Element descriptionElement = // projectElement.addElement("description"); String description = antDoc.valueOf("/project/description"); insertDocumentation(projectElement, description); // descriptionElement.setText(description); if (!antFile.contains("antlib.xml") && description.equals("")) { log("Project has no comment: " + projectName, Project.MSG_WARN); } Element defaultElement = projectElement.addElement("default"); defaultElement.setText(antDoc.valueOf("/project/@default")); // Project import statements List importNodes = antDoc.selectNodes("//import"); for (Iterator iterator = importNodes.iterator(); iterator.hasNext();) { Element importCurrentNode = (Element) iterator.next(); addTextElement(projectElement, "fileDependency", importCurrentNode.attributeValue("file")); } projectElement.addElement("pythonDependency"); // Project exec statements List execNodes = antDoc.selectNodes("//exec//arg"); for (Iterator iterator = execNodes.iterator(); iterator.hasNext();) { Element argNode = (Element) iterator.next(); String argValue = argNode.attributeValue("value"); if (argValue == null) argValue = argNode.attributeValue("line"); if (argValue != null) { Pattern filePattern = Pattern.compile(".pl|.py|.bat|.xml|.txt"); Matcher fileMatcher = filePattern.matcher(argValue); if (fileMatcher.find()) { addTextElement(projectElement, "fileDependency", argValue); } } } List targetNodes = antDoc.selectNodes("//target"); for (Iterator iterator = targetNodes.iterator(); iterator.hasNext();) { Element targetNode = (Element) iterator.next(); processTarget(targetNode, projectElement); } // Process macrodef and scriptdef tasks // TODO - maybe scriptdefs should be separate? List macroNodes = antDoc.selectNodes("//macrodef | //scriptdef"); for (Iterator iterator = macroNodes.iterator(); iterator.hasNext();) { Element macroNode = (Element) iterator.next(); processMacro(macroNode, projectElement, antFile); } // Project properties List propertyNodes = antDoc.selectNodes("//property"); for (Iterator iterator = propertyNodes.iterator(); iterator.hasNext();) { Element propertyNode = (Element) iterator.next(); processProperty(propertyNode, projectElement); } }
From source file:com.nokia.ant.ModelPropertiesParser.java
License:Open Source License
/** * Reads model xml file, changes description format. * // ww w.ja va 2s . c o m * @throws DocumentException * @throws IOException */ public void parsePropertiesDescription() throws IOException, DocumentException { SAXReader xmlReader = new SAXReader(); doc = xmlReader.read(inputPath); List importNodes = doc.selectNodes("//description"); for (Iterator iterator = importNodes.iterator(); iterator.hasNext();) { Element importCurrentNode = (Element) iterator.next(); importCurrentNode.setText(renderWikiModel(importCurrentNode.getText())); writeXMLFile(); } }
From source file:com.nokia.ant.taskdefs.AntDependencyTask.java
License:Open Source License
public void findLicense(String name, JarFile jar) { try {//from ww w . j a va 2 s . co m ZipEntry entry = jar.getEntry("META-INF/LICENSE"); if (entry == null) { entry = jar.getEntry("META-INF/LICENSE.txt"); } if (entry != null) { /**/ log("File in " + name + " in jar file ", Project.MSG_DEBUG); byte[] data = new byte[1024]; jar.getInputStream(entry).read(data); for (String line : new String(data).split("\n")) { if (line.contains("License") || line.contains("LICENSE ") || line.contains("Copyright")) { log("Replace License information with * " + line.replace("*", "").trim(), Project.MSG_INFO); break; } } } else { // http://mirrors.ibiblio.org/pub/mirrors/maven2/ String mavenUrl = "http://repo2.maven.org/maven2/"; Enumeration jarfiles = jar.entries(); boolean found = false; while (!found && jarfiles.hasMoreElements()) { ZipEntry file = (ZipEntry) jarfiles.nextElement(); if (file.isDirectory()) { String filename = file.getName(); String[] split = file.getName().split("/"); String end = split[split.length - 1]; String specialfilename = filename + end; URL url = new URL(mavenUrl + filename + end + "/maven-metadata.xml"); if (!end.equals("apache")) { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { filename = filename.replace(end, name.replace(".jar", "")); end = name.replace(".jar", ""); specialfilename = filename; url = new URL(mavenUrl + filename + "maven-metadata.xml"); connection = (HttpURLConnection) url.openConnection(); } if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { SAXReader xmlReader = new SAXReader(); Document antDoc = xmlReader.read(url.openStream()); List versions = antDoc.selectNodes("//versioning/versions/version"); // if (version.equals("")) // { // version = antDoc.valueOf("/metadata/version"); // } Collections.reverse(versions); for (Object tmpversion : versions) { String version = ((Element) tmpversion).getText(); URL url2 = new URL(mavenUrl + specialfilename + "/" + version + "/" + end + "-" + version + ".pom"); HttpURLConnection connection2 = (HttpURLConnection) url2.openConnection(); if (connection2.getResponseCode() == HttpURLConnection.HTTP_OK) { BufferedReader din = new BufferedReader( new InputStreamReader(url2.openStream())); StringBuffer sb = new StringBuffer(); String line = null; while ((line = din.readLine()) != null) { line = line.replace("xmlns=\"http://maven.apache.org/POM/4.0.0\"", ""); sb.append(line + "\n"); } xmlReader = new SAXReader(); // Document antDoc2 = xmlReader .read(new ByteArrayInputStream(new String(sb).getBytes())); String license = antDoc2.valueOf("/project/licenses/license/name"); if (!license.equals("")) { found = true; break; } } } } } } } if (!found) { log(name + " not found in " + jar, Project.MSG_INFO); } } } catch (IOException e) { // We are Ignoring the errors as no need to fail the build. e.printStackTrace(); } catch (DocumentException e) { // We are Ignoring the errors as no need to fail the build. e.printStackTrace(); } }
From source file:com.nokia.config.SAXConfigParser.java
License:Open Source License
/** * Constructor//from ww w . j a v a 2s. co m * @return list of available configurations that can be built. */ public String getConfigs() { File file = new File(sysdefFile); SAXReader reader = new SAXReader(); reader.addHandler("/SystemDefinition/build/target", new ElementHandler() { public void onStart(ElementPath path) { } public void onEnd(ElementPath path) { Element row = path.getCurrent(); Iterator itr = row.attributeIterator(); while (itr.hasNext()) { Attribute child = (Attribute) itr.next(); String attrName = child.getQualifiedName(); if (attrName.equals("name")) { configs += (String) child.getValue() + ","; } } row.detach(); } }); try { Document doc = reader.read(file); } catch (Exception e) { e.printStackTrace(); } return configs; }
From source file:com.nokia.helium.ant.data.Database.java
License:Open Source License
@SuppressWarnings("unchecked") private void readSignals(String antFile) throws IOException { SAXReader xmlReader = new SAXReader(); Document antDoc;//from ww w . j a va 2s . c o m try { antDoc = xmlReader.read(new File(antFile)); } catch (DocumentException e) { throw new IOException(e.getMessage()); } XPath xpath = DocumentHelper.createXPath("//hlm:signalListenerConfig"); xpath.setNamespaceURIs(namespaceMap); List<Node> signalNodes = xpath.selectNodes(antDoc); for (Iterator<Node> iterator = signalNodes.iterator(); iterator.hasNext();) { signaldoc = antDoc; Element propertyNode = (Element) iterator.next(); String signalid = propertyNode.attributeValue("id"); String signaltarget = propertyNode.attributeValue("target"); List<String> existinglist = globalSignalList.get(signaltarget); String failbuild = findSignalFailMode(signalid, signaldoc); if (existinglist == null) { existinglist = new ArrayList<String>(); } existinglist.add(signalid + "," + failbuild); globalSignalList.put(signaltarget, existinglist); } }
From source file:com.nokia.helium.antlint.ant.taskdefs.AntLintTask.java
License:Open Source License
/** * Triggers the antlint checking.// w ww .ja v a2s. c o m * * @throws Exception * if the checking fails. */ private void startAntLintCheck() throws Exception { runOneTimeCheck(); for (FileSet fs : antFileSetList) { DirectoryScanner ds = fs.getDirectoryScanner(getProject()); String[] srcFiles = ds.getIncludedFiles(); String basedir = ds.getBasedir().getPath(); for (int i = 0; i < srcFiles.length; i++) { String antFileName = basedir + File.separator + srcFiles[i]; getProject().log("*************** Ant File: " + antFileName); run(antFileName); SAXReader saxReader = new SAXReader(); Document doc = saxReader.read(new File(antFileName)); treeWalk(doc); } Collections.sort(antFilelist); } }
From source file:com.nokia.helium.diamonds.DiamondsConfig.java
License:Open Source License
/** * Method accessed by loggers to load the diamonds specific configuration. * /* w w w. j a v a 2 s . co m*/ * @param configFile * - configuration to load * */ public static void parseConfiguration(String configFile) throws DiamondsException { if (log == null) { log = Logger.getLogger(DiamondsConfig.class); } SAXReader saxReader = new SAXReader(); Document document = null; try { log.debug("Reading diamonds configuration."); document = saxReader.read(configFile); } catch (Exception e) { // No need to fail the build due to internal Helium configuration errors. log.debug("Diamonds configuration parsing error: " + e.getMessage()); } parseConfig(document); diamondsProperties = parseDiamondsProperties(document); stages = parseStages(document); targets = parseTargets(document); }