From 8bcd7f58acd38f5d5e1731f89be4a10a79d0fdb7 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 23 Jun 2012 22:44:40 +0530 Subject: scruf is "bzr"ed now. --- license/Liberate.java | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 license/Liberate.java (limited to 'license/Liberate.java') diff --git a/license/Liberate.java b/license/Liberate.java new file mode 100644 index 0000000..bd97b1d --- /dev/null +++ b/license/Liberate.java @@ -0,0 +1,72 @@ +/*+ + * Copyright (C) 2012-2013 rsiddharth + * Contact me : rsiddharth@ninthfloor.org + * + * 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 3 of the License, or + * (at your option) 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, see . + */ + +package scruf.license; + +import java.io.*; +import java.util.regex.*; +import scruf.io.*; + +public class Liberate { + private String gpl; + + public Liberate() { + gpl = new ReadFile(new File("./scruf/license/gpl")).getContent(); + } + + private Pattern pattern; + private Matcher matcher; + private PrintWriter writer; + + public void baptize(String directory, String regex) { + File dir = new File(directory).getAbsoluteFile(); + File[] dirContents = dir.listFiles(); + String fileContent; + pattern = pattern.compile(regex); + for(File file:dirContents) { + if(file.isFile()) { + matcher = pattern.matcher(file.getName()); + if(matcher.find()) { + fileContent = new ReadFile(file).getContent(); + gpl(file,fileContent); + } + } + else { + // is a Directory. + baptize(file.getPath(),regex); + } + } + } + + private void gpl(File file, String fileContent) { + Matcher matcher = Pattern.compile("^/\\*\\+").matcher(fileContent); + if(!(matcher.find())) { + StringBuilder sbuilder = new StringBuilder(); + sbuilder.append(gpl+"\n"); + sbuilder.append(fileContent); + // write baptized content to file. + new WriteFile(file,fileContent).write(); + } + } + + public static void main(String[] args) { + Liberate libre = new Liberate(); + libre.baptize("./scruf/",".+\\.java"); + } + +} \ No newline at end of file -- cgit v1.2.3