Home | History | Annotate | Download | only in headers
      1 /*******************************************************************************
      2  * Copyright 2011 See AUTHORS file.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *   http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  ******************************************************************************/
     16 
     17 package com.badlogic.gdx.tools.headers;
     18 
     19 import java.io.BufferedWriter;
     20 import java.io.File;
     21 import java.io.OutputStreamWriter;
     22 import java.util.ArrayList;
     23 
     24 import com.badlogic.gdx.files.FileHandle;
     25 import com.badlogic.gdx.tools.FileProcessor;
     26 
     27 public class HeaderFixer {
     28 	static int filesScanned;
     29 	static int filesChanged;
     30 	static class HeaderFileProcessor extends FileProcessor {
     31 		final String header;
     32 
     33 		public HeaderFileProcessor () {
     34 			header = new FileHandle("assets/licence-header.txt").readString();
     35 			addInputSuffix(".java");
     36 			setFlattenOutput(false);
     37 			setRecursive(true);
     38 		}
     39 
     40 		@Override
     41 		protected void processFile (Entry inputFile) throws Exception {
     42 			filesScanned++;
     43 			String content = new FileHandle(inputFile.inputFile).readString();
     44 			if (content.trim().startsWith("package")) {
     45 				System.out.println("File '" + inputFile.inputFile + "' header fixed");
     46 				filesChanged++;
     47 				BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileHandle(inputFile.outputFile).write(false)));
     48 
     49 				writer.write(header + "\n\n" + content);
     50 				writer.close();
     51 			}
     52 		}
     53 
     54 		@Override
     55 		protected void processDir (Entry inputDir, ArrayList<Entry> value) throws Exception {
     56 		}
     57 	}
     58 
     59 	public static void process (String directory) throws Exception {
     60 		HeaderFileProcessor processor = new HeaderFileProcessor();
     61 		processor.process(new File(directory), new File(directory));
     62 	}
     63 
     64 	public static void main (String[] args) throws Exception {
     65 		if (args.length != 1) {
     66 			HeaderFixer.process("../../gdx/");
     67 			HeaderFixer.process("../../backends/");
     68 			HeaderFixer.process("../../tests/");
     69 			HeaderFixer.process("../../extensions/");
     70 		} else {
     71 			HeaderFixer.process(args[0]);
     72 		}
     73 		System.out.println("Changed " + filesChanged + " / " + filesScanned + " files.");
     74 	}
     75 }
     76