| /******************************************************************************* |
| * Copyright (c) 2014-2015 Red Hat Inc., and others |
| * 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 API and implementation |
| ******************************************************************************/ |
| package org.eclipse.ui.internal.wizards.datatransfer; |
| |
| import java.io.File; |
| import java.util.Collections; |
| import java.util.HashSet; |
| import java.util.Set; |
| |
| import org.eclipse.core.resources.IContainer; |
| import org.eclipse.core.resources.IFolder; |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.resources.IProjectDescription; |
| import org.eclipse.core.resources.IResource; |
| 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.Path; |
| import org.eclipse.core.runtime.Status; |
| import org.eclipse.jface.wizard.IWizard; |
| import org.eclipse.ui.wizards.datatransfer.ProjectConfigurator; |
| |
| public class EclipseProjectConfigurator implements ProjectConfigurator { |
| |
| @Override |
| public Set<File> findConfigurableLocations(File root, IProgressMonitor monitor) { |
| HashSet<File> res = new HashSet<>(); |
| collectProjectDirectories(res, root, monitor); |
| return res; |
| } |
| |
| private void collectProjectDirectories(HashSet<File> res, File root, IProgressMonitor monitor) { |
| if (new File(root, IProjectDescription.DESCRIPTION_FILE_NAME).isFile()) { |
| res.add(root); |
| } |
| if (!monitor.isCanceled()) { |
| for (File child : root.listFiles()) { |
| if (child.isDirectory()) { |
| collectProjectDirectories(res, child, monitor); |
| } |
| } |
| } |
| } |
| |
| @Override |
| public boolean shouldBeAnEclipseProject(IContainer container, IProgressMonitor monitor) { |
| return container.getFile(new Path(IProjectDescription.DESCRIPTION_FILE_NAME)).exists(); |
| } |
| |
| @Override |
| public Set<IFolder> getDirectoriesToIgnore(IProject project, IProgressMonitor monitor) { |
| return null; |
| } |
| |
| @Override |
| public boolean canConfigure(IProject project, Set<IPath> ignoredPaths, IProgressMonitor monitor) { |
| return true; |
| } |
| |
| @Override |
| public IWizard getConfigurationWizard() { |
| return null; |
| } |
| |
| @Override |
| public void configure(IProject project, Set<IPath> excludedDirectories, IProgressMonitor monitor) { |
| try { |
| project.refreshLocal(IResource.DEPTH_INFINITE, monitor); |
| } catch (CoreException ex) { |
| Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), ex.getMessage(), ex)); |
| } |
| } |
| |
| } |