use of org.eclipse.ui.wizards.datatransfer.RecursiveFileFinder in project jbosstools-hibernate by jbosstools.
the class JPAProjectConfigurator method configure.
@Override
public void configure(IProject project, Set<IPath> ignoredDirectories, IProgressMonitor monitor) {
try {
IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor);
// $NON-NLS-1$
IProjectFacet JPA_FACET = ProjectFacetsManager.getProjectFacet("jpt.jpa");
if (!facetedProject.hasProjectFacet(JPA_FACET)) {
Set<Action> actions = new LinkedHashSet<>(2, 1);
IProjectFacetVersion javaFv = JavaFacet.FACET.getVersion(JavaFacetUtil.getCompilerLevel(project));
if (!facetedProject.hasProjectFacet(JavaFacet.FACET)) {
actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, javaFv, null));
} else if (!facetedProject.hasProjectFacet(javaFv)) {
actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.VERSION_CHANGE, javaFv, null));
}
// $NON-NLS-1$
RecursiveFileFinder finder = new RecursiveFileFinder("persistence.xml", ignoredDirectories);
project.accept(finder);
PersistenceXmlResourceProvider provider = PersistenceXmlResourceProvider.getXmlResourceProvider(finder.getFile());
JptXmlResource jpaXmlResource = provider.getXmlResource();
IProjectFacetVersion version = null;
if (jpaXmlResource.getVersion() != null) {
version = JpaProject.FACET.getVersion(jpaXmlResource.getVersion());
}
if (version == null) {
version = JpaProject.FACET.getLatestVersion();
}
// use default
JpaPlatform platform = null;
// TODO improve platform detection
LibraryInstallDelegate libraryDelegate = new LibraryInstallDelegate(facetedProject, version);
// $NON-NLS-1$
ILibraryProvider libraryProvider = LibraryProviderFramework.getProvider("jpa-no-op-library-provider");
libraryDelegate.setLibraryProvider(libraryProvider);
IDataModel dm = DataModelFactory.createDataModel(new JpaFacetInstallDataModelProvider());
dm.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, version.getVersionString());
dm.setProperty(JpaFacetDataModelProperties.PLATFORM, platform);
dm.setProperty(JpaFacetInstallDataModelProperties.DISCOVER_ANNOTATED_CLASSES, true);
dm.setProperty(JpaFacetInstallDataModelProperties.LIBRARY_PROVIDER_DELEGATE, libraryDelegate);
actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, version, dm));
facetedProject.modify(actions, monitor);
}
} catch (Exception ex) {
HibernateJptUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, HibernateJptUIPlugin.PLUGIN_ID, ex.getMessage(), ex));
}
}
use of org.eclipse.ui.wizards.datatransfer.RecursiveFileFinder in project jbosstools-hibernate by jbosstools.
the class JPAProjectConfigurator method canConfigure.
@Override
public boolean canConfigure(IProject project, Set<IPath> ignoredDirectories, IProgressMonitor monitor) {
try {
// $NON-NLS-1$
RecursiveFileFinder finder = new RecursiveFileFinder("persistence.xml", ignoredDirectories);
project.accept(finder);
return finder.getFile() != null;
} catch (CoreException ex) {
return false;
}
}
Aggregations