1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.portal.util.FileImpl;
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  public class ReleaseInfoBuilder {
41  
42      public static void main(String[] args) {
43          new ReleaseInfoBuilder();
44      }
45  
46      public ReleaseInfoBuilder() {
47          try {
48  
49              // Get version
50  
51              Properties releaseProps =
52                  _fileUtil.toProperties("../release.properties");
53  
54              String version = releaseProps.getProperty("lp.version");
55  
56              File file = new File(
57                  "../portal-kernel/src/com/liferay/portal/kernel/util/" +
58                      "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     private static FileImpl _fileUtil = FileImpl.getInstance();
122 
123 }