diff options
author | Brian Vosburgh | 2017-05-18 04:20:03 +0000 |
---|---|---|
committer | Brian Vosburgh | 2017-05-18 05:10:37 +0000 |
commit | 6262f79f0993c205ebac07d17a092d270c954e94 (patch) | |
tree | f3308c239e16bffa49492d0919344788bf58fbd8 | |
parent | 6e77c46aaa51b524ad4b815acb1358bd25c4e0ba (diff) | |
download | webtools.dali-6262f79f0993c205ebac07d17a092d270c954e94.tar.gz webtools.dali-6262f79f0993c205ebac07d17a092d270c954e94.tar.xz webtools.dali-6262f79f0993c205ebac07d17a092d270c954e94.zip |
[492323] add JPAProjectConfigurator
3 files changed, 112 insertions, 1 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.jpa.ui/META-INF/MANIFEST.MF index a030f2712f..3bd83dc0d5 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.ui/META-INF/MANIFEST.MF +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/META-INF/MANIFEST.MF @@ -34,7 +34,7 @@ Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)", org.eclipse.jst.j2ee;bundle-version="[1.1.200,2.0.0)", org.eclipse.jst.j2ee.ui;bundle-version="[1.1.200,2.0.0)", org.eclipse.persistence.jpa.jpql;bundle-version="[2.1.0,3.0.0)", - org.eclipse.ui.ide;bundle-version="[3.4.0,4.0.0)", + org.eclipse.ui.ide;bundle-version="[3.12.0,4.0.0)", org.eclipse.ui.views.properties.tabbed;bundle-version="[3.4.0,4.0.0)", org.eclipse.ui.navigator;bundle-version="[3.3.100,4.0.0)", org.eclipse.ui.navigator.resources;bundle-version="[3.3.100,4.0.0)", diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml b/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml index 1abe17c62e..26e5ebe2bd 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml @@ -1346,4 +1346,18 @@ </extension> + <extension + point="org.eclipse.ui.ide.projectConfigurators"> + + <projectConfigurator + class="org.eclipse.jpt.jpa.ui.internal.wizards.JPAProjectConfigurator" + label="JPA"> + <activeWhen> + <hasFileRecursively + filename="persistence.xml"> + </hasFileRecursively> + </activeWhen> + </projectConfigurator> + </extension> + </plugin> diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JPAProjectConfigurator.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JPAProjectConfigurator.java new file mode 100644 index 0000000000..f034f29275 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JPAProjectConfigurator.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2016 Red Hat Inc. + * 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: + * Mickael Istria (Red Hat Inc.) - initial implementation + ******************************************************************************/ +package org.eclipse.jpt.jpa.ui.internal.wizards; + +import java.io.File; +import java.io.InputStream; +import java.util.Collections; +import java.util.Set; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.wizard.IWizard; +import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetInstallDataModelProvider; +import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin; +import org.eclipse.jst.j2ee.project.facet.IJ2EEModuleFacetInstallDataModelProperties; +import org.eclipse.ui.wizards.datatransfer.ProjectConfigurator; +import org.eclipse.ui.wizards.datatransfer.RecursiveFileFinder; +import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; +import org.eclipse.wst.common.frameworks.datamodel.IDataModel; +import org.eclipse.wst.common.project.facet.core.IFacetedProject; +import org.eclipse.wst.common.project.facet.core.IProjectFacet; +import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; +import org.w3c.dom.Document; + +public class JPAProjectConfigurator implements ProjectConfigurator { + + @Override + public boolean canConfigure(IProject project, Set<IPath> ignoredDirectories, IProgressMonitor monitor) { + try { + RecursiveFileFinder finder = new RecursiveFileFinder("persistence.xml", ignoredDirectories); + project.accept(finder); + return finder.getFile() != null; + } catch (CoreException ex) { + return false; + } + } + + @Override + public void configure(IProject project, Set<IPath> ignoredDirectories, IProgressMonitor monitor) { + try { + IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor); + + IProjectFacet JPA_FACET = ProjectFacetsManager.getProjectFacet("jpt.jpa"); + if (!facetedProject.hasProjectFacet(JPA_FACET)) { + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + RecursiveFileFinder finder = new RecursiveFileFinder("persistence.xml", ignoredDirectories); + project.accept(finder); + InputStream webXmlStream = finder.getFile().getContents(); + Document doc = dBuilder.parse(webXmlStream); + webXmlStream.close(); + + IDataModel aFacetInstallDataModel = DataModelFactory.createDataModel(new JpaFacetInstallDataModelProvider()); + aFacetInstallDataModel.setBooleanProperty(IJ2EEModuleFacetInstallDataModelProperties.ADD_TO_EAR, false); + String version = doc.getElementById("persistence").getAttribute("version"); + facetedProject.installProjectFacet(JPA_FACET.getVersion(version), aFacetInstallDataModel, monitor); + } + } catch (Exception ex) { + JptJpaUiPlugin.instance().logError(ex); + } + } + + @Override + public boolean shouldBeAnEclipseProject(IContainer container, IProgressMonitor monitor) { + return false; // TODO can we make sure a given dir is actually a JPA project + } + + @Override + public Set<IFolder> getFoldersToIgnore(IProject project, IProgressMonitor monitor) { + return null; + } + + // TODO uncomment @Override when adopting newer Easymport + // @Override + public Set<File> findConfigurableLocations(File root, IProgressMonitor monitor) { + // No easy way to deduce project roots from jee files... + return Collections.emptySet(); + } + +} |