I can never figure why a java programming list strips java attachments :-(( reattached by trick Stephen
----- Original Message ----- From: "Stephen Colebourne" <[EMAIL PROTECTED]> > [collections] and [convert] done. > > My Java program for assisting with this is attached. Requires CVS HEAD [io] > and manual hacking of paths. > > xdocs need editing by hand, I added LICENSE-INCLUDE2.txt at the top. > > Maybe worth someone checking basics of [collections], as its first commons > proper one. > > Stephen
package generate; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.util.Collection; import java.util.Iterator; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; /** * @author Stephen Colebourne */ public class Licence { public static void main(String[] args) { try { final File dir = new File("D:/dev/collections/src/test"); final File licenceFile = new File("D:/dev/zstuff/license-include.txt"); final Collection coll = FileUtils.listFiles(dir, new String[] {"java"}, true); final String licence = IOUtils.toString(new FileInputStream(licenceFile)); for (Iterator it = coll.iterator(); it.hasNext();) { final File file = (File) it.next(); System.out.println(file); String data = IOUtils.toString(new FileInputStream(file)); int pos = data.indexOf("package"); if (pos == -1) { System.err.println("No license in " + file); System.exit(0); } String loopLicence = data.substring(0, pos); if (loopLicence.indexOf("Licensed under the Apache License, Version 2.0") >= 0) { System.out.println("Not processed - already v2.0 licence"); continue; } loopLicence = getLicense(loopLicence, licence); data = loopLicence + data.substring(pos); // SPLAT new licence // int pos2 = data.indexOf("@version"); // if (pos2 != -1) { // int pos3 = data.indexOf("\n", pos2); // data = data.substring(0, pos2) + "@version $I" + "d: $" + data.substring(pos3); // } FileWriter out = new FileWriter(file); out.write(data); out.close(); } } catch (Throwable ex) { ex.printStackTrace(); } } private static String getLicense(String oldLicence, String licence) { int copyStart = oldLicence.indexOf("Copyright (c) "); if (copyStart == -1) { System.err.println("Bad licence (1)"); System.exit(0); } copyStart += 14; int copyEnd = oldLicence.indexOf(" The Apache", copyStart); if (copyEnd == -1) { System.err.println("Bad licence (2)"); System.exit(0); } String oldText = oldLicence.substring(copyStart, copyEnd); String years = null; if (oldText.length() == 4) { if (oldText.equals("2004")) { years = oldText; } else { years = oldText + "-2004"; } } else if (oldText.length() == 9) { years = oldText.substring(0, 4) + "-2004"; } else { System.err.println("Bad oldText: " + oldText); System.exit(0); } System.out.println("Licence years from: " + oldText + " to: " + years); int copyStart2 = licence.indexOf("Copyright "); if (copyStart2 == -1) { System.err.println("Bad licence (3)"); System.exit(0); } copyStart2 += 10; int copyEnd2 = licence.indexOf(" The Apache", copyStart2); if (copyEnd2 == -1) { System.err.println("Bad licence (4)"); System.exit(0); } return licence.substring(0, copyStart2) + years + licence.substring(copyEnd2); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]