From: John W. <jo...@wa...> - 2004-05-25 17:30:37
Attachments:
compile.bsh
|
// ************************************************************ // Ant.bsh -- view and run ant targets // Requires java 1.4 and the ProjectViewer plugin // // Copyright (C) 2004 John Watson // mailto://jo...@wa... // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // ' // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // ************************************************************ // Gets the root of the current project and looks for a build.xml file there. // Then cds to that directory and runs ant there. import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; import org.w3c.dom.*; import org.xml.sax.*; public void main() { // store last used target in this property variable String PROP = "macro.jdw.ant.lasttarget"; projectviewer.vpt.VPTProject proj = projectviewer.PVActions.getCurrentProject(view); if (proj != null) { String root = proj.getRootPath(); if (root != null) { File buildfile = new File(root, "build.xml"); if (buildfile.exists()) { // Get available targets Document doc = null; DocumentBuilder db = null; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); try { db = factory.newDocumentBuilder(); doc = db.parse(buildfile); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Could not parse build.xml:\n" + ex); print("Could not parse build.xml: " + ex); return; } catch (ParserConfigurationException ex) { JOptionPane.showMessageDialog(null, "Could not parse build.xml:\n" + ex); print("Could not parse build.xml: " + ex); return; } catch (SAXException ex) { JOptionPane.showMessageDialog(null, "Could not parse build.xml:\n" + ex); print("Could not parse build.xml: " + ex); return; } String[] target = null; if (doc != null) { NodeList t = doc.getDocumentElement().getElementsByTagName("target"); if (t.getLength() > 0) { target = new String[t.getLength()]; for(int i=0; i<t.getLength(); i++) { target[i] = new String(t.item(i).getAttributes().getNamedItem("name").getNodeValue()); } } } String chosen = null; if (target != null) { chosen = (String)JOptionPane.showInputDialog(null, "Target: ", "Choose a target", JOptionPane.PLAIN_MESSAGE, null, target, jEdit.getProperty(PROP)); } if (chosen == null) { // cancel return; } else { // ok, save last target jEdit.setProperty(PROP, chosen); } runInSystemShell(view, "cd " + root); runInSystemShell(view, "ant " + chosen); } } } } main(); |