litesoft
@ 949
litesoft / trunk / Java / core / jvm1.5 / src / org / litesoft / versioning / TimeStampVersion.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.versioning; import org.litesoft.commonfoundation.typeutils.*; import org.litesoft.commonfoundation.typeutils.gregorian.*; import org.litesoft.util.*; import java.io.*; public class TimeStampVersion { private static final String TO_LOCATE_PREFIX = " String "; private static final String TO_LOCATE_SUFFIX = " = "; public static final String VERSION = "2008/03/17 17:10:00"; public static void main( String[] args ) throws Exception { System.out.println( "TimeStampVersion vs " + VERSION ); if ( args.length != 2 ) { System.out.println( "" ); System.out.println( " Usage:" ); System.out.println( "" ); System.out.println( " TimeStampVersion.jar filepath stringVariable" ); System.out.println( "" ); System.out.println( " The parameters are:" ); System.out.println( " 1) full file path" ); System.out.println( " 2) 'String' variable name to set" ); System.out.println( "" ); System.out.println( " -D parameters are:" ); System.out.println( " Template=FullFilePath" ); System.out.println( " Build=FullFilePath" ); System.out.println( " BuildNumber=ActualBuildNumber" ); System.exit( 1 ); } String fileName = args[0]; String varName = args[1]; File file = new File( fileName ); String[] lines = loadSource( file ); modify( lines, varName ); FileUtils.storeTextFile( file, lines ); } private static String[] loadSource( File pFile ) { String template = System.getProperty( "Template" ); if ( template != null ) { template = template.trim(); if ( template.length() != 0 ) { pFile = new File( template ); } } return FileUtils.loadTextFile( pFile ); } private static void modify( String[] pLines, String pVarName ) throws NoSuchFieldException { String toLocate = TO_LOCATE_PREFIX + pVarName + TO_LOCATE_SUFFIX; for ( int i = 0; i < pLines.length; i++ ) { String line = pLines[i]; int at = line.indexOf( toLocate ); if ( at != -1 ) { at += toLocate.length(); String t = line.substring( at ); if ( (t.length() > 2) && t.startsWith( "\"" ) && t.endsWith( "\";" ) ) { line = line.substring( 0, at + 1 ) + Timestamps.nowToYMDHMS() + getBuild() + "\";"; pLines[i] = line; return; } } } throw new NoSuchFieldException( pVarName ); } private static String getBuild() { String build = getBuildFromProperty() + getBuildFromFile(); return (build.length() == 0) ? build : " Build: " + build; } private static String getBuildFromProperty() { return filterBuild( Strings.deNull( System.getProperty( "BuildNumber" ) ).trim() ); } private static String getBuildFromFile() { String buildPath = Strings.deNull( System.getProperty( "Build" ) ).trim(); if ( buildPath.length() != 0 ) { String[] lines = FileUtils.loadTextFile( new File( buildPath ) ); for ( String line : lines ) { line = filterBuild( line.trim() ); if ( line.length() != 0 ) { return line; } } } return ""; } private static String filterBuild( String pLine ) { int at = pLine.indexOf( ' ' ); if ( at != -1 ) { pLine = pLine.substring( 0, at ); } at = pLine.indexOf( ':' ); return (at == -1) ? pLine : pLine.substring( at + 1 ); } } |
Commits for litesoft/trunk/Java/core/jvm1.5/src/org/litesoft/versioning/TimeStampVersion.java
Revision | Author | Commited | Message |
---|---|---|---|
949 Diff | GeorgeS | Sun 08 Jun, 2014 17:19:33 +0000 | Normalization |
948 Diff | GeorgeS | Sat 07 Jun, 2014 23:42:39 +0000 | Jusefuls Formatter Updated to New Code Format |
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
858 Diff | GeorgeS | Sun 04 Nov, 2012 18:40:40 +0000 | |
802 Diff | GeorgeS | Wed 15 Aug, 2012 04:04:47 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |