diff options
author | pfullbright | 2011-02-10 16:38:16 +0000 |
---|---|---|
committer | pfullbright | 2011-02-10 16:38:16 +0000 |
commit | 6de8839b3e12fe0a98160e586e20ad1b5095528e (patch) | |
tree | 1dbb2ba78da43929b2715319d00fbc021835c157 /common | |
parent | cf55637525917a2b9fb420fd459c3d2bfbbeb671 (diff) | |
download | webtools.dali-6de8839b3e12fe0a98160e586e20ad1b5095528e.tar.gz webtools.dali-6de8839b3e12fe0a98160e586e20ad1b5095528e.tar.xz webtools.dali-6de8839b3e12fe0a98160e586e20ad1b5095528e.zip |
moved eclipselink version validation to common.eclipselink.core
Diffstat (limited to 'common')
8 files changed, 233 insertions, 1 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.eclipselink.core/.classpath b/common/plugins/org.eclipse.jpt.common.eclipselink.core/.classpath index 56a95d68f1..934fb38085 100644 --- a/common/plugins/org.eclipse.jpt.common.eclipselink.core/.classpath +++ b/common/plugins/org.eclipse.jpt.common.eclipselink.core/.classpath @@ -1,5 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="property_files"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"> <accessrules> diff --git a/common/plugins/org.eclipse.jpt.common.eclipselink.core/META-INF/MANIFEST.MF b/common/plugins/org.eclipse.jpt.common.eclipselink.core/META-INF/MANIFEST.MF index 098e210a38..96ee6c28a2 100644 --- a/common/plugins/org.eclipse.jpt.common.eclipselink.core/META-INF/MANIFEST.MF +++ b/common/plugins/org.eclipse.jpt.common.eclipselink.core/META-INF/MANIFEST.MF @@ -4,7 +4,16 @@ Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.jpt.common.eclipselink.core;singleton:=true Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.eclipse.jpt.common.eclipselink.core.JptCommonEclipseLinkCorePlugin +Bundle-ActivationPolicy: lazy +Bundle-ClassPath: . Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: J2SE-1.5 Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.7.0,4.0.0)", + org.eclipse.jdt.core;bundle-version="[3.7.0,4.0.0)", + org.eclipse.jpt.common.utility;bundle-version="[2.0.0,3.0.0)", org.eclipse.jst.common.project.facet.core;bundle-version="[1.4.200,2.0.0)" +Export-Package: org.eclipse.jpt.common.eclipselink.core, + org.eclipse.jpt.common.eclipselink.core.internal, + org.eclipse.jpt.common.eclipselink.core.internal.libval; + x-friends:="org.eclipse.jpt.jpa.eclipselink.core" diff --git a/common/plugins/org.eclipse.jpt.common.eclipselink.core/build.properties b/common/plugins/org.eclipse.jpt.common.eclipselink.core/build.properties index ccd428d609..fad3689f9d 100644 --- a/common/plugins/org.eclipse.jpt.common.eclipselink.core/build.properties +++ b/common/plugins/org.eclipse.jpt.common.eclipselink.core/build.properties @@ -9,7 +9,8 @@ ################################################################################ javacSource=1.5 javacTarget=1.5 -source.. = src/ +source.. = src/,\ + property_files/ output.. = bin/ bin.includes = .,\ META-INF/,\ diff --git a/common/plugins/org.eclipse.jpt.common.eclipselink.core/property_files/jpt_common_eclipselink_core.properties b/common/plugins/org.eclipse.jpt.common.eclipselink.core/property_files/jpt_common_eclipselink_core.properties new file mode 100644 index 0000000000..a0173b3f3b --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.eclipselink.core/property_files/jpt_common_eclipselink_core.properties @@ -0,0 +1,13 @@ +################################################################################ +# Copyright (c) 2010 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 +################################################################################ + +EclipseLinkLibraryValidator_noEclipseLinkVersion=Selected libraries do not include required EclipseLink annotation classes. +EclipseLinkLibraryValidator_multipleEclipseLinkVersions=There are multiple versions of EclipseLink in selected libraries. +EclipseLinkLibraryValidator_improperEclipseLinkVersion=EclipseLink version does not meet platform requirements. diff --git a/common/plugins/org.eclipse.jpt.common.eclipselink.core/src/org/eclipse/jpt/common/eclipselink/core/JptCommonEclipseLinkCorePlugin.java b/common/plugins/org.eclipse.jpt.common.eclipselink.core/src/org/eclipse/jpt/common/eclipselink/core/JptCommonEclipseLinkCorePlugin.java new file mode 100644 index 0000000000..60cb45646a --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.eclipselink.core/src/org/eclipse/jpt/common/eclipselink/core/JptCommonEclipseLinkCorePlugin.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * 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.eclipselink.core; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; +import org.osgi.framework.BundleContext; + + +public class JptCommonEclipseLinkCorePlugin + extends Plugin { + + // ********** public constants ********** + + /** + * The plug-in identifier of the jpt common core support + * (value <code>"org.eclipse.jpt.common.core"</code>). + */ + public static final String PLUGIN_ID = "org.eclipse.jpt.common.eclipselink.core"; //$NON-NLS-1$ + public static final String PLUGIN_ID_ = PLUGIN_ID + '.'; + + + // ********** singleton ********** + + private static JptCommonEclipseLinkCorePlugin INSTANCE; + + /** + * Return the singleton jpt common eclipselink core plug-in. + */ + public static JptCommonEclipseLinkCorePlugin instance() { + return INSTANCE; + } + + + // ********** public static methods ********** + + /** + * Log the specified status. + */ + public static void log(IStatus status) { + INSTANCE.getLog().log(status); + } + + /** + * Log the specified message. + */ + public static void log(String msg) { + log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, msg, null)); + } + + /** + * Log the specified exception or error. + */ + public static void log(Throwable throwable) { + log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, throwable.getLocalizedMessage(), throwable)); + } + + + // ********** plug-in implementation ********** + + public JptCommonEclipseLinkCorePlugin() { + super(); + if (INSTANCE != null) { + throw new IllegalStateException(); + } + // this convention is *wack*... ~bjv + INSTANCE = this; + } + + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + // nothing yet... + } + + @Override + public void stop(BundleContext context) throws Exception { + super.stop(context); + // nothing yet... + } +} diff --git a/common/plugins/org.eclipse.jpt.common.eclipselink.core/src/org/eclipse/jpt/common/eclipselink/core/internal/JptCommonEclipseLinkCoreMessages.java b/common/plugins/org.eclipse.jpt.common.eclipselink.core/src/org/eclipse/jpt/common/eclipselink/core/internal/JptCommonEclipseLinkCoreMessages.java new file mode 100644 index 0000000000..3489feb18f --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.eclipselink.core/src/org/eclipse/jpt/common/eclipselink/core/internal/JptCommonEclipseLinkCoreMessages.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * 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.eclipselink.core.internal; + +import org.eclipse.osgi.util.NLS; + +public class JptCommonEclipseLinkCoreMessages { + + public static String EclipseLinkLibraryValidator_noEclipseLinkVersion; + public static String EclipseLinkLibraryValidator_multipleEclipseLinkVersions; + public static String EclipseLinkLibraryValidator_improperEclipseLinkVersion; + + + private static final String BUNDLE_NAME = "jpt_common_eclipselink_core"; //$NON-NLS-1$ + + private static final Class<?> BUNDLE_CLASS = JptCommonEclipseLinkCoreMessages.class; + + static { + NLS.initializeMessages(BUNDLE_NAME, BUNDLE_CLASS); + } + + private JptCommonEclipseLinkCoreMessages() { + throw new UnsupportedOperationException(); + } +} diff --git a/common/plugins/org.eclipse.jpt.common.eclipselink.core/src/org/eclipse/jpt/common/eclipselink/core/internal/libval/EclipseLinkLibValUtil.java b/common/plugins/org.eclipse.jpt.common.eclipselink.core/src/org/eclipse/jpt/common/eclipselink/core/internal/libval/EclipseLinkLibValUtil.java new file mode 100644 index 0000000000..1ad52aba44 --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.eclipselink.core/src/org/eclipse/jpt/common/eclipselink/core/internal/libval/EclipseLinkLibValUtil.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * 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.eclipselink.core.internal.libval; + +import java.util.Set; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.util.IClassFileReader; +import org.eclipse.jdt.core.util.IFieldInfo; +import org.eclipse.jpt.common.eclipselink.core.JptCommonEclipseLinkCorePlugin; +import org.eclipse.jpt.common.eclipselink.core.internal.JptCommonEclipseLinkCoreMessages; +import org.eclipse.jpt.common.utility.internal.StringTools; +import org.eclipse.osgi.service.resolver.VersionRange; +import org.osgi.framework.Version; + + +public class EclipseLinkLibValUtil { + + private final static String VERSION_CLASS_PATH = "org/eclipse/persistence/Version.class"; //$NON-NLS-1$ + + private final static String VERSION_FIELD_NAME = "version"; //$NON-NLS-1$ + + + public static IStatus validate(Iterable<IClasspathEntry> libraryEntries, Set<VersionRange> versionRanges) { + Version version = null; + for (IClasspathEntry entry : libraryEntries) { + String versionString = null; + if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { + IClassFileReader classReader = + ToolFactory.createDefaultClassFileReader( + entry.getPath().toFile().getAbsolutePath(), VERSION_CLASS_PATH, IClassFileReader.FIELD_INFOS); + if (classReader != null) { + for (IFieldInfo field : classReader.getFieldInfos()) { + if (StringTools.stringsAreEqual(field.getName(), VERSION_FIELD_NAME.toCharArray())) { + try { + versionString = field.getConstantValueAttribute().getConstantValue().getStringValue(); + } + catch (Exception e) { + // potentially a bit could go wrong with that last line, but if any + // assumptions aren't met, there's no value + } + break; + } + } + } + if (versionString != null) { + if (version != null) { + return new Status( + IStatus.ERROR, JptCommonEclipseLinkCorePlugin.PLUGIN_ID, + JptCommonEclipseLinkCoreMessages.EclipseLinkLibraryValidator_multipleEclipseLinkVersions); + } + else { + version = new Version(versionString); + } + } + } + } + + if (version == null) { + return new Status( + IStatus.ERROR, JptCommonEclipseLinkCorePlugin.PLUGIN_ID, + JptCommonEclipseLinkCoreMessages.EclipseLinkLibraryValidator_noEclipseLinkVersion); + } + + for (VersionRange versionRange : versionRanges) { + if (! versionRange.isIncluded(version)) { + return new Status( + IStatus.ERROR, JptCommonEclipseLinkCorePlugin.PLUGIN_ID, + JptCommonEclipseLinkCoreMessages.EclipseLinkLibraryValidator_improperEclipseLinkVersion); + } + } + + return Status.OK_STATUS; + } +} diff --git a/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF b/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF index 3b17d42b88..2e8e2d8d0a 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF +++ b/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF @@ -10,6 +10,7 @@ Export-Package: org.eclipse.jpt.common.utility, org.eclipse.jpt.common.utility.internal; x-friends:="org.eclipse.jpt.jpa.core, org.eclipse.jpt.common.core, + org.eclipse.jpt.common.eclipselink.core, org.eclipse.jpt.common.ui, org.eclipse.jpt.jaxb.core, org.eclipse.jpt.jaxb.ui, |