001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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 = _fileUtil.toProperties(
042                                    "../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    
054                            x = content.indexOf("\"", x) + 1;
055    
056                            int y = content.indexOf("\"", x);
057    
058                            content =
059                                    content.substring(0, x) + version +
060                                            content.substring(y, content.length());
061    
062                            // Get build
063    
064                            x = content.indexOf("String _BUILD = \"");
065                            x = content.indexOf("\"", x) + 1;
066    
067                            y = content.indexOf("\"", x);
068    
069                            int build = GetterUtil.getInteger(content.substring(x, y)) + 1;
070    
071                            content =
072                                    content.substring(0, x) + build +
073                                            content.substring(y, content.length());
074    
075                            // Get date
076    
077                            DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG);
078    
079                            String date = dateFormat.format(new Date());
080    
081                            x = content.indexOf("String _DATE = \"");
082                            x = content.indexOf("\"", x) + 1;
083    
084                            y = content.indexOf("\"", x);
085    
086                            content =
087                                    content.substring(0, x) + date +
088                                            content.substring(y, content.length());
089    
090                            // Update ReleaseInfo.java
091    
092                            _fileUtil.write(file, content);
093    
094                            // Update portal-release.sql
095    
096                            file = new File("../sql/portal-data-release.sql");
097    
098                            content = _fileUtil.read(file);
099    
100                            x = content.indexOf("insert into Release_");
101                            y = content.indexOf(", FALSE);", x);
102                            x = content.lastIndexOf(" ", y - 1) + 1;
103    
104                            content =
105                                    content.substring(0, x) + build +
106                                    content.substring(y, content.length());
107    
108                            _fileUtil.write(file, content);
109                    }
110                    catch (Exception e) {
111                            e.printStackTrace();
112                    }
113            }
114    
115            private static FileImpl _fileUtil = FileImpl.getInstance();
116    
117    }