Search in sources :

Example 1 with TarException

use of org.eclipse.ui.internal.wizards.datatransfer.TarException in project tdi-studio-se by Talend.

the class ImportProjectAsWizard method performFinish.

/**
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
     */
@Override
public boolean performFinish() {
    if (getContainer().getCurrentPage().equals(manyProjectsPage)) {
        isImportedSeveralProject = true;
        return manyProjectsPage.createProjects();
    } else {
        isImportedSeveralProject = false;
        name = mainPage.getName().trim().replace(' ', '_');
        final String technicalName = mainPage.getTechnicalName();
        final String sourcePath = mainPage.getSourcePath();
        final boolean isArchive = mainPage.isArchive();
        // see bug 4600, update the external lib path, make it possible to
        // copy external jar files into tos
        updateExternalLibPath();
        final Shell shell = getShell();
        ProgressDialog progressDialog = new ProgressDialog(shell) {

            private IProgressMonitor monitorWrap;

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitorWrap = new EventLoopProgressMonitor(monitor);
                try {
                    if (!isArchive) {
                        ImportProjectsUtilities.importProjectAs(shell, name, technicalName, sourcePath, monitorWrap);
                    } else {
                        // type.equalsIgnoreCase("archive")
                        ImportProjectsUtilities.importArchiveProjectAs(shell, name, technicalName, sourcePath, monitorWrap);
                    }
                } catch (IOException e) {
                    throw new InvocationTargetException(e);
                } catch (TarException e) {
                    throw new InvocationTargetException(e);
                }
                monitorWrap.done();
                //$NON-NLS-1$
                MessageDialog.openInformation(//$NON-NLS-1$
                shell, //$NON-NLS-1$
                Messages.getString("ImportProjectAction.messageDialogTitle.project"), //$NON-NLS-1$
                Messages.getString("ImportProjectAction.messageDialogContent.projectImportedSuccessfully"));
            }
        };
        try {
            progressDialog.executeProcess();
        } catch (InvocationTargetException e) {
            MessageBoxExceptionHandler.process(e.getTargetException(), shell);
            return false;
        } catch (InterruptedException e) {
            IProject[] projects = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getProjects();
            for (IProject project : projects) {
                if (project.getName().equalsIgnoreCase(name)) {
                    try {
                        project.delete(true, true, null);
                    } catch (CoreException ee) {
                        ExceptionHandler.process(ee);
                    }
                }
            }
            return false;
        }
        return true;
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TarException(org.eclipse.ui.internal.wizards.datatransfer.TarException) CoreException(org.eclipse.core.runtime.CoreException) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) IOException(java.io.IOException) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProject(org.eclipse.core.resources.IProject)

Example 2 with TarException

use of org.eclipse.ui.internal.wizards.datatransfer.TarException in project tdi-studio-se by Talend.

the class TalendWizardProjectsImportPage method getProjectRecords.

@Override
public ProjectRecord[] getProjectRecords() {
    if (sourcePath == null || sourcePath.length() == 0) {
        return new ProjectRecord[0];
    }
    ProjectRecord[] selectedProjects = super.getProjectRecords();
    Collection files = new ArrayList();
    List projects = new ArrayList();
    ProjectRecord[] selected = null;
    for (ProjectRecord selectedProject : selectedProjects) {
        projects.add(selectedProject);
    }
    final File directory = new File(sourcePath);
    if (ArchiveFileManipulations.isTarFile(sourcePath)) {
        try {
            TarFile sourceTarFile = new TarFile(sourcePath);
            if (sourceTarFile == null) {
                return new ProjectRecord[0];
            }
            structureProvider = new TarLeveledStructureProvider(sourceTarFile);
            Object child = structureProvider.getRoot();
            collectProjectFilesFromProvider(files, child, 0);
            selected = new ProjectRecord[files.size()];
            Iterator filesIterator = files.iterator();
            int j = 0;
            while (filesIterator.hasNext()) {
                TalendProjectRecord file = (TalendProjectRecord) filesIterator.next();
                for (int i = 0; i < projects.size(); i++) {
                    if (file.getProjectName().equals(((ProjectRecord) projects.get(i)).getProjectName())) {
                        selected[j] = (ProjectRecord) projects.get(i);
                        j++;
                    }
                }
            }
        } catch (TarException e) {
            // displayErrorDialog(DataTransferMessages.TarImport_badFormat);
            //$NON-NLS-1$
            displayErrorDialog(Messages.getString("DataTransferMessages.TarImport_badFormat"));
        } catch (IOException e) {
            // displayErrorDialog(DataTransferMessages.ZipImport_couldNotRead);
            //$NON-NLS-1$
            displayErrorDialog(Messages.getString("DataTransferMessages.ZipImport_couldNotRead"));
        }
    } else if (ArchiveFileManipulations.isZipFile(sourcePath)) {
        try {
            ZipFile sourceFile = new ZipFile(sourcePath);
            if (sourceFile == null) {
                return new ProjectRecord[0];
            }
            structureProvider = new ZipLeveledStructureProvider(sourceFile);
            Object child = structureProvider.getRoot();
            collectProjectFilesFromProvider(files, child, 0);
            selected = new ProjectRecord[files.size()];
            Iterator filesIterator = files.iterator();
            int j = 0;
            while (filesIterator.hasNext()) {
                TalendProjectRecord file = (TalendProjectRecord) filesIterator.next();
                for (int i = 0; i < projects.size(); i++) {
                    if (file.getProjectName().equals(((ProjectRecord) projects.get(i)).getProjectName())) {
                        selected[j] = (ProjectRecord) projects.get(i);
                        j++;
                    }
                }
            }
        } catch (IOException e) {
            // displayErrorDialog(DataTransferMessages.ZipImport_badFormat);
            //$NON-NLS-1$
            displayErrorDialog(Messages.getString("DataTransferMessages.ZipImport_badFormat"));
        }
    } else if (directory.isDirectory()) {
        collectProjectFilesFromDirectory(files, directory, null);
        selected = new ProjectRecord[files.size()];
        Iterator filesIterator = files.iterator();
        int j = 0;
        while (filesIterator.hasNext()) {
            File file = (File) filesIterator.next();
            for (int i = 0; i < projects.size(); i++) {
                if (file.getParentFile().getName().equals(((ProjectRecord) projects.get(i)).getProjectName())) {
                    selected[j] = (ProjectRecord) projects.get(i);
                    j++;
                }
            }
        }
    }
    return selected;
}
Also used : TarException(org.eclipse.ui.internal.wizards.datatransfer.TarException) ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TarLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) Iterator(java.util.Iterator) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) ZipFile(java.util.zip.ZipFile) File(java.io.File) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile)

Example 3 with TarException

use of org.eclipse.ui.internal.wizards.datatransfer.TarException in project tdi-studio-se by Talend.

the class DemoImportTestUtil method getResourceManager.

public static ResourcesManager getResourceManager(DemoProjectBean checkedProjectBean) {
    ResourcesManager resManager = null;
    try {
        Bundle bundle = Platform.getBundle(checkedProjectBean.getPluginId());
        URL demoURL = FileLocator.find(bundle, new Path(checkedProjectBean.getDemoProjectFilePath()), null);
        demoURL = FileLocator.toFileURL(demoURL);
        String filePath = new Path(demoURL.getFile()).toOSString();
        File srcFile = new File(filePath);
        FileResourcesUnityManager fileUnityManager = ResourcesManagerFactory.getInstance().createFileUnityManager(srcFile);
        resManager = fileUnityManager.doUnify();
    } catch (ZipException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (TarException e) {
        e.printStackTrace();
    }
    return resManager;
}
Also used : Path(org.eclipse.core.runtime.Path) TarException(org.eclipse.ui.internal.wizards.datatransfer.TarException) Bundle(org.osgi.framework.Bundle) FileNotFoundException(java.io.FileNotFoundException) ResourcesManager(org.talend.repository.items.importexport.manager.ResourcesManager) FileResourcesUnityManager(org.talend.repository.items.importexport.ui.managers.FileResourcesUnityManager) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL)

Example 4 with TarException

use of org.eclipse.ui.internal.wizards.datatransfer.TarException in project tdi-studio-se by Talend.

the class ImportDemoProjectItemsPage method getResourceManagers.

private List<ResourcesManager> getResourceManagers(List<DemoProjectBean> checkedProjectBean) {
    List<ResourcesManager> resManagers = new ArrayList<ResourcesManager>();
    try {
        for (DemoProjectBean pro : checkedProjectBean) {
            ResourcesManager resManager = null;
            Bundle bundle = Platform.getBundle(pro.getPluginId());
            URL demoURL = FileLocator.find(bundle, new Path(pro.getDemoProjectFilePath()), null);
            demoURL = FileLocator.toFileURL(demoURL);
            String filePath = new Path(demoURL.getFile()).toOSString();
            File srcFile = new File(filePath);
            // TUP-1924:use UnityManager here ,same with import normal items.
            FileResourcesUnityManager fileUnityManager = ResourcesManagerFactory.getInstance().createFileUnityManager(srcFile);
            resManager = fileUnityManager.doUnify();
            if (resManager != null) {
                resManagers.add(resManager);
            }
        }
    } catch (ZipException e) {
        //$NON-NLS-1$ 
        displayErrorDialog(Messages.getString("ImportItemsWizardPage_ZipImport_badFormat"));
    } catch (TarException e) {
        //$NON-NLS-1$ 
        displayErrorDialog(Messages.getString("ImportItemsWizardPage_TarImport_badFormat"));
    } catch (FileNotFoundException e) {
        ExceptionHandler.process(e);
    } catch (IOException e) {
        ExceptionHandler.process(e);
    }
    return resManagers;
}
Also used : Path(org.eclipse.core.runtime.Path) TarException(org.eclipse.ui.internal.wizards.datatransfer.TarException) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) FileResourcesUnityManager(org.talend.repository.items.importexport.ui.managers.FileResourcesUnityManager) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) URL(java.net.URL) ResourcesManager(org.talend.repository.items.importexport.manager.ResourcesManager) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) File(java.io.File)

Example 5 with TarException

use of org.eclipse.ui.internal.wizards.datatransfer.TarException in project tdi-studio-se by Talend.

the class DemoImportTestUtil method getResourceManagers.

public static List<ResourcesManager> getResourceManagers(List<DemoProjectBean> checkedProjectBean) {
    List<ResourcesManager> resManagers = new ArrayList<ResourcesManager>();
    try {
        for (DemoProjectBean pro : checkedProjectBean) {
            ResourcesManager resManager = null;
            Bundle bundle = Platform.getBundle(pro.getPluginId());
            URL demoURL = FileLocator.find(bundle, new Path(pro.getDemoProjectFilePath()), null);
            demoURL = FileLocator.toFileURL(demoURL);
            String filePath = new Path(demoURL.getFile()).toOSString();
            File srcFile = new File(filePath);
            FileResourcesUnityManager fileUnityManager = ResourcesManagerFactory.getInstance().createFileUnityManager(srcFile);
            resManager = fileUnityManager.doUnify();
            if (resManager != null) {
                resManagers.add(resManager);
            }
        }
    } catch (ZipException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (TarException e) {
        e.printStackTrace();
    }
    return resManagers;
}
Also used : Path(org.eclipse.core.runtime.Path) TarException(org.eclipse.ui.internal.wizards.datatransfer.TarException) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) FileResourcesUnityManager(org.talend.repository.items.importexport.ui.managers.FileResourcesUnityManager) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) URL(java.net.URL) DemoProjectBean(org.talend.repository.ui.actions.importproject.DemoProjectBean) ResourcesManager(org.talend.repository.items.importexport.manager.ResourcesManager) File(java.io.File)

Aggregations

IOException (java.io.IOException)5 TarException (org.eclipse.ui.internal.wizards.datatransfer.TarException)5 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 ZipException (java.util.zip.ZipException)3 Path (org.eclipse.core.runtime.Path)3 Bundle (org.osgi.framework.Bundle)3 ResourcesManager (org.talend.repository.items.importexport.manager.ResourcesManager)3 FileResourcesUnityManager (org.talend.repository.items.importexport.ui.managers.FileResourcesUnityManager)3 ZipFile (java.util.zip.ZipFile)2 TarFile (org.eclipse.ui.internal.wizards.datatransfer.TarFile)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1