Search in sources :

Example 11 with ResourceAttributes

use of org.eclipse.core.resources.ResourceAttributes in project mdw-designer by CenturyLinkCloud.

the class WorkflowAsset method ensureFileWritable.

public void ensureFileWritable() throws CoreException {
    IFile file = getFile();
    if (file.isReadOnly()) {
        ResourceAttributes resourceAttrs = file.getResourceAttributes();
        resourceAttrs.setReadOnly(false);
        file.setResourceAttributes(resourceAttrs);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes)

Example 12 with ResourceAttributes

use of org.eclipse.core.resources.ResourceAttributes in project whole by wholeplatform.

the class WorkspaceTemplate method buildDirectory.

protected void buildDirectory(IFolder directory) {
    getBindings().wEnterScope();
    ab.FolderArtifact_();
    String directoryName = directory.getName();
    ab.Name(directoryName);
    getBindings().wDefValue("file", directory.getLocation().toFile());
    getBindings().wDefValue("fileName", directoryName);
    ResourceAttributes resourceAttributes = directory.getResourceAttributes();
    if (resourceAttributes != null && resourceAttributes.isReadOnly())
        buildMetadata("readonly");
    else
        buildMetadata();
    if (!testAndClearPurge()) {
        IJavaElement javaElement = JavaCore.create(directory);
        if (javaElement != null && javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) {
            IJavaElement[] children = null;
            try {
                children = ((IPackageFragmentRoot) javaElement).getChildren();
            } catch (JavaModelException e) {
            }
            if (children != null && children.length > 0) {
                Arrays.sort(children, new JavaElementComparator());
                ab.Artifacts_(children.length);
                for (IJavaElement artifact : children) buildPackage((IPackageFragment) artifact);
                ab._Artifacts();
            } else
                ab.Artifacts();
        } else {
            IResource[] artifacts = null;
            try {
                artifacts = directory.members();
            } catch (CoreException e) {
            }
            if (artifacts != null && artifacts.length > 0) {
                Arrays.sort(artifacts, new ResourceComparator());
                ab.Artifacts_(artifacts.length);
                for (IResource artifact : artifacts) buildArtifact(artifact);
                ab._Artifacts();
            } else
                ab.Artifacts();
        }
    } else
        ab.Artifacts();
    ab._FolderArtifact();
    getBindings().wExitScope();
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaModelException(org.eclipse.jdt.core.JavaModelException) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) CoreException(org.eclipse.core.runtime.CoreException) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes) IResource(org.eclipse.core.resources.IResource)

Example 13 with ResourceAttributes

use of org.eclipse.core.resources.ResourceAttributes in project whole by wholeplatform.

the class WorkspaceArtifactsGeneratorVisitor method visitFolderArtifact.

public void visitFolderArtifact(FolderArtifact entity) {
    env().wEnterScope();
    if (!Matcher.matchImplAndBind(ArtifactsEntityDescriptorEnum.Name, entity.getName(), env(), "folderName"))
        throw new VisitException("No Folder name");
    entity.getMetadata().accept(this);
    try {
        IPath path;
        if (env().wIsSet("folder")) {
            IFolder parentFolder = (IFolder) env().wGetValue("folder");
            path = parentFolder.getFullPath();
        } else {
            IProject project = (IProject) env().wGetValue("project");
            path = project.getFullPath();
        }
        IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
        IFolder folder = null;
        String[] folderPath = env().wStringValue("folderName").split("/");
        for (int i = 0; i < folderPath.length; i++) {
            path = path.append(folderPath[i]);
            folder = workspaceRoot.getFolder(path);
            if (!folder.exists())
                folder.create(true, true, progressMonitor());
        }
        env().wDefValue("folder", folder);
        if (env().wIsSet("derived"))
            folder.setDerived(true, progressMonitor());
        if (env().wIsSet("readonly")) {
            ResourceAttributes attributes = folder.getResourceAttributes();
            if (attributes != null) {
                attributes.setReadOnly(true);
                folder.setResourceAttributes(attributes);
            }
        }
        if (env().wLocalNames().contains("source") && env().wIsSet("javaProject")) {
            List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
            IJavaProject javaProject = (IJavaProject) env().wGetValue("javaProject");
            classpathEntries.addAll(Arrays.asList(javaProject.getRawClasspath()));
            IClasspathEntry sourceEntry = JavaCore.newSourceEntry(folder.getFullPath());
            if (classpathEntries.size() == 1 && ((IClasspathEntry) classpathEntries.get(0)).getPath().equals(javaProject.getPath()))
                classpathEntries.remove(0);
            else
                for (Iterator<IClasspathEntry> i = classpathEntries.iterator(); i.hasNext(); ) {
                    IClasspathEntry entry = i.next();
                    if (entry.getPath().equals(sourceEntry.getPath()))
                        i.remove();
                }
            classpathEntries.add(0, sourceEntry);
            javaProject.setRawClasspath((IClasspathEntry[]) classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), progressMonitor());
        }
    } catch (CoreException e) {
        throw new VisitException(e);
    // } catch (NullPointerException e) {
    // throw new VisitException("No Project");
    }
    entity.getArtifacts().accept(this);
    env().wExitScope();
}
Also used : IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) Iterator(java.util.Iterator) IFolder(org.eclipse.core.resources.IFolder)

Example 14 with ResourceAttributes

use of org.eclipse.core.resources.ResourceAttributes in project whole by wholeplatform.

the class WorkspaceArtifactsGeneratorVisitor method visitPackageArtifact.

public void visitPackageArtifact(PackageArtifact entity) {
    env().wEnterScope();
    if (!Matcher.matchImplAndBind(ArtifactsEntityDescriptorEnum.Name, entity.getName(), env(), "packageName"))
        throw new VisitException("No Package name");
    entity.getMetadata().accept(this);
    try {
        IPath path;
        if (env().wIsSet("folder")) {
            IFolder parentFolder = (IFolder) env().wGetValue("folder");
            path = parentFolder.getFullPath();
        } else {
            IProject project = (IProject) env().wGetValue("project");
            path = project.getFullPath();
        }
        IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
        IFolder folder = null;
        String[] packagePath = env().wStringValue("packageName").split("\\.");
        for (int i = 0; i < packagePath.length; i++) {
            path = path.append(packagePath[i]);
            folder = workspaceRoot.getFolder(path);
            if (!folder.exists())
                folder.create(true, true, progressMonitor());
        }
        env().wDefValue("folder", folder);
        if (env().wIsSet("derived"))
            folder.setDerived(true, progressMonitor());
        if (env().wIsSet("readonly")) {
            ResourceAttributes attributes = folder.getResourceAttributes();
            if (attributes != null) {
                attributes.setReadOnly(true);
                folder.setResourceAttributes(attributes);
            }
        }
    } catch (CoreException e) {
        throw new VisitException(e);
    // } catch (NullPointerException e) {
    // throw new VisitException("No Project");
    }
    entity.getArtifacts().accept(this);
    env().wExitScope();
}
Also used : IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes) IFolder(org.eclipse.core.resources.IFolder)

Example 15 with ResourceAttributes

use of org.eclipse.core.resources.ResourceAttributes in project flux by eclipse.

the class Resources method setReadOnly.

static void setReadOnly(IResource resource, boolean readOnly) {
    ResourceAttributes resourceAttributes = resource.getResourceAttributes();
    if (// not supported on this platform for this resource
    resourceAttributes == null)
        return;
    resourceAttributes.setReadOnly(readOnly);
    try {
        resource.setResourceAttributes(resourceAttributes);
    } catch (CoreException e) {
    //JavaPlugin.log(e);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes)

Aggregations

ResourceAttributes (org.eclipse.core.resources.ResourceAttributes)26 IFile (org.eclipse.core.resources.IFile)10 CoreException (org.eclipse.core.runtime.CoreException)9 IResource (org.eclipse.core.resources.IResource)7 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IFolder (org.eclipse.core.resources.IFolder)4 InputStream (java.io.InputStream)3 IProject (org.eclipse.core.resources.IProject)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 IPath (org.eclipse.core.runtime.IPath)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 Activity (com.centurylink.mdw.plugin.designer.model.Activity)1 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)1 ArtifactResourceListener (com.centurylink.mdw.plugin.workspace.ArtifactResourceListener)1 TempFileRemover (com.centurylink.mdw.plugin.workspace.TempFileRemover)1 BufferedInputStream (java.io.BufferedInputStream)1