1   /**
2    * Copyright (c) 2000-2009 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.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   */
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                  "../portal-kernel/src/com/liferay/portal/kernel/util/" +
59                      "ReleaseInfo.java");
60  
61              String content = _fileUtil.read(file);
62  
63              int x = content.indexOf("String version = \"");
64              x = content.indexOf("\"", x) + 1;
65              int y = content.indexOf("\"", x);
66  
67              content =
68                  content.substring(0, x) + version +
69                  content.substring(y, content.length());
70  
71              // Get build
72  
73              x = content.indexOf("String build = \"");
74              x = content.indexOf("\"", x) + 1;
75              y = content.indexOf("\"", x);
76  
77              int build = GetterUtil.getInteger(content.substring(x, y)) + 1;
78  
79              content =
80                  content.substring(0, x) + build +
81                  content.substring(y, content.length());
82  
83              // Get date
84  
85              DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
86  
87              String date = df.format(new Date());
88  
89              x = content.indexOf("String date = \"");
90              x = content.indexOf("\"", x) + 1;
91              y = content.indexOf("\"", x);
92  
93              content =
94                  content.substring(0, x) + date +
95                  content.substring(y, content.length());
96  
97              // Update ReleaseInfo.java
98  
99              _fileUtil.write(file, content);
100 
101             // Update portal-release.sql
102 
103             file = new File("../sql/portal-data-release.sql");
104 
105             content = _fileUtil.read(file);
106 
107             x = content.indexOf("insert into Release_");
108             y = content.indexOf(", FALSE);", x);
109             x = content.lastIndexOf(" ", y - 1) + 1;
110 
111             content =
112                 content.substring(0, x) + build +
113                 content.substring(y, content.length());
114 
115             _fileUtil.write(file, content);
116         }
117         catch (Exception e) {
118             e.printStackTrace();
119         }
120     }
121 
122     private static FileImpl _fileUtil = FileImpl.getInstance();
123 
124 }