Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Vosburgh2013-01-11 19:15:26 +0000
committerBrian Vosburgh2013-01-11 19:15:26 +0000
commit4618c40bf1d2e0a440c63f86667e4c0288f51614 (patch)
tree3929c01f9a65f19aa4b040893d8c2c948886fbd0
parenta325faa745ed97124f6a9f54e5fbfb3b00bcea1f (diff)
downloadwebtools.dali-4618c40bf1d2e0a440c63f86667e4c0288f51614.tar.gz
webtools.dali-4618c40bf1d2e0a440c63f86667e4c0288f51614.tar.xz
webtools.dali-4618c40bf1d2e0a440c63f86667e4c0288f51614.zip
tweak the JAXB facet version constants again
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libval/LibraryValidatorTools.java10
-rw-r--r--common/plugins/org.eclipse.jpt.common.eclipselink.core/src/org/eclipse/jpt/common/eclipselink/core/internal/libval/EclipseLinkLibraryValidatorTools.java5
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbProject.java25
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/GenericJaxbUserLibraryValidator.java9
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbJreLibraryValidator.java7
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbLibValUtil.java170
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbLibraryValidatorTools.java184
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbTestCase.java3
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbContextModelTestCase.java4
9 files changed, 209 insertions, 208 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libval/LibraryValidatorTools.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libval/LibraryValidatorTools.java
index 83abed1838..132d801b0e 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libval/LibraryValidatorTools.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libval/LibraryValidatorTools.java
@@ -22,14 +22,17 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jpt.common.core.internal.JptCommonCoreMessages;
import org.eclipse.jpt.common.core.internal.plugin.JptCommonCorePlugin;
+import org.eclipse.jpt.common.core.libprov.JptLibraryProviderInstallOperationConfig;
import org.eclipse.jpt.common.utility.internal.collection.CollectionTools;
import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable;
import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter;
import org.eclipse.jpt.common.utility.transformer.Transformer;
+import org.eclipse.jst.common.project.facet.core.JavaFacet;
import org.eclipse.jst.common.project.facet.core.libprov.osgi.BundleReference;
import org.eclipse.jst.common.project.facet.core.libprov.osgi.OsgiBundlesLibraryProviderInstallOperationConfig;
import org.eclipse.jst.common.project.facet.core.libprov.user.UserLibraryProviderInstallOperationConfig;
import org.eclipse.osgi.service.resolver.VersionRange;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.osgi.framework.Bundle;
import org.osgi.framework.Version;
@@ -161,6 +164,13 @@ public class LibraryValidatorTools {
// ********** misc **********
+ /**
+ * Return the specified config's Java facet version.
+ */
+ public static IProjectFacetVersion getJavaFacetVersion(JptLibraryProviderInstallOperationConfig config) {
+ return config.getFacetedProject().getProjectFacetVersion(JavaFacet.FACET);
+ }
+
private static IStatus buildErrorStatus(String message, Object... args) {
return JptCommonCorePlugin.instance().buildErrorStatus(message, args);
}
diff --git a/common/plugins/org.eclipse.jpt.common.eclipselink.core/src/org/eclipse/jpt/common/eclipselink/core/internal/libval/EclipseLinkLibraryValidatorTools.java b/common/plugins/org.eclipse.jpt.common.eclipselink.core/src/org/eclipse/jpt/common/eclipselink/core/internal/libval/EclipseLinkLibraryValidatorTools.java
index 7680901d04..6d4b6ec0b5 100644
--- a/common/plugins/org.eclipse.jpt.common.eclipselink.core/src/org/eclipse/jpt/common/eclipselink/core/internal/libval/EclipseLinkLibraryValidatorTools.java
+++ b/common/plugins/org.eclipse.jpt.common.eclipselink.core/src/org/eclipse/jpt/common/eclipselink/core/internal/libval/EclipseLinkLibraryValidatorTools.java
@@ -29,8 +29,9 @@ import org.osgi.framework.Version;
public class EclipseLinkLibraryValidatorTools {
/**
- * Validate that the version of EclipseLink on the specified config's
- * library classpath is within the specified version range.
+ * Validate that there is a one and only one occurrence of EclipseLink
+ * on the specified config's library classpath and that its version
+ * is within the specified version range.
*/
public static IStatus validateEclipseLinkVersion(UserLibraryProviderInstallOperationConfig config, VersionRange versionRange) {
return validateEclipseLinkVersion(config.resolve(), versionRange);
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbProject.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbProject.java
index 33ce132436..3bafbdf752 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbProject.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbProject.java
@@ -30,7 +30,6 @@ import org.eclipse.jpt.jaxb.core.resource.jaxbprops.JaxbPropertiesResource;
import org.eclipse.jpt.jaxb.core.utility.CallbackSynchronizer;
import org.eclipse.jpt.jaxb.core.utility.Synchronizer;
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
-import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -70,30 +69,6 @@ public interface JaxbProject
*/
IProjectFacet FACET = ProjectFacetsManager.getProjectFacet(FACET_ID);
- /**
- * The JAXB project facet version string 2.1.
- * <p>
- * Value: {@value}
- */
- String FACET_VERSION_STRING_2_1 = "2.1"; //$NON-NLS-1$
-
- /**
- * The JAXB project facet version 2.1.
- */
- IProjectFacetVersion FACET_VERSION_2_1 = FACET.getVersion(FACET_VERSION_STRING_2_1);
-
- /**
- * The JAXB project facet version string 2.2.
- * <p>
- * Value: {@value}
- */
- String FACET_VERSION_STRING_2_2 = "2.2"; //$NON-NLS-1$
-
- /**
- * The JAXB project facet version 2.2.
- */
- IProjectFacetVersion FACET_VERSION_2_2 = FACET.getVersion(FACET_VERSION_STRING_2_2);
-
// ********** general **********
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/GenericJaxbUserLibraryValidator.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/GenericJaxbUserLibraryValidator.java
index a9c29ccdf2..f3e370bb3d 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/GenericJaxbUserLibraryValidator.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/GenericJaxbUserLibraryValidator.java
@@ -16,7 +16,6 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.jpt.common.core.internal.libval.LibraryValidatorTools;
import org.eclipse.jpt.common.core.libprov.JptLibraryProviderInstallOperationConfig;
import org.eclipse.jpt.common.core.libval.LibraryValidator;
-import org.eclipse.jpt.jaxb.core.JaxbProject;
import org.eclipse.jpt.jaxb.core.internal.JptJaxbCoreMessages;
import org.eclipse.jpt.jaxb.core.internal.libprov.JaxbUserLibraryProviderInstallOperationConfig;
import org.eclipse.jpt.jaxb.core.internal.plugin.JptJaxbCorePlugin;
@@ -31,13 +30,13 @@ public class GenericJaxbUserLibraryValidator
= (JaxbUserLibraryProviderInstallOperationConfig) config;
IProjectFacetVersion jaxbVersion = config.getProjectFacetVersion();
- IProjectFacetVersion javaVersion = JaxbLibValUtil.getJavaVersion(jaxbConfig);
- IProjectFacetVersion javaJaxbVersion = JaxbLibValUtil.findJavaJaxbVersion(jaxbConfig);
+ IProjectFacetVersion javaVersion = LibraryValidatorTools.getJavaFacetVersion(jaxbConfig);
+ IProjectFacetVersion javaJaxbVersion = JaxbLibraryValidatorTools.findJavaJaxbVersion(jaxbConfig);
// dev-time portion of validation - error if actual java library *conflicts with* jaxb facet
// or if library does not provide supplemental classes
- IProjectFacetVersion jreJaxbVersion = JaxbLibValUtil.findJreJaxbVersion(jaxbConfig);
+ IProjectFacetVersion jreJaxbVersion = JaxbLibraryValidatorTools.findJreJaxbVersion(jaxbConfig);
// null here implies something prior to jaxb 2.1
if (jreJaxbVersion != null) {
@@ -50,7 +49,7 @@ public class GenericJaxbUserLibraryValidator
Set<String> classNames = new HashSet<String>();
classNames.add("javax.xml.bind.annotation.XmlSeeAlso"); //$NON-NLS-1$
- if (jaxbVersion.compareTo(JaxbProject.FACET_VERSION_2_2) >= 0) {
+ if (jaxbVersion.compareTo(JaxbLibraryValidatorTools.FACET_VERSION_2_2) >= 0) {
classNames.add("javax.xml.bind.JAXBPermission"); //$NON-NLS-1$
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbJreLibraryValidator.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbJreLibraryValidator.java
index c8954fad89..7d153b9121 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbJreLibraryValidator.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbJreLibraryValidator.java
@@ -11,6 +11,7 @@ package org.eclipse.jpt.jaxb.core.internal.libval;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jpt.common.core.internal.libval.LibraryValidatorTools;
import org.eclipse.jpt.common.core.libprov.JptLibraryProviderInstallOperationConfig;
import org.eclipse.jpt.common.core.libval.LibraryValidator;
import org.eclipse.jpt.jaxb.core.internal.GenericJaxbPlatformDefinition;
@@ -33,12 +34,12 @@ public class JaxbJreLibraryValidator
}
IProjectFacetVersion jaxbVersion = config.getProjectFacetVersion();
- IProjectFacetVersion javaVersion = JaxbLibValUtil.getJavaVersion(jaxbConfig);
- IProjectFacetVersion javaJaxbVersion = JaxbLibValUtil.findJavaJaxbVersion(jaxbConfig);
+ IProjectFacetVersion javaVersion = LibraryValidatorTools.getJavaFacetVersion(jaxbConfig);
+ IProjectFacetVersion javaJaxbVersion = JaxbLibraryValidatorTools.findJavaJaxbVersion(jaxbConfig);
// dev-time portion of validation - error if actual java library does not support jaxb facet
- IProjectFacetVersion jreJaxbVersion = JaxbLibValUtil.findJreJaxbVersion(jaxbConfig);
+ IProjectFacetVersion jreJaxbVersion = JaxbLibraryValidatorTools.findJreJaxbVersion(jaxbConfig);
// null here implies something prior to jaxb 2.1
if (jreJaxbVersion == null || jreJaxbVersion.compareTo(jaxbVersion) < 0) {
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbLibValUtil.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbLibValUtil.java
deleted file mode 100644
index ad971ce84f..0000000000
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbLibValUtil.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2013 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.jaxb.core.internal.libval;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.zip.ZipFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.launching.IVMInstall;
-import org.eclipse.jdt.launching.IVMInstall2;
-import org.eclipse.jdt.launching.IVMInstallType;
-import org.eclipse.jdt.launching.JavaRuntime;
-import org.eclipse.jdt.launching.LibraryLocation;
-import org.eclipse.jpt.common.utility.internal.iterable.ArrayIterable;
-import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable;
-import org.eclipse.jpt.jaxb.core.JaxbProject;
-import org.eclipse.jpt.jaxb.core.libprov.JaxbLibraryProviderInstallOperationConfig;
-import org.eclipse.jst.common.project.facet.core.JavaFacet;
-import org.eclipse.jst.common.project.facet.core.StandardJreRuntimeComponent;
-import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
-import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
-import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponent;
-
-
-public class JaxbLibValUtil {
-
- static IProjectFacetVersion getJavaVersion(JaxbLibraryProviderInstallOperationConfig config) {
- return config.getFacetedProject().getProjectFacetVersion(JavaFacet.FACET);
- }
-
- /**
- * Return jaxb version determined by java facet version.
- * Assume highest update of java (i.e. java 1.6 maps to jaxb 2.1)
- */
- static IProjectFacetVersion findJavaJaxbVersion(JaxbLibraryProviderInstallOperationConfig config) {
- IProjectFacetVersion javaVersion = getJavaVersion(config);
-
- if (javaVersion == JavaFacet.VERSION_1_6) {
- return JaxbProject.FACET_VERSION_2_1;
- }
- else if (javaVersion == JavaFacet.VERSION_1_7) {
- return JaxbProject.FACET_VERSION_2_2;
- }
-
- return null;
- }
-
- static IProjectFacetVersion findJreJaxbVersion(JaxbLibraryProviderInstallOperationConfig config) {
- IRuntime runtime = config.getFacetedProject().getPrimaryRuntime();
-
- if (runtime != null) {
- for (IRuntimeComponent rc : runtime.getRuntimeComponents()) {
- IVMInstall vm = findVMInstall(rc);
- if (vm != null) {
- return findJreJaxbVersion(vm);
- }
- }
- }
-
- IVMInstall vm = JavaRuntime.getDefaultVMInstall();
-
- IJavaProject javaProject = JavaCore.create(config.getFacetedProject().getProject());
- if (javaProject != null) {
- try {
- vm = JavaRuntime.getVMInstall(javaProject);
- }
- catch (CoreException ce) {
- // do nothing, just use the default install
- }
- }
-
- if (vm != null) {
- return findJreJaxbVersion(vm);
- }
-
- return null;
- }
-
- private static IVMInstall findVMInstall(IRuntimeComponent rc) {
- String vmInstallTypeId
- = rc.getProperty(StandardJreRuntimeComponent.PROP_VM_INSTALL_TYPE);
- String vmInstallId
- = rc.getProperty(StandardJreRuntimeComponent.PROP_VM_INSTALL_ID);
-
- if (vmInstallTypeId == null || vmInstallId == null) {
- return null;
- }
-
- IVMInstallType vmInstallType = JavaRuntime.getVMInstallType(vmInstallTypeId);
-
- if( vmInstallType == null ) {
- return null;
- }
-
- return vmInstallType.findVMInstall(vmInstallId);
- }
-
- private static IProjectFacetVersion findJreJaxbVersion(IVMInstall vm) {
- if (vm instanceof IVMInstall2) {
- String javaVersion = ((IVMInstall2) vm).getJavaVersion();
- if (javaVersion != null) {
- // all other versions except 1.7 and 1.6 have no corresponding version (as of yet)
- if (javaVersion.startsWith(JavaCore.VERSION_1_7)) {
- return JaxbProject.FACET_VERSION_2_2;
- }
- // 1.6 must be further analyzed
- if (! javaVersion.startsWith(JavaCore.VERSION_1_6)) {
- return null;
- }
- }
- }
-
- Iterable<IPath> vmLibPaths
- = new TransformationIterable<LibraryLocation, IPath>(
- new ArrayIterable<LibraryLocation>(JavaRuntime.getLibraryLocations(vm))) {
- @Override
- protected IPath transform(LibraryLocation o) {
- return o.getSystemLibraryPath();
- }
- };
-
- boolean foundXmlSeeAlso = false; // marker for jaxb 2.1 +
- boolean foundJAXBPermission = false; // marker for jaxb 2.2 +
-
- for (IPath vmLibPath : vmLibPaths) {
- File file = vmLibPath.toFile();
-
- if (file.exists()) {
- ZipFile zip = null;
-
- try {
- zip = new ZipFile(file);
-
- foundXmlSeeAlso |= zip.getEntry("javax/xml/bind/annotation/XmlSeeAlso.class") != null;
- foundJAXBPermission |= zip.getEntry("javax/xml/bind/JAXBPermission.class") != null;
-
- // short circuit for JAXB 2.2
- if (foundJAXBPermission) {
- return JaxbProject.FACET_VERSION_2_2;
- }
- }
- catch (IOException e) {}
- finally {
- if (zip != null) {
- try {
- zip.close();
- }
- catch (IOException e) {}
- }
- }
- }
- }
-
- if (foundXmlSeeAlso) {
- return JaxbProject.FACET_VERSION_2_1;
- }
-
- return null;
- }
-}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbLibraryValidatorTools.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbLibraryValidatorTools.java
new file mode 100644
index 0000000000..53cd6f73b6
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbLibraryValidatorTools.java
@@ -0,0 +1,184 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2013 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.jaxb.core.internal.libval;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.zip.ZipFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.launching.IVMInstall;
+import org.eclipse.jdt.launching.IVMInstall2;
+import org.eclipse.jdt.launching.IVMInstallType;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jdt.launching.LibraryLocation;
+import org.eclipse.jpt.common.core.internal.libval.LibraryValidatorTools;
+import org.eclipse.jpt.common.core.libprov.JptLibraryProviderInstallOperationConfig;
+import org.eclipse.jpt.common.utility.internal.iterable.ArrayIterable;
+import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable;
+import org.eclipse.jpt.jaxb.core.JaxbProject;
+import org.eclipse.jst.common.project.facet.core.JavaFacet;
+import org.eclipse.jst.common.project.facet.core.StandardJreRuntimeComponent;
+import org.eclipse.wst.common.project.facet.core.IFacetedProjectBase;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
+import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponent;
+
+/**
+ * JAXB
+ * {@link org.eclipse.jpt.common.core.libval.LibraryValidator} utility methods.
+ */
+public class JaxbLibraryValidatorTools {
+
+ /**
+ * The JAXB facet version string 2.1.
+ * <p>
+ * Value: {@value}
+ */
+ public static final String FACET_VERSION_STRING_2_1 = "2.1"; //$NON-NLS-1$
+
+ /**
+ * The JAXB facet version 2.1.
+ */
+ public static final IProjectFacetVersion FACET_VERSION_2_1 = JaxbProject.FACET.getVersion(FACET_VERSION_STRING_2_1);
+
+ /**
+ * The JAXB facet version string 2.2.
+ * <p>
+ * Value: {@value}
+ */
+ public static final String FACET_VERSION_STRING_2_2 = "2.2"; //$NON-NLS-1$
+
+ /**
+ * The JAXB facet version 2.2.
+ */
+ public static final IProjectFacetVersion FACET_VERSION_2_2 = JaxbProject.FACET.getVersion(FACET_VERSION_STRING_2_2);
+
+
+ /**
+ * Return the JAXB facet version corresponding to the specified config's
+ * Java facet version.
+ * Assume highest update of Java (e.g. Java 1.6 maps to JAXB 2.1)
+ */
+ public static IProjectFacetVersion findJavaJaxbVersion(JptLibraryProviderInstallOperationConfig config) {
+ IProjectFacetVersion javaVersion = LibraryValidatorTools.getJavaFacetVersion(config);
+
+ if (javaVersion == JavaFacet.VERSION_1_6) {
+ return FACET_VERSION_2_1;
+ }
+ if (javaVersion == JavaFacet.VERSION_1_7) {
+ return FACET_VERSION_2_2;
+ }
+
+ return null;
+ }
+
+ /**
+ * Return the JAXB facet version corresponding to the specified config's JRE.
+ */
+ public static IProjectFacetVersion findJreJaxbVersion(JptLibraryProviderInstallOperationConfig config) {
+ IVMInstall vmInstall = findVMInstall(config.getFacetedProject());
+ return (vmInstall == null) ? null : findJreJaxbVersion(vmInstall);
+ }
+
+ private static IVMInstall findVMInstall(IFacetedProjectBase facetedProject) {
+ IVMInstall vm = null;
+ IRuntime runtime = facetedProject.getPrimaryRuntime();
+ if (runtime != null) {
+ for (IRuntimeComponent rc : runtime.getRuntimeComponents()) {
+ vm = findVMInstall(rc);
+ if (vm != null) {
+ return vm;
+ }
+ }
+ }
+
+ IJavaProject javaProject = JavaCore.create(facetedProject.getProject());
+ if (javaProject != null) {
+ try {
+ vm = JavaRuntime.getVMInstall(javaProject);
+ } catch (CoreException ce) {
+ // do nothing, just use the default install
+ }
+ }
+ return (vm != null) ? vm : JavaRuntime.getDefaultVMInstall();
+ }
+
+ private static IVMInstall findVMInstall(IRuntimeComponent rc) {
+ String vmInstallTypeId = rc.getProperty(StandardJreRuntimeComponent.PROP_VM_INSTALL_TYPE);
+ if (vmInstallTypeId == null) {
+ return null;
+ }
+ String vmInstallId = rc.getProperty(StandardJreRuntimeComponent.PROP_VM_INSTALL_ID);
+ if (vmInstallId == null) {
+ return null;
+ }
+ IVMInstallType vmInstallType = JavaRuntime.getVMInstallType(vmInstallTypeId);
+ return (vmInstallType == null) ? null : vmInstallType.findVMInstall(vmInstallId);
+ }
+
+ private static IProjectFacetVersion findJreJaxbVersion(IVMInstall vm) {
+ if (vm instanceof IVMInstall2) {
+ String javaVersion = ((IVMInstall2) vm).getJavaVersion();
+ if (javaVersion != null) {
+ // all other versions except 1.7 and 1.6 have no corresponding version (as of yet)
+ if (javaVersion.startsWith(JavaCore.VERSION_1_7)) {
+ return FACET_VERSION_2_2;
+ }
+ // 1.6 must be further analyzed
+ if (! javaVersion.startsWith(JavaCore.VERSION_1_6)) {
+ return null;
+ }
+ }
+ }
+
+ boolean foundXmlSeeAlso = false; // marker for jaxb 2.1 +
+ for (IPath vmLibPath : buildLibraryPaths(vm)) {
+ File file = vmLibPath.toFile();
+ if (file.exists()) {
+ ZipFile zipFile = null;
+ try {
+ zipFile = new ZipFile(file);
+ if (zipFile.getEntry(JAXB_PERMISSION) != null) {
+ // short circuit for JAXB 2.2
+ return FACET_VERSION_2_2;
+ }
+ foundXmlSeeAlso |= (zipFile.getEntry(XML_SEE_ALSO) != null);
+ } catch (IOException ex) {
+ // ignore
+ } finally {
+ if (zipFile != null) {
+ try {
+ zipFile.close();
+ } catch (IOException ex) {
+ // ignore
+ }
+ }
+ }
+ }
+ }
+ return foundXmlSeeAlso ? FACET_VERSION_2_1 : null;
+ }
+
+ private static Iterable<IPath> buildLibraryPaths(IVMInstall vm) {
+ return new TransformationIterable<LibraryLocation, IPath>(
+ new ArrayIterable<LibraryLocation>(JavaRuntime.getLibraryLocations(vm))) {
+ @Override
+ protected IPath transform(LibraryLocation libraryLocation) {
+ return libraryLocation.getSystemLibraryPath();
+ }
+ };
+ }
+
+ private static final String XML_SEE_ALSO = "javax/xml/bind/annotation/XmlSeeAlso.class"; //$NON-NLS-1$
+ private static final String JAXB_PERMISSION = "javax/xml/bind/JAXBPermission.class"; //$NON-NLS-1$
+}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbTestCase.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbTestCase.java
index efd27a1687..18f886b02d 100644
--- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbTestCase.java
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbTestCase.java
@@ -18,6 +18,7 @@ import org.eclipse.jpt.jaxb.core.JaxbProject;
import org.eclipse.jpt.jaxb.core.JaxbWorkspace;
import org.eclipse.jpt.jaxb.core.internal.facet.JaxbFacetDataModelProperties;
import org.eclipse.jpt.jaxb.core.internal.facet.JaxbFacetInstallDataModelProvider;
+import org.eclipse.jpt.jaxb.core.internal.libval.JaxbLibraryValidatorTools;
import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformConfig;
import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformManager;
import org.eclipse.jpt.jaxb.core.tests.internal.projects.TestJaxbProject;
@@ -73,7 +74,7 @@ public class JaxbTestCase
}
protected IProjectFacetVersion getProjectFacetVersion() {
- return JaxbProject.FACET_VERSION_2_2;
+ return JaxbLibraryValidatorTools.FACET_VERSION_2_2;
}
@Override
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbContextModelTestCase.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbContextModelTestCase.java
index 79fc741f5c..845adc9255 100644
--- a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbContextModelTestCase.java
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbContextModelTestCase.java
@@ -9,7 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jaxb.eclipselink.core.tests.internal.context;
-import org.eclipse.jpt.jaxb.core.JaxbProject;
+import org.eclipse.jpt.jaxb.core.internal.libval.JaxbLibraryValidatorTools;
import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase;
import org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_1.ELJaxb_2_1_PlatformDefinition;
import org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_4.ELJaxb_2_4_PlatformDefinition;
@@ -25,7 +25,7 @@ public abstract class ELJaxbContextModelTestCase
@Override
protected String getPlatformID() {
- return this.getProjectFacetVersion().equals(JaxbProject.FACET_VERSION_2_1) ?
+ return this.getProjectFacetVersion().equals(JaxbLibraryValidatorTools.FACET_VERSION_2_1) ?
ELJaxb_2_1_PlatformDefinition.ID :
ELJaxb_2_4_PlatformDefinition.ID;
}

Back to the top