| ReleaseInfoBuilder.java |
1 /**
2 * Copyright (c) 2000-2008 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.FileUtil;
26 import com.liferay.portal.kernel.util.GetterUtil;
27 import com.liferay.portal.util.InitUtil;
28
29 import java.io.File;
30
31 import java.text.DateFormat;
32
33 import java.util.Date;
34 import java.util.Properties;
35
36 /**
37 * <a href="ReleaseInfoBuilder.java.html"><b><i>View Source</i></b></a>
38 *
39 * @author Brian Wing Shun Chan
40 *
41 */
42 public class ReleaseInfoBuilder {
43
44 public static void main(String[] args) {
45 InitUtil.initWithSpring();
46
47 new ReleaseInfoBuilder();
48 }
49
50 public ReleaseInfoBuilder() {
51 try {
52
53 // Get version
54
55 Properties releaseProps =
56 FileUtil.toProperties("../release.properties");
57
58 String version = releaseProps.getProperty("lp.version");
59
60 File file = new File(
61 "../portal-kernel/src/com/liferay/portal/kernel/util/" +
62 "ReleaseInfo.java");
63
64 String content = FileUtil.read(file);
65
66 int x = content.indexOf("String version = \"");
67 x = content.indexOf("\"", x) + 1;
68 int y = content.indexOf("\"", x);
69
70 content =
71 content.substring(0, x) + version +
72 content.substring(y, content.length());
73
74 // Get build
75
76 x = content.indexOf("String build = \"");
77 x = content.indexOf("\"", x) + 1;
78 y = content.indexOf("\"", x);
79
80 int build = GetterUtil.getInteger(content.substring(x, y)) + 1;
81
82 content =
83 content.substring(0, x) + build +
84 content.substring(y, content.length());
85
86 // Get date
87
88 DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
89
90 String date = df.format(new Date());
91
92 x = content.indexOf("String date = \"");
93 x = content.indexOf("\"", x) + 1;
94 y = content.indexOf("\"", x);
95
96 content =
97 content.substring(0, x) + date +
98 content.substring(y, content.length());
99
100 // Update ReleaseInfo.java
101
102 FileUtil.write(file, content);
103
104 // Update portal-release.sql
105
106 file = new File("../sql/portal-data-release.sql");
107
108 content = FileUtil.read(file);
109
110 x = content.indexOf("insert into Release_");
111 y = content.indexOf(", FALSE);", x);
112 x = content.lastIndexOf(" ", y - 1) + 1;
113
114 content =
115 content.substring(0, x) + build +
116 content.substring(y, content.length());
117
118 FileUtil.write(file, content);
119 }
120 catch (Exception e) {
121 e.printStackTrace();
122 }
123 }
124
125 }