| ReleaseInfoBuilder.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 * The contents of this file are subject to the terms of the Liferay Enterprise
5 * Subscription License ("License"). You may not use this file except in
6 * compliance with the License. You can obtain a copy of the License by
7 * contacting Liferay, Inc. See the License for the specific language governing
8 * permissions and limitations under the License, including but not limited to
9 * distribution rights of the Software.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17 * SOFTWARE.
18 */
19
20 package com.liferay.portal.tools;
21
22 import com.liferay.portal.kernel.util.GetterUtil;
23 import com.liferay.portal.util.FileImpl;
24
25 import java.io.File;
26
27 import java.text.DateFormat;
28
29 import java.util.Date;
30 import java.util.Properties;
31
32 /**
33 * <a href="ReleaseInfoBuilder.java.html"><b><i>View Source</i></b></a>
34 *
35 * @author Brian Wing Shun Chan
36 *
37 */
38 public class ReleaseInfoBuilder {
39
40 public static void main(String[] args) {
41 new ReleaseInfoBuilder();
42 }
43
44 public ReleaseInfoBuilder() {
45 try {
46
47 // Get version
48
49 Properties releaseProps =
50 _fileUtil.toProperties("../release.properties");
51
52 String version = releaseProps.getProperty("lp.version");
53
54 File file = new File(
55 "../portal-kernel/src/com/liferay/portal/kernel/util/" +
56 "ReleaseInfo.java");
57
58 String content = _fileUtil.read(file);
59
60 int x = content.indexOf("String version = \"");
61 x = content.indexOf("\"", x) + 1;
62 int y = content.indexOf("\"", x);
63
64 content =
65 content.substring(0, x) + version +
66 content.substring(y, content.length());
67
68 // Get build
69
70 x = content.indexOf("String build = \"");
71 x = content.indexOf("\"", x) + 1;
72 y = content.indexOf("\"", x);
73
74 int build = GetterUtil.getInteger(content.substring(x, y)) + 1;
75
76 content =
77 content.substring(0, x) + build +
78 content.substring(y, content.length());
79
80 // Get date
81
82 DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
83
84 String date = df.format(new Date());
85
86 x = content.indexOf("String date = \"");
87 x = content.indexOf("\"", x) + 1;
88 y = content.indexOf("\"", x);
89
90 content =
91 content.substring(0, x) + date +
92 content.substring(y, content.length());
93
94 // Update ReleaseInfo.java
95
96 _fileUtil.write(file, content);
97
98 // Update portal-release.sql
99
100 file = new File("../sql/portal-data-release.sql");
101
102 content = _fileUtil.read(file);
103
104 x = content.indexOf("insert into Release_");
105 y = content.indexOf(", FALSE);", x);
106 x = content.lastIndexOf(" ", y - 1) + 1;
107
108 content =
109 content.substring(0, x) + build +
110 content.substring(y, content.length());
111
112 _fileUtil.write(file, content);
113 }
114 catch (Exception e) {
115 e.printStackTrace();
116 }
117 }
118
119 private static FileImpl _fileUtil = FileImpl.getInstance();
120
121 }