Search in sources :

Example 91 with IProject

use of org.eclipse.core.resources.IProject in project che by eclipse.

the class DeltaProcessor method traverseDelta.

/*
     * Converts an <code>IResourceDelta</code> and its children into
     * the corresponding <code>IJavaElementDelta</code>s.
     */
private void traverseDelta(IResourceDelta delta, int elementType, RootInfo rootInfo, OutputsInfo outputsInfo) {
    IResource res = delta.getResource();
    // set stack of elements
    if (this.currentElement == null && rootInfo != null) {
        this.currentElement = rootInfo.project;
    }
    // process current delta
    boolean processChildren = true;
    if (res instanceof IProject) {
        // reset source element parser cache
        this.sourceElementParserCache = null;
        processChildren = updateCurrentDeltaAndIndex(delta, elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT ? // case of prj=src
        IJavaElement.JAVA_PROJECT : elementType, rootInfo);
    } else if (rootInfo != null) {
        processChildren = updateCurrentDeltaAndIndex(delta, elementType, rootInfo);
    } else {
        // not yet inside a package fragment root
        processChildren = true;
    }
    // process children if needed
    if (processChildren) {
        IResourceDelta[] children = (IResourceDelta[]) delta.getAffectedChildren();
        boolean oneChildOnClasspath = false;
        int length = children.length;
        IResourceDelta[] orphanChildren = null;
        Openable parent = null;
        boolean isValidParent = true;
        for (int i = 0; i < length; i++) {
            IResourceDelta child = children[i];
            IResource childRes = child.getResource();
            // check source attachment change
            checkSourceAttachmentChange(child, childRes);
            // find out whether the child is a package fragment root of the current project
            IPath childPath = externalPath(childRes);
            int childKind = child.getKind();
            RootInfo childRootInfo = rootInfo(childPath, childKind);
            RootInfo originalChildRootInfo = childRootInfo;
            if (childRootInfo != null && !childRootInfo.isRootOfProject(childPath)) {
                // package fragment root of another project (dealt with later)
                childRootInfo = null;
            }
            // compute child type
            int childType = elementType(childRes, childKind, elementType, rootInfo == null ? childRootInfo : rootInfo);
            // is childRes in the output folder and is it filtered out ?
            boolean isResFilteredFromOutput = isResFilteredFromOutput(rootInfo, outputsInfo, childRes, childType);
            boolean isNestedRoot = rootInfo != null && childRootInfo != null;
            if (!isResFilteredFromOutput && !isNestedRoot) {
                // do not treat as non-java rsc if nested root
                traverseDelta(child, childType, rootInfo == null ? childRootInfo : rootInfo, // traverse delta for child in the same project
                outputsInfo);
                if (childType == NON_JAVA_RESOURCE) {
                    if (rootInfo != null) {
                        // if inside a package fragment root
                        if (!isValidParent)
                            continue;
                        if (parent == null) {
                            // find the parent of the non-java resource to attach to
                            if (this.currentElement == null || !rootInfo.project.equals(this.currentElement.getJavaProject())) {
                                // note if currentElement is the
                                // IJavaModel, getJavaProject() is null
                                // force the currentProject to be used
                                this.currentElement = rootInfo.project;
                            }
                            if (elementType == IJavaElement.JAVA_PROJECT || (elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT && res instanceof IProject)) {
                                // NB: attach non-java resource to project (not to its package fragment root)
                                parent = rootInfo.project;
                            } else {
                                parent = createElement(res, elementType, rootInfo);
                            }
                            if (parent == null) {
                                isValidParent = false;
                                continue;
                            }
                        }
                        // add child as non java resource
                        try {
                            nonJavaResourcesChanged(parent, child);
                        } catch (JavaModelException e) {
                        // ignore
                        }
                    } else {
                        // the non-java resource (or its parent folder) will be attached to the java project
                        if (orphanChildren == null)
                            orphanChildren = new IResourceDelta[length];
                        orphanChildren[i] = child;
                    }
                } else {
                    if (rootInfo == null && childRootInfo == null) {
                        // the non-java resource (or its parent folder) will be attached to the java project
                        if (orphanChildren == null)
                            orphanChildren = new IResourceDelta[length];
                        orphanChildren[i] = child;
                    }
                }
            } else {
                // to avoid reporting child delta as non-java resource delta
                oneChildOnClasspath = true;
            }
            // but it is a package fragment root of another project, traverse delta too
            if (isNestedRoot || (childRootInfo == null && originalChildRootInfo != null)) {
                traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT, originalChildRootInfo, // binary output of childRootInfo.project cannot be this root
                null);
            }
            // if the child is a package fragment root of one or several other projects
            ArrayList rootList;
            if ((rootList = otherRootsInfo(childPath, childKind)) != null) {
                Iterator iterator = rootList.iterator();
                while (iterator.hasNext()) {
                    originalChildRootInfo = (RootInfo) iterator.next();
                    this.currentElement = // ensure that 2 roots refering to the same resource don't share the current element (see
                    null;
                    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=210746 )
                    traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT, originalChildRootInfo, // binary output of childRootInfo.project cannot be this root
                    null);
                }
            }
        }
        if (orphanChildren != null && (// orphan children are siblings of a package fragment root
        oneChildOnClasspath || res instanceof IProject)) {
        // non-java resource directly under a project
        //				// attach orphan children
        //				IProject rscProject = res.getProject();
        //				JavaProject adoptiveProject = (JavaProject)JavaCore.create(rscProject);
        //				if (adoptiveProject != null
        //						&& JavaProject.hasJavaNature(rscProject)) { // delta iff Java project (18698)
        //					for (int i = 0; i < length; i++) {
        //						if (orphanChildren[i] != null) {
        //							try {
        //								nonJavaResourcesChanged(adoptiveProject, orphanChildren[i]);
        //							} catch (JavaModelException e) {
        //								// ignore
        //							}
        //						}
        //					}
        //				}
        }
    // else resource delta will be added by parent
    }
// else resource delta will be added by parent
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 92 with IProject

use of org.eclipse.core.resources.IProject in project che by eclipse.

the class DeleteResourcesProcessor method checkDirtyResources.

private void checkDirtyResources(final RefactoringStatus result) throws CoreException {
    for (int i = 0; i < fResources.length; i++) {
        IResource resource = fResources[i];
        if (resource instanceof IProject && !((IProject) resource).isOpen())
            continue;
        resource.accept(new IResourceVisitor() {

            public boolean visit(IResource visitedResource) throws CoreException {
                if (visitedResource instanceof IFile) {
                    checkDirtyFile(result, (IFile) visitedResource);
                }
                return true;
            }
        }, IResource.DEPTH_INFINITE, false);
    }
}
Also used : IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 93 with IProject

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

the class AutoConversionTypesEditor method applyChange.

private void applyChange() {
    try {
        IProject project = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
        IFolder prefsSettingFolder = ResourceUtils.getFolder(project, RepositoryConstants.SETTING_DIRECTORY, false);
        AutoConvertTypesUtils.save(typeModel.getBeansList(), AutoConvertTypesUtils.getTypeFile());
        prefsSettingFolder.refreshLocal(IResource.DEPTH_ONE, null);
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    } catch (PersistenceException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) IFolder(org.eclipse.core.resources.IFolder)

Example 94 with IProject

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

the class CustomComponentSettingPage method finish.

private void finish(IProgressMonitor... monitorWrap) {
    IProgressMonitor monitor = null;
    if (monitorWrap != null && monitorWrap.length == 1) {
        monitor = monitorWrap[0];
    }
    final IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
    if (PluginChecker.isSVNProviderPluginLoaded() && (!sharedAdded.isEmpty() || !backAdded.isEmpty())) {
        RepositoryWorkUnit repositoryWorkUnit = new RepositoryWorkUnit("Update custom components") {

            @Override
            public void run() throws PersistenceException {
                final IWorkspaceRunnable op = new IWorkspaceRunnable() {

                    @Override
                    public void run(IProgressMonitor subMonitor) throws CoreException {
                        ISVNProviderService service = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
                        String projectLabel = pro.getTechnicalLabel();
                        IWorkspace workspace = ResourcesPlugin.getWorkspace();
                        IProject eclipseProject = workspace.getRoot().getProject(projectLabel);
                        String targetRoot = eclipseProject.getLocation().toString() + "/" + ERepositoryObjectType.getFolderName(ERepositoryObjectType.COMPONENTS);
                        File componentFolder = new File(targetRoot);
                        URL url = null;
                        try {
                            if (!componentFolder.exists()) {
                                FilesUtils.createFoldersIfNotExists(targetRoot, false);
                            }
                            Bundle b = Platform.getBundle(IComponentsFactory.COMPONENTS_LOCATION);
                            url = FileLocator.toFileURL(FileLocator.find(b, new Path(""), null));
                            String sourceRoot = url.getFile();
                            // delete share
                            for (IComponent component : backAdded.keySet()) {
                                String componentFullPath = targetRoot + File.separator + component.getName();
                                if (service.isSVNProject(pro)) {
                                    service.svnEclipseHandlerDelete(eclipseProject, pro, componentFullPath);
                                    if (subMonitor != null) {
                                        subMonitor.worked(10);
                                    }
                                } else {
                                    File file = new File(componentFullPath);
                                    if (file != null && file.exists()) {
                                        org.talend.utils.io.FilesUtils.deleteFolder(file, true);
                                    }
                                }
                            }
                            if (!backAdded.isEmpty()) {
                                getCustomComponentSettings().removeAll(backAdded.values());
                            }
                            FileFilter ff = new FileFilter() {

                                @Override
                                public boolean accept(File pathname) {
                                    if (FilesUtils.isSVNFolder(pathname)) {
                                        return false;
                                    }
                                    return true;
                                }
                            };
                            // share
                            for (IComponent component : sharedAdded.keySet()) {
                                String sourcePath = sourceRoot + component.getPathSource() + File.separator + component.getName();
                                File sourceFile = new File(sourcePath);
                                String targetPath = targetRoot + File.separatorChar + component.getName();
                                File targetFile = new File(targetPath);
                                FilesUtils.copyFolder(sourceFile, targetFile, true, ff, null, true, false);
                                if (subMonitor != null) {
                                    subMonitor.worked(10);
                                }
                            }
                        } catch (Exception e) {
                            resetCustomComponentSetting();
                            ExceptionHandler.process(e);
                        }
                        try {
                            prf.saveProject(pro);
                        } catch (PersistenceException e) {
                            ExceptionHandler.process(e);
                        }
                        try {
                            eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, subMonitor);
                        } catch (CoreException e1) {
                            ExceptionHandler.process(e1);
                        }
                    }
                };
                IWorkspace workspace = ResourcesPlugin.getWorkspace();
                try {
                    ISchedulingRule schedulingRule = workspace.getRoot();
                    // the update the project files need to be done in the workspace runnable to avoid all
                    // notification
                    // of changes before the end of the modifications.
                    workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
                } catch (CoreException e) {
                    throw new PersistenceException(e.getCause());
                }
            }
        };
        repositoryWorkUnit.setRefreshRepository(false);
        repositoryWorkUnit.setForceTransaction(true);
        prf.executeRepositoryWorkUnit(repositoryWorkUnit);
        try {
            repositoryWorkUnit.throwPersistenceExceptionIfAny();
        } catch (PersistenceException e) {
            e.printStackTrace();
        }
    }
    if (monitor != null) {
        monitor.done();
    }
    // refresh again after the gui closed .
    try {
        String projectLabel = pro.getTechnicalLabel();
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IProject eclipseProject = workspace.getRoot().getProject(projectLabel);
        eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    } catch (CoreException e1) {
        ExceptionHandler.process(e1);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Bundle(org.osgi.framework.Bundle) IComponent(org.talend.core.model.components.IComponent) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) ISVNProviderService(org.talend.core.services.ISVNProviderService) IProject(org.eclipse.core.resources.IProject) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) FileFilter(java.io.FileFilter) File(java.io.File) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 95 with IProject

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

the class AddCopyBookXc2jFileMigrationTask method getReferenceXc2jFile.

public static IFile getReferenceXc2jFile(ConnectionItem connectionItem) {
    IFile x2cjFile = null;
    try {
        IProject currentProject = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
        String label = connectionItem.getProperty().getLabel();
        String version = connectionItem.getProperty().getVersion();
        String xc2jFileName = label + "_" + version + ".xc2j";
        String folderPath = "";
        String folder = "";
        if (connectionItem.getState() != null) {
            folderPath = connectionItem.getState().getPath();
        }
        if (!folderPath.equals("")) {
            folder = "/" + folderPath;
        }
        x2cjFile = currentProject.getFolder("metadata/fileEBCDIC" + folder).getFile(xc2jFileName);
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    return x2cjFile;
}
Also used : IFile(org.eclipse.core.resources.IFile) PersistenceException(org.talend.commons.exception.PersistenceException) IProject(org.eclipse.core.resources.IProject)

Aggregations

IProject (org.eclipse.core.resources.IProject)665 CoreException (org.eclipse.core.runtime.CoreException)157 IFile (org.eclipse.core.resources.IFile)142 Test (org.junit.Test)130 IResource (org.eclipse.core.resources.IResource)112 IPath (org.eclipse.core.runtime.IPath)98 IFolder (org.eclipse.core.resources.IFolder)77 File (java.io.File)73 IOException (java.io.IOException)70 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)70 Path (org.eclipse.core.runtime.Path)70 IJavaProject (org.eclipse.jdt.core.IJavaProject)68 ArrayList (java.util.ArrayList)67 IWorkspace (org.eclipse.core.resources.IWorkspace)55 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)48 ByteArrayInputStream (java.io.ByteArrayInputStream)45 ProjectAdapter (org.apache.sling.ide.test.impl.helpers.ProjectAdapter)45 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)41 IProjectDescription (org.eclipse.core.resources.IProjectDescription)38 IStatus (org.eclipse.core.runtime.IStatus)35