/* * [InsertVersion.java] * * Summary: insert missing (@)version and (@)since. MUST BE CUSTOMISED FIRST. * * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2009-04-19 initial version */ package com.mindprod.repair; import com.mindprod.commandline.CommandLine; import com.mindprod.common18.EIO; import com.mindprod.filter.AllButSVNDirectoriesFilter; import com.mindprod.filter.ExtensionListFilter; import com.mindprod.hunkio.HunkIO; import java.io.File; import java.io.IOException; import static java.lang.System.*; /** * insert missing (@)version and (@)since. MUST BE CUSTOMISED FIRST. *

* if no (@)version, inserts standard hard coded text. Ditto for (@)since. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2009-04-20 initial version * @since 2009-04-20 */ public class InsertVersion { /** * hard coded (@)since comment to insert including the (@)since */ private static final String atSinceToInsert = "@since 2008"; /** * hard coded (@)version comment to insert including the (@)version */ private static final String atVersionToInsert = "@version 1.1 2008-08-31 - screen scrape sizes and prices."; /** * true if proofing, false if actually tidying. */ private static boolean proof; /** * Insert @version if there is none * * @param file Java source file to tidy * * @throws java.io.IOException if can't write logs or update the sourse */ private static void tidyOneFile( final File file ) throws IOException { String big = HunkIO.readEntireFile( file ); out.println( EIO.getCanOrAbsPath( file ) ); int start = big.indexOf( "/**" ); if ( start < 0 ) { out.println( ">>> Missing /**" ); return; } int end = big.indexOf( "*/", start + "/**".length() ); if ( end < 0 ) { out.println( ">>> Missing */" ); return; } boolean changed = false; String javadocComment = big.substring( start + "/**".length(), end ); if ( !javadocComment.contains( "@version" ) ) { out.println( ">>> Missing @version" ); if ( !proof ) { big = big.substring( 0, start + "/**".length() ) + "\n " + atVersionToInsert + "\n" + big.substring( start + "/**".length() ); out.println( ">>> Restoring missing @version" ); changed = true; } } if ( !javadocComment.contains( "@since" ) ) { out.println( ">>> Missing @since" ); if ( !proof ) { big = big.substring( 0, start + "/**".length() ) + "\n " + atSinceToInsert + "\n" + big.substring( start + "/**".length() ); out.println( ">>> Restoring missing @since" ); changed = true; } } if ( changed ) { HunkIO.writeEntireFile( file, big ); } } /** * prepare java source files by replacing the first header comment with a standard. * When proofing, logs to old.txt and new.txt in the current directory. * * @param args word proof or tidy followed by a list of files and directories to process. * -s mean means process subdirs of subsquently mentioned dirs. * * @throws java.io.IOException if cannot read or write source files. */ public static void main( final String[] args ) throws IOException { final String flavour = args[ 0 ]; if ( flavour.equals( "proof" ) ) { proof = true; } else if ( flavour.equals( "tidy" ) ) { proof = false; } else { throw new IllegalArgumentException( "Usage: InsertVersion [proof/tidy] [list of dirs/files]" ); } args[ 0 ] = null; final CommandLine files = new CommandLine( args, new AllButSVNDirectoriesFilter(), new ExtensionListFilter( "java" ) ); for ( File file : files ) { tidyOneFile( file ); } // end for } }