[jbosstools-commits] JBoss Tools SVN: r12925 - trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Jan 8 03:58:58 EST 2009


Author: rob.stryker at jboss.com
Date: 2009-01-08 03:58:58 -0500 (Thu, 08 Jan 2009)
New Revision: 12925

Added:
   trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/JBossServerType.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/ServerBeanLoader.java
Log:
forgot to commit these when changing wizard fragment

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/JBossServerType.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/JBossServerType.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/JBossServerType.java	2009-01-08 08:58:58 UTC (rev 12925)
@@ -0,0 +1,78 @@
+/******************************************************************************* 
+ * Copyright (c) 2007 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/ 
+
+package org.jboss.ide.eclipse.as.core.util;
+
+import java.io.File;
+
+public class JBossServerType {
+	
+	private static final String SYSTEM_JAR_NAME = "twiddle.jar";
+	private String type;
+	private String jbossSystemJarPath;
+	private String[] versions = new String[0];
+	
+	private JBossServerType(String type, String jbossSystemJarPath, String[] versions) {
+		this.type = type;
+		this.jbossSystemJarPath = jbossSystemJarPath;
+		this.versions = versions;
+	}
+
+	public static final JBossServerType AS = new JBossServerType(
+			"AS",
+			"bin"+File.separatorChar + SYSTEM_JAR_NAME,
+			new String[]{"5.0", "4.2", "4.0", "3.2"});
+	
+	public static final JBossServerType EAP = new JBossServerType(
+			"EAP",
+			"jboss-as" + File.separatorChar + "bin"+ File.separatorChar + SYSTEM_JAR_NAME, 
+			new String[]{"4.2","4.3"});
+	
+	public static final JBossServerType SOAP = new JBossServerType(
+			"SOA-P",
+			"jboss-as" + File.separatorChar + "bin"+ File.separatorChar + SYSTEM_JAR_NAME,
+			new String[]{"4.3"});
+	
+	public static final JBossServerType UNKNOWN = new JBossServerType(
+			"UNKNOWN",
+			"",
+			new String[]{"5.0", "4.3", "4.2", "4.0", "3.2"});
+
+	public String toString() {
+		return type;
+	}
+	
+	public static JBossServerType getType(String name) {
+		if(AS.type.equals(name)) {
+			return AS;
+		} else if(EAP.type.equals(name)) {
+			return EAP;
+		} else if(SOAP.type.equals(name)) {
+			return SOAP;
+		}
+		throw new IllegalArgumentException("Name '" + name + "' cannot be converted to ServerType");
+	}
+
+	public String[] getVersions() {
+		return versions;
+	}
+	
+	public String getType() {
+		return type;
+	}
+	
+	public String getSystemJarPath() {
+		return jbossSystemJarPath;
+	}
+	
+	public static final JBossServerType[] KNOWN_TYPES = {AS, EAP, SOAP};
+	
+}
\ No newline at end of file

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/ServerBeanLoader.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/ServerBeanLoader.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/ServerBeanLoader.java	2009-01-08 08:58:58 UTC (rev 12925)
@@ -0,0 +1,116 @@
+/******************************************************************************* 
+ * Copyright (c) 2007 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/ 
+
+package org.jboss.ide.eclipse.as.core.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+/**
+ * @author eskimo
+ *
+ */
+public class ServerBeanLoader {
+	
+	public static final String SOAP_JBPM_JPDL_PATH = "jbpm-jpdl";
+	
+	public JBossServerType getServerType(File location) {
+		File asSystemJar = new File(location, JBossServerType.AS.getSystemJarPath());
+		if(asSystemJar.exists() && asSystemJar.isFile()) {
+			return JBossServerType.AS;
+		} else {
+			File eapSystemJar = new File(location, JBossServerType.EAP.getSystemJarPath());
+			File jbpmJpdlFolder = new File(location, this.SOAP_JBPM_JPDL_PATH);
+			if(eapSystemJar.exists() && eapSystemJar.isFile()) {
+				if(jbpmJpdlFolder.exists() && jbpmJpdlFolder.isDirectory()) {
+					return JBossServerType.SOAP;
+				} else {
+					return JBossServerType.EAP;
+				}
+			} 
+		}
+		return JBossServerType.UNKNOWN;
+	}
+	
+	public String getName(File location) {
+		return location.getName();
+	}
+	
+	public String getFullServerVersion(File systemJarFile) {
+		String version = null;
+		if(systemJarFile.canRead()) {
+			try {
+				ZipFile jar = new ZipFile(systemJarFile);
+				ZipEntry manifest = jar.getEntry("META-INF/MANIFEST.MF");
+				Properties props = new Properties();
+				props.load(jar.getInputStream(manifest));
+				version = (String)props.get("Specification-Version");
+			} catch (IOException e) {
+				// version = ""
+			}
+		}
+		return version;
+	}
+	
+	public String getServerVersion(String version) {
+		if(version==null) return "";
+		String[] versions = JBossServerType.UNKNOWN.getVersions();
+		String adapterVersion = "";
+		//  trying to match adapter version by X.X version
+		for (String currentVersion : versions) {
+			String pattern = currentVersion.replace(".", "\\.") + ".*";
+			if(version.matches(pattern)) {
+				adapterVersion = currentVersion;
+				break;
+			}
+		}
+		
+		if("".equals(adapterVersion)) {
+			// trying to match by major version
+			for (String currentVersion : versions) {
+				String pattern = currentVersion.substring(0, 2).replace(".", "\\.") + ".*";
+				if(version.matches(pattern)) {
+					adapterVersion = currentVersion;
+					break;
+				}
+			}
+		}
+		return adapterVersion;
+	}
+	
+	public String getAdapterVersion(String version) {
+		String[] versions = JBossServerType.UNKNOWN.getVersions();
+		String adapterVersion = "";
+		//  trying to match adapter version by X.X version
+		for (String currentVersion : versions) {
+			String pattern = currentVersion.replace(".", "\\.") + ".*";
+			if(version.matches(pattern)) {
+				adapterVersion = currentVersion;
+				break;
+			}
+		}
+		
+		if("".equals(adapterVersion)) {
+			// trying to match by major version
+			for (String currentVersion : versions) {
+				String pattern = currentVersion.substring(0, 2).replace(".", "\\.") + ".*";
+				if(version.matches(pattern)) {
+					adapterVersion = currentVersion;
+					break;
+				}
+			}
+		}
+		return adapterVersion;
+	}
+}




More information about the jbosstools-commits mailing list