001: /* ====================================================================
002: * The JRefactory License, Version 1.0
003: *
004: * Copyright (c) 2001 JRefactory. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by the
021: * JRefactory (http://www.sourceforge.org/projects/jrefactory)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. The names "JRefactory" must not be used to endorse or promote
026: * products derived from this software without prior written
027: * permission. For written permission, please contact seguin@acm.org.
028: *
029: * 5. Products derived from this software may not be called "JRefactory",
030: * nor may "JRefactory" appear in their name, without prior written
031: * permission of Chris Seguin.
032: *
033: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
034: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
035: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
036: * DISCLAIMED. IN NO EVENT SHALL THE CHRIS SEGUIN OR
037: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
038: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
039: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
040: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
041: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
042: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
043: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
044: * SUCH DAMAGE.
045: * ====================================================================
046: *
047: * This software consists of voluntary contributions made by many
048: * individuals on behalf of JRefactory. For more information on
049: * JRefactory, please see
050: * <http://www.sourceforge.org/projects/jrefactory>.
051: */
052: package org.acm.seguin.tools.build;
053:
054: import java.io.PrintWriter;
055: import java.io.FileWriter;
056: import java.io.IOException;
057: import java.util.StringTokenizer;
058:
059: /**
060: * Creates a JRefactoryVersion object from a command line string specifying the
061: * version.
062: *
063: *@author Chris Seguin
064: *@created September 12, 2001
065: */
066: public class CreateVersion {
067: private String major;
068: private String minor;
069: private String build;
070:
071: private String output;
072:
073: /**
074: * Constructor for the CreateVersion object
075: *
076: *@param input the command line argument
077: *@param output Description of the Parameter
078: */
079: public CreateVersion(String input, String output) {
080: StringTokenizer tok = new StringTokenizer(input, ".");
081:
082: major = tok.nextToken();
083: minor = tok.nextToken();
084: build = tok.nextToken();
085:
086: this .output = output;
087: System.out.println(output);
088: }
089:
090: /**
091: * Main processing method for the CreateVersion object
092: */
093: public void run() {
094: try {
095: java.io.File op = new java.io.File(output);
096: System.out.println("op=" + op.getCanonicalFile());
097: PrintWriter printer = new PrintWriter(new FileWriter(op));
098:
099: printer.println("package org.acm.seguin;");
100: printer.println("");
101: printer.println("/**");
102: printer.println(" * The current version of JRefactory");
103: printer.println(" *");
104: printer.println(" *@author Chris Seguin");
105: printer.println(" */");
106: printer.println("public class JRefactoryVersion {");
107: printer.println(" /**");
108: printer
109: .println(" * Gets the MajorVersion attribute of the JRefactoryVersion object");
110: printer.println(" *");
111: printer.println(" *@return The MajorVersion value");
112: printer.println(" */");
113: printer.println(" public int getMajorVersion() {");
114: printer.println(" return " + major + ";");
115: printer.println(" }");
116: printer.println("");
117: printer.println("");
118: printer.println(" /**");
119: printer
120: .println(" * Gets the MinorVersion attribute of the JRefactoryVersion object");
121: printer.println(" *");
122: printer.println(" *@return The MinorVersion value");
123: printer.println(" */");
124: printer.println(" public int getMinorVersion() {");
125: printer.println(" return " + minor + ";");
126: printer.println(" }");
127: printer.println("");
128: printer.println("");
129: printer.println(" /**");
130: printer
131: .println(" * Gets the Build attribute of the JRefactoryVersion object");
132: printer.println(" *");
133: printer.println(" *@return The Build value");
134: printer.println(" */");
135: printer.println(" public int getBuild() {");
136: printer.println(" return " + build + ";");
137: printer.println(" }");
138: printer.println("");
139: printer.println("");
140: printer.println(" /**");
141: printer
142: .println(" * Converts the JRefactoryVersion to a string");
143: printer.println(" *");
144: printer
145: .println(" *@return a string representing the version");
146: printer.println(" */");
147: printer.println(" public String toString() {");
148: printer
149: .println(" StringBuffer buffer = new StringBuffer();");
150: printer.println("");
151: printer.println(" buffer.append(getMajorVersion());");
152: printer.println(" buffer.append('.');");
153: printer.println("");
154: printer.println(" buffer.append(getMinorVersion());");
155: printer.println(" buffer.append('.');");
156: printer.println("");
157: printer.println(" buffer.append(getBuild());");
158: printer.println("");
159: printer.println(" return buffer.toString();");
160: printer.println(" }");
161: printer.println("");
162: printer
163: .println(" public static void main(String[] args) {");
164: printer
165: .println(" System.out.println(\"Version: \" + (new JRefactoryVersion()).toString());");
166: printer.println(" }");
167: printer.println("}");
168:
169: printer.flush();
170: printer.close();
171: } catch (IOException ioe) {
172: ioe.printStackTrace();
173: }
174: }
175:
176: /**
177: * The main program for the CreateVersion class
178: *
179: *@param args The command line arguments
180: */
181: public static void main(String[] args) {
182: CreateVersion cv = new CreateVersion(args[0], args[1]);
183: cv.run();
184: }
185: }
|