### Eclipse Workspace Patch 1.0 #P org.jboss.tools.esb.project.ui Index: src/org/jboss/tools/esb/project/ui/preference/controls/JBossRuntimeListFieldEditor.java =================================================================== --- src/org/jboss/tools/esb/project/ui/preference/controls/JBossRuntimeListFieldEditor.java (revision 19456) +++ src/org/jboss/tools/esb/project/ui/preference/controls/JBossRuntimeListFieldEditor.java (working copy) @@ -678,10 +678,21 @@ configuration.setText(source.getConfiguration()); } } + + // set version automatically according esb home location and configuration + updateDefaultVersion(); return configList; } + + private void updateDefaultVersion(){ + String homeLocation = homeDir.getValueAsString(); + String config = configuration.getText(); + String defaultVersion = JBossRuntimeManager.getInstance().getVersion(homeLocation, config); + version.setValue(defaultVersion); + + } /** * Return JBossWS Runtime instance initialized by user input * Index: src/org/jboss/tools/esb/project/ui/messages/JBossESBUI.properties =================================================================== --- src/org/jboss/tools/esb/project/ui/messages/JBossESBUI.properties (revision 19456) +++ src/org/jboss/tools/esb/project/ui/messages/JBossESBUI.properties (working copy) @@ -66,6 +66,8 @@ ESBFacetInstallationPage_Label_Source_Directory=Java Source Directory ESBFacetInstallationPage_Title=Install ESB Facet +ESBRuntimeContainerPage_Button_Text=Create an ESB Runtime + ESBProjectFirstPage_Description=Create a new JBoss ESB project. ESBProjectFirstPage_Title=JBoss ESB Project Index: src/org/jboss/tools/esb/project/ui/messages/JBossESBUIMessages.java =================================================================== --- src/org/jboss/tools/esb/project/ui/messages/JBossESBUIMessages.java (revision 19456) +++ src/org/jboss/tools/esb/project/ui/messages/JBossESBUIMessages.java (working copy) @@ -53,6 +53,8 @@ public static String JBoss_Button_Field_Editor_Browse; public static String JBoss_ESBRuntime_Classpath_Container_5; public static String JBoss_Runtime_List_Field_Editor_Configuration; + + public static String ESBRuntimeContainerPage_Button_Text; public static String JBoss_ESBRuntime_Classpath_Container_Description; #P org.jboss.tools.esb.project.core Index: src/org/jboss/tools/esb/core/runtime/JBossRuntimeManager.java =================================================================== --- src/org/jboss/tools/esb/core/runtime/JBossRuntimeManager.java (revision 19456) +++ src/org/jboss/tools/esb/core/runtime/JBossRuntimeManager.java (working copy) @@ -13,12 +13,17 @@ import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Set; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; @@ -31,6 +36,7 @@ import org.eclipse.wst.common.project.facet.core.IFacetedProject; import org.eclipse.wst.common.project.facet.core.IProjectFacet; import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; +import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager; import org.jboss.tools.esb.core.ESBProjectCorePlugin; import org.jboss.tools.esb.core.facet.IJBossESBFacetDataModelProperties; import org.jboss.tools.esb.core.messages.JBossFacetCoreMessages; @@ -50,6 +56,11 @@ static String ATT_VERSION = "esbVersion"; //$NON-NLS-1$ static String ATT_ID = "id"; static String VERSION_SEPARATOR = ","; + static String VERSION_FILE_NAME = "VERSION"; + static String VERSION_PROPERTIES_KEY = "Version"; + static String VERSION_PROPERTIES_SEPERATOR = "_"; + + static Map parserMap = new HashMap(); @@ -455,5 +466,62 @@ } } } + + + public String getVersion(String location, String configuration){ + String version = ""; + File rosettaJar = null; + Collection resolvers = parserMap.values(); + for(IESBRuntimeResolver resolver : resolvers){ + rosettaJar = resolver.getRosettaJar(location, configuration); + if(rosettaJar != null && rosettaJar.exists()){ + break; + } + } + + if(rosettaJar == null || !rosettaJar.exists()){ + return ""; + } + + try { + ZipFile zfile = new ZipFile(rosettaJar); + ZipEntry entry = zfile.getEntry(VERSION_FILE_NAME); + + if(entry == null) return ""; + + InputStream input = zfile.getInputStream(entry); + Properties properties = new Properties(); + properties.load(input); + version = properties.getProperty(VERSION_PROPERTIES_KEY); + + + if(version == null){ + return ""; + } + // soa-p5.0 and higher + else if(version.indexOf(VERSION_PROPERTIES_SEPERATOR) > 0){ + version = version.substring(0, version.indexOf(VERSION_PROPERTIES_SEPERATOR)); + } + //soa-p 4.3 + else if(version.equals("4.3.0")) { + version = "4.4"; + } + else if(version.length() > 3){ + version = version.substring(0,3); + } + + } catch (ZipException e) { + ESBProjectCorePlugin.log(e.getLocalizedMessage(), e); + } catch (IOException e) { + ESBProjectCorePlugin.log(e.getLocalizedMessage(), e); + } + + return version; + } + + public static void main(String[] args){ + File file = new File("/home/fugang/jboss-all/jboss-soa-p.5.0.0/"); + JBossRuntimeManager.getInstance().getVersion(file.getAbsolutePath().toString(), "default"); + } } \ No newline at end of file Index: src/org/jboss/tools/esb/core/runtime/AbstractESBRuntimeResolver.java =================================================================== --- src/org/jboss/tools/esb/core/runtime/AbstractESBRuntimeResolver.java (revision 19456) +++ src/org/jboss/tools/esb/core/runtime/AbstractESBRuntimeResolver.java (working copy) @@ -54,6 +54,17 @@ return directories; } + public File getRosettaJar(String runtimeLocation , String configuration){ + List jars = getAllRuntimeJars(runtimeLocation, configuration); + for(File file : jars){ + if(file.getName().equals(ROSETTA_JAR)){ + return file; + } + } + + return null; + } + public List getAllRuntimeJars(String runtimeLocation, String configuration) { List jarList = new ArrayList(); Index: src/org/jboss/tools/esb/core/runtime/IESBRuntimeResolver.java =================================================================== --- src/org/jboss/tools/esb/core/runtime/IESBRuntimeResolver.java (revision 19456) +++ src/org/jboss/tools/esb/core/runtime/IESBRuntimeResolver.java (working copy) @@ -23,4 +23,6 @@ public List getJarDirectories(String runtimeLocation, String configuration); public List getAllRuntimeJars(String runtimeLocation, String configuration); + + public File getRosettaJar(String runtimeLocation , String configuration); }