Search in sources :

Example 51 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class WSDL2JAVAController method syncRoutine.

/**
     * DOC xtan there will be refactor for this method with JavaRoutineSynchronizer.syncRoutine().
     * 
     * @param routineItem
     * @param copyToTemp
     * @return
     * @throws SystemException
     */
private IFile syncRoutine(RoutineItem routineItem, boolean copyToTemp, String name) throws SystemException {
    FileOutputStream fos = null;
    try {
        IRunProcessService service = DesignerPlugin.getDefault().getRunProcessService();
        ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
        if (talendProcessJavaProject == null) {
            return null;
        }
        IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
        IFile file = srcFolder.getFile(JavaUtils.JAVA_ROUTINES_DIRECTORY + '/' + routineItem.getProperty().getLabel() + JavaUtils.JAVA_EXTENSION);
        if (copyToTemp) {
            String routineContent = new String(routineItem.getContent().getInnerContent());
            routineContent = chanageRoutinesPackage(routineContent, name);
            String label = routineItem.getProperty().getLabel();
            if (!label.equals(ITalendSynchronizer.TEMPLATE)) {
                routineContent = routineContent.replaceAll(ITalendSynchronizer.TEMPLATE, label);
                File f = file.getLocation().toFile();
                fos = new FileOutputStream(f);
                fos.write(routineContent.getBytes());
                fos.close();
            }
        }
        if (!file.exists()) {
            file.refreshLocal(1, null);
        }
        return file;
    } catch (CoreException e) {
        throw new SystemException(e);
    } catch (IOException e) {
        throw new SystemException(e);
    } finally {
        try {
            fos.close();
        } catch (Exception e) {
            // ignore me even if i'm null
            ExceptionHandler.process(e);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) SystemException(org.talend.commons.exception.SystemException) FileOutputStream(java.io.FileOutputStream) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) IOException(java.io.IOException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) CoreException(org.eclipse.core.runtime.CoreException) SystemException(org.talend.commons.exception.SystemException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) IFolder(org.eclipse.core.resources.IFolder)

Example 52 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class RemoveBinFolderMigrationTask method execute.

@Override
public ExecutionResult execute(Project project) {
    XmiResourceManager xmiResourceManager = new XmiResourceManager();
    IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
    IProxyRepositoryFactory factory = service.getProxyRepositoryFactory();
    for (ERepositoryObjectType type : getTypes()) {
        IFolder folder = null;
        if (type != null && type.hasFolder()) {
            try {
                IProject fsProject = ResourceUtils.getProject(project.getTechnicalLabel());
                if (!fsProject.getFolder(ERepositoryObjectType.getFolderName(type)).exists()) {
                    continue;
                }
                folder = ResourceUtils.getFolder(fsProject, ERepositoryObjectType.getFolderName(type), true);
                for (IResource current : ResourceUtils.getMembers(folder)) {
                    if ((current instanceof IFolder) && ((IFolder) current).getName().equals("bin")) {
                        for (IResource fileCurrent : ResourceUtils.getMembers((IFolder) current)) {
                            if (fileCurrent instanceof IFile) {
                                if (xmiResourceManager.isPropertyFile((IFile) fileCurrent)) {
                                    Property property = null;
                                    try {
                                        property = xmiResourceManager.loadProperty(fileCurrent);
                                    } catch (RuntimeException e) {
                                        // property will be null
                                        ExceptionHandler.process(e);
                                    }
                                    if (property != null) {
                                        // restore folder if doesn't exist anymore.
                                        Item propertyItem = property.getItem();
                                        propertyItem.getState().setDeleted(true);
                                        EmfHelper.saveResource(propertyItem.eResource());
                                        String oldPath = propertyItem.getState().getPath();
                                        IPath path = new Path(oldPath);
                                        factory.createParentFoldersRecursively(project, type, path, true);
                                        FolderItem folderItem = factory.getFolderItem(project, type, path);
                                        propertyItem.setParent(folderItem);
                                        String name = fileCurrent.getName().replace(".properties", "");
                                        // take all the files starting by the same name
                                        IFolder typeRootFolder = ResourceUtils.getFolder(fsProject, ERepositoryObjectType.getFolderName(type), true);
                                        for (IResource filesToMove : ResourceUtils.getMembers((IFolder) current)) {
                                            if (filesToMove.getName().startsWith(name)) {
                                                IPath originalPath = filesToMove.getFullPath();
                                                IPath finalPath = typeRootFolder.getFullPath().append(path).append(originalPath.lastSegment());
                                                if (fsProject.getWorkspace().getRoot().getFile(finalPath).exists()) {
                                                    // if the file exists in both bin and target directory, delete
                                                    // the one from bin.
                                                    filesToMove.delete(true, new NullProgressMonitor());
                                                } else {
                                                    ResourceUtils.moveResource(filesToMove, finalPath);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        IResource[] binFolder = ResourceUtils.getMembers((IFolder) current);
                        if (binFolder.length == 0 || (binFolder.length == 1 && FilesUtils.isSVNFolder(binFolder[0]))) {
                            try {
                                ((IFolder) current).delete(true, null);
                            } catch (CoreException e) {
                            // not catched, not important if can delete or not
                            }
                        }
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            } catch (CoreException e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    // }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IProject(org.eclipse.core.resources.IProject) IRepositoryService(org.talend.repository.model.IRepositoryService) Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) FolderItem(org.talend.core.model.properties.FolderItem) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 53 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class RemoveProjectLibsFolder method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.migration.IProjectMigrationTask#execute(org.talend.core.model.general.Project)
     */
@Override
public ExecutionResult execute(Project project) {
    String libsFolderName = "libs";
    IFolder libsF = null;
    try {
        IProject fsProject = ResourceUtils.getProject(project.getTechnicalLabel());
        libsF = fsProject.getFolder(libsFolderName);
        if (!libsF.exists()) {
            return ExecutionResult.NOTHING_TO_DO;
        }
        final IPath location = libsF.getLocation();
        libsFolder = new File(location.toPortableString());
        ShareProjectLibsMigration migration = new ShareProjectLibsMigration();
        migration.shareLibs(null, new NullProgressMonitor());
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    try {
        libsF.delete(true, new NullProgressMonitor());
    } catch (CoreException e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) File(java.io.File) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 54 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class SelectDeleteProjectDialog method delProjectItem.

private void delProjectItem() {
    try {
        if (delItemList.size() != 0) {
            for (Object obj : delItemList) {
                if (obj instanceof IProject) {
                    IProject project = (IProject) obj;
                    // project.delete(true, null);
                    project.delete(!chkButton.getSelection(), true, null);
                // IResourceChangeDescriptionFactory factory =
                // ResourceChangeValidator.getValidator().createDeltaFactory();
                // factory.delete(project);
                } else if (obj instanceof IFolder) {
                    IFolder folder = (IFolder) obj;
                    folder.delete(false, null);
                }
            }
        }
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 55 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class ImportProjectAsAction method clearExternalLibraries.

/**
     * DOC zwang Comment method "clearExternalLibraries".
     */
private void clearExternalLibraries() {
    try {
        IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
        Project[] projects = repositoryFactory.readProject();
        for (Project project : projects) {
            IProject fsProject = ResourceUtils.getProject(project);
            IFolder libJavaFolder = fsProject.getFolder(ImportProjectAsAction.LIB);
            if (!libJavaFolder.exists()) {
                continue;
            }
            libJavaFolder.delete(true, null);
        }
    } catch (Exception e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
}
Also used : Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IFolder (org.eclipse.core.resources.IFolder)299 IFile (org.eclipse.core.resources.IFile)129 IPath (org.eclipse.core.runtime.IPath)90 IProject (org.eclipse.core.resources.IProject)77 CoreException (org.eclipse.core.runtime.CoreException)72 IResource (org.eclipse.core.resources.IResource)66 Path (org.eclipse.core.runtime.Path)47 IContainer (org.eclipse.core.resources.IContainer)45 File (java.io.File)43 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)28 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)26 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)23 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)19 InputStream (java.io.InputStream)18 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)17 IRunProcessService (org.talend.designer.runprocess.IRunProcessService)17 PersistenceException (org.talend.commons.exception.PersistenceException)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15