| 1 | /* |
| 2 | * $Id: AnthillVersionProperties.java,v 1.5 2005/01/25 07:58:10 hastings Exp $ |
| 3 | * |
| 4 | * Copyright (c) 2004, Moebius Solutions, Inc. |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * |
| 11 | * Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * |
| 14 | * Redistributions in binary form must reproduce the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer in the documentation and/or other materials provided |
| 17 | * with the distribution. |
| 18 | * |
| 19 | * Neither the name of Moebius Solutions, Inc. nor the names of |
| 20 | * its contributors may be used to endorse or promote products |
| 21 | * derived from this software without specific prior written |
| 22 | * permission. |
| 23 | * |
| 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 30 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 33 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 35 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | package com.moesol.util; |
| 38 | |
| 39 | import java.io.BufferedReader; |
| 40 | import java.io.FileReader; |
| 41 | import java.io.IOException; |
| 42 | import java.io.Reader; |
| 43 | import java.text.MessageFormat; |
| 44 | import java.text.SimpleDateFormat; |
| 45 | import java.util.Date; |
| 46 | |
| 47 | /** |
| 48 | * @author Robert Hastings |
| 49 | * |
| 50 | * Extract the version number from an Anthill version file and |
| 51 | * write out a properties file that represents the extracted version |
| 52 | * information. The version is expected to be formated '{a}.{b}.{c}.{d}'. |
| 53 | */ |
| 54 | public class AnthillVersionProperties extends BaseVersionProperties { |
| 55 | public static void main(String[] args) { |
| 56 | if (args.length != 2) { |
| 57 | System.err.println("usage: " + CvsVersionProperties.class.getName() |
| 58 | + " <filename> <outputname>"); |
| 59 | System.exit(2); |
| 60 | } |
| 61 | AnthillVersionProperties vp = new AnthillVersionProperties(); |
| 62 | try { |
| 63 | vp.readVersionProperties(args[0]); |
| 64 | vp.writeVersionProperties(args[1]); |
| 65 | } catch (IOException e) { |
| 66 | System.err.println(e); |
| 67 | System.exit(1); |
| 68 | } |
| 69 | System.exit(0); |
| 70 | } |
| 71 | private void readVersionProperties(String filename) throws IOException { |
| 72 | FileReader fr = new FileReader(filename); |
| 73 | try { |
| 74 | readVersionProperties(fr); |
| 75 | } finally { |
| 76 | fr.close(); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | void readVersionProperties(Reader r) throws IOException { |
| 81 | BufferedReader br = new BufferedReader(r); |
| 82 | String line = br.readLine(); |
| 83 | parseLine(line); |
| 84 | } |
| 85 | void parseLine(String line) throws IOException { |
| 86 | String[] parts = line.split("\\."); |
| 87 | if (parts.length != 4) { |
| 88 | throw new IOException("Parse failed"); |
| 89 | } |
| 90 | Date today = new Date(); |
| 91 | |
| 92 | m_properties.setProperty("buildVersion", |
| 93 | new MessageFormat("{0}.{1}.{2}.{3}").format(parts)); |
| 94 | m_properties.setProperty("buildVersionCommas", |
| 95 | new MessageFormat("{0},{1},{2},{3}").format(parts)); |
| 96 | m_properties.setProperty("buildDate", |
| 97 | new SimpleDateFormat("MM/dd/yyyy").format(today)); |
| 98 | } |
| 99 | } |