Author: akazakov
Date: 2008-11-11 10:39:10 -0500 (Tue, 11 Nov 2008)
New Revision: 11677
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamUtil.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/project/facet/SeamRuntime.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamBaseOperation.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamConversationWizard.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2489 Fixed
Added:
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
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamUtil.java 2008-11-11
15:39:10 UTC (rev 11677)
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tools.seam.core;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+
+import org.eclipse.core.resources.IProject;
+import org.jboss.tools.seam.core.project.facet.SeamRuntime;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class SeamUtil {
+
+ /**
+ * Returns Seam version from <Seam
Runtime>/lib/jboss-seam.jar/META-INF/MANIFEST.MF
+ * from Seam Runtime which is set for the project.
+ * @param project
+ * @return
+ */
+ public static String getSeamVersionFromManifest(IProject project) {
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, false);
+ if(seamProject == null) {
+ SeamCorePlugin.getPluginLog().logWarning("Can't find Seam Project for "
+ project.getName());
+ return null;
+ }
+ return getSeamVersionFromManifest(seamProject);
+ }
+
+ /**
+ * Returns Seam version from <Seam
Runtime>/lib/jboss-seam.jar/META-INF/MANIFEST.MF
+ * from Seam Runtime which is set for the project.
+ * @param project
+ * @return
+ */
+ public static String getSeamVersionFromManifest(ISeamProject project) {
+ SeamRuntime runtime = project.getRuntime();
+ if(runtime==null) {
+ SeamCorePlugin.getPluginLog().logWarning("Seam Runtime for " +
project.getProject().getName() + " is null.");
+ return null;
+ }
+ return getSeamVersionFromManifest(runtime);
+ }
+
+ private final static String seamJarName = "jboss-seam.jar";
+ private final static String seamVersionAttributeName = "Seam-Version";
+
+ /**
+ * Returns Seam version from <Seam
Runtime>/lib/jboss-seam.jar/META-INF/MANIFEST.MF
+ * from Seam Runtime.
+ * @param runtime
+ * @return
+ */
+ public static String getSeamVersionFromManifest(SeamRuntime runtime) {
+ File jarFile = new File(runtime.getLibDir(), seamJarName);
+ if(!jarFile.isFile()) {
+ jarFile = new File(runtime.getHomeDir(), 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());
+ return null;
+ }
+ }
+ try {
+ JarFile jar = new JarFile(jarFile);
+ Attributes attributes = jar.getManifest().getMainAttributes();
+ String version = attributes.getValue(seamVersionAttributeName);
+ if(version==null) {
+ SeamCorePlugin.getPluginLog().logWarning("Can't get Seam-Version from "
+ jar.getName() + " MANIFEST.");
+ }
+ return version;
+ } catch (IOException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ return null;
+ }
+ }
+}
\ No newline at end of file
Property changes on:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamUtil.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/project/facet/SeamRuntime.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/project/facet/SeamRuntime.java 2008-11-11
14:58:09 UTC (rev 11676)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/project/facet/SeamRuntime.java 2008-11-11
15:39:10 UTC (rev 11677)
@@ -133,6 +133,15 @@
}
/**
+ * Calculate path to lib folder
+ *
+ * @return absolute path to lib folder
+ */
+ public String getLibDir() {
+ return getHomeDir() + "/lib"; //$NON-NLS-1$
+ }
+
+ /**
* Calculate path to source templates
*
* @return absolute path to source templates
@@ -176,5 +185,4 @@
public String getTemplatesDir() {
return getSeamGenDir();
}
-
-}
+}
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamBaseOperation.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamBaseOperation.java 2008-11-11
14:58:09 UTC (rev 11676)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamBaseOperation.java 2008-11-11
15:39:10 UTC (rev 11677)
@@ -87,6 +87,8 @@
}
}
+ protected IAdaptable info;
+
/**
* @see AbstractOperation#execute(IProgressMonitor, IAdaptable)
*/
@@ -94,12 +96,11 @@
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
IStatus result = Status.OK_STATUS;
-
-
+ this.info = info;
+
final SeamProjectsSet seamPrjSet = new SeamProjectsSet(getProject(info));
try {
-
Map<String, Object> vars = loadParameters(info, seamPrjSet);
List<FileMapping> fileMapping = getFileMappings(vars);
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamConversationWizard.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamConversationWizard.java 2008-11-11
14:58:09 UTC (rev 11676)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/SeamConversationWizard.java 2008-11-11
15:39:10 UTC (rev 11677)
@@ -20,6 +20,7 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.seam.core.SeamUtil;
import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
import org.jboss.tools.seam.ui.ISeamHelpContextIds;
import org.jboss.tools.seam.ui.SeamUIMessages;
@@ -58,47 +59,50 @@
super((SeamUIMessages.SEAM_CONVERSATION_WIZARD_ENTITY_CREATING_OPERATION));
}
+ private List<FileMapping> actionMapping;
+
@Override
public List<FileMapping> getFileMappings(Map<String, Object> vars) {
- return ACTION_MAPPING;
- }
+ // initialize war files mapping
+ actionMapping = new ArrayList<FileMapping>();
- public static final List<FileMapping> ACTION_MAPPING = new
ArrayList<FileMapping>();
+ // seam-gen uses @interfaceName@ as class name since 2.0.1
+ // but seam-gen 2.0.0 and lower ones use @beanName@ (looks like a bug)
+ String version = SeamUtil.getSeamVersionFromManifest(getProject(info));
+ String interfaceName = IParameter.SEAM_BEAN_NAME;
+ if(version!=null && version.compareTo("2.0.1")>=0) {
+ interfaceName = IParameter.SEAM_LOCAL_INTERFACE_NAME;
+ }
- static {
- // initialize war files mapping
-
- ACTION_MAPPING.add(new FileMapping(
+ actionMapping.add(new FileMapping(
"${" + ISeamFacetDataModelProperties.JBOSS_SEAM_HOME +
"}/seam-gen/src/ConversationJavaBean.java", //$NON-NLS-1$ //$NON-NLS-2$
- // seam-gen uses @interfaceName@ as class name since 2.0.1
- // but seam-gen 2.0.0 and lower uses @beanName@ (looks like a bug)
- // So if we want it works for 2.0.* we should uncomment the following line:
- // "${" + IParameter.SEAM_PROJECT_SRC_ACTION + "}/${" +
ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_PATH + "}/${" +
IParameter.SEAM_LOCAL_INTERFACE_NAME +"}.java", //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$
- "${" + IParameter.SEAM_PROJECT_SRC_ACTION + "}/${" +
ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_PATH + "}/${" +
IParameter.SEAM_BEAN_NAME +"}.java", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
+ "${" + IParameter.SEAM_PROJECT_SRC_ACTION + "}/${" +
ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_PATH + "}/${" + interfaceName
+"}.java", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
FileMapping.TYPE.WAR,
false));
- ACTION_MAPPING.add(new FileMapping(
+ actionMapping.add(new FileMapping(
"${" + ISeamFacetDataModelProperties.JBOSS_SEAM_HOME +
"}/seam-gen/view/conversation.xhtml", //$NON-NLS-1$ //$NON-NLS-2$
"${" + IParameter.SEAM_PROJECT_WEBCONTENT_PATH + "}/${" +
IParameter.SEAM_PAGE_NAME +"}.xhtml", //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
FileMapping.TYPE.WAR,
false));
// initialize ear files mapping
- ACTION_MAPPING.add(new FileMapping(
+ actionMapping.add(new FileMapping(
"${" + ISeamFacetDataModelProperties.JBOSS_SEAM_HOME +
"}/seam-gen/src/ConversationBean.java", //$NON-NLS-1$ //$NON-NLS-2$
"${" + IParameter.SEAM_PROJECT_SRC_ACTION + "}/${" +
ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_PATH + "}/${" +
IParameter.SEAM_BEAN_NAME +"}.java", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
FileMapping.TYPE.EAR,
false));
- ACTION_MAPPING.add(new FileMapping(
+ actionMapping.add(new FileMapping(
"${" + ISeamFacetDataModelProperties.JBOSS_SEAM_HOME +
"}/seam-gen/src/Conversation.java", //$NON-NLS-1$ //$NON-NLS-2$
"${" + IParameter.SEAM_PROJECT_SRC_ACTION + "}/${" +
ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_PATH + "}/${" +
IParameter.SEAM_LOCAL_INTERFACE_NAME +"}.java", //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$
FileMapping.TYPE.EAR,
false));
- ACTION_MAPPING.add(new FileMapping(
+ actionMapping.add(new FileMapping(
"${" + ISeamFacetDataModelProperties.JBOSS_SEAM_HOME +
"}/seam-gen/view/conversation.xhtml", //$NON-NLS-1$ //$NON-NLS-2$
"${" + IParameter.SEAM_PROJECT_WEBCONTENT_PATH + "}/${" +
IParameter.SEAM_PAGE_NAME +"}.xhtml", //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
FileMapping.TYPE.EAR,
false));
+
+ return actionMapping;
}
/*