Skip to content

Instantly share code, notes, and snippets.

@sbilo
Last active August 29, 2015 14:03
Show Gist options
  • Save sbilo/73b3dd74d097b3bac8de to your computer and use it in GitHub Desktop.
Save sbilo/73b3dd74d097b3bac8de to your computer and use it in GitHub Desktop.
com.liferay.portal.tools.BuildInfoBuilder
/**
* Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.tools;
import java.io.File;
import java.text.DateFormat;
import java.util.Date;
import java.util.Properties;
import com.liferay.portal.util.FileImpl;
/**
* @author Brian Wing Shun Chan
* @author Sander Bilo
*/
public class BuildInfoBuilder {
public static void main(String[] args) {
new BuildInfoBuilder();
}
public BuildInfoBuilder() {
try {
// Get version
String machineName = System.getProperty("user.name");
Properties releaseProps = _fileUtil.toProperties(
"../release.properties");
Properties releaseMachineProps = _fileUtil.toProperties("../release." + machineName + ".properties");
if (releaseMachineProps != null) {
releaseProps.putAll(releaseMachineProps);
}
String version = releaseProps.getProperty("lp.version");
File file = new File(
"../portal-service/src/com/liferay/portal/kernel/util/" +
"ReleaseInfo.java");
String content = _fileUtil.read(file);
int x = content.indexOf("String _VERSION = \"");
x = content.indexOf("\"", x) + 1;
int y = content.indexOf("\"", x);
content = content.substring(0, x) + version + content.substring(y);
String gitCommitTag = releaseProps.getProperty("git.commit.tag");
x = content.indexOf("String _VERSION_DISPLAY_NAME = \"");
x = content.indexOf("\"", x) + 1;
y = content.indexOf("\"", x);
String versionDisplayName = content.substring(x, y);
content = content.substring(0, x) + versionDisplayName.replace(" (git:"+ gitCommitTag +")", "") + " (git:"+ gitCommitTag +")"+ content.substring(y);
// Get date
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG);
String date = dateFormat.format(new Date());
x = content.indexOf("String _DATE = \"");
x = content.indexOf("\"", x) + 1;
y = content.indexOf("\"", x);
content = content.substring(0, x) + date + content.substring(y);
// Update ReleaseInfo.java
_fileUtil.write(file, content);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static FileImpl _fileUtil = FileImpl.getInstance();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment