Skip to content

Commit

Permalink
IDE-273
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Amerson <gregory.amerson@liferay.com>
  • Loading branch information
Cindy Li authored and gamerson committed Oct 12, 2012
1 parent ca61cd7 commit 3b8b0bf
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,24 @@ public IPath getRuntimeLocation() {
return getRuntime().getLocation();
}

public String getServerInfo() {
public String getServerInfo() {
try {
String serverInfoFromManifest = LiferayTomcatUtil.getConfigInfoFromManifest( "server", getPortalDir() );

if( serverInfoFromManifest!=null ) {
return serverInfoFromManifest;
}

return getServerInfoFromClass();
}
catch( IOException e ) {
LiferayTomcatPlugin.logError(e);
}

return null;
}

public String getServerInfoFromClass() {
// check for existing server info
IPath location = getRuntime().getLocation();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

import javax.xml.parsers.DocumentBuilderFactory;

Expand Down Expand Up @@ -239,6 +241,18 @@ public static String[] getSupportedHookProperties(IPath runtimeLocation, IPath p
}

public static String getVersion(IPath location, IPath portalDir)
throws IOException {

String versionFromManifest = getConfigInfoFromManifest("version", portalDir);

if (versionFromManifest!=null) {
return versionFromManifest;
}

return getVersionFromClass(location, portalDir);
}

public static String getVersionFromClass(IPath location, IPath portalDir)
throws IOException {

IPath versionsInfoPath = LiferayTomcatPlugin.getDefault().getStateLocation().append("version.properties");
Expand Down Expand Up @@ -294,6 +308,44 @@ public static String getVersion(IPath location, IPath portalDir)
return version.toString();
}

public static String getConfigInfoFromManifest(String configType, IPath portalDir)
throws IOException {

File implJar = portalDir.append( "WEB-INF/lib/portal-impl.jar").toFile();
String version = null;
String serverInfo = null;

if (implJar.exists()) {
try {
JarFile jar = new JarFile(implJar);

Manifest manifest = jar.getManifest();
Attributes attributes = manifest.getMainAttributes();

version = attributes.getValue( "Liferay-Portal-Version" );
serverInfo = attributes.getValue( "Liferay-Portal-Server-Info" );

if(CoreUtil.compareVersions( Version.parseVersion( version ), new Version( 6, 2, 0 ) ) < 0) {
version = null;
serverInfo = null;
}
}
catch (IOException e) {
LiferayTomcatPlugin.logError(e);
}
}

if(configType.equals( "version" )) {
return version;
}

if(configType.equals( "server" )) {
return serverInfo;
}

return null;
}

public static boolean isExtProjectContext(Context context) {

return false;
Expand Down

0 comments on commit 3b8b0bf

Please sign in to comment.