001    /**
002     * Copyright (c) 2000-2013 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 = content.substring(0, x) + version + content.substring(y);
059    
060                            // Get build
061    
062                            x = content.indexOf("String _BUILD = \"");
063                            x = content.indexOf("\"", x) + 1;
064    
065                            y = content.indexOf("\"", x);
066    
067                            int build = GetterUtil.getInteger(content.substring(x, y)) + 1;
068    
069                            content = content.substring(0, x) + build + content.substring(y);
070    
071                            // Get date
072    
073                            DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG);
074    
075                            String date = dateFormat.format(new Date());
076    
077                            x = content.indexOf("String _DATE = \"");
078                            x = content.indexOf("\"", x) + 1;
079    
080                            y = content.indexOf("\"", x);
081    
082                            content = content.substring(0, x) + date + content.substring(y);
083    
084                            // Update ReleaseInfo.java
085    
086                            _fileUtil.write(file, content);
087    
088                            // Update portal-release.sql
089    
090                            file = new File("../sql/portal-data-release.sql");
091    
092                            content = _fileUtil.read(file);
093    
094                            x = content.indexOf("insert into Release_");
095                            y = content.indexOf(", FALSE);", x);
096                            x = content.lastIndexOf(" ", y - 1) + 1;
097    
098                            content = content.substring(0, x) + build + content.substring(y);
099    
100                            _fileUtil.write(file, content);
101                    }
102                    catch (Exception e) {
103                            e.printStackTrace();
104                    }
105            }
106    
107            private static FileImpl _fileUtil = FileImpl.getInstance();
108    
109    }