Search in sources :

Example 1 with TarFile

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

the class ImportProjectsUtilities method importArchiveProject.

public static void importArchiveProject(Shell shell, String technicalName, String sourcePath, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException, TarException, IOException {
    IImportStructureProvider provider;
    Object source;
    if (ArchiveFileManipulations.isZipFile(sourcePath)) {
        ZipLeveledStructureProvider zipProvider = new ZipLeveledStructureProvider(new ZipFile(sourcePath));
        source = zipProvider.getRoot();
        boolean ok = true;
        for (Object o : zipProvider.getChildren(source)) {
            String label = zipProvider.getLabel(o);
            if (!label.equals(IProjectDescription.DESCRIPTION_FILE_NAME) && ok) {
                source = o;
            } else {
                ok = false;
            }
        }
        if (!ok) {
            source = zipProvider.getRoot();
        }
        provider = zipProvider;
    } else if (ArchiveFileManipulations.isTarFile(sourcePath)) {
        TarLeveledStructureProvider tarProvider = new TarLeveledStructureProvider(new TarFile(sourcePath));
        source = tarProvider.getRoot();
        boolean ok = true;
        for (Object o : tarProvider.getChildren(source)) {
            String label = tarProvider.getLabel(o);
            if (!label.equals(IProjectDescription.DESCRIPTION_FILE_NAME) && ok) {
                source = o;
            } else {
                ok = false;
            }
        }
        if (!ok) {
            source = tarProvider.getRoot();
        }
        provider = tarProvider;
    } else {
        //$NON-NLS-1$
        throw new IllegalArgumentException(Messages.getString("ImportProjectsUtilities.fileFormatError", sourcePath));
    }
    importProject(shell, provider, source, new Path(technicalName), false, false, monitor);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) TarLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider) ZipFile(java.util.zip.ZipFile) ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) IImportStructureProvider(org.eclipse.ui.wizards.datatransfer.IImportStructureProvider)

Example 2 with TarFile

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

the class ImportProjectAsWizardPage method evaluateSpecifiedPath.

private void evaluateSpecifiedPath(String path) {
    if (path.equals(lastPath)) {
        return;
    }
    // on an empty path empty selectedProjects
    if (path == null || path.length() == 0) {
        checkFieldsValue();
        return;
    }
    final boolean dirSelected = this.projectFromDirectoryRadio.getSelection();
    File directory = new File(path);
    Collection projectFiles = new ArrayList();
    Collection talendProjectFiles = new ArrayList();
    if (!dirSelected && ArchiveFileManipulations.isTarFile(path)) {
        TarFile sourceTarFile = getSpecifiedTarSourceFile(path);
        if (sourceTarFile == null) {
            return;
        }
        TarLeveledStructureProvider provider = new TarLeveledStructureProvider(sourceTarFile);
        Object child = provider.getRoot();
        if (!ImportProjectsUtilities.collectProjectFilesFromProvider(projectFiles, provider, child, 0, null, IProjectDescription.DESCRIPTION_FILE_NAME)) {
            return;
        }
        if (!ImportProjectsUtilities.collectProjectFilesFromProvider(talendProjectFiles, provider, child, 0, null, FileConstants.LOCAL_PROJECT_FILENAME)) {
            return;
        }
        if (!ImportProjectsUtilities.collectProjectFilesFromProvider(talendProjectFiles, provider, child, 0, null, FileConstants.OLD_TALEND_PROJECT_FILENAME)) {
            return;
        }
    } else if (!dirSelected && ArchiveFileManipulations.isZipFile(path)) {
        ZipFile sourceFile = getSpecifiedZipSourceFile(path);
        if (sourceFile == null) {
            return;
        }
        ZipLeveledStructureProvider provider = new ZipLeveledStructureProvider(sourceFile);
        Object child = provider.getRoot();
        if (!ImportProjectsUtilities.collectProjectFilesFromProvider(projectFiles, provider, child, 0, null, IProjectDescription.DESCRIPTION_FILE_NAME)) {
            return;
        }
        if (!ImportProjectsUtilities.collectProjectFilesFromProvider(talendProjectFiles, provider, child, 0, null, FileConstants.LOCAL_PROJECT_FILENAME)) {
            return;
        }
        if (!ImportProjectsUtilities.collectProjectFilesFromProvider(talendProjectFiles, provider, child, 0, null, FileConstants.OLD_TALEND_PROJECT_FILENAME)) {
            return;
        }
    } else if (dirSelected && directory.isDirectory()) {
        if (!ImportProjectsUtilities.collectProjectFilesFromDirectory(projectFiles, directory, null, IProjectDescription.DESCRIPTION_FILE_NAME)) {
            return;
        }
        if (!ImportProjectsUtilities.collectProjectFilesFromDirectory(talendProjectFiles, directory, null, FileConstants.LOCAL_PROJECT_FILENAME)) {
            return;
        }
        if (!ImportProjectsUtilities.collectProjectFilesFromDirectory(talendProjectFiles, directory, null, FileConstants.OLD_TALEND_PROJECT_FILENAME)) {
            return;
        }
    }
    lastPath = path;
    if (projectFiles.size() != 1 || talendProjectFiles.size() != 1) {
        IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
        String string = //$NON-NLS-1$
        Messages.getString(//$NON-NLS-1$
        "ImportProjectAsWizardPage.error.notATalendProject", brandingService.getShortProductName());
        fileContentStatus = new Status(IStatus.ERROR, RepositoryPlugin.PLUGIN_ID, IStatus.OK, string, null);
    } else {
        fileContentStatus = createOkStatus();
    }
    checkFieldsValue();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TarLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider) ZipFile(java.util.zip.ZipFile) ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) ArrayList(java.util.ArrayList) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) Collection(java.util.Collection) IBrandingService(org.talend.core.ui.branding.IBrandingService) ZipFile(java.util.zip.ZipFile) File(java.io.File) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile)

Example 3 with TarFile

use of org.eclipse.ui.internal.wizards.datatransfer.TarFile 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 4 with TarFile

use of org.eclipse.ui.internal.wizards.datatransfer.TarFile in project translationstudio8 by heartsome.

the class ImportProjectWizardPage2 method updateProjectsList.

public void updateProjectsList(final String path) {
    if (path == null || path.length() == 0) {
        setMessage(Messages.getString("wizard.ImportProjectWizardPage.desc"));
        selectedProjects = new ProjectRecord[0];
        setPageComplete(selectElementTree.getCheckedElements().length > 0);
        lastPath = path;
        return;
    }
    final File directory = new File(path);
    long modified = directory.lastModified();
    if (path.equals(lastPath) && lastModified == modified && lastCopyFiles == copyFiles) {
        // change, no refreshing is required
        return;
    }
    lastPath = path;
    lastModified = modified;
    lastCopyFiles = copyFiles;
    // We can't access the radio button from the inner class so get the
    // status beforehand
    final boolean dirSelected = false;
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            @SuppressWarnings({ "rawtypes", "restriction" })
            public void run(IProgressMonitor monitor) {
                monitor.beginTask(Messages.getString("importProjectWizardPage.searchingMessage"), 100);
                selectedProjects = new ProjectRecord[0];
                Collection files = new ArrayList();
                monitor.worked(10);
                if (!dirSelected && ArchiveFileManipulations.isTarFile(path)) {
                    TarFile sourceTarFile = getSpecifiedTarSourceFile(path);
                    if (sourceTarFile == null) {
                        return;
                    }
                    structureProvider = new TarLeveledStructureProvider(sourceTarFile);
                    Object child = structureProvider.getRoot();
                    if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
                        return;
                    }
                    Iterator filesIterator = files.iterator();
                    selectedProjects = new ProjectRecord[files.size()];
                    int index = 0;
                    monitor.worked(50);
                    monitor.subTask(Messages.getString("importProjectWizardPage.processingMessage"));
                    while (filesIterator.hasNext()) {
                        selectedProjects[index++] = (ProjectRecord) filesIterator.next();
                    }
                } else if (!dirSelected && ArchiveFileManipulations.isZipFile(path)) {
                    ZipFile sourceFile = getSpecifiedZipSourceFile(path);
                    if (sourceFile == null) {
                        return;
                    }
                    structureProvider = new ZipLeveledStructureProvider(sourceFile);
                    Object child = structureProvider.getRoot();
                    if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
                        return;
                    }
                    Iterator filesIterator = files.iterator();
                    selectedProjects = new ProjectRecord[files.size()];
                    int index = 0;
                    monitor.worked(50);
                    monitor.subTask(Messages.getString("importProjectWizardPage.processingMessage"));
                    while (filesIterator.hasNext()) {
                        selectedProjects[index++] = (ProjectRecord) filesIterator.next();
                    }
                } else {
                    monitor.worked(60);
                }
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (InterruptedException e) {
        LOGGER.error(e.getMessage(), e);
    }
    // 开始处理导入项目中的项目名称不合法的情况
    String projectName = "";
    StringBuffer errorProjectNameSB = new StringBuffer();
    StringBuffer errorCharSB = new StringBuffer();
    List<ProjectRecord> tempList = new ArrayList<ProjectRecord>();
    boolean isError = false;
    for (int i = 0; i < selectedProjects.length; i++) {
        projectName = selectedProjects[i].getProjectName();
        isError = false;
        for (int j = 0; j < Constant.RESOURCE_ERRORCHAR.length; j++) {
            if (projectName.indexOf(Constant.RESOURCE_ERRORCHAR[j]) != -1) {
                errorCharSB.append(Constant.RESOURCE_ERRORCHAR[j]);
                errorProjectNameSB.append(projectName + ", ");
                isError = true;
            }
        }
        if (!isError) {
            tempList.add(selectedProjects[i]);
        }
    }
    if (errorProjectNameSB.length() > 0) {
        final String errorTip = MessageFormat.format(Messages.getString("importProjectWizardPage.projectError"), new Object[] { errorProjectNameSB.toString().substring(0, errorProjectNameSB.toString().length() - 2), errorCharSB.toString() });
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                MessageDialog.openWarning(getShell(), Messages.getString("importProject.all.dialog.warning"), errorTip);
            }
        });
    }
    selectedProjects = tempList.toArray(new ProjectRecord[tempList.size()]);
    setPageComplete(selectElementTree.getCheckedElements().length > 0);
    selectElementTree.refresh(true);
}
Also used : ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) 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) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 5 with TarFile

use of org.eclipse.ui.internal.wizards.datatransfer.TarFile in project translationstudio8 by heartsome.

the class ImportProjectWizardPage method updateProjectsList.

/**
	 * Update the list of projects based on path. Method declared public only
	 * for test suite.
	 * 
	 * @param path
	 */
public void updateProjectsList(final String path) {
    // on an empty path empty selectedProjects
    if (path == null || path.length() == 0) {
        setMessage(Messages.getString("wizard.ImportProjectWizardPage.desc"));
        selectedProjects = new ProjectRecord[0];
        projectsList.refresh(true);
        projectsList.setCheckedElements(selectedProjects);
        setPageComplete(projectsList.getCheckedElements().length > 0);
        lastPath = path;
        return;
    }
    final File directory = new File(path);
    long modified = directory.lastModified();
    if (path.equals(lastPath) && lastModified == modified && lastCopyFiles == copyFiles) {
        // change, no refreshing is required
        return;
    }
    lastPath = path;
    lastModified = modified;
    lastCopyFiles = copyFiles;
    // We can't access the radio button from the inner class so get the
    // status beforehand
    final boolean dirSelected = false;
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            /*
				 * (non-Javadoc)
				 * 
				 * @see
				 * org.eclipse.jface.operation.IRunnableWithProgress#run(org
				 * .eclipse.core.runtime.IProgressMonitor)
				 */
            @SuppressWarnings("rawtypes")
            public void run(IProgressMonitor monitor) {
                monitor.beginTask(DataTransferMessages.WizardProjectsImportPage_SearchingMessage, 100);
                selectedProjects = new ProjectRecord[0];
                Collection files = new ArrayList();
                monitor.worked(10);
                if (!dirSelected && ArchiveFileManipulations.isTarFile(path)) {
                    TarFile sourceTarFile = getSpecifiedTarSourceFile(path);
                    if (sourceTarFile == null) {
                        return;
                    }
                    structureProvider = new TarLeveledStructureProvider(sourceTarFile);
                    Object child = structureProvider.getRoot();
                    if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
                        return;
                    }
                    Iterator filesIterator = files.iterator();
                    selectedProjects = new ProjectRecord[files.size()];
                    int index = 0;
                    monitor.worked(50);
                    monitor.subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
                    while (filesIterator.hasNext()) {
                        selectedProjects[index++] = (ProjectRecord) filesIterator.next();
                    }
                } else if (!dirSelected && ArchiveFileManipulations.isZipFile(path)) {
                    ZipFile sourceFile = getSpecifiedZipSourceFile(path);
                    if (sourceFile == null) {
                        return;
                    }
                    structureProvider = new ZipLeveledStructureProvider(sourceFile);
                    Object child = structureProvider.getRoot();
                    if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
                        return;
                    }
                    Iterator filesIterator = files.iterator();
                    selectedProjects = new ProjectRecord[files.size()];
                    int index = 0;
                    monitor.worked(50);
                    monitor.subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
                    while (filesIterator.hasNext()) {
                        selectedProjects[index++] = (ProjectRecord) filesIterator.next();
                    }
                } else {
                    monitor.worked(60);
                }
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        IDEWorkbenchPlugin.log(e.getMessage(), e);
    } catch (InterruptedException e) {
    // Nothing to do if the user interrupts.
    }
    projectsList.refresh(true);
    ProjectRecord[] projects = getProjectRecords();
    boolean displayWarning = false;
    for (int i = 0; i < projects.length; i++) {
        if (projects[i].hasConflicts) {
            displayWarning = true;
            projectsList.setGrayed(projects[i], true);
        } else {
            projectsList.setChecked(projects[i], true);
        }
    }
    if (displayWarning) {
        setMessage(DataTransferMessages.WizardProjectsImportPage_projectsInWorkspace, WARNING);
    } else {
        setMessage("");
    }
    setPageComplete(projectsList.getCheckedElements().length > 0);
    if (selectedProjects.length == 0) {
        setMessage(DataTransferMessages.WizardProjectsImportPage_noProjectsToImport, WARNING);
    }
}
Also used : ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) 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) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) File(java.io.File)

Aggregations

TarFile (org.eclipse.ui.internal.wizards.datatransfer.TarFile)11 ZipFile (java.util.zip.ZipFile)10 File (java.io.File)9 TarLeveledStructureProvider (org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider)6 ZipLeveledStructureProvider (org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Iterator (java.util.Iterator)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)3 FileOutputStream (java.io.FileOutputStream)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 TarException (org.eclipse.ui.internal.wizards.datatransfer.TarException)2 ZipToFile (org.talend.mdm.commmon.util.workbench.ZipToFile)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 List (java.util.List)1