diff --git a/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/PortletCoreActivator.java b/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/PortletCoreActivator.java index 7b5dade..b49d4b4 100644 --- a/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/PortletCoreActivator.java +++ b/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/PortletCoreActivator.java @@ -346,4 +346,9 @@ public static boolean isWebApp25(final Object webApp) { return true; return false; } + + public static void logMessage(String message) { + IStatus status = new Status(IStatus.INFO, PLUGIN_ID, message); + PortletCoreActivator.getDefault().getLog().log(status); + } } diff --git a/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/JSFPortletFacetInstallDelegate.java b/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/JSFPortletFacetInstallDelegate.java index 3c84b51..73ce131 100644 --- a/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/JSFPortletFacetInstallDelegate.java +++ b/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/JSFPortletFacetInstallDelegate.java @@ -18,7 +18,6 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.emf.common.util.EList; import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate; import org.eclipse.jst.j2ee.model.IModelProvider; @@ -36,6 +35,7 @@ import org.jboss.tools.portlet.core.JBossWebUtil25; import org.jboss.tools.portlet.core.Messages; import org.jboss.tools.portlet.core.PortletCoreActivator; +import org.jboss.tools.portlet.core.internal.util.PortletUtil; /** * @author snjeza @@ -88,11 +88,12 @@ public void execute(final IProject project, final IProjectFacetVersion fv, } } - configureFacesConfig(project, monitor, config); - + //Configure libraries ( (LibraryInstallDelegate) config.getProperty( IPortletConstants.JSFPORTLET_LIBRARY_PROVIDER_DELEGATE ) ).execute( monitor ); + configureFacesConfig(project, monitor, config, fv); + if (monitor != null) { monitor.worked(1); } @@ -105,8 +106,13 @@ public void execute(final IProject project, final IProjectFacetVersion fv, } private void configureFacesConfig(IProject project, - IProgressMonitor monitor, IDataModel config) { + IProgressMonitor monitor, IDataModel config, IProjectFacetVersion fv) { + int version = PortletUtil.getPortletBridgeVersion(project); + // faces_config.xml mustn't be updated for portletbridge 3.x + if (version >= 3) { + return; + } String facesConfigString = getFacesConfigFile(project, monitor); if (facesConfigString == null || facesConfigString.trim().length() <= 0) { return; diff --git a/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletPostInstallListener.java b/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletPostInstallListener.java index 9e2a898..24bc167 100644 --- a/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletPostInstallListener.java +++ b/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletPostInstallListener.java @@ -1,9 +1,20 @@ +/************************************************************************************* + * Copyright (c) 2008-2013 Red Hat, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ package org.jboss.tools.portlet.core.internal.project.facet; import java.io.File; import java.io.FileFilter; import java.io.FilenameFilter; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Arrays; import java.util.Enumeration; @@ -59,11 +70,16 @@ import org.jboss.tools.portlet.core.JBossWebUtil25; import org.jboss.tools.portlet.core.Messages; import org.jboss.tools.portlet.core.PortletCoreActivator; +import org.jboss.tools.portlet.core.internal.util.PortletUtil; import org.jboss.tools.portlet.core.libprov.AbstractLibraryProviderInstallOperationConfig; import org.jboss.tools.portlet.core.libprov.JSFPortletbridgeRuntimeLibraryProviderInstallOperationConfig; public class PortletPostInstallListener implements IFacetedProjectListener { + private static final String JAR = ".jar"; //$NON-NLS-1$ + + private static final String SOURCES_JAR = "sources.jar"; //$NON-NLS-1$ + private static final String JST_SEAM_FACET = "jst.seam"; //$NON-NLS-1$ private static final IProjectFacet seamFacet = ProjectFacetsManager.getProjectFacet(JST_SEAM_FACET); @@ -123,7 +139,7 @@ public void handleEvent(IFacetedProjectEvent event) { } else { portletbridgeRuntime = null; } - richfacesFromServerRuntime = PortletCoreActivator.JSFPORTLET_LIBRARY_PROVIDER.equals(providerId); //$NON-NLS-1$ + richfacesFromServerRuntime = PortletCoreActivator.JSFPORTLET_LIBRARY_PROVIDER.equals(providerId); if (PortletCoreActivator.JSFPORTLETBRIDGE_LIBRARY_PROVIDER.equals(providerId) || PortletCoreActivator.JSFPORTLET_LIBRARY_PROVIDER.equals(providerId)) { @@ -142,7 +158,7 @@ public void handleEvent(IFacetedProjectEvent event) { if (isJSFPortlet) { if (portletbridgeRuntime != null || isEPP) { - addLibrariesFromPortletBridgeRuntime(facetedProject,portletbridgeRuntime); + addLibrariesFromPortletBridgeRuntime(facetedProject,portletbridgeRuntime, richfacesCapabilities); } else if (richfacesFromServerRuntime) { addLibrariesFromServerRuntime(facetedProject); @@ -185,7 +201,7 @@ public void run() { // RichFaces settings - int portletBridgeVersion = getPortletBridgeVersion(project); + int portletBridgeVersion = PortletUtil.getPortletBridgeVersion(project); if (portletBridgeVersion <= 1) { value = "NONE"; //$NON-NLS-1$ } else { @@ -232,59 +248,7 @@ public void run() { }, modelPath); } - protected int getPortletBridgeVersion(IProject project) { - if (project == null || !project.isOpen()) { - return 0; - } - IVirtualComponent component = ComponentCore.createComponent(project); - IVirtualFolder rootFolder = component.getRootFolder(); - IContainer folder = rootFolder.getUnderlyingFolder(); - IContainer webinf = folder.getFolder(new Path(IPortletConstants.WEB_INF_LIB)); - String libResource = webinf.getLocation().toOSString(); - File libFile = new File(libResource); - if (!libFile.exists()) { - return 0; - } - File[] files = libFile.listFiles(new FilenameFilter() { - - public boolean accept(File dir, String name) { - if (name != null && name.startsWith("portletbridge-api") //$NON-NLS-1$ - && name.endsWith(".jar")) { //$NON-NLS-1$ - return true; - } - return false; - } - }); - if (files == null || files.length <= 0) { - return 0; - } - File jarFile = files[0]; - if(jarFile.isFile()) { - try { - JarFile jar = new JarFile(jarFile); - Attributes attributes = jar.getManifest().getMainAttributes(); - String versionString = attributes.getValue("Implementation-Version"); //$NON-NLS-1$ - if (versionString != null && versionString.trim().length() > 0) { - StringTokenizer tokenizer = new StringTokenizer(versionString,"."); //$NON-NLS-1$ - if (tokenizer.hasMoreTokens()) { - String firstNumber = tokenizer.nextToken(); - int version = 0; - try { - version = new Integer(firstNumber).intValue(); - } catch (NumberFormatException e) { - // ignore - } - return version; - } - } - - } catch (IOException e) { - return 0; - } - } - return 0; - } - + private boolean addRichfacesLibraries(IProject project) { boolean isSeamFacet = false; try { @@ -328,11 +292,11 @@ private void addLibrariesFromServerRuntime(IFacetedProject facetedProject) { } File richfacesLib = libFile; if (!richfacesLib.exists()) { - PortletCoreActivator.log(null, Messages.PortletPostInstallListener_Cannot_find_Richfaces_ibraries); + PortletCoreActivator.logMessage(Messages.PortletPostInstallListener_Cannot_find_Richfaces_ibraries); return; } if (!richfacesLib.isDirectory()) { - PortletCoreActivator.log(null, Messages.PortletPostInstallListener_Cannot_find_Richfaces_ibraries); + PortletCoreActivator.logMessage(Messages.PortletPostInstallListener_Cannot_find_Richfaces_ibraries); return; } try { @@ -343,14 +307,14 @@ private void addLibrariesFromServerRuntime(IFacetedProject facetedProject) { public boolean accept(File dir, String name) { if (!addRichfacesFromRichfacesRuntime) { - if (name.startsWith("richfaces-ui") && name.endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$ + if (name.startsWith("richfaces-ui") && name.endsWith(JAR)) { //$NON-NLS-1$ return true; } - if (name.startsWith("richfaces-impl") && name.endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$ + if (name.startsWith("richfaces-impl") && name.endsWith(JAR)) { //$NON-NLS-1$ return true; } if (earProject == null) { - if (name.startsWith("richfaces-api") && name.endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$ + if (name.startsWith("richfaces-api") && name.endsWith(JAR)) { //$NON-NLS-1$ return true; } } @@ -388,7 +352,7 @@ public boolean accept(File dir, String name) { 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$ + if (name.startsWith("richfaces-api") && name.endsWith(JAR)) { //$NON-NLS-1$ return true; } return false; @@ -426,38 +390,40 @@ private void addRichfacesFromRichfacesRuntime( } 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); + // RF 4.x + File artifacts = new File(richfacesRuntimeHome, "artifacts"); //$NON-NLS-1$ + File ui = new File(artifacts, "ui"); //$NON-NLS-1$ + File framework = new File(artifacts, "framework"); //$NON-NLS-1$ + if (!ui.isDirectory() || !framework.isDirectory()) { + PortletCoreActivator.logMessage(Messages.PortletPostInstallListener_Invalid_Richfaces_Runtime); + return; + } + addRichfaces4(facetedProject, isSeamProject, ui, framework); return; } + + addRichfaces3(facetedProject, isSeamProject, richfacesLib); + } + + private void addRichfaces4(IFacetedProject facetedProject, + final boolean isSeamProject, File ui, File framework) { try { IProject project = facetedProject.getProject(); final IProject earProject = getEarProject(project, isSeamProject); - String[] fileList = richfacesLib.list(new FilenameFilter() { + String[] fileList = framework.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$ + if (name.startsWith("richfaces-core") && name.endsWith(JAR) && !name.endsWith(SOURCES_JAR)) { //$NON-NLS-1$ return true; } - if (earProject == null) { - if (name.startsWith("richfaces-api") && name.endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$ - return true; - } - } return false; } }); List filesToImport = new ArrayList(); for (int i = 0; i < fileList.length; i++) { - filesToImport.add(new File(richfacesLib, fileList[i])); + filesToImport.add(new File(framework, fileList[i])); } IVirtualComponent component = ComponentCore .createComponent(project); @@ -467,43 +433,120 @@ public boolean accept(File dir, String name) { IPortletConstants.WEB_INF_LIB)); deleteOldRichfacesLibs(earProject, webinf); + importFiles(project, earProject, filesToImport, framework, webinf, + isSeamProject); + + fileList = ui.list(new FilenameFilter() { + + public boolean accept(File dir, String name) { + if (name.startsWith("richfaces-components") && name.endsWith(JAR) && !name.endsWith(SOURCES_JAR)) { //$NON-NLS-1$ + return true; + } + return false; + } + + }); + for (int i = 0; i < fileList.length; i++) { + filesToImport.add(new File(ui, fileList[i])); + } + importFiles(project, earProject, filesToImport, ui, webinf, + isSeamProject); + + } catch (Exception e) { + PortletCoreActivator + .log(e,Messages.JSFPortletFacetInstallDelegate_Error_loading_classpath_container); + } + } - ImportOperation importOperation = new ImportOperation(webinf - .getFullPath(), richfacesLib, + private void importFiles(IProject project, final IProject earProject, + List filesToImport, File sourceDir, IContainer webinf, + final boolean isSeamProject) throws InvocationTargetException, + InterruptedException, CoreException { + String[] fileList; + IVirtualComponent component; + IVirtualFolder rootFolder; + IContainer folder; + ImportOperation importOperation = new ImportOperation(webinf + .getFullPath(), sourceDir, + FileSystemStructureProvider.INSTANCE, + PortletCoreActivator.OVERWRITE_ALL_QUERY, filesToImport); + importOperation.setCreateContainerStructure(false); + importOperation.run(new NullProgressMonitor()); + if (earProject != null) { + fileList = sourceDir.list(new FilenameFilter() { + + public boolean accept(File dir, String name) { + if (name.startsWith("richfaces-core-api") && name.endsWith(JAR) && !name.endsWith(SOURCES_JAR)) { //$NON-NLS-1$ + return true; + } + if (name.startsWith("richfaces-components-api") && name.endsWith(JAR) && !name.endsWith(SOURCES_JAR)) { //$NON-NLS-1$ + return true; + } + if (name.startsWith("richfaces-api") && name.endsWith(JAR) && !name.endsWith(SOURCES_JAR)) { //$NON-NLS-1$ + return true; + } + return false; + } + + }); + filesToImport = new ArrayList(); + for (int i = 0; i < fileList.length; i++) { + filesToImport.add(new File(sourceDir, fileList[i])); + } + component = ComponentCore + .createComponent(earProject); + rootFolder = component.getRootFolder(); + folder = rootFolder.getUnderlyingFolder(); + + deleteOldRichFacesApi(folder); + + importOperation = new ImportOperation(folder + .getFullPath(), sourceDir, FileSystemStructureProvider.INSTANCE, PortletCoreActivator.OVERWRITE_ALL_QUERY, filesToImport); importOperation.setCreateContainerStructure(false); importOperation.run(new NullProgressMonitor()); - if (earProject != null) { - fileList = richfacesLib.list(new FilenameFilter() { + updateEARLibraries(project,isSeamProject); + } + } - public boolean accept(File dir, String name) { - if (name.startsWith("richfaces-api") && name.endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$ + private void addRichfaces3(IFacetedProject facetedProject, + final boolean isSeamProject, File richfacesLib) { + 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$ + return true; + } + if (name.startsWith("richfaces-impl") && name.endsWith(JAR)) { //$NON-NLS-1$ + return true; + } + if (earProject == null) { + if (name.startsWith("richfaces-api") && name.endsWith(JAR)) { //$NON-NLS-1$ return true; } - return false; } - - }); - filesToImport = new ArrayList(); - for (int i = 0; i < fileList.length; i++) { - filesToImport.add(new File(richfacesLib, fileList[i])); + return false; } - 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); + }); + List filesToImport = new ArrayList(); + for (int i = 0; i < fileList.length; i++) { + filesToImport.add(new File(richfacesLib, fileList[i])); } + 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); + + importFiles(project, earProject, filesToImport, richfacesLib, webinf, isSeamProject); } catch (Exception e) { PortletCoreActivator .log(e,Messages.JSFPortletFacetInstallDelegate_Error_loading_classpath_container); @@ -521,7 +564,7 @@ private void updateEARLibraries(IProject project, boolean isSeamProject) { 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$ + return name.lastIndexOf(JAR) > 0; } }); String clientURI = ""; //$NON-NLS-1$ @@ -537,7 +580,7 @@ public boolean accept(File dir, String name) { } } - private void addLibrariesFromPortletBridgeRuntime(IFacetedProject facetedProject, String portletbridgeRuntime) { + private void addLibrariesFromPortletBridgeRuntime(IFacetedProject facetedProject, String portletbridgeRuntime, boolean addRichfaces) { File portletbridgeHome; if (isEPP) { portletbridgeHome = PortletCoreActivator.getEPPDir(facetedProject, PortletCoreActivator.PORTLETBRIDGE); @@ -545,11 +588,11 @@ private void addLibrariesFromPortletBridgeRuntime(IFacetedProject facetedProject portletbridgeHome = new File(portletbridgeRuntime); } if (portletbridgeHome == null || !portletbridgeHome.exists()) { - PortletCoreActivator.log(null, Messages.PortletPostInstallListener_Cannot_find_Portletbridge_Runtime); + PortletCoreActivator.logMessage(Messages.PortletPostInstallListener_Cannot_find_Portletbridge_Runtime); return; } if (!portletbridgeHome.isDirectory()) { - PortletCoreActivator.log(null, Messages.PortletPostInstallListener_Invalid_Portletbridge_Runtime); + PortletCoreActivator.logMessage(Messages.PortletPostInstallListener_Invalid_Portletbridge_Runtime); return; } if (isEPP) { @@ -564,8 +607,7 @@ private void getLibrariesFromEPP(IFacetedProject facetedProject) { PortletCoreActivator.SEAM); File seamLib = new File(seamHome, "lib"); //$NON-NLS-1$ if (seamLib == null || !seamLib.isDirectory()) { - PortletCoreActivator.log(null, - Messages.PortletPostInstallListener_Cannot_find_the_seam_lib_directory); + PortletCoreActivator.logMessage(Messages.PortletPostInstallListener_Cannot_find_the_seam_lib_directory); return; } try { @@ -612,7 +654,7 @@ private List prepareEarList(File seamLib) { public boolean accept(File pathname) { String name = pathname.getName(); - if (name.endsWith(".jar") && name.startsWith("richfaces-api")) { //$NON-NLS-1$ //$NON-NLS-2$ + if (name.endsWith(JAR) && name.startsWith("richfaces-api")) { //$NON-NLS-1$ return true; } @@ -636,7 +678,7 @@ public boolean accept(File pathname) { if (name == null) { return false; } - if (!name.endsWith(".jar")) { //$NON-NLS-1$ + if (!name.endsWith(JAR)) { return false; } if (name.startsWith("jsf-facelets")) { //$NON-NLS-1$ @@ -649,10 +691,23 @@ public boolean accept(File pathname) { if (name.startsWith("richfaces-impl")) { //$NON-NLS-1$ return true; } + if (name.startsWith("richfaces-core-impl")) { //$NON-NLS-1$ + return true; + } + if (name.startsWith("richfaces-components-ui")) { //$NON-NLS-1$ + return true; + } if (earProject == null) { if (name.startsWith("richfaces-api")) { //$NON-NLS-1$ return true; } + if (name.startsWith("richfaces-core-api")) { //$NON-NLS-1$ + return true; + } + + if (name.startsWith("richfaces-components-api")) { //$NON-NLS-1$ + return true; + } } } if (!isSeamProject) { @@ -676,14 +731,12 @@ private void getLibrariesFromExamples(IFacetedProject facetedProject, File portletbridgeHome) { File examplesHome = new File(portletbridgeHome, "examples"); //$NON-NLS-1$ if (!examplesHome.exists() || !examplesHome.isDirectory()) { - PortletCoreActivator.log(null, - Messages.PortletPostInstallListener_Cannot_find_the_examples_directory); + PortletCoreActivator.logMessage(Messages.PortletPostInstallListener_Cannot_find_the_examples_directory); return; } File richFacesPortletZip = getRichFacesExamples(examplesHome); if (!richFacesPortletZip.exists() || !richFacesPortletZip.isFile()) { - PortletCoreActivator.log(null, - Messages.PortletPostInstallListener_Cannot_find_the_RichFacesPortlet_war_file); + PortletCoreActivator.logMessage(Messages.PortletPostInstallListener_Cannot_find_the_RichFacesPortlet_war_file); return; } try { @@ -780,6 +833,13 @@ public boolean accept(File dir, String name) { return null; } + /** + * + * remove richfaces libraries added with a facet + * + * @param folder + * @throws CoreException + */ private void deleteOldRichFacesApi(IContainer folder) throws CoreException { IResource[] members = folder.members(); for (int i = 0; i < members.length; i++) { @@ -788,12 +848,27 @@ private void deleteOldRichFacesApi(IContainer folder) throws CoreException { if (resource.getName().startsWith("richfaces-api") //$NON-NLS-1$ && resource.getName().endsWith("jar")) { //$NON-NLS-1$ resource.delete(true, null); - break; + } + if (resource.getName().startsWith("richfaces-core-api") //$NON-NLS-1$ + && resource.getName().endsWith("jar")) { //$NON-NLS-1$ + resource.delete(true, null); + } + if (resource.getName().startsWith("richfaces-components-api") //$NON-NLS-1$ + && resource.getName().endsWith("jar")) { //$NON-NLS-1$ + resource.delete(true, null); } } } } + /** + * + * remove richfaces libraries added with a facet + * + * @param earProject + * @param webinf + * @throws CoreException + */ private void deleteOldRichfacesLibs(IProject earProject, IContainer webinf) throws CoreException { @@ -806,6 +881,14 @@ private void deleteOldRichfacesLibs(IProject earProject, IContainer webinf) && resource.getName().endsWith("jar")) { //$NON-NLS-1$ resource.delete(true, null); } + if (resource.getName().startsWith("richfaces-core") //$NON-NLS-1$ + && resource.getName().endsWith("jar")) { //$NON-NLS-1$ + resource.delete(true, null); + } + if (resource.getName().startsWith("richfaces-components") //$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); @@ -870,7 +953,7 @@ private List prepareList(ZipFile rootEntry, IFacetedProject facetedPro while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); - if (entry.getName().endsWith(".jar")) { //$NON-NLS-1$ + if (entry.getName().endsWith(JAR)) { if (!addRichfacesFromRichfacesRuntime) { if (entry.getName().startsWith("WEB-INF/lib/richfaces-ui")) { //$NON-NLS-1$ list.add(entry); @@ -910,7 +993,7 @@ private List prepareEarList(ZipFile zipFile) { while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); - if (entry.getName().endsWith(".jar")) { //$NON-NLS-1$ + if (entry.getName().endsWith(JAR)) { if (entry.getName().startsWith("WEB-INF/lib/richfaces-api")) { //$NON-NLS-1$ list.add(entry); } diff --git a/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/util/PortletUtil.java b/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/util/PortletUtil.java new file mode 100644 index 0000000..18e11b6 --- /dev/null +++ b/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/util/PortletUtil.java @@ -0,0 +1,101 @@ +/************************************************************************************* + * Copyright (c) 2013 Red Hat, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.portlet.core.internal.util; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.util.StringTokenizer; +import java.util.jar.Attributes; +import java.util.jar.JarFile; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.Path; +import org.eclipse.wst.common.componentcore.ComponentCore; +import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; +import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; +import org.jboss.tools.portlet.core.IPortletConstants; + +/** + * + * @author snjeza + * + */ +public class PortletUtil { + + private static final String IMPLEMENTATION_VERSION = "Implementation-Version"; //$NON-NLS-1$ + + private static final String PORTLETBRIDGE_API = "portletbridge-api"; //$NON-NLS-1$ + + private static final String PORTLETBRIDGE_CORE_API = "portletbridge-core-api"; //$NON-NLS-1$ + + private static final String JAR = ".jar"; //$NON-NLS-1$ + + + public static int getPortletBridgeVersion(IProject project) { + if (project == null || !project.isOpen()) { + return 0; + } + IVirtualComponent component = ComponentCore.createComponent(project); + IVirtualFolder rootFolder = component.getRootFolder(); + IContainer folder = rootFolder.getUnderlyingFolder(); + IContainer webinf = folder.getFolder(new Path(IPortletConstants.WEB_INF_LIB)); + String libResource = webinf.getLocation().toOSString(); + File libFile = new File(libResource); + if (!libFile.exists()) { + return 0; + } + File[] files = libFile.listFiles(new FilenameFilter() { + + public boolean accept(File dir, String name) { + if (name != null && name.startsWith(PORTLETBRIDGE_API) + && name.endsWith(JAR)) { + return true; + } + if (name != null && name.startsWith(PORTLETBRIDGE_CORE_API) + && name.endsWith(JAR)) { + return true; + } + return false; + } + }); + if (files == null || files.length <= 0) { + return 0; + } + File jarFile = files[0]; + if(jarFile.isFile()) { + try { + JarFile jar = new JarFile(jarFile); + Attributes attributes = jar.getManifest().getMainAttributes(); + String versionString = attributes.getValue(IMPLEMENTATION_VERSION); + if (versionString != null && versionString.trim().length() > 0) { + StringTokenizer tokenizer = new StringTokenizer(versionString,"."); //$NON-NLS-1$ + if (tokenizer.hasMoreTokens()) { + String firstNumber = tokenizer.nextToken(); + int version = 0; + try { + version = new Integer(firstNumber).intValue(); + } catch (NumberFormatException e) { + // ignore + } + return version; + } + } + + } catch (IOException e) { + return 0; + } + } + return 0; + } + +} diff --git a/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/libprov/AbstractLibraryProviderInstallOperationConfig.java b/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/libprov/AbstractLibraryProviderInstallOperationConfig.java index 7c24db0..eae4af7 100644 --- a/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/libprov/AbstractLibraryProviderInstallOperationConfig.java +++ b/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/libprov/AbstractLibraryProviderInstallOperationConfig.java @@ -54,11 +54,18 @@ public synchronized IStatus validate() { if (!folder.exists() || !folder.isDirectory()) { return getInvalidRichfacesRuntime(); } - folder = new File(folder,"lib"); //$NON-NLS-1$ - if (!folder.exists() || !folder.isDirectory()) { + File lib = new File(folder,"lib"); //$NON-NLS-1$ + if (!lib.isDirectory()) { + // RF 4.x + File artifacts = new File(folder, "artifacts"); //$NON-NLS-1$ + File ui = new File(artifacts, "ui"); //$NON-NLS-1$ + File framework = new File(artifacts, "framework"); //$NON-NLS-1$ + if (ui.isDirectory() && framework.isDirectory()) { + return Status.OK_STATUS; + } return getInvalidRichfacesRuntime(); } - String[] fileList = folder.list(new FilenameFilter() { + String[] fileList = lib.list(new FilenameFilter() { public boolean accept(File dir, String name) { if (name.startsWith("richfaces") || name.endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/libprov/JSFPortletbridgeRuntimeLibraryProviderInstallOperation.java b/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/libprov/JSFPortletbridgeRuntimeLibraryProviderInstallOperation.java index 1310f92..675e5b4 100644 --- a/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/libprov/JSFPortletbridgeRuntimeLibraryProviderInstallOperation.java +++ b/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/libprov/JSFPortletbridgeRuntimeLibraryProviderInstallOperation.java @@ -34,8 +34,8 @@ public void execute(LibraryProviderOperationConfig config, IProject project = facetedProject.getProject(); JSFPortletbridgeRuntimeLibraryProviderInstallOperationConfig portletbridgeConfig = (JSFPortletbridgeRuntimeLibraryProviderInstallOperationConfig) config; String pbRuntime = portletbridgeConfig.getPortletbridgeHome(); - getPortletbridgeLibraries(monitor, project, pbRuntime); boolean addRichfacesCapabilities = portletbridgeConfig.isAddRichfacesCapabilities(); + getPortletbridgeLibraries(monitor, project, pbRuntime, addRichfacesCapabilities); boolean isEPP = portletbridgeConfig.isEPP(); String richfacesType = portletbridgeConfig.getRichfacesType(); String richfacesRuntime = portletbridgeConfig.getRichfacesRuntime(); @@ -54,7 +54,7 @@ public void execute(LibraryProviderOperationConfig config, } private void getPortletbridgeLibraries(IProgressMonitor monitor, - IProject project, String pbRuntime) { + IProject project, String pbRuntime, final boolean addRichfacesCapabilities) { if (pbRuntime != null && pbRuntime.trim().length() > 0) { pbRuntime = pbRuntime.trim(); File pbFolder = new File(pbRuntime); @@ -62,6 +62,9 @@ private void getPortletbridgeLibraries(IProgressMonitor monitor, String[] fileList = pbFolder.list(new FilenameFilter() { public boolean accept(File dir, String name) { + if (!addRichfacesCapabilities && name.contains("richfaces")) { + return false; + } if (name.startsWith("portletbridge") || name.endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$ return true; }