| ReleaseInfoBuilder.java |
1 /**
2 * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.liferay.portal.tools;
24
25 import com.liferay.portal.kernel.util.GetterUtil;
26 import com.liferay.util.FileUtil;
27
28 import java.io.File;
29
30 import java.text.DateFormat;
31
32 import java.util.Date;
33 import java.util.Properties;
34
35 /**
36 * <a href="ReleaseInfoBuilder.java.html"><b><i>View Source</i></b></a>
37 *
38 * @author Brian Wing Shun Chan
39 *
40 */
41 public class ReleaseInfoBuilder {
42
43 public static void main(String[] args) {
44 new ReleaseInfoBuilder();
45 }
46
47 public ReleaseInfoBuilder() {
48 try {
49
50 // Get version
51
52 Properties releaseProps =
53 FileUtil.toProperties("../release.properties");
54
55 String version = releaseProps.getProperty("lp.version");
56
57 File file = new File(
58 "src/com/liferay/portal/util/ReleaseInfo.java");
59
60 String content = FileUtil.read(file);
61
62 int x = content.indexOf("String version = \"");
63 x = content.indexOf("\"", x) + 1;
64 int y = content.indexOf("\"", x);
65
66 content =
67 content.substring(0, x) + version +
68 content.substring(y, content.length());
69
70 // Get build
71
72 x = content.indexOf("String build = \"");
73 x = content.indexOf("\"", x) + 1;
74 y = content.indexOf("\"", x);
75
76 int build = GetterUtil.getInteger(content.substring(x, y)) + 1;
77
78 content =
79 content.substring(0, x) + build +
80 content.substring(y, content.length());
81
82 // Get date
83
84 DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
85
86 String date = df.format(new Date());
87
88 x = content.indexOf("String date = \"");
89 x = content.indexOf("\"", x) + 1;
90 y = content.indexOf("\"", x);
91
92 content =
93 content.substring(0, x) + date +
94 content.substring(y, content.length());
95
96 // Update ReleaseInfo.java
97
98 FileUtil.write(file, content);
99
100 // Update portal-release.sql
101
102 file = new File("../sql/portal-data-release.sql");
103
104 content = FileUtil.read(file);
105
106 x = content.indexOf("insert into Release_");
107 y = content.indexOf(", FALSE);", x);
108 x = content.lastIndexOf(" ", y - 1) + 1;
109
110 content =
111 content.substring(0, x) + build +
112 content.substring(y, content.length());
113
114 FileUtil.write(file, content);
115 }
116 catch (Exception e) {
117 e.printStackTrace();
118 }
119 }
120
121 }