use of org.eclipse.ui.wizards.datatransfer.ImportOperation in project linuxtools by eclipse.
the class AbstractTest method createProject.
protected ICProject createProject(Bundle bundle, String projname) throws CoreException, URISyntaxException, IOException, InvocationTargetException, InterruptedException {
// Turn off auto-building
IWorkspace wsp = ResourcesPlugin.getWorkspace();
IWorkspaceDescription desc = wsp.getDescription();
desc.setAutoBuilding(false);
wsp.setDescription(desc);
ICProject proj = CProjectHelper.createCProject(projname, BIN_DIR);
URL location = FileLocator.find(bundle, new Path("resources/" + projname), // $NON-NLS-1$
null);
File testDir = new File(FileLocator.toFileURL(location).toURI());
IProject project = proj.getProject();
// Add these natures before project is imported due to #273079
ManagedCProjectNature.addManagedNature(project, null);
ScannerConfigNature.addScannerConfigNature(project);
ImportOperation op = new ImportOperation(project.getFullPath(), testDir, FileSystemStructureProvider.INSTANCE, pathString -> IOverwriteQuery.ALL);
op.setCreateContainerStructure(false);
op.run(null);
IStatus status = op.getStatus();
if (!status.isOK()) {
throw new CoreException(status);
}
// Index the project
IIndexManager indexManager = CCorePlugin.getIndexManager();
indexManager.reindex(proj);
indexManager.joinIndexer(IIndexManager.FOREVER, new NullProgressMonitor());
// These natures must be enabled at this point to continue
assertTrue(project.isNatureEnabled(ScannerConfigNature.NATURE_ID));
assertTrue(project.isNatureEnabled(ManagedCProjectNature.MNG_NATURE_ID));
return proj;
}
use of org.eclipse.ui.wizards.datatransfer.ImportOperation in project linuxtools by eclipse.
the class ProjectInitializationRule method getTargetWorkspaceProject.
/**
* Creates or opens the project in the target/JUnit workspace.
*
* @param projectSourcePath
* the absolute path to the project
* @param targetWorkspace
* the target workspace in which the project should be created
* @return the project
* @throws CoreException
* @throws InvocationTargetException
* @throws InterruptedException
*/
public static IProject getTargetWorkspaceProject(final IPath projectSourcePath, final IWorkspace targetWorkspace) throws CoreException, InvocationTargetException, InterruptedException {
final IPath dotProjectPath = projectSourcePath.addTrailingSeparator().append(".project");
final IProjectDescription description = targetWorkspace.loadProjectDescription(dotProjectPath);
final String projectName = description.getName();
final IProject project = targetWorkspace.getRoot().getProject(projectName);
if (project.exists() && !targetWorkspace.getRoot().getFile(project.getFile(".project").getFullPath()).exists()) {
project.delete(true, null);
} else if (project.exists() && !project.isOpen()) {
project.open(null);
} else if (!project.exists()) {
createProject(description, projectName, targetWorkspace, project);
final SyncFileSystemStructureProvider syncFileSystemStructureProvider = new SyncFileSystemStructureProvider.Builder(projectSourcePath, project.getLocation()).ignoreRelativeSourcePaths(".svn", ".git", "target", "bin").build();
final List<File> filesToImport = syncFileSystemStructureProvider.getChildren(projectSourcePath.toFile());
if (filesToImport != null && filesToImport.size() > 0) {
ImportOperation operation = new ImportOperation(project.getFullPath(), projectSourcePath.toFile(), syncFileSystemStructureProvider, pathString -> IOverwriteQuery.YES, filesToImport);
operation.setContext(null);
// need to overwrite modified files
operation.setOverwriteResources(true);
operation.setCreateContainerStructure(false);
operation.run(null);
}
}
return project;
}
use of org.eclipse.ui.wizards.datatransfer.ImportOperation in project knime-core by knime.
the class KnimeResourceUtil method importWorkflowIntoWorkspace.
/**
* Stores the flow in the archive in the local workspace.
*
* @param destination the name of the new workflow. Must denote a flow (if
* it exists it is overwritten).
* @param zippedWorkflow
* @throws IOException
* @throws ZipException
* @throws InterruptedException
* @throws InvocationTargetException
*/
private static void importWorkflowIntoWorkspace(final IPath destination, final File zippedWorkflow) throws ZipException, IOException, InvocationTargetException, InterruptedException {
ZipFile zFile = new ZipFile(zippedWorkflow);
ZipLeveledStructProvider importStructureProvider = new ZipLeveledStructProvider(zFile);
importStructureProvider.setStrip(1);
ZipEntry root = (ZipEntry) importStructureProvider.getRoot();
List<ZipEntry> rootChild = importStructureProvider.getChildren(root);
if (rootChild.size() == 1) {
// the zipped workflow normally contains only one dir
root = rootChild.get(0);
}
LOGGER.debug("Importing workflow. Destination:" + destination.toString());
try {
final ImportOperation iOper = new ImportOperation(destination, root, importStructureProvider, new IOverwriteQuery() {
@Override
public String queryOverwrite(final String pathString) {
return IOverwriteQuery.YES;
}
});
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
iOper.run(monitor);
}
});
} finally {
importStructureProvider.closeArchive();
}
}
use of org.eclipse.ui.wizards.datatransfer.ImportOperation in project knime-core by knime.
the class WorkflowImportOperation method handleCopyProject.
private ILeveledImportStructureProvider handleCopyProject(final IWorkflowImportElement importElement, final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
IPath destination = m_targetPath.append(importElement.getRenamedPath());
ImportOperation operation = null;
ILeveledImportStructureProvider provider = null;
if (importElement instanceof WorkflowImportElementFromFile) {
operation = createWorkflowFromFile((WorkflowImportElementFromFile) importElement, destination, new SubProgressMonitor(monitor, 1));
} else if (importElement instanceof WorkflowImportElementFromArchive) {
WorkflowImportElementFromArchive zip = (WorkflowImportElementFromArchive) importElement;
provider = zip.getProvider();
operation = createWorkflowFromArchive(zip, destination, new SubProgressMonitor(monitor, 1));
}
if (operation != null) {
operation.setContext(m_shell);
operation.setOverwriteResources(true);
operation.setCreateContainerStructure(false);
operation.run(monitor);
// if we created a project -> set the correct nature
if (Path.ROOT.equals(m_targetPath)) {
setProjectNature(importElement);
}
IResource newProject = ResourcesPlugin.getWorkspace().getRoot().findMember(destination);
if (newProject != null) {
newProject.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
monitor.worked(1);
}
return provider;
}
use of org.eclipse.ui.wizards.datatransfer.ImportOperation in project jbosstools-hibernate by jbosstools.
the class JavaProjectHelper method importFilesFromZip.
private static void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException {
ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(srcZipFile);
try {
ImportOperation op = new ImportOperation(destPath, structureProvider.getRoot(), structureProvider, new ImportOverwriteQuery());
op.run(monitor);
} catch (InterruptedException e) {
// should not happen
}
}
Aggregations