001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.tools;
022:
023: import com.liferay.portal.kernel.util.GetterUtil;
024: import com.liferay.util.FileUtil;
025:
026: import java.io.File;
027:
028: import java.text.DateFormat;
029:
030: import java.util.Date;
031: import java.util.Properties;
032:
033: /**
034: * <a href="ReleaseInfoBuilder.java.html"><b><i>View Source</i></b></a>
035: *
036: * @author Brian Wing Shun Chan
037: *
038: */
039: public class ReleaseInfoBuilder {
040:
041: public static void main(String[] args) {
042: new ReleaseInfoBuilder();
043: }
044:
045: public ReleaseInfoBuilder() {
046: try {
047:
048: // Get version
049:
050: Properties releaseProps = FileUtil
051: .toProperties("../release.properties");
052:
053: String version = releaseProps.getProperty("lp.version");
054:
055: File file = new File(
056: "../portal-kernel/src/com/liferay/portal/kernel/util/"
057: + "ReleaseInfo.java");
058:
059: String content = FileUtil.read(file);
060:
061: int x = content.indexOf("String version = \"");
062: x = content.indexOf("\"", x) + 1;
063: int y = content.indexOf("\"", x);
064:
065: content = content.substring(0, x) + version
066: + content.substring(y, content.length());
067:
068: // Get build
069:
070: x = content.indexOf("String build = \"");
071: x = content.indexOf("\"", x) + 1;
072: y = content.indexOf("\"", x);
073:
074: int build = GetterUtil.getInteger(content.substring(x, y)) + 1;
075:
076: content = content.substring(0, x) + build
077: + content.substring(y, content.length());
078:
079: // Get date
080:
081: DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
082:
083: String date = df.format(new Date());
084:
085: x = content.indexOf("String date = \"");
086: x = content.indexOf("\"", x) + 1;
087: y = content.indexOf("\"", x);
088:
089: content = content.substring(0, x) + date
090: + content.substring(y, content.length());
091:
092: // Update ReleaseInfo.java
093:
094: FileUtil.write(file, content);
095:
096: // Update portal-release.sql
097:
098: file = new File("../sql/portal-data-release.sql");
099:
100: content = FileUtil.read(file);
101:
102: x = content.indexOf("insert into Release_");
103: y = content.indexOf(", FALSE);", x);
104: x = content.lastIndexOf(" ", y - 1) + 1;
105:
106: content = content.substring(0, x) + build
107: + content.substring(y, content.length());
108:
109: FileUtil.write(file, content);
110: } catch (Exception e) {
111: e.printStackTrace();
112: }
113: }
114:
115: }
|