From: <ls...@us...> - 2013-02-24 17:25:16
|
Revision: 5986 http://jnode.svn.sourceforge.net/jnode/?rev=5986&view=rev Author: lsantha Date: 2013-02-24 17:25:09 +0000 (Sun, 24 Feb 2013) Log Message: ----------- Added support for XML headers in HeaderTask. Modified Paths: -------------- trunk/all/build.xml trunk/builder/src/builder/org/jnode/ant/taskdefs/HeaderTask.java Modified: trunk/all/build.xml =================================================================== --- trunk/all/build.xml 2013-02-24 17:23:41 UTC (rev 5985) +++ trunk/all/build.xml 2013-02-24 17:25:09 UTC (rev 5986) @@ -1,3 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + $Id$ + + Copyright (C) 2003-2013 JNode.org + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This library 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this library; If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +--> <project name="JNode" default="help" basedir="."> <property name="root.dir" value="${basedir}/.."/> @@ -866,6 +886,31 @@ <fileset dir="${root.dir}/shell/src/shell" includes="**/*.java"/> <fileset dir="${root.dir}/shell/src/test" includes="**/*.java"/> </header> + <header update="on" xml="on" headerFile="${root.dir}/all/template/header.xml"> + <fileset dir="${root.dir}/all" includes="*.xml"/> + <fileset dir="${root.dir}/all/conf" includes="*.xml"/> + <fileset dir="${root.dir}/all/conf-source" includes="*.xml"/> + <fileset dir="${root.dir}/all/lib" includes="*.xml"/> + <fileset dir="${root.dir}/builder" includes="*.xml"/> + <fileset dir="${root.dir}/cli" includes="*.xml"/> + <fileset dir="${root.dir}/cli/descriptors" includes="*.xml"/> + <fileset dir="${root.dir}/core" includes="*.xml"/> + <fileset dir="${root.dir}/core/descriptors" includes="*.xml"/> + <fileset dir="${root.dir}/distr" includes="*.xml"/> + <fileset dir="${root.dir}/distr/descriptors" includes="*.xml"/> + <fileset dir="${root.dir}/fs" includes="*.xml"/> + <fileset dir="${root.dir}/fs/descriptors" includes="*.xml"/> + <fileset dir="${root.dir}/gui" includes="*.xml"/> + <fileset dir="${root.dir}/gui/descriptors" includes="*.xml"/> + <fileset dir="${root.dir}/net" includes="*.xml"/> + <fileset dir="${root.dir}/net/descriptors" includes="*.xml"/> + <fileset dir="${root.dir}/shell" includes="*.xml"/> + <fileset dir="${root.dir}/shell/descriptors" includes="*.xml"/> + <fileset dir="${root.dir}/sound" includes="*.xml"/> + <fileset dir="${root.dir}/sound/descriptors" includes="*.xml"/> + <fileset dir="${root.dir}/textui" includes="*.xml"/> + <fileset dir="${root.dir}/textui/descriptors" includes="*.xml"/> + </header> </target> <target name="check-debugger-properties" depends="prepare"> Modified: trunk/builder/src/builder/org/jnode/ant/taskdefs/HeaderTask.java =================================================================== --- trunk/builder/src/builder/org/jnode/ant/taskdefs/HeaderTask.java 2013-02-24 17:23:41 UTC (rev 5985) +++ trunk/builder/src/builder/org/jnode/ant/taskdefs/HeaderTask.java 2013-02-24 17:25:09 UTC (rev 5986) @@ -38,6 +38,7 @@ private String[] header; private boolean update = false; + private boolean xml = false; private boolean compareHeader(String[] lines, String[] header) { final int linesCnt = lines.length; @@ -63,6 +64,31 @@ return false; } + private boolean compareXMLHeader(String[] lines, String[] header) { + final int linesCnt = lines.length; + final int hdrCnt = header.length; + + for (int i = 0; i < linesCnt; i++) { + final String line = lines[i]; + if (i < hdrCnt) { + if (!compareLine(line, header[i])) { + return false; + } + } else { + String trimmedLine = line.trim(); + if (trimmedLine.startsWith("<")) { + return true; + } + if (trimmedLine.length() > 0) { + return false; + } + } + } + + return false; + } + + private boolean compareLine(String line, String hdrLine) { if ((line.indexOf('$') >= 0) && (hdrLine.indexOf('$') >= 0)) { return true; @@ -93,13 +119,24 @@ @Override protected void processFile(File file) throws IOException { final String[] inp = readFile(file); - if (!compareHeader(inp, header)) { - if (update) { - log("Updating " + file); - writeUpdateFile(file, inp, header); - } else { - log("Wrong header in " + file); + if (xml) { + if (!compareXMLHeader(inp, header)) { + if (update) { + log("Updating " + file); + writeUpdateXMLFile(file, inp, header); + } else { + log("Wrong header in " + file); + } } + } else { + if (!compareHeader(inp, header)) { + if (update) { + log("Updating " + file); + writeUpdateFile(file, inp, header); + } else { + log("Wrong header in " + file); + } + } } } @@ -128,7 +165,48 @@ } } + private void writeUpdateXMLFile(File file, String[] lines, String[] header) throws IOException { + PrintWriter out = new PrintWriter(new FileWriter(file)); + try { + boolean write = true; + boolean headerAdded = false; + for (String line : lines) { + String trimmedLine = line.trim(); + if (!headerAdded) { + if (!write) { + for (String aHeader : header) { + out.println(aHeader); + } + headerAdded = true; + if (!trimmedLine.startsWith("<!--")) { + write = true; + } + } + if (trimmedLine.startsWith("<?xml")) { + write = false; + } else if (!headerAdded) { + for (String aHeader : header) { + out.println(aHeader); + } + headerAdded = true; + } + } + + if (write) { + out.println(line); + } + + if (trimmedLine.endsWith("-->")) { + write = true; + } + } + } finally { + out.close(); + } + } + + private String[] readFile(File file) throws IOException { final BufferedReader in = new BufferedReader(new FileReader(file)); try { @@ -150,4 +228,8 @@ public final void setUpdate(boolean update) { this.update = update; } + + public void setXml(boolean xml) { + this.xml = xml; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |