Author: akazakov
Date: 2009-03-19 12:30:07 -0400 (Thu, 19 Mar 2009)
New Revision: 14268
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamUtil.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/project/facet/SeamVersion.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SeamRuntimeListFieldEditor.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/SeamRuntimeManagerTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3933 Seam version should be set 2.1 not 2.0 when
Seam 2.1.x runtime selected. - Fixed.
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamUtil.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamUtil.java 2009-03-19
15:58:41 UTC (rev 14267)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamUtil.java 2009-03-19
16:30:07 UTC (rev 14268)
@@ -12,6 +12,7 @@
import java.io.File;
import java.io.IOException;
+import java.util.StringTokenizer;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
@@ -68,11 +69,50 @@
* @return
*/
public static String getSeamVersionFromManifest(SeamRuntime runtime) {
- File jarFile = new File(runtime.getLibDir(), seamJarName);
+ return getSeamVersionFromManifest(runtime.getHomeDir());
+ }
+
+ /**
+ * Returns trimmed Seam version from
<SeamHome>/lib/jboss-seam.jar/META-INF/MANIFEST.MF
+ * @param depth - number of segments of Seam version string.
+ * @param seamHome
+ * @return
+ */
+ public static String getSeamVersionFromManifest(String seamHome, int depth) {
+ return trimSeamVersion(getSeamVersionFromManifest(seamHome), depth);
+ }
+
+ /**
+ * Returns true if two versions are matched.
+ * For example "2.1.1.GA" matches "2.1"
+ * @param version1
+ * @param version2
+ * @return
+ */
+ public static boolean areSeamVersionsMatched(String version1, String version2) {
+ String longerVersion = version1.length()>version2.length()?version1:version2;
+ String shorterVersion = longerVersion==version1?version2:version1;
+ StringTokenizer sSt = new StringTokenizer(shorterVersion, ".", false);
+ StringTokenizer lSt = new StringTokenizer(longerVersion, ".", false);
+ while (sSt.hasMoreElements() && lSt.hasMoreElements()) {
+ if(!sSt.nextToken().equals(lSt.nextToken())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Returns Seam version from <SeamHome>/lib/jboss-seam.jar/META-INF/MANIFEST.MF
+ * @param seamHome
+ * @return
+ */
+ public static String getSeamVersionFromManifest(String seamHome) {
+ File jarFile = new File(seamHome, "lib/" + seamJarName);
if(!jarFile.isFile()) {
- jarFile = new File(runtime.getHomeDir(), seamJarName);
+ jarFile = new File(seamHome, seamJarName);
if(!jarFile.isFile()) {
- SeamCorePlugin.getPluginLog().logWarning(jarFile.getAbsolutePath() + " as well
as " + new File(runtime.getLibDir(), seamJarName).getAbsolutePath() + "
don't exist for Seam Runtime " + runtime.getName());
+ SeamCorePlugin.getPluginLog().logWarning(jarFile.getAbsolutePath() + " as well
as " + new File(seamHome, "lib/" + seamJarName).getAbsolutePath() + "
don't exist.");
return null;
}
}
@@ -89,8 +129,31 @@
return null;
}
}
-
+
/**
+ * Trims Seam version string.
+ * For example "2.1.0.SP1" will be trimmed to 2.1 (depth=2);
"2.1.1.GA" -> "2.1.1" (depth=3); "2.0.0.SP1" ->
"2.0.0.SP1" (depth<1)
+ * @param fullSeamVersion
+ * @param depth - number of segments of Seam version string.
+ * @return
+ */
+ public static String trimSeamVersion(String fullSeamVersion, int depth) {
+ if(fullSeamVersion==null || depth<1) {
+ return fullSeamVersion;
+ }
+ StringBuffer version = new StringBuffer();
+ StringTokenizer st = new StringTokenizer(fullSeamVersion, ".", false);
+ while (st.hasMoreElements() && depth>0) {
+ version.append(st.nextToken());
+ depth--;
+ if(st.hasMoreElements() && depth>0) {
+ version.append('.');
+ }
+ }
+ return version.toString();
+ }
+
+ /**
* Converts seam project name to string which suitable for package names
* @param projectNamePackage
* @return
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/project/facet/SeamVersion.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/project/facet/SeamVersion.java 2009-03-19
15:58:41 UTC (rev 14267)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/project/facet/SeamVersion.java 2009-03-19
16:30:07 UTC (rev 14268)
@@ -11,6 +11,7 @@
package org.jboss.tools.seam.core.project.facet;
import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.seam.core.SeamUtil;
/**
* Seam Versions enumeration
@@ -92,4 +93,25 @@
}
return null;
}
-}
+
+ /**
+ * Find matching version
+ * @param vs
+ * @return
+ */
+ public static SeamVersion findMatchingVersion(String vs) {
+ if(vs == null) {
+ return null;
+ }
+ if(SeamUtil.areSeamVersionsMatched(SeamVersion.SEAM_1_2.toString(), vs)) {
+ return SeamVersion.SEAM_1_2;
+ }
+ if(SeamUtil.areSeamVersionsMatched(SeamVersion.SEAM_2_0.toString(), vs)) {
+ return SeamVersion.SEAM_2_0;
+ }
+ if(SeamUtil.areSeamVersionsMatched(SeamVersion.SEAM_2_1.toString(), vs)) {
+ return SeamVersion.SEAM_2_1;
+ }
+ return null;
+ }
+}
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java 2009-03-19
15:58:41 UTC (rev 14267)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java 2009-03-19
16:30:07 UTC (rev 14268)
@@ -67,7 +67,6 @@
import org.jboss.tools.seam.ui.internal.project.facet.ValidatorFactory;
import org.jboss.tools.seam.ui.widget.editor.IFieldEditor;
import org.jboss.tools.seam.ui.widget.editor.IFieldEditorFactory;
-import org.jboss.tools.seam.ui.widget.editor.SeamRuntimeListFieldEditor;
import org.jboss.tools.seam.ui.wizard.IParameter;
import org.jboss.tools.seam.ui.wizard.SeamWizardFactory;
import org.jboss.tools.seam.ui.wizard.SeamWizardUtils;
@@ -959,8 +958,8 @@
String jarLocation = getJBossSeamJarLocation();
if(jarLocation != null) {
String folder = new File(jarLocation).getParent();
- String vs = SeamRuntimeListFieldEditor.SeamRuntimeWizardPage.getSeamVersion(folder);
- SeamVersion v = findMatchingVersion(vs);
+ String vs = SeamUtil.getSeamVersionFromManifest(folder);
+ SeamVersion v = SeamVersion.findMatchingVersion(vs);
if(v != null) {
return new SeamVersion[]{v};
}
@@ -969,20 +968,6 @@
return SeamVersion.ALL_VERSIONS;
}
- private SeamVersion findMatchingVersion(String vs) {
- if(vs == null) return null;
- if(vs.matches(SeamVersion.SEAM_1_2.toString().replace(".", "\\.") +
".*")) {
- return SeamVersion.SEAM_1_2;
- }
- if(vs.matches(SeamVersion.SEAM_2_0.toString().replace(".", "\\.") +
".*")) {
- return SeamVersion.SEAM_2_0;
- }
- if(vs.matches(SeamVersion.SEAM_2_1.toString().replace(".", "\\.") +
".*")) {
- return SeamVersion.SEAM_2_1;
- }
- return null;
- }
-
private String getJBossSeamJarLocation() {
IJavaProject jp = EclipseResourceUtil.getJavaProject(project);
if(jp == null) return null;
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SeamRuntimeListFieldEditor.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SeamRuntimeListFieldEditor.java 2009-03-19
15:58:41 UTC (rev 14267)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/widget/editor/SeamRuntimeListFieldEditor.java 2009-03-19
16:30:07 UTC (rev 14268)
@@ -67,6 +67,7 @@
import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.core.SeamUtil;
import org.jboss.tools.seam.core.project.facet.SeamRuntime;
import org.jboss.tools.seam.core.project.facet.SeamVersion;
import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
@@ -558,16 +559,15 @@
}
name.setValue(homeDirName);
- String seamVersion = getSeamVersion(homeDir
- .getValueAsString());
+ String seamVersion =
SeamUtil.getSeamVersionFromManifest(homeDir.getValueAsString());
if (seamVersion == null) {
setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_CANNOT_FIND_JBOSS_SEAM_JAR);
setPageComplete(false);
return;
}
- if (seamVersion != null && validSeamVersions != null) {
+ if (validSeamVersions != null) {
for (SeamVersion ver : validSeamVersions) {
- if (seamVersion.matches(ver.toString().substring(0,1)+ ".*")) {
//$NON-NLS-1$
+ if(SeamUtil.areSeamVersionsMatched(ver.toString(), seamVersion)) {
version.setValue(ver.toString());
break;
}
@@ -575,7 +575,7 @@
}
}
}
-
+
if (name.getValueAsString() == null || "".equals(//$NON-NLS-1$
name.getValueAsString().toString().trim())) {
setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_NAME_CANNOT_BE_EMPTY);
@@ -620,7 +620,7 @@
return;
}
- String seamVersion = getSeamVersion(homeDir.getValueAsString());
+ String seamVersion = SeamUtil.getSeamVersionFromManifest(homeDir.getValueAsString());
if (seamVersion == null) {
setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_CANNOT_FIND_JBOSS_SEAM_JAR);
setPageComplete(false);
@@ -630,19 +630,11 @@
IMessageProvider.WARNING);
setPageComplete(true);
return;
- } else if (!seamVersion.matches(version.getValueAsString().replace(
- ".", "\\.") + ".*")) { //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
- if(seamVersion.matches(version.getValueAsString().substring(0,1)+".*")) {
//$NON-NLS-1$
- if(!seamVersion.matches(version.getValueAsString().substring(0,1)+"\\.1\\..*"))
{ //$NON-NLS-1$
- setMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_THE_SELECTED_SEAM_APPEARS_TO_BE_OF_INCOMATIBLE_VERSION
- + seamVersion + "'", IMessageProvider.WARNING); //$NON-NLS-1$
- }
- } else {
- setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_THE_SELECTED_SEAM_APPEARS_TO_BE_OF_INCOMATIBLE_VERSION
- + seamVersion + "'"); //$NON-NLS-1$
- setPageComplete(false);
- return;
- }
+ } else if(!SeamUtil.areSeamVersionsMatched(version.getValueAsString(), seamVersion))
{
+ setErrorMessage(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_THE_SELECTED_SEAM_APPEARS_TO_BE_OF_INCOMATIBLE_VERSION
+ + seamVersion + "'"); //$NON-NLS-1$
+ setPageComplete(false);
+ return;
} else {
setMessage(null);
}
@@ -662,59 +654,6 @@
}
/**
- * Return Seam runtime version obtained form jboss-seam.jar manifest
- * 'Seam Version' property
- *
- * @param path
- * path to Seam home folder
- * @return String value of 'Seam Version' manifest property
- */
- public static String getSeamVersion(String path) {
- File seamJarFile = new File(path, "jboss-seam.jar"); //$NON-NLS-1$
- if (!seamJarFile.exists()) {
- seamJarFile = new File(path, "lib/jboss-seam.jar"); // hack to
//$NON-NLS-1$
- // make it
- // work for
- // seam2
- if (!seamJarFile.exists()) {
- return null;
- }
- }
- InputStream str = null;
- ZipFile seamJar;
- try {
- seamJar = new ZipFile(seamJarFile);
-
- ZipFileStructureProvider provider = new ZipFileStructureProvider(
- seamJar);
- ZipEntry entry = seamJar.getEntry("META-INF/MANIFEST.MF"); //$NON-NLS-1$
- str = provider.getContents(entry);
-
- Properties manifest = new Properties();
- manifest.load(str);
- Object sv = manifest
- .get(SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_SEAM_VERSION);
- return sv == null ? "" : sv.toString(); //$NON-NLS-1$
-
- } catch (IOException e) {
- SeamCorePlugin
- .getPluginLog()
- .logError(
- SeamUIMessages.SEAM_RUNTIME_LIST_FIELD_EDITOR_CANNOT_READ_JAR_FILE,
- e);
- } finally {
- if (str != null) {
- try {
- str.close();
- } catch (IOException e) {
- SeamGuiPlugin.getPluginLog().logError(e);
- }
- }
- }
- return ""; //$NON-NLS-1$
- }
-
- /**
* Return Seam Runtime instance initialized by user input
*
* @return SeamRuntime instance
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/SeamRuntimeManagerTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/SeamRuntimeManagerTest.java 2009-03-19
15:58:41 UTC (rev 14267)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/SeamRuntimeManagerTest.java 2009-03-19
16:30:07 UTC (rev 14268)
@@ -16,6 +16,7 @@
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
+import org.jboss.tools.seam.core.SeamUtil;
import org.jboss.tools.seam.core.project.facet.SeamRuntime;
import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
import org.jboss.tools.seam.core.project.facet.SeamVersion;
@@ -83,6 +84,17 @@
assertNotNull("Cannot find runtime 'Seam 1.2.0'",srt);
}
+ public void testMatchedRuntimes() {
+ assertTrue(SeamUtil.areSeamVersionsMatched("2.1", "2.1.1.GA"));
+ assertFalse(SeamUtil.areSeamVersionsMatched("1.2", "2.1.1.GA"));
+ assertFalse(SeamUtil.areSeamVersionsMatched("2.0", "2.1.1.GA"));
+ assertTrue(SeamUtil.areSeamVersionsMatched("2.0", "2.0.1.SP1"));
+ assertTrue(SeamUtil.areSeamVersionsMatched("1.2", "1.2.1.GA"));
+ assertTrue(SeamUtil.areSeamVersionsMatched("1.2", "1.2.0"));
+ assertTrue(SeamUtil.areSeamVersionsMatched("2", "2.0.0"));
+ assertFalse(SeamUtil.areSeamVersionsMatched("2.1", "2.0.0"));
+ }
+
/**
* Test method for {@link
org.jboss.tools.seam.core.project.facet.SeamRuntimeManager#removeRuntime(org.jboss.tools.seam.core.project.facet.SeamRuntime)}.
*/