001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.tools;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.util.FileImpl;
019    
020    import java.io.File;
021    
022    import java.text.DateFormat;
023    
024    import java.util.Date;
025    import java.util.Properties;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class ReleaseInfoBuilder {
031    
032            public static void main(String[] args) {
033                    new ReleaseInfoBuilder();
034            }
035    
036            public ReleaseInfoBuilder() {
037                    try {
038    
039                            // Get version
040    
041                            Properties releaseProps =
042                                    _fileUtil.toProperties("../release.properties");
043    
044                            String version = releaseProps.getProperty("lp.version");
045    
046                            File file = new File(
047                                    "../portal-service/src/com/liferay/portal/kernel/util/" +
048                                            "ReleaseInfo.java");
049    
050                            String content = _fileUtil.read(file);
051    
052                            int x = content.indexOf("String version = \"");
053                            x = content.indexOf("\"", x) + 1;
054                            int y = content.indexOf("\"", x);
055    
056                            content =
057                                    content.substring(0, x) + version +
058                                    content.substring(y, content.length());
059    
060                            // Get build
061    
062                            x = content.indexOf("String build = \"");
063                            x = content.indexOf("\"", x) + 1;
064                            y = content.indexOf("\"", x);
065    
066                            int build = GetterUtil.getInteger(content.substring(x, y)) + 1;
067    
068                            content =
069                                    content.substring(0, x) + build +
070                                    content.substring(y, content.length());
071    
072                            // Get date
073    
074                            DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
075    
076                            String date = df.format(new Date());
077    
078                            x = content.indexOf("String date = \"");
079                            x = content.indexOf("\"", x) + 1;
080                            y = content.indexOf("\"", x);
081    
082                            content =
083                                    content.substring(0, x) + date +
084                                    content.substring(y, content.length());
085    
086                            // Update ReleaseInfo.java
087    
088                            _fileUtil.write(file, content);
089    
090                            // Update portal-release.sql
091    
092                            file = new File("../sql/portal-data-release.sql");
093    
094                            content = _fileUtil.read(file);
095    
096                            x = content.indexOf("insert into Release_");
097                            y = content.indexOf(", FALSE);", x);
098                            x = content.lastIndexOf(" ", y - 1) + 1;
099    
100                            content =
101                                    content.substring(0, x) + build +
102                                    content.substring(y, content.length());
103    
104                            _fileUtil.write(file, content);
105                    }
106                    catch (Exception e) {
107                            e.printStackTrace();
108                    }
109            }
110    
111            private static FileImpl _fileUtil = FileImpl.getInstance();
112    
113    }