Author: snjeza
Date: 2009-02-15 18:46:19 -0500 (Sun, 15 Feb 2009)
New Revision: 13624
Modified:
trunk/portlet/plugins/org.jboss.tools.portlet.core/META-INF/MANIFEST.MF
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/IPortletConstants.java
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/Messages.java
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/PortletCoreActivator.java
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/JSFPortletFacetInstallDataModelProvider.java
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/JSFPortletFacetInstallDelegate.java
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletPostInstallListener.java
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/messages.properties
Log:
JBIDE-3635 Fix compatibility issues with Portletbridge distribution
Modified: trunk/portlet/plugins/org.jboss.tools.portlet.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/portlet/plugins/org.jboss.tools.portlet.core/META-INF/MANIFEST.MF 2009-02-15
23:46:07 UTC (rev 13623)
+++ trunk/portlet/plugins/org.jboss.tools.portlet.core/META-INF/MANIFEST.MF 2009-02-15
23:46:19 UTC (rev 13624)
@@ -21,9 +21,10 @@
org.eclipse.ui.ide,
org.eclipse.jem,
org.eclipse.jst.jsf.facesconfig,
- org.eclipse.wst.server.core,
+ org.eclipse.wst.server.core;visibility:=reexport,
org.eclipse.jem.util,
- org.jboss.ide.eclipse.as.core
+ org.jboss.ide.eclipse.as.core;visibility:=reexport,
+ org.eclipse.core.commands
Bundle-ActivationPolicy: lazy
Export-Package: org.jboss.tools.portlet.core,
org.jboss.tools.portlet.core.internal,
Modified:
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/IPortletConstants.java
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/IPortletConstants.java 2009-02-15
23:46:07 UTC (rev 13623)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/IPortletConstants.java 2009-02-15
23:46:19 UTC (rev 13624)
@@ -63,8 +63,6 @@
static final String USER_LIBRARY = Messages.IPortletConstants_User_library;
- //static final String LIBRARY_PROVIDED_BY_JBOSS_TOOLS =
Messages.IPortletConstants_Library_provided_by_JBoss_Tools;
-
static final String LIBRARIES_PROVIDED_BY_SERVER_RUNTIME =
Messages.IPortletConstants_Libraries_provided_by_server_runtime;
static final String IMPLEMENTATION_LIBRARY = "implementationLibrary";
//$NON-NLS-1$
@@ -83,5 +81,19 @@
static final String PORTLET_API = "portlet-api"; //$NON-NLS-1$
+ static final String LIBRARIES_PROVIDED_BY_PORTLETBRIDGE =
Messages.Libraries_provided_by_portletbridge;
+
+ static final String LIBRARIES_PROVIDED_BY_RICHFACES =
Messages.Libraries_provided_by_richfaces;
+
+ static final String RICHFACES_RUNTIME = "RICHFACES_RUNTIME"; //$NON-NLS-1$
+
+ static final String RICHFACES_LIBRARIES_SELECTED =
"RICHFACES_LIBRARIES_SELECTED"; //$NON-NLS-1$
+ static final String RICHFACES_LIBRARIES_TYPE = "RICHFACES_LIBRARIES_TYPE";
//$NON-NLS-1$
+
+ static final String RICHFACES_CAPABILITIES = "RICHFACES_CAPABILITIES";
//$NON-NLS-1$
+
+ static final String PORTLET_SAR_LIB =
"deploy/jboss-portal.sar/portal-identity.sar/portal-identity.war/WEB-INF/lib";
//$NON-NLS-1$
+
+ static final String PORTLET_SAR_HA_LIB =
"deploy/jboss-portal-ha.sar/portal-identity.sar/portal-identity.war/WEB-INF/lib";
//$NON-NLS-1$
}
Modified:
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/Messages.java
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/Messages.java 2009-02-15
23:46:07 UTC (rev 13623)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/Messages.java 2009-02-15
23:46:19 UTC (rev 13624)
@@ -4,9 +4,12 @@
public class Messages extends NLS {
private static final String BUNDLE_NAME =
"org.jboss.tools.portlet.core.messages"; //$NON-NLS-1$
+ public static String PortletPostInstallListener_Invalid_Richfaces_Runtime;
+ public static String PortletPostInstallListener_Cannot_find_Richfaces_Runtime;
+ public static String Libraries_provided_by_richfaces;
+ public static String Libraries_provided_by_portletbridge ;
public static String BasePortletClasspathContainer_Error_loading_classpath_container;
public static String IPortletConstants_Libraries_provided_by_server_runtime;
- public static String IPortletConstants_Library_provided_by_JBoss_Tools;
public static String IPortletConstants_User_library;
public static String
JSFPortlet10LibrariesContainerInitializer_Error_loading_classpath_container;
public static String
JSFPortlet10LibrariesContainerInitializer_JBoss_JSF_Portlet_Libraries_v1_0;
Modified:
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/PortletCoreActivator.java
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/PortletCoreActivator.java 2009-02-15
23:46:07 UTC (rev 13623)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/PortletCoreActivator.java 2009-02-15
23:46:19 UTC (rev 13624)
@@ -22,6 +22,8 @@
import org.eclipse.jst.j2ee.model.ModelProviderManager;
import org.eclipse.ui.dialogs.IOverwriteQuery;
import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.ServerCore;
import org.osgi.framework.BundleContext;
/**
@@ -236,4 +238,20 @@
file.create(source, true, new NullProgressMonitor());
}
+ public static IRuntime
getRuntime(org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime) {
+ if (runtime == null)
+ throw new IllegalArgumentException();
+
+ String id = runtime.getProperty("id"); //$NON-NLS-1$
+ if (id == null)
+ return null;
+
+ IRuntime[] runtimes = ServerCore.getRuntimes();
+ for (IRuntime r : runtimes) {
+ if (id.equals(r.getId()))
+ return r;
+ }
+
+ return null;
+ }
}
Modified:
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/JSFPortletFacetInstallDataModelProvider.java
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/JSFPortletFacetInstallDataModelProvider.java 2009-02-15
23:46:07 UTC (rev 13623)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/JSFPortletFacetInstallDataModelProvider.java 2009-02-15
23:46:19 UTC (rev 13624)
@@ -31,9 +31,27 @@
if (propertyName.equals(IPortletConstants.DEPLOY_JARS)) {
return Boolean.TRUE;
}
+ if (propertyName.equals(IPortletConstants.RICHFACES_LIBRARIES_SELECTED)) {
+ return Boolean.FALSE;
+ }
+ if (propertyName.equals(IPortletConstants.RICHFACES_LIBRARIES_TYPE)) {
+ return ""; //$NON-NLS-1$
+ }
+ if (propertyName.equals(IPortletConstants.RICHFACES_CAPABILITIES)) {
+ return Boolean.TRUE;
+ }
if (propertyName.equals(IPortletConstants.PORTLET_BRIDGE_RUNTIME)) {
return ""; //$NON-NLS-1$
}
+ if (propertyName.equals(IPortletConstants.RICHFACES_RUNTIME)) {
+ return ""; //$NON-NLS-1$
+ }
+ if (propertyName.equals(IPortletConstants.IMPLEMENTATION_LIBRARY)) {
+ return IPortletConstants.LIBRARIES_PROVIDED_BY_PORTLETBRIDGE;
+ }
+ if (propertyName.equals(IPortletConstants.USER_LIBRARY_NAME)) {
+ return ""; //$NON-NLS-1$
+ }
return super.getDefaultProperty(propertyName);
}
@@ -42,6 +60,12 @@
Set<String> propertyNames = super.getPropertyNames();
propertyNames.add(IPortletConstants.DEPLOY_JARS);
propertyNames.add(IPortletConstants.PORTLET_BRIDGE_RUNTIME);
+ propertyNames.add(IPortletConstants.IMPLEMENTATION_LIBRARY);
+ propertyNames.add(IPortletConstants.USER_LIBRARY_NAME);
+ propertyNames.add(IPortletConstants.RICHFACES_RUNTIME);
+ propertyNames.add(IPortletConstants.RICHFACES_LIBRARIES_SELECTED);
+ propertyNames.add(IPortletConstants.RICHFACES_LIBRARIES_TYPE);
+ propertyNames.add(IPortletConstants.RICHFACES_CAPABILITIES);
return propertyNames;
}
}
Modified:
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/JSFPortletFacetInstallDelegate.java
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/JSFPortletFacetInstallDelegate.java 2009-02-15
23:46:07 UTC (rev 13623)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/JSFPortletFacetInstallDelegate.java 2009-02-15
23:46:19 UTC (rev 13624)
@@ -12,24 +12,26 @@
import java.io.File;
import java.io.FilenameFilter;
-import java.net.URL;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.EList;
+import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil;
+import org.eclipse.jst.j2ee.classpathdep.IClasspathDependencyConstants;
import org.eclipse.jst.j2ee.model.IModelProvider;
import org.eclipse.jst.javaee.web.WebApp;
import org.eclipse.jst.javaee.web.WebAppVersionType;
@@ -42,11 +44,16 @@
import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
import org.eclipse.wst.common.componentcore.ComponentCore;
+import
org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.componentcore.resources.IVirtualFile;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
import org.eclipse.wst.common.project.facet.core.IDelegate;
+import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.server.core.IRuntime;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerConstants;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
import org.jboss.tools.portlet.core.IJBossWebUtil;
import org.jboss.tools.portlet.core.IPortletConstants;
import org.jboss.tools.portlet.core.JBossWebUtil;
@@ -275,66 +282,171 @@
private void configureClassPath(final IProject project,
final IProgressMonitor monitor, IDataModel config)
throws JavaModelException {
+
+ String implementationLibrary =
config.getStringProperty(IPortletConstants.IMPLEMENTATION_LIBRARY);
+
+ if
(IPortletConstants.LIBRARIES_PROVIDED_BY_PORTLETBRIDGE.equals(implementationLibrary)) {
+ addLibrariesFromPortletBridgeRuntime(project,monitor,config);
+ } else if
(IPortletConstants.LIBRARIES_PROVIDED_BY_SERVER_RUNTIME.equals(implementationLibrary)) {
+ addLibrariesFromServerRuntime(project,monitor,config);
+ } else if (IPortletConstants.USER_LIBRARY.equals(implementationLibrary)) {
+ addUserLibrary(project,monitor,config);
+ }
+
+ }
+
+ private void addUserLibrary(IProject project, IProgressMonitor monitor,
+ IDataModel config) throws JavaModelException {
+ String userLibraryName =
config.getStringProperty(IPortletConstants.USER_LIBRARY_NAME);
+ IPath containerPath = new
Path(JavaCore.USER_LIBRARY_CONTAINER_ID).append(userLibraryName);
IJavaProject javaProject = JavaCore.create(project);
+ IClasspathAttribute dependencyAttribute = JavaCore.newClasspathAttribute(
+ IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY,
+ ClasspathDependencyUtil.getDefaultRuntimePath(
+ true).toString());
+ IClasspathEntry[] oldClasspathEntries = javaProject.getRawClasspath();
+ IClasspathEntry[] newClasspathEntries = null;
+ for (int i = 0; i < oldClasspathEntries.length; i++) {
+ IClasspathEntry entry = oldClasspathEntries[i];
+ if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER &&
+ containerPath.equals(entry.getPath())) {
+ LinkedHashMap<String, IClasspathAttribute> attrs = new LinkedHashMap<String,
IClasspathAttribute>();
+ for(IClasspathAttribute attr : entry.getExtraAttributes()) {
+ attrs.put(attr.getName(), attr);
+ }
+ attrs.put(dependencyAttribute.getName(), dependencyAttribute);
+ IClasspathAttribute[] newAttrs = attrs.values().toArray(new
IClasspathAttribute[attrs.size()]);
+ entry = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(),
newAttrs, entry.isExported());
+ oldClasspathEntries[i] = entry;
+ newClasspathEntries = oldClasspathEntries;
+ break;
+ }
+ }
+ if (newClasspathEntries == null) {
+ newClasspathEntries = new IClasspathEntry[oldClasspathEntries.length + 1];
+ for (int i = 0; i < oldClasspathEntries.length; i++) {
+ newClasspathEntries[i] = oldClasspathEntries[i];
+ }
+ IClasspathEntry newClasspath = JavaCore.newContainerEntry(containerPath, null,
+ new IClasspathAttribute[] { dependencyAttribute }, true);
+ newClasspathEntries[oldClasspathEntries.length] = newClasspath;
+ }
+ javaProject.setRawClasspath(newClasspathEntries, monitor);
+ }
- boolean deployJars = config
- .getBooleanProperty(IPortletConstants.DEPLOY_JARS);
- if (deployJars) {
- try {
+ private void addLibrariesFromServerRuntime(IProject project,
+ IProgressMonitor monitor, IDataModel config) {
+ IFacetedProjectWorkingCopy fpwc = (IFacetedProjectWorkingCopy)
config.getProperty(IFacetDataModelProperties.FACETED_PROJECT_WORKING_COPY);
+
+ org.eclipse.wst.common.project.facet.core.runtime.IRuntime facetRuntime =
fpwc.getPrimaryRuntime();
+ IRuntime runtime = PortletCoreActivator.getRuntime(facetRuntime);
+ IJBossServerRuntime jbossRuntime =
(IJBossServerRuntime)runtime.loadAdapter(IJBossServerRuntime.class, new
NullProgressMonitor());
+ if (jbossRuntime != null) {
+ // JBoss Portal server
+ IPath jbossLocation = runtime.getLocation();
+ IPath configPath =
jbossLocation.append(IJBossServerConstants.SERVER).append(jbossRuntime.getJBossConfiguration());
+ IPath portletLib = configPath.append(IPortletConstants.PORTLET_SAR_LIB);
+ File portletLibFile = portletLib.toFile();
+ String[] files = getPortletbridgeLibraries(portletLibFile);
+ if (files == null) {
+ portletLib = configPath.append(IPortletConstants.PORTLET_SAR_HA_LIB);
+ portletLibFile = portletLib.toFile();
+ files = getPortletbridgeLibraries(portletLibFile);
+
+ }
+ if (files != null) {
+ try {
+ List<File> filesToImport = new ArrayList<File>();
+
+ for (int i = 0; i < files.length; i++) {
+ filesToImport.add(new File(portletLibFile, files[i]));
+ }
+ IVirtualComponent component = ComponentCore
+ .createComponent(project);
+ IVirtualFile libVirtualFile = component.getRootFolder()
+ .getFile(IPortletConstants.WEB_INF_LIB);
+
+ IFile folder = libVirtualFile.getUnderlyingFile();
+
+ File sourceFolder = new File(portletLib.toOSString());
+ ImportOperation importOperation = new ImportOperation(
+ folder.getFullPath(), sourceFolder,
+ FileSystemStructureProvider.INSTANCE,
+ PortletCoreActivator.OVERWRITE_ALL_QUERY,
+ filesToImport);
+ importOperation.setCreateContainerStructure(false);
+ importOperation.run(monitor);
+ } catch (Exception e) {
+ PortletCoreActivator
+ .log(e, Messages.JSFPortletFacetInstallDelegate_Error_loading_classpath_container);
+ }
+ }
+ }
+
+ }
+
+ private String[] getPortletbridgeLibraries(File file) {
+ if (file != null && file.isDirectory()) {
+ String[] list = file.list(new FilenameFilter() {
+
+ public boolean accept(File dir, String name) {
+ if ("portletbridge-api.jar".equals(name) || //$NON-NLS-1$
+ "portletbridge-impl.jar".equals(name)) { //$NON-NLS-1$
+ return true;
+ }
+ return false;
+ }
- String pbRuntime = config
- .getStringProperty(IPortletConstants.PORTLET_BRIDGE_RUNTIME);
- if (pbRuntime != null && pbRuntime.trim().length() > 0) {
- pbRuntime = pbRuntime.trim();
- File pbFolder = new File(pbRuntime);
- if (pbFolder.exists() && pbFolder.isDirectory()) {
- String[] fileList = pbFolder.list(new FilenameFilter() {
+ });
+ return list;
+ }
+ return null;
+ }
+ private void addLibrariesFromPortletBridgeRuntime(IProject project,
+ IProgressMonitor monitor, IDataModel config) {
+ try {
- public boolean accept(File dir, String name) {
- if (name.startsWith("portletbridge") ||
name.endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$
- return true;
- }
- return false;
+ String pbRuntime = config
+ .getStringProperty(IPortletConstants.PORTLET_BRIDGE_RUNTIME);
+ if (pbRuntime != null && pbRuntime.trim().length() > 0) {
+ pbRuntime = pbRuntime.trim();
+ File pbFolder = new File(pbRuntime);
+ if (pbFolder.exists() && pbFolder.isDirectory()) {
+ String[] fileList = pbFolder.list(new FilenameFilter() {
+
+ public boolean accept(File dir, String name) {
+ if (name.startsWith("portletbridge") || name.endsWith(".jar"))
{ //$NON-NLS-1$ //$NON-NLS-2$
+ return true;
}
-
- });
-
- List<File> filesToImport = new ArrayList<File>();
-
- for (int i = 0; i < fileList.length; i++) {
- filesToImport.add(new File(pbRuntime,fileList[i]));
+ return false;
}
- IVirtualComponent component = ComponentCore
- .createComponent(project);
- IVirtualFile libVirtualFile = component.getRootFolder()
- .getFile(IPortletConstants.WEB_INF_LIB);
- IFile folder = libVirtualFile.getUnderlyingFile();
+ });
- ImportOperation importOperation = new ImportOperation(
- folder.getFullPath(), pbFolder,
- FileSystemStructureProvider.INSTANCE,
- PortletCoreActivator.OVERWRITE_ALL_QUERY,
- filesToImport);
- importOperation.setCreateContainerStructure(false);
- importOperation.run(monitor);
+ List<File> filesToImport = new ArrayList<File>();
+
+ for (int i = 0; i < fileList.length; i++) {
+ filesToImport.add(new File(pbRuntime, fileList[i]));
}
+ IVirtualComponent component = ComponentCore
+ .createComponent(project);
+ IVirtualFile libVirtualFile = component.getRootFolder()
+ .getFile(IPortletConstants.WEB_INF_LIB);
+
+ IFile folder = libVirtualFile.getUnderlyingFile();
+
+ ImportOperation importOperation = new ImportOperation(
+ folder.getFullPath(), pbFolder,
+ FileSystemStructureProvider.INSTANCE,
+ PortletCoreActivator.OVERWRITE_ALL_QUERY,
+ filesToImport);
+ importOperation.setCreateContainerStructure(false);
+ importOperation.run(monitor);
}
- } catch (Exception e) {
- PortletCoreActivator
- .log(e,
Messages.JSFPortletFacetInstallDelegate_Error_loading_classpath_container);
}
- } else {
- IPath containerPath = new Path(
- IPortletConstants.JSFPORTLET_CONTAINER_10_ID);
-
- IClasspathEntry entry = JavaCore.newContainerEntry(containerPath,
- true);
- IClasspathEntry[] entries = javaProject.getRawClasspath();
- IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
- System.arraycopy(entries, 0, newEntries, 0, entries.length);
- newEntries[entries.length] = entry;
- javaProject.setRawClasspath(newEntries, monitor);
+ } catch (Exception e) {
+ PortletCoreActivator
+ .log(e, Messages.JSFPortletFacetInstallDelegate_Error_loading_classpath_container);
}
}
Modified:
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletPostInstallListener.java
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletPostInstallListener.java 2009-02-15
23:46:07 UTC (rev 13623)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletPostInstallListener.java 2009-02-15
23:46:19 UTC (rev 13624)
@@ -1,6 +1,8 @@
package org.jboss.tools.portlet.core.internal.project.facet;
import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
@@ -9,16 +11,26 @@
import java.util.zip.ZipFile;
import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveManifest;
+import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveManifestImpl;
+import org.eclipse.jst.j2ee.commonarchivecore.internal.util.ArchiveUtil;
+import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
import org.eclipse.ui.dialogs.IOverwriteQuery;
+import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
-import org.eclipse.wst.common.componentcore.resources.IVirtualFile;
import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
@@ -42,8 +54,20 @@
}
};
private String portletbridgeRuntime;
-
+ private boolean richfacesCapabilities;
+ private boolean richfacesSelected;
+ private String richfacesType;
+ private String richfacesRuntime;
+
public void handleEvent(IFacetedProjectEvent event) {
+ if (event instanceof IProjectFacetActionEvent) {
+ IProjectFacetActionEvent actionEvent = (IProjectFacetActionEvent) event;
+ IProjectFacet projectFacet = actionEvent.getProjectFacet();
+ if (!IPortletConstants.JSFPORTLET_FACET_ID.equals(projectFacet
+ .getId())) {
+ return;
+ }
+ }
IFacetedProject facetedProject = event.getProject();
Set<IProjectFacetVersion> projectFacets = facetedProject
.getProjectFacets();
@@ -69,74 +93,306 @@
try {
portletbridgeRuntime = dataModel
.getStringProperty(IPortletConstants.PORTLET_BRIDGE_RUNTIME);
- if (portletbridgeRuntime == null) {
- PortletCoreActivator.log(null,
Messages.PortletPostInstallListener_Invalid_Portletbridge_Runtime);
- return;
- }
+ richfacesCapabilities =
dataModel.getBooleanProperty(IPortletConstants.RICHFACES_CAPABILITIES);
+ richfacesSelected =
dataModel.getBooleanProperty(IPortletConstants.RICHFACES_LIBRARIES_SELECTED);
+ richfacesType =
dataModel.getStringProperty(IPortletConstants.RICHFACES_LIBRARIES_TYPE);
+ richfacesRuntime = dataModel.getStringProperty(IPortletConstants.RICHFACES_RUNTIME);
} catch (Exception e) {
//PortletCoreActivator.log(e);
}
}
+ if (!richfacesCapabilities || !richfacesSelected) {
+ return;
+ }
if (isJSFPortlet) {
- File portletbridgeHome = new File(portletbridgeRuntime);
- if (!portletbridgeHome.exists()) {
- PortletCoreActivator.log(null,
Messages.PortletPostInstallListener_Cannot_find_Portletbridge_Runtime);
- return;
+ if (IPortletConstants.LIBRARIES_PROVIDED_BY_PORTLETBRIDGE.equals(richfacesType)) {
+ addRichfacesFromPortletBridgeRuntime(facetedProject,isSeamProject);
+ } else {
+ addRichfacesFromRichfacesRuntime(facetedProject,isSeamProject);
}
- if (!portletbridgeHome.isDirectory()) {
- PortletCoreActivator.log(null,
Messages.PortletPostInstallListener_Invalid_Portletbridge_Runtime);
- return;
+ }
+ }
+
+ private void addRichfacesFromRichfacesRuntime(
+ IFacetedProject facetedProject, boolean isSeamProject) {
+ File richfacesRuntimeHome = new File(richfacesRuntime);
+ File richfacesLib = new File(richfacesRuntimeHome, "lib"); //$NON-NLS-1$
+ if (!richfacesLib.exists()) {
+ PortletCoreActivator.log(null,
Messages.PortletPostInstallListener_Cannot_find_Richfaces_Runtime);
+ return;
+ }
+ if (!richfacesLib.isDirectory()) {
+ PortletCoreActivator.log(null,Messages.PortletPostInstallListener_Invalid_Richfaces_Runtime);
+ return;
+ }
+ try {
+ IProject project = facetedProject.getProject();
+ final IProject earProject = getEarProject(project, isSeamProject);
+ String[] fileList = richfacesLib.list(new FilenameFilter() {
+
+ public boolean accept(File dir, String name) {
+ if (name.startsWith("richfaces-ui") &&
name.endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$
+ return true;
+ }
+ if (name.startsWith("richfaces-impl") &&
name.endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$
+ return true;
+ }
+ if (earProject == null) {
+ if (name.startsWith("richfaces-api") &&
name.endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$
+ return true;
+ }
+ }
+ return false;
+ }
+
+ });
+ List<File> filesToImport = new ArrayList<File>();
+ for (int i = 0; i < fileList.length; i++) {
+ filesToImport.add(new File(richfacesLib, fileList[i]));
}
- File examplesHome = new File(portletbridgeHome,"examples"); //$NON-NLS-1$
- if (!examplesHome.exists() || !examplesHome.isDirectory()) {
- PortletCoreActivator.log(null,
Messages.PortletPostInstallListener_Cannot_find_the_examples_directory);
- return;
+ IVirtualComponent component = ComponentCore
+ .createComponent(project);
+ IVirtualFolder rootFolder = component.getRootFolder();
+ IContainer folder = rootFolder.getUnderlyingFolder();
+ IContainer webinf = folder.getFolder(new Path(
+ IPortletConstants.WEB_INF_LIB));
+
+ deleteOldRichfacesLibs(earProject, webinf);
+
+ ImportOperation importOperation = new ImportOperation(webinf
+ .getFullPath(), richfacesLib,
+ FileSystemStructureProvider.INSTANCE,
+ PortletCoreActivator.OVERWRITE_ALL_QUERY, filesToImport);
+ importOperation.setCreateContainerStructure(false);
+ importOperation.run(new NullProgressMonitor());
+ if (earProject != null) {
+ fileList = richfacesLib.list(new FilenameFilter() {
+
+ public boolean accept(File dir, String name) {
+ if (name.startsWith("richfaces-api") &&
name.endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$
+ return true;
+ }
+ return false;
+ }
+
+ });
+ filesToImport = new ArrayList<File>();
+ for (int i = 0; i < fileList.length; i++) {
+ filesToImport.add(new File(richfacesLib, fileList[i]));
+ }
+ component = ComponentCore
+ .createComponent(earProject);
+ rootFolder = component.getRootFolder();
+ folder = rootFolder.getUnderlyingFolder();
+
+ deleteOldRichFacesApi(folder);
+
+ importOperation = new ImportOperation(folder
+ .getFullPath(), richfacesLib,
+ FileSystemStructureProvider.INSTANCE,
+ PortletCoreActivator.OVERWRITE_ALL_QUERY, filesToImport);
+ importOperation.setCreateContainerStructure(false);
+ importOperation.run(new NullProgressMonitor());
+ updateEARLibraries(project,isSeamProject);
}
- File richFacesPortletZip = new File(examplesHome,"RichFacesPortlet.war");
//$NON-NLS-1$
- if (!richFacesPortletZip.exists() || !richFacesPortletZip.isFile()) {
- PortletCoreActivator.log(null,
Messages.PortletPostInstallListener_Cannot_find_the_RichFacesPortlet_war_file);
- return;
+ } catch (Exception e) {
+ PortletCoreActivator
+ .log(e,Messages.JSFPortletFacetInstallDelegate_Error_loading_classpath_container);
+ }
+ }
+
+ private void updateEARLibraries(IProject project, boolean isSeamProject) {
+ IProject ejbProj = getEjbProject(project, isSeamProject);
+
+ IProject earProject = getEarProject(project, isSeamProject);
+ IVirtualComponent component = ComponentCore
+ .createComponent(earProject);
+ IVirtualFolder rootFolder = component.getRootFolder();
+ IContainer folder = rootFolder.getUnderlyingFolder();
+ File earContentFolder = folder.getLocation().toFile();
+ File[] earJars = earContentFolder.listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.lastIndexOf(".jar") > 0; //$NON-NLS-1$
}
- try {
- ZipFile zipFile = new ZipFile(richFacesPortletZip);
- ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(
- zipFile );
- List<ZipEntry> list = prepareList(zipFile, isSeamProject);
+ });
+ String clientURI = ""; //$NON-NLS-1$
+ for (File file : earJars) {
+ clientURI += " " + file.getName(); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ try {
+ new UpdateManifestOperation(ejbProj,clientURI,true).run();
+ new UpdateManifestOperation(project,clientURI,true).run();
+ } catch (Exception e) {
+ PortletCoreActivator.log(e);
+ }
+ }
+
+ private void addRichfacesFromPortletBridgeRuntime(IFacetedProject facetedProject,
boolean isSeamProject) {
+ File portletbridgeHome = new File(portletbridgeRuntime);
+ if (!portletbridgeHome.exists()) {
+ PortletCoreActivator.log(null,
Messages.PortletPostInstallListener_Cannot_find_Portletbridge_Runtime);
+ return;
+ }
+ if (!portletbridgeHome.isDirectory()) {
+ PortletCoreActivator.log(null,
Messages.PortletPostInstallListener_Invalid_Portletbridge_Runtime);
+ return;
+ }
+ File examplesHome = new File(portletbridgeHome,"examples"); //$NON-NLS-1$
+ if (!examplesHome.exists() || !examplesHome.isDirectory()) {
+ PortletCoreActivator.log(null,
Messages.PortletPostInstallListener_Cannot_find_the_examples_directory);
+ return;
+ }
+ File richFacesPortletZip = new File(examplesHome,"RichFacesPortlet.war");
//$NON-NLS-1$
+ if (!richFacesPortletZip.exists() || !richFacesPortletZip.isFile()) {
+ PortletCoreActivator.log(null,
Messages.PortletPostInstallListener_Cannot_find_the_RichFacesPortlet_war_file);
+ return;
+ }
+ try {
+ ZipFile zipFile = new ZipFile(richFacesPortletZip);
+ ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(
+ zipFile );
+ List<ZipEntry> list = prepareList(zipFile, facetedProject, isSeamProject);
+
+ IProject project = facetedProject.getProject();
+ IProject earProject = getEarProject(project, isSeamProject);
+
+ IVirtualComponent component = ComponentCore
+ .createComponent(project);
+
+ IVirtualFolder rootFolder = component.getRootFolder();
+ IContainer folder = rootFolder.getUnderlyingFolder();
+ IContainer webinf = folder.getFolder(new Path(
+ IPortletConstants.WEB_INF_LIB));
+ deleteOldRichfacesLibs(earProject, webinf);
+ IPath destPath = folder.getFullPath();
+
+ ImportOperation op = new ImportOperation( destPath,
+ structureProvider.getRoot( ), structureProvider, OVERWRITE_NONE_QUERY,
+ list );
+ op.run(new NullProgressMonitor() );
+ if (earProject != null) {
+ list = prepareEarList(zipFile);
- IProject project = facetedProject.getProject();
- IVirtualComponent component = ComponentCore
- .createComponent(project);
- //IVirtualFile libVirtualFile = component.getRootFolder()
- // .getFile(IPortletConstants.WEB_INF_LIB);
-
- IVirtualFolder rootFolder = component.getRootFolder();
- IContainer folder = rootFolder.getUnderlyingFolder();
- IPath destPath = folder.getFullPath();
-
- ImportOperation op = new ImportOperation( destPath,
- structureProvider.getRoot( ), structureProvider, OVERWRITE_NONE_QUERY,
+ component = ComponentCore
+ .createComponent(earProject);
+ rootFolder = component.getRootFolder();
+ folder = rootFolder.getUnderlyingFolder();
+ deleteOldRichFacesApi(folder);
+ destPath = folder.getFullPath();
+ ZipEntry root = zipFile.getEntry(IPortletConstants.WEB_INF_LIB);
+ op = new ImportOperation( destPath,
+ root, structureProvider, OVERWRITE_NONE_QUERY,
list );
+ op.setCreateContainerStructure(false);
op.run(new NullProgressMonitor() );
- } catch (Exception e) {
- PortletCoreActivator.log(e);
- }
-
+ updateEARLibraries(project, isSeamProject);
+ }
+ } catch (Exception e) {
+ PortletCoreActivator.log(e);
+ }
+ }
+
+ private void deleteOldRichFacesApi(IContainer folder) throws CoreException {
+ IResource[] members = folder.members();
+ for (int i = 0; i < members.length; i++) {
+ IResource resource = members[i];
+ if (resource != null && resource.exists()) {
+ if (resource.getName().startsWith("richfaces-api") //$NON-NLS-1$
+ && resource.getName().endsWith("jar")) { //$NON-NLS-1$
+ resource.delete(true, null);
+ break;
+ }
+ }
}
}
- private List<ZipEntry> prepareList(ZipFile zipFile, boolean isSeamProject) {
- if (zipFile == null) {
+ private void deleteOldRichfacesLibs(IProject earProject, IContainer webinf)
+ throws CoreException {
+
+ if (webinf != null && webinf.exists()) {
+ IResource[] members = webinf.members();
+ for (int i = 0; i < members.length; i++) {
+ IResource resource = members[i];
+ if (resource != null && resource.exists()) {
+ if (resource.getName().startsWith("richfaces-ui") //$NON-NLS-1$
+ && resource.getName().endsWith("jar")) { //$NON-NLS-1$
+ resource.delete(true, null);
+ }
+ if (resource.getName().startsWith("richfaces-impl") //$NON-NLS-1$
+ && resource.getName().endsWith("jar")) { //$NON-NLS-1$
+ resource.delete(true, null);
+ }
+ if (earProject == null) {
+ if (resource.getName().startsWith("richfaces-api") //$NON-NLS-1$
+ && resource.getName().endsWith("jar")) { //$NON-NLS-1$
+ resource.delete(true, null);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private IProject getEarProject(IProject project, boolean isSeamProject) {
+ if (isSeamProject && project != null) {
+ IEclipsePreferences preferences = getSeamPreferences(project);
+ String earProjectName = preferences.get("seam.ear.project", null);
//$NON-NLS-1$
+ if (earProjectName == null) {
+ return null;
+ }
+ IProject earProject =
ResourcesPlugin.getWorkspace().getRoot().getProject(earProjectName);
+ if (earProject != null && earProject.isOpen()) {
+ return earProject;
+ }
+ }
+ return null;
+ }
+
+ private IProject getEjbProject(IProject project, boolean isSeamProject) {
+ if (isSeamProject && project != null) {
+ IEclipsePreferences preferences = getSeamPreferences(project);
+ String ejbProjectName = preferences.get("seam.ejb.project", null);
//$NON-NLS-1$
+ if (ejbProjectName == null) {
+ return null;
+ }
+ IProject ejbProject =
ResourcesPlugin.getWorkspace().getRoot().getProject(ejbProjectName);
+ if (ejbProject != null && ejbProject.isOpen()) {
+ return ejbProject;
+ }
+ }
+ return null;
+ }
+
+ public static IEclipsePreferences getSeamPreferences(IProject project) {
+ IScopeContext projectScope = new ProjectScope(project);
+ return projectScope.getNode("org.jboss.tools.seam.core"); //$NON-NLS-1$
+ }
+
+ private List<ZipEntry> prepareList(ZipFile rootEntry, IFacetedProject
facetedProject, boolean isSeamProject) {
+ if (rootEntry == null) {
return null;
}
List<ZipEntry> list = new ArrayList<ZipEntry>();
- Enumeration<? extends ZipEntry> entries = zipFile.entries();
+ Enumeration<? extends ZipEntry> entries = rootEntry.entries();
+ IProject earProject = getEarProject(facetedProject.getProject(),isSeamProject);
+
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (entry.getName().endsWith(".jar")) { //$NON-NLS-1$
- if (entry.getName().startsWith("WEB-INF/lib/richfaces")) { //$NON-NLS-1$
+ if (entry.getName().startsWith("WEB-INF/lib/richfaces-ui")) {
//$NON-NLS-1$
list.add(entry);
}
+ if (entry.getName().startsWith("WEB-INF/lib/richfaces-impl")) {
//$NON-NLS-1$
+ list.add(entry);
+ }
+ if (earProject == null) {
+ if (entry.getName().startsWith("WEB-INF/lib/richfaces-api")) {
//$NON-NLS-1$
+ list.add(entry);
+ }
+ }
+
if (!isSeamProject) {
if (entry.getName().startsWith(
"WEB-INF/lib/commons-beanutils") //$NON-NLS-1$
@@ -152,4 +408,53 @@
return list;
}
+ private List<ZipEntry> prepareEarList(ZipFile zipFile) {
+ if (zipFile == null) {
+ return null;
+ }
+ List<ZipEntry> list = new ArrayList<ZipEntry>();
+ Enumeration<? extends ZipEntry> entries = zipFile.entries();
+
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = entries.nextElement();
+ if (entry.getName().endsWith(".jar")) { //$NON-NLS-1$
+ if (entry.getName().startsWith("WEB-INF/lib/richfaces-api")) {
//$NON-NLS-1$
+ list.add(entry);
+ }
+ }
+ }
+ return list;
+ }
+
+ private class UpdateManifestOperation implements Runnable {
+ protected IProject project;
+ protected String classPathValue;
+ protected boolean replace;
+
+ public UpdateManifestOperation(IProject project,
+ String aSpaceDelimitedPath, boolean replaceInsteadOfMerge) {
+ super();
+ this.project = project;
+ classPathValue = aSpaceDelimitedPath;
+ replace = replaceInsteadOfMerge;
+ }
+
+ public void run() {
+ ArchiveManifest mf = J2EEProjectUtilities.readManifest(project);
+ if (mf == null)
+ mf = new ArchiveManifestImpl();
+ mf.addVersionIfNecessary();
+ if (replace)
+ mf.setClassPath(classPathValue);
+ else
+ mf.mergeClassPath(ArchiveUtil.getTokens(classPathValue));
+ try {
+ J2EEProjectUtilities.writeManifest(project, mf);
+ } catch (IOException e) {
+ PortletCoreActivator.log(e);
+ }
+
+ }
+ }
+
}
Modified:
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/messages.properties
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/messages.properties 2009-02-15
23:46:07 UTC (rev 13623)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/messages.properties 2009-02-15
23:46:19 UTC (rev 13624)
@@ -1,6 +1,5 @@
BasePortletClasspathContainer_Error_loading_classpath_container=Error loading classpath
container
IPortletConstants_Libraries_provided_by_server_runtime=Libraries provided by server
runtime
-IPortletConstants_Library_provided_by_JBoss_Tools=Library provided by JBoss Tools
IPortletConstants_User_library=User library
JSFPortlet10LibrariesContainerInitializer_Error_loading_classpath_container=Error loading
classpath container
JSFPortlet10LibrariesContainerInitializer_JBoss_JSF_Portlet_Libraries_v1_0=JBoss JSF
Portlet Libraries v1.0
@@ -22,10 +21,14 @@
PortletFacetInstallDelegate_The_web_xml_file_is_not_updateable=The web.xml file is not
updateable
PortletFacetInstallDelegate_User_library_name_is_invalid=User library name is invalid.
PortletPostInstallListener_Cannot_find_Portletbridge_Runtime=Cannot find Portletbridge
Runtime.
+PortletPostInstallListener_Cannot_find_Richfaces_Runtime=Cannot find Richfaces Runtime.
PortletPostInstallListener_Cannot_find_the_examples_directory=Cannot find the examples
directory.
PortletPostInstallListener_Cannot_find_the_RichFacesPortlet_war_file=Cannot find the
RichFacesPortlet.war file.
PortletPostInstallListener_Invalid_Portletbridge_Runtime=Invalid Portletbridge Runtime.
+PortletPostInstallListener_Invalid_Richfaces_Runtime=Invalid Richfaces Runtime.
SeamPortletConfigurationPresetFactory10_JBoss_Seam_Portlet_Project_v1_0=JBoss Seam
Portlet Project v1.0
SeamPortletFacetInstallDelegate_Cannot_configure_web_module_for_JBoss_Seam_Portlet_Facet=Cannot
configure web module for JBoss Seam Portlet Facet
SeamPortletFacetInstallDelegate_Missing_configuration=Internal Error creating JBoss Seam
Portlet Facet. Missing configuration.
SeamPortletFacetInstallDelegate_The_web_xml_file_is_not_updateable=The web.xml file is
not updateable
+Libraries_provided_by_portletbridge=Libraries provided by portletbridge distribution
+Libraries_provided_by_richfaces=Libraries provided by richfaces distribution
\ No newline at end of file