Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfullbright2011-02-08 18:02:19 -0500
committerpfullbright2011-02-08 18:02:19 -0500
commit5aca11b85e9bd7b46f7ea3be7dd99fb47b075148 (patch)
treebbd8add50fa64fd7aca01f17f7ac21f06ef4aa0b /common/plugins
parent7f520335fa39603d63a4590255ac2a0bbb6fb5a5 (diff)
downloadwebtools.dali-5aca11b85e9bd7b46f7ea3be7dd99fb47b075148.tar.gz
webtools.dali-5aca11b85e9bd7b46f7ea3be7dd99fb47b075148.tar.xz
webtools.dali-5aca11b85e9bd7b46f7ea3be7dd99fb47b075148.zip
moved library validation guts to common plugin
Diffstat (limited to 'common/plugins')
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/property_files/jpt_common_core.properties1
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/JptCommonCoreMessages.java1
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libval/LibValUtil.java92
3 files changed, 94 insertions, 0 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/property_files/jpt_common_core.properties b/common/plugins/org.eclipse.jpt.common.core/property_files/jpt_common_core.properties
index 3db352b1b7..e474609500 100644
--- a/common/plugins/org.eclipse.jpt.common.core/property_files/jpt_common_core.properties
+++ b/common/plugins/org.eclipse.jpt.common.core/property_files/jpt_common_core.properties
@@ -17,6 +17,7 @@ REGISTRY_DUPLICATE=An extension of ''{0}'' with the ''{1}'' value of ''{2}'' is
REGISTRY_FAILED_CLASS_LOAD=Unable to load the class ''{0}'' declared for the extension point ''{1}'' in the plug-in ''{2}''.
REGISTRY_FAILED_INTERFACE_ASSIGNMENT=Unable to assign the class ''{0}'' declared for the extension point ''{1}'' in the plug-in ''{2}'' to the interface ''{3}''.
REGISTRY_FAILED_INSTANTIATION=Unable to instantiate the class ''{0}'' declared for the extension point ''{1}'' in the plug-in ''{2}''.
+USER_LIBRARY_VALIDATOR__CLASS_NOT_FOUND=The class ''{0}'' is required to be in the selected libraries.
VALIDATE_CONTAINER_NOT_SPECIFIED=Parent folder must be specified
VALIDATE_FILE_NAME_NOT_SPECIFIED=File name must be specified
VALIDATE_FILE_ALREADY_EXISTS=File already exist \ No newline at end of file
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/JptCommonCoreMessages.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/JptCommonCoreMessages.java
index 3b43e56034..5a7511d6e9 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/JptCommonCoreMessages.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/JptCommonCoreMessages.java
@@ -27,6 +27,7 @@ public class JptCommonCoreMessages {
public static String REGISTRY_FAILED_CLASS_LOAD;
public static String REGISTRY_FAILED_INTERFACE_ASSIGNMENT;
public static String REGISTRY_FAILED_INSTANTIATION;
+ public static String USER_LIBRARY_VALIDATOR__CLASS_NOT_FOUND;;
public static String VALIDATE_CONTAINER_NOT_SPECIFIED;
public static String VALIDATE_FILE_NAME_NOT_SPECIFIED;
public static String VALIDATE_FILE_ALREADY_EXISTS;
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libval/LibValUtil.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libval/LibValUtil.java
new file mode 100644
index 0000000000..34afb0c83b
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libval/LibValUtil.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Oracle. 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 - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.common.core.internal.libval;
+
+import static org.eclipse.jst.common.project.facet.core.internal.FacetedProjectFrameworkJavaPlugin.PLUGIN_ID;
+import java.io.File;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jpt.common.core.internal.JptCommonCoreMessages;
+import org.eclipse.osgi.util.NLS;
+
+
+public class LibValUtil {
+
+ public static IStatus validate(Iterable<IPath> libraryPaths, Set<String> classNames) {
+ Set<String> classFileNames = new HashSet<String>();
+ Map<String,String> classFileNameToClassName = new HashMap<String,String>();
+ for (String className : classNames) {
+ String classFileName = className.replace('.', '/') + ".class"; //$NON-NLS-1$
+ classFileNames.add(classFileName);
+ classFileNameToClassName.put(classFileName, className);
+ }
+
+ final Map<String,Integer> classAppearanceCounts = new HashMap<String,Integer>();
+
+ for (String classFileName : classFileNames) {
+ classAppearanceCounts.put(classFileName, 0);
+ }
+
+ for (IPath libraryPath : libraryPaths) {
+ final File file = libraryPath.toFile();
+
+ if (file.exists()) {
+ ZipFile zip = null;
+
+ try {
+ zip = new ZipFile(file);
+
+ for (Enumeration<? extends ZipEntry> itr = zip.entries(); itr.hasMoreElements(); ) {
+ final ZipEntry zipEntry = itr.nextElement();
+ final String name = zipEntry.getName();
+
+ Integer count = classAppearanceCounts.get(name);
+
+ if (count != null) {
+ classAppearanceCounts.put(name, count + 1);
+ }
+ }
+ }
+ catch (IOException e) {}
+ finally {
+ if (zip != null) {
+ try {
+ zip.close();
+ }
+ catch (IOException e) {}
+ }
+ }
+ }
+ }
+
+ for (Map.Entry<String,Integer> entry : classAppearanceCounts.entrySet()) {
+ final int count = entry.getValue();
+
+ if (count == 0) {
+ final String classFileName = entry.getKey();
+ final String className = classFileNameToClassName.get(classFileName);
+ final String message =
+ NLS.bind(JptCommonCoreMessages.USER_LIBRARY_VALIDATOR__CLASS_NOT_FOUND, className);
+ return new Status(IStatus.ERROR, PLUGIN_ID, message);
+ }
+ }
+
+ return Status.OK_STATUS;
+ }
+}

Back to the top