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      static {
45          InitUtil.init();
46      }
47  
48      public static void main(String[] args) {
49          new ReleaseInfoBuilder();
50      }
51  
52      public ReleaseInfoBuilder() {
53          try {
54  
55              // Get version
56  
57              Properties releaseProps =
58                  FileUtil.toProperties("../release.properties");
59  
60              String version = releaseProps.getProperty("lp.version");
61  
62              File file = new File(
63                  "../portal-kernel/src/com/liferay/portal/kernel/util/" +
64                      "ReleaseInfo.java");
65  
66              String content = FileUtil.read(file);
67  
68              int x = content.indexOf("String version = \"");
69              x = content.indexOf("\"", x) + 1;
70              int y = content.indexOf("\"", x);
71  
72              content =
73                  content.substring(0, x) + version +
74                  content.substring(y, content.length());
75  
76              // Get build
77  
78              x = content.indexOf("String build = \"");
79              x = content.indexOf("\"", x) + 1;
80              y = content.indexOf("\"", x);
81  
82              int build = GetterUtil.getInteger(content.substring(x, y)) + 1;
83  
84              content =
85                  content.substring(0, x) + build +
86                  content.substring(y, content.length());
87  
88              // Get date
89  
90              DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
91  
92              String date = df.format(new Date());
93  
94              x = content.indexOf("String date = \"");
95              x = content.indexOf("\"", x) + 1;
96              y = content.indexOf("\"", x);
97  
98              content =
99                  content.substring(0, x) + date +
100                 content.substring(y, content.length());
101 
102             // Update ReleaseInfo.java
103 
104             FileUtil.write(file, content);
105 
106             // Update portal-release.sql
107 
108             file = new File("../sql/portal-data-release.sql");
109 
110             content = FileUtil.read(file);
111 
112             x = content.indexOf("insert into Release_");
113             y = content.indexOf(", FALSE);", x);
114             x = content.lastIndexOf(" ", y - 1) + 1;
115 
116             content =
117                 content.substring(0, x) + build +
118                 content.substring(y, content.length());
119 
120             FileUtil.write(file, content);
121         }
122         catch (Exception e) {
123             e.printStackTrace();
124         }
125     }
126 
127 }