View Javadoc
1   /*
2    * This file is a part of the SchemaSpy project (http://schemaspy.sourceforge.net).
3    * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 John Currier
4    *
5    * SchemaSpy is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2.1 of the License, or (at your option) any later version.
9    *
10   * SchemaSpy is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with this library; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18   */
19  package net.sourceforge.schemaspy;
20  
21  import java.io.BufferedReader;
22  import java.io.File;
23  import java.io.FileReader;
24  import java.io.FileWriter;
25  import java.io.IOException;
26  import java.io.InputStream;
27  import java.io.InputStreamReader;
28  
29  /**
30   * @author John Currier
31   */
32  public class Revision {
33      private static String rev = "Unknown";
34      private static final String resourceName = "/schemaSpy.rev";
35  
36      static {
37          initialize();
38      }
39  
40      private static void initialize() {
41          InputStream in = null;
42          BufferedReader reader = null;
43  
44          try {
45              in = Revision.class.getResourceAsStream(resourceName);
46  
47              if (in != null) {
48                  reader = new BufferedReader(new InputStreamReader(in));
49                  try {
50                      rev = reader.readLine();
51                  } catch (IOException exc) {
52                  }
53              }
54          } finally {
55              try {
56                  if (reader != null)
57                      reader.close();
58                  else if (in != null)
59                      in.close();
60              } catch (IOException ignore) {}
61          }
62      }
63  
64      @Override
65      public String toString() {
66          return rev;
67      }
68  
69      public static void main(String[] args) throws IOException {
70          File entriesFile = new File(".svn", "entries");
71          BufferedReader entries = new BufferedReader(new FileReader(entriesFile));
72          entries.readLine(); // lines
73          entries.readLine(); // blank
74          entries.readLine(); // type
75          String revision = entries.readLine(); // rev
76          entries.close();
77  
78          String buildDir = "output";
79          if (args.length < 1)
80              buildDir = args[0];
81          File revFile = new File(buildDir, resourceName);
82          FileWriter out = new FileWriter(revFile);
83          out.write(revision);
84          out.close();
85  
86          initialize();
87          System.out.println("Subversion revision " + new Revision());
88      }
89  }