Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 141582 Details for
Bug 283472
JSF facet does not validate user library version for JSF
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Patch to add library version validation for JSF facet
patch.txt (text/plain), 13.34 KB, created by
Debajit Adhikary
on 2009-07-14 18:43:54 EDT
(
hide
)
Description:
Patch to add library version validation for JSF facet
Filename:
MIME Type:
Creator:
Debajit Adhikary
Created:
2009-07-14 18:43:54 EDT
Size:
13.34 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jst.jsf.common >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/webtools/org.eclipse.jsf/components/jsf/plugins/org.eclipse.jst.jsf.common/META-INF/MANIFEST.MF,v >retrieving revision 1.35 >diff -u -r1.35 MANIFEST.MF >--- META-INF/MANIFEST.MF 17 Mar 2009 17:25:10 -0000 1.35 >+++ META-INF/MANIFEST.MF 14 Jul 2009 22:22:41 -0000 >@@ -7,6 +7,8 @@ > Bundle-Localization: plugin > Export-Package: org.eclipse.jst.jsf.common;x-internal:=true, > org.eclipse.jst.jsf.common.dom, >+ org.eclipse.jst.jsf.common.facet, >+ org.eclipse.jst.jsf.common.facet.libraryprovider, > org.eclipse.jst.jsf.common.internal;x-friends:="org.eclipse.jst.jsf.core", > org.eclipse.jst.jsf.common.internal.managedobject;x-internal:=true, > org.eclipse.jst.jsf.common.internal.policy;x-internal:=true, >@@ -55,7 +57,9 @@ > org.eclipse.jdt.core;bundle-version="[3.2.0,4.0.0)", > org.eclipse.emf.edit.ui;bundle-version="[2.2.0,3.0.0)", > org.eclipse.emf.ecore.xmi;bundle-version="[2.2.0,3.0.0)", >- org.eclipse.jdt.ui;bundle-version="[3.2.0,4.0.0)" >+ org.eclipse.jdt.ui;bundle-version="[3.2.0,4.0.0)", >+ org.eclipse.jst.common.project.facet.core, >+ org.eclipse.wst.common.project.facet.core > Bundle-ActivationPolicy: lazy > Bundle-Vendor: %plugin.provider > Bundle-RequiredExecutionEnvironment: J2SE-1.5 >Index: src/org/eclipse/jst/jsf/common/facet/libraryprovider/UserLibraryVersionValidator.java >=================================================================== >RCS file: src/org/eclipse/jst/jsf/common/facet/libraryprovider/UserLibraryVersionValidator.java >diff -N src/org/eclipse/jst/jsf/common/facet/libraryprovider/UserLibraryVersionValidator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jst/jsf/common/facet/libraryprovider/UserLibraryVersionValidator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,205 @@ >+/******************************************************************************* >+ * Copyright (c) 2001, 2008 Oracle Corporation 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: >+ * Oracle Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+ >+package org.eclipse.jst.jsf.common.facet.libraryprovider; >+ >+import java.io.File; >+import java.io.IOException; >+import java.util.Enumeration; >+import java.util.jar.JarFile; >+import java.util.jar.Manifest; >+import java.util.zip.ZipEntry; >+import java.util.zip.ZipFile; >+ >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.jdt.core.IClasspathEntry; >+import org.eclipse.jst.common.project.facet.core.libprov.user.KeyClassesValidator; >+import org.eclipse.jst.common.project.facet.core.libprov.user.UserLibraryProviderInstallOperationConfig; >+import org.eclipse.jst.jsf.common.JSFCommonPlugin; >+import org.eclipse.jst.jsf.common.facet.Messages; >+import org.eclipse.osgi.util.NLS; >+ >+ >+/** >+ * Checks that a user library is version-compatible with the facet. >+ * >+ * @author Debajit Adhikary >+ * >+ */ >+public abstract class UserLibraryVersionValidator extends KeyClassesValidator >+{ >+ private static final String MANIFEST_IMPLEMENTATION_VERSION = "Implementation-Version"; //$NON-NLS-1$ >+ >+ private final String classNameIdentifyingImplementationJar; >+ >+ >+ /** >+ * @param classNameIdentifyingImplementationJar >+ */ >+ public UserLibraryVersionValidator (final String classNameIdentifyingImplementationJar) >+ { >+ this.classNameIdentifyingImplementationJar = classNameIdentifyingImplementationJar; >+ } >+ >+ >+ @Override >+ public IStatus validate (final UserLibraryProviderInstallOperationConfig config) >+ { >+ // Check super validator >+ final IStatus status = super.validate(config); >+ if (status.getSeverity() != IStatus.OK) >+ return status; >+ >+ // Superclass validated this lib successfully. >+ // Check user library version now. >+ final String facetVersion = getFacetVersion(config); >+ final String libraryVersion = getLibraryVersion(config); >+ return validateVersionStrings(facetVersion, libraryVersion); >+ } >+ >+ >+ /** >+ * @param facetVersion >+ * @param libraryVersion >+ * @return the diagnostic for whether the facetVersion and libraryVersion >+ * match. >+ */ >+ protected IStatus validateVersionStrings (final String facetVersion, >+ final String libraryVersion) >+ { >+ if (facetVersion == null) >+ throw new IllegalArgumentException("Cannot read facet version"); //$NON-NLS-1$ >+ >+ if (libraryVersion == null) >+ return new Status(IStatus.WARNING, JSFCommonPlugin.PLUGIN_ID, Messages.UserLibraryVersionValidator_cannotReadLibraryVersion); >+ >+ if (isLibraryFacetCompatible(facetVersion, libraryVersion)) >+ return Status.OK_STATUS; >+ >+ final String errorMessage = NLS.bind(Messages.UserLibraryVersionValidator_versionMismatch, libraryVersion, facetVersion); >+ return new Status(IStatus.ERROR, JSFCommonPlugin.PLUGIN_ID, errorMessage); >+ } >+ >+ >+ private boolean isLibraryFacetCompatible (final String facetVersion, >+ final String libraryVersion) >+ { >+ return libraryVersion.startsWith(facetVersion); >+ } >+ >+ >+ private String getFacetVersion (final UserLibraryProviderInstallOperationConfig config) >+ { >+ return config.getProjectFacetVersion().getVersionString(); >+ } >+ >+ >+ private String getLibraryVersion (final UserLibraryProviderInstallOperationConfig config) >+ { >+ String libraryVersion = null; >+ >+ try >+ { >+ for (final IClasspathEntry cpe : config.resolve()) >+ { >+ if (isLibrary(cpe)) >+ { >+ final File libraryFile = cpe.getPath().toFile(); >+ >+ if (libraryFile.exists() && isCorrectLibraryJar(cpe, this.classNameIdentifyingImplementationJar)) >+ { >+ JarFile jarFile = null; >+ try >+ { >+ jarFile = new JarFile(libraryFile); >+ libraryVersion = getLibraryVersion(jarFile); >+ } >+ finally >+ { >+ if (jarFile != null) >+ jarFile.close(); >+ } >+ } >+ } >+ } >+ } >+ catch (final IOException e) >+ { >+ JSFCommonPlugin.log(e, e.getLocalizedMessage()); >+ } >+ >+ return libraryVersion; >+ } >+ >+ >+ private boolean isLibrary (final IClasspathEntry cpe) >+ { >+ return cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY; >+ } >+ >+ >+ private boolean isCorrectLibraryJar (final IClasspathEntry cpe, >+ final String classNameIdentifyingJar) >+ throws IOException >+ { >+ final File libraryFile = cpe.getPath().toFile(); >+ >+ if (!libraryFile.exists()) >+ return false; >+ >+ ZipFile zipFile = null; >+ >+ try >+ { >+ zipFile = new ZipFile(libraryFile); >+ >+ for (final Enumeration<? extends ZipEntry> entries = zipFile.entries(); entries.hasMoreElements();) >+ { >+ final ZipEntry entry = entries.nextElement(); >+ final String entryName = entry.getName(); >+ if (entryName.equals(classNameIdentifyingJar)) >+ return true; >+ } >+ } >+ finally >+ { >+ if (zipFile != null) >+ zipFile.close(); >+ } >+ >+ return false; >+ } >+ >+ >+ /** >+ * Reads the Implementation-Version attribute of a library jar manifest, and >+ * returns its value. >+ * >+ * @param jarFile >+ * Library jar file to read >+ * >+ * @return Value of Implementation-Version attribute in manifest. >+ * >+ * @throws IOException >+ */ >+ protected String getLibraryVersion (final JarFile jarFile) >+ throws IOException >+ { >+ final Manifest manifest = jarFile.getManifest(); >+ >+ if (manifest != null) >+ return manifest.getMainAttributes().getValue(MANIFEST_IMPLEMENTATION_VERSION); >+ >+ return null; >+ } >+} >Index: src/org/eclipse/jst/jsf/common/facet/Messages.java >=================================================================== >RCS file: src/org/eclipse/jst/jsf/common/facet/Messages.java >diff -N src/org/eclipse/jst/jsf/common/facet/Messages.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jst/jsf/common/facet/Messages.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,36 @@ >+/** >+ * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. >+ */ >+ >+ >+package org.eclipse.jst.jsf.common.facet; >+ >+ >+import org.eclipse.osgi.util.NLS; >+ >+ >+/** >+ * Resource bundle >+ * >+ * @author Debajit Adhikary >+ */ >+public class Messages extends NLS >+{ >+ private static final String BUNDLE_NAME = "org.eclipse.jst.jsf.common.facet.messages"; //$NON-NLS-1$ >+ >+ public static String UserLibraryVersionValidator_cannotReadLibraryVersion; >+ >+ public static String UserLibraryVersionValidator_versionMismatch; >+ >+ static >+ { >+ // initialize resource bundle >+ NLS.initializeMessages(BUNDLE_NAME, Messages.class); >+ } >+ >+ >+ private Messages () >+ { >+ // >+ } >+} >Index: src/org/eclipse/jst/jsf/common/facet/messages.properties >=================================================================== >RCS file: src/org/eclipse/jst/jsf/common/facet/messages.properties >diff -N src/org/eclipse/jst/jsf/common/facet/messages.properties >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jst/jsf/common/facet/messages.properties 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,2 @@ >+UserLibraryVersionValidator_cannotReadLibraryVersion=Could not read version for selected library. The library may not be correct for this facet version. >+UserLibraryVersionValidator_versionMismatch=Incorrect library version: The selected library version ({0}) does not match the facet version ({1}) >\ No newline at end of file >#P org.eclipse.jst.jsf.core >Index: src/org/eclipse/jst/jsf/core/internal/project/facet/JSFLibraryValidator.java >=================================================================== >RCS file: /cvsroot/webtools/org.eclipse.jsf/components/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFLibraryValidator.java,v >retrieving revision 1.1 >diff -u -r1.1 JSFLibraryValidator.java >--- src/org/eclipse/jst/jsf/core/internal/project/facet/JSFLibraryValidator.java 22 Nov 2008 00:57:21 -0000 1.1 >+++ src/org/eclipse/jst/jsf/core/internal/project/facet/JSFLibraryValidator.java 14 Jul 2009 22:22:42 -0000 >@@ -1,27 +1,31 @@ >+/******************************************************************************* >+ * Copyright (c) 2001, 2009 Oracle Corporation 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: Oracle Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+ > package org.eclipse.jst.jsf.core.internal.project.facet; > >-import static org.eclipse.jst.common.project.facet.core.internal.FacetedProjectFrameworkJavaPlugin.PLUGIN_ID; >+import org.eclipse.jst.jsf.common.facet.libraryprovider.UserLibraryVersionValidator; > >-import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.Status; >-import org.eclipse.jst.common.project.facet.core.libprov.user.KeyClassesValidator; >-import org.eclipse.jst.common.project.facet.core.libprov.user.UserLibraryProviderInstallOperationConfig; >-import org.eclipse.jst.jsf.core.internal.Messages; > > /** >- * Return custom message for JSF Libraries when KeyClassesValidator returns an error status >+ * Checks that the JSF user library is version-compatible with the JSF facet. >+ * >+ * @author Debajit Adhikary >+ * > */ >-public class JSFLibraryValidator extends KeyClassesValidator { >- >- @Override >- public IStatus validate(UserLibraryProviderInstallOperationConfig config) { >- IStatus status = super.validate(config); >- if (status.getSeverity() == IStatus.OK) >- return status; >- >- String message = Messages.JSFLibraryValidator_MISSING_JSF_IMPLEMENTATION_CLASSES; >- return new Status( IStatus.ERROR, PLUGIN_ID, message ); >+public class JSFLibraryValidator extends UserLibraryVersionValidator >+{ >+ private static final String CLASS_NAME_IDENTIFYING_IMPLEMENTATION_JAR = "javax/faces/render/RenderKit.class"; //$NON-NLS-1$ > >- } > >+ public JSFLibraryValidator () >+ { >+ super(CLASS_NAME_IDENTIFYING_IMPLEMENTATION_JAR); >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 283472
: 141582 |
141730