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