001    /**
002     * Copyright (c) 2000-2010 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 =
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    }