Search in sources :

Example 1 with ImportOperation

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) ICProject(org.eclipse.cdt.core.model.ICProject) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) IIndexManager(org.eclipse.cdt.core.index.IIndexManager) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) File(java.io.File) URL(java.net.URL) IProject(org.eclipse.core.resources.IProject)

Example 2 with ImportOperation

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IncrementalProjectBuilder(org.eclipse.core.resources.IncrementalProjectBuilder) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) IProjectDescription(org.eclipse.core.resources.IProjectDescription) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Example 3 with ImportOperation

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();
    }
}
Also used : IOverwriteQuery(org.eclipse.ui.dialogs.IOverwriteQuery) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 4 with ImportOperation

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) ILeveledImportStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IResource(org.eclipse.core.resources.IResource)

Example 5 with ImportOperation

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
    }
}
Also used : ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) ZipFileStructureProvider(org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider)

Aggregations

ImportOperation (org.eclipse.ui.wizards.datatransfer.ImportOperation)18 File (java.io.File)9 IOverwriteQuery (org.eclipse.ui.dialogs.IOverwriteQuery)8 IPath (org.eclipse.core.runtime.IPath)7 IProject (org.eclipse.core.resources.IProject)6 CoreException (org.eclipse.core.runtime.CoreException)6 Path (org.eclipse.core.runtime.Path)6 IOException (java.io.IOException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IProjectDescription (org.eclipse.core.resources.IProjectDescription)5 ZipFile (java.util.zip.ZipFile)4 IWorkspace (org.eclipse.core.resources.IWorkspace)4 IStatus (org.eclipse.core.runtime.IStatus)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 ArrayList (java.util.ArrayList)3 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 ZipFileStructureProvider (org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider)3 URI (java.net.URI)2 URL (java.net.URL)2 IIndexManager (org.eclipse.cdt.core.index.IIndexManager)2