private void disableRunningGraphResource(IEditorInput editorInput,String partName){ if(editorInput instanceof IFileEditorInput){ IFileEditorInput input = (IFileEditorInput)editorInput ; IFile fileJob = input.getFile(); IPath xmlFileIPath =new Path(input.getFile().getFullPath().toOSString().replace(".job", ".xml")); IFile fileXml = ResourcesPlugin.getWorkspace().getRoot().getFile(xmlFileIPath); ResourceAttributes attributes = new ResourceAttributes(); attributes.setReadOnly(true); attributes.setExecutable(true); try { fileJob.setResourceAttributes(attributes); fileXml.setResourceAttributes(attributes); } catch (CoreException e) { logger.error("Unable to disable running job resources", e); } } }
private void enableRunningGraphResource(IEditorInput editorInput, String partName) { IFileEditorInput input = (IFileEditorInput)editorInput ; IFile fileJob = input.getFile(); IPath xmlFileIPath =new Path(input.getFile().getFullPath().toOSString().replace(".job", ".xml")); IFile fileXml = ResourcesPlugin.getWorkspace().getRoot().getFile(xmlFileIPath); ResourceAttributes attributes = new ResourceAttributes(); attributes.setReadOnly(false); attributes.setExecutable(true); try { if(fileJob.exists()){ fileJob.setResourceAttributes(attributes); } if(fileXml.exists()){ fileXml.setResourceAttributes(attributes); } } catch (CoreException e) { logger.error("Unable to enable locked job resources",e); } }
/** * Check if the supplied resource is read only or null. If it is then ask * the user if they want to continue. Return true if the resource is not * read only or if the user has given permission. * * @return boolean */ private boolean checkReadOnlyAndNull(IResource currentResource) { // Do a quick read only and null check if (currentResource == null) { return false; } // Do a quick read only check final ResourceAttributes attributes = currentResource .getResourceAttributes(); if (attributes != null && attributes.isReadOnly()) { return MessageDialog.openQuestion(shellProvider.getShell(), CHECK_RENAME_TITLE, MessageFormat.format(CHECK_RENAME_MESSAGE, new Object[] { currentResource.getName() })); } return true; }
private void setFileAccess(IFile file) { if (file != null && isInstalled()) { ResourceAttributes resourceAttributes = new ResourceAttributes(); resourceAttributes.setReadOnly(true); try { file.setResourceAttributes(resourceAttributes); } catch (CoreException e) { String logMessage = Utils.generateCoreExceptionLog(e); logger.warn("Unable to set read-only on file " + resource.getName() + ": " + logMessage); } if (logger.isDebugEnabled()) { logger.debug("Set read-only access on " + file.getName()); } } }
@Override public boolean isReadOnly() { if (fTextFileBuffer != null) { return fTextFileBuffer.isCommitable(); } ResourceAttributes attributes = fFile.getResourceAttributes(); return attributes != null ? attributes.isReadOnly() : false; }
@Test public void testReadOnly() throws Exception { if (BUG_6054) { printTestDisabledMessage( "see bug#6054 (renaming a read-only package resets the read-only flag)"); return; } fIsPreDeltaTest = true; String[] packageNames = new String[] {"r"}; String[][] packageFileNames = new String[][] {{"A"}}; String newPackageName = "p1"; IPackageFragment[] packages = new IPackageFragment[packageNames.length]; ICompilationUnit[][] cus = new ICompilationUnit[packageFileNames.length][packageFileNames[0].length]; for (int i = 0; i < packageNames.length; i++) { packages[i] = getRoot().createPackageFragment(packageNames[i], true, null); for (int j = 0; j < packageFileNames[i].length; j++) { cus[i][j] = createCUfromTestFile( packages[i], packageFileNames[i][j], packageNames[i].replace('.', '/') + "/"); } } IPackageFragment thisPackage = packages[0]; final IResource resource = thisPackage.getCorrespondingResource(); final ResourceAttributes attributes = resource.getResourceAttributes(); if (attributes != null) attributes.setReadOnly(true); RefactoringStatus result = performRefactoring(createRefactoringDescriptor(thisPackage, newPackageName)); TestCase.assertEquals("preconditions were supposed to pass", null, result); assertTrue("package not renamed", !getRoot().getPackageFragment(packageNames[0]).exists()); IPackageFragment newPackage = getRoot().getPackageFragment(newPackageName); assertTrue("new package does not exist", newPackage.exists()); assertTrue("new package should be read-only", attributes == null || attributes.isReadOnly()); }
static void setReadOnly(IResource resource, boolean readOnly) { ResourceAttributes resourceAttributes = resource.getResourceAttributes(); if (resourceAttributes == null) // not supported on this platform for this resource return; resourceAttributes.setReadOnly(readOnly); try { resource.setResourceAttributes(resourceAttributes); } catch (CoreException e) { JavaPlugin.log(e); } }
@Override public boolean canEnable() throws JavaModelException { if (!super.canEnable()) return false; IPackageFragmentRoot[] roots = getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { IPackageFragmentRoot root = roots[i]; if (root.isReadOnly() && !root.isArchive() && !root.isExternal()) { final ResourceAttributes attributes = roots[i].getResource().getResourceAttributes(); if (attributes == null || attributes.isReadOnly()) return false; } } return roots.length > 0; }
public boolean isReadOnly() { // if (fTextFileBuffer != null) // return !fTextFileBuffer.isCommitable(); IResource resource = getUnderlyingResource(); if (resource == null) return true; final ResourceAttributes attributes = resource.getResourceAttributes(); return attributes == null ? false : attributes.isReadOnly(); }
static void setReadOnly(IResource resource, boolean readOnly) { ResourceAttributes resourceAttributes = resource.getResourceAttributes(); if (resourceAttributes == null) // not supported on this platform for this resource return; resourceAttributes.setReadOnly(readOnly); try { resource.setResourceAttributes(resourceAttributes); } catch (CoreException e) { RefactoringCorePlugin.log(e); } }
/** * Check if the supplied resource is read only or null. If it is then ask the user if they want to continue. Return * true if the resource is not read only or if the user has given permission. * * @return boolean */ private boolean checkReadOnlyAndNull(final IResource currentResource) { // Do a quick read only and null check if (currentResource == null) { return false; } // Do a quick read only check final ResourceAttributes attributes = currentResource.getResourceAttributes(); if (attributes != null && attributes .isReadOnly()) { return MessageDialog.openQuestion(WorkbenchHelper.getShell(), CHECK_RENAME_TITLE, MessageFormat.format(CHECK_RENAME_MESSAGE, new Object[] { currentResource.getName() })); } return true; }
/** * Writes data into a resource with the given resourceName residing in the * source folder of the given project. The previous file content is lost. * Temporarily resets the "read-only" file attribute if one is present. * * @param file to set contents for * @param data to write into the file * @throws CoreException */ public static void writeFile(IFile file, String data) throws CoreException { if (file != null && file.exists()) { ResourceAttributes resourceAttributes = file.getResourceAttributes(); if (resourceAttributes.isReadOnly()) { resourceAttributes.setReadOnly(false); file.setResourceAttributes(resourceAttributes); } file.setContents(new ByteArrayInputStream(data.getBytes()), IFile.FORCE, null); resourceAttributes.setReadOnly(true); file.setResourceAttributes(resourceAttributes); } }
@Override public boolean canEnable() throws JavaModelException { if (!super.canEnable()) return false; IPackageFragmentRoot[] roots= getPackageFragmentRoots(); for (int i= 0; i < roots.length; i++) { IPackageFragmentRoot root= roots[i]; if (root.isReadOnly() && !root.isArchive() && !root.isExternal()) { final ResourceAttributes attributes= roots[i].getResource().getResourceAttributes(); if (attributes == null || attributes.isReadOnly()) return false; } } return roots.length > 0; }
public boolean isReadOnly() { if (fTextFileBuffer != null) return !fTextFileBuffer.isCommitable(); IResource resource= getUnderlyingResource(); if (resource == null) return true; final ResourceAttributes attributes= resource.getResourceAttributes(); return attributes == null ? false : attributes.isReadOnly(); }
public static boolean isReadOnly(IResource resource) { ResourceAttributes resourceAttributes = resource.getResourceAttributes(); if (resourceAttributes == null) { return false; } return resourceAttributes.isReadOnly(); }
@Override public ResourceAttributes getResourceAttributes() { // not required return null; }
@Override public void setResourceAttributes(ResourceAttributes attributes) throws CoreException { // not required }
@Override public ResourceAttributes getResourceAttributes() { // throw new UnsupportedOperationException(); return new ResourceAttributes(); }
@Override public void setResourceAttributes(ResourceAttributes attributes) throws CoreException { throw new UnsupportedOperationException(); }
private boolean isReadOnly(IResource resource) { ResourceAttributes attributes = resource.getResourceAttributes(); return attributes == null ? false : attributes.isReadOnly(); }
public static boolean isReadOnly(IResource resource) { ResourceAttributes resourceAttributes = resource.getResourceAttributes(); if (resourceAttributes == null) // not supported on this platform for this resource return false; return resourceAttributes.isReadOnly(); }
/** * {@inheritDoc} */ @Override public ResourceAttributes getResourceAttributes() { return resource().getResourceAttributes(); }
/** * {@inheritDoc} */ @Override public void setResourceAttributes(final ResourceAttributes attributes) throws CoreException { resource().setResourceAttributes(attributes); }
public ResourceAttributes getResourceAttributes() { throw new RuntimeException("not implemented"); //$NON-NLS-1$ // return null; }
public void setResourceAttributes(ResourceAttributes arg0) throws CoreException { throw new RuntimeException("not implemented"); //$NON-NLS-1$ }
public static Map<String, ?> attributes(String platformResourcePath, Map<?, ?> options) { IResource resource = workspaceRoot.findMember(new Path(platformResourcePath)); Map<String, Object> result = new HashMap<String, Object>(); if (resource != null) { @SuppressWarnings("unchecked") Set<String> requestedAttributes = options == null ? null : (Set<String>)options.get(URIConverter.OPTION_REQUESTED_ATTRIBUTES); if (requestedAttributes == null || requestedAttributes.contains(URIConverter.ATTRIBUTE_TIME_STAMP)) { result.put(URIConverter.ATTRIBUTE_TIME_STAMP, resource.getLocalTimeStamp()); } ResourceAttributes resourceAttributes = null; if (requestedAttributes == null || requestedAttributes.contains(URIConverter.ATTRIBUTE_READ_ONLY)) { resourceAttributes = resource.getResourceAttributes(); if (resourceAttributes == null) { return result; } result.put(URIConverter.ATTRIBUTE_READ_ONLY, resourceAttributes.isReadOnly()); } if (requestedAttributes == null || requestedAttributes.contains(URIConverter.ATTRIBUTE_ARCHIVE)) { if (resourceAttributes == null) { resourceAttributes = resource.getResourceAttributes(); if (resourceAttributes == null) { return result; } } result.put(URIConverter.ATTRIBUTE_ARCHIVE, resourceAttributes.isArchive()); } if (requestedAttributes == null || requestedAttributes.contains(URIConverter.ATTRIBUTE_EXECUTABLE)) { if (resourceAttributes == null) { resourceAttributes = resource.getResourceAttributes(); if (resourceAttributes == null) { return result; } } result.put(URIConverter.ATTRIBUTE_EXECUTABLE, resourceAttributes.isExecutable()); } if (requestedAttributes == null || requestedAttributes.contains(URIConverter.ATTRIBUTE_HIDDEN)) { if (resourceAttributes == null) { resourceAttributes = resource.getResourceAttributes(); if (resourceAttributes == null) { return result; } } result.put(URIConverter.ATTRIBUTE_HIDDEN, resourceAttributes.isHidden()); } if (requestedAttributes == null || requestedAttributes.contains(URIConverter.ATTRIBUTE_DIRECTORY)) { if (resourceAttributes == null) { resourceAttributes = resource.getResourceAttributes(); if (resourceAttributes == null) { return result; } } result.put(URIConverter.ATTRIBUTE_DIRECTORY, resource instanceof IContainer); } } return result; }
public static void updateAttributes(String platformResourcePath, Map<String, ?> attributes, Map<?, ?> options) throws IOException { IResource resource = workspaceRoot.findMember(new Path(platformResourcePath)); if (resource == null) { throw new FileNotFoundException("The resource " + platformResourcePath + " does not exist"); } else { try { Long timeStamp = (Long)attributes.get(URIConverter.ATTRIBUTE_TIME_STAMP); if (timeStamp != null) { resource.setLocalTimeStamp(timeStamp); } ResourceAttributes resourceAttributes = null; Boolean readOnly = (Boolean)attributes.get(URIConverter.ATTRIBUTE_READ_ONLY); if (readOnly != null) { resourceAttributes = resource.getResourceAttributes(); if (resourceAttributes == null) { return; } resourceAttributes.setReadOnly(readOnly); } Boolean archive = (Boolean)attributes.get(URIConverter.ATTRIBUTE_ARCHIVE); if (archive != null) { if (resourceAttributes == null) { resourceAttributes = resource.getResourceAttributes(); if (resourceAttributes == null) { return; } } resourceAttributes.setArchive(archive); } Boolean executable = (Boolean)attributes.get(URIConverter.ATTRIBUTE_EXECUTABLE); if (executable != null) { if (resourceAttributes == null) { resourceAttributes = resource.getResourceAttributes(); if (resourceAttributes == null) { return; } } resourceAttributes.setExecutable(executable); } Boolean hidden = (Boolean)attributes.get(URIConverter.ATTRIBUTE_HIDDEN); if (hidden != null) { if (resourceAttributes == null) { resourceAttributes = resource.getResourceAttributes(); if (resourceAttributes == null) { return; } } resourceAttributes.setHidden(hidden); } if (resourceAttributes != null) { resource.setResourceAttributes(resourceAttributes); } } catch (CoreException exception) { throw new Resource.IOWrappedException(exception); } } }
@Override public ResourceAttributes getResourceAttributes() { throw new RuntimeException("Not implemented"); }
public static Map<String, ?> attributes(String platformResourcePath, Map<?, ?> options) { IResource resource = workspaceRoot.findMember(new Path(platformResourcePath)); Map<String, Object> result = new HashMap<String, Object>(); if (resource != null) { @SuppressWarnings("unchecked") Set<String> requestedAttributes = options == null ? null : (Set<String>)options.get(URIConverter.OPTION_REQUESTED_ATTRIBUTES); if (requestedAttributes == null || requestedAttributes.contains(URIConverter.ATTRIBUTE_TIME_STAMP)) { result.put(URIConverter.ATTRIBUTE_TIME_STAMP, resource.getLocalTimeStamp()); } ResourceAttributes resourceAttributes = null; if (requestedAttributes == null || requestedAttributes.contains(URIConverter.ATTRIBUTE_READ_ONLY)) { resourceAttributes = resource.getResourceAttributes(); result.put(URIConverter.ATTRIBUTE_READ_ONLY, resourceAttributes.isReadOnly()); } if (requestedAttributes == null || requestedAttributes.contains(URIConverter.ATTRIBUTE_ARCHIVE)) { if (resourceAttributes == null) { resourceAttributes = resource.getResourceAttributes(); } result.put(URIConverter.ATTRIBUTE_ARCHIVE, resourceAttributes.isArchive()); } if (requestedAttributes == null || requestedAttributes.contains(URIConverter.ATTRIBUTE_EXECUTABLE)) { if (resourceAttributes == null) { resourceAttributes = resource.getResourceAttributes(); } result.put(URIConverter.ATTRIBUTE_EXECUTABLE, resourceAttributes.isExecutable()); } if (requestedAttributes == null || requestedAttributes.contains(URIConverter.ATTRIBUTE_HIDDEN)) { if (resourceAttributes == null) { resourceAttributes = resource.getResourceAttributes(); } result.put(URIConverter.ATTRIBUTE_HIDDEN, resourceAttributes.isHidden()); } if (requestedAttributes == null || requestedAttributes.contains(URIConverter.ATTRIBUTE_DIRECTORY)) { if (resourceAttributes == null) { resourceAttributes = resource.getResourceAttributes(); } result.put(URIConverter.ATTRIBUTE_DIRECTORY, resource instanceof IContainer); } } return result; }
public static void updateAttributes(String platformResourcePath, Map<String, ?> attributes, Map<?, ?> options) throws IOException { IResource resource = workspaceRoot.findMember(new Path(platformResourcePath)); if (resource == null) { throw new FileNotFoundException("The resource " + platformResourcePath + " does not exist"); } else { try { Long timeStamp = (Long)attributes.get(URIConverter.ATTRIBUTE_TIME_STAMP); if (timeStamp != null) { resource.setLocalTimeStamp(timeStamp); } ResourceAttributes resourceAttributes = null; Boolean readOnly = (Boolean)attributes.get(URIConverter.ATTRIBUTE_READ_ONLY); if (readOnly != null) { resourceAttributes = resource.getResourceAttributes(); resourceAttributes.setReadOnly(readOnly); } Boolean archive = (Boolean)attributes.get(URIConverter.ATTRIBUTE_ARCHIVE); if (archive != null) { if (resourceAttributes == null) { resourceAttributes = resource.getResourceAttributes(); } resourceAttributes.setArchive(archive); } Boolean executable = (Boolean)attributes.get(URIConverter.ATTRIBUTE_EXECUTABLE); if (executable != null) { if (resourceAttributes == null) { resourceAttributes = resource.getResourceAttributes(); } resourceAttributes.setExecutable(executable); } Boolean hidden = (Boolean)attributes.get(URIConverter.ATTRIBUTE_HIDDEN); if (hidden != null) { if (resourceAttributes == null) { resourceAttributes = resource.getResourceAttributes(); } resourceAttributes.setHidden(hidden); } if (resourceAttributes != null) { resource.setResourceAttributes(resourceAttributes); } } catch (CoreException exception) { throw new Resource.IOWrappedException(exception); } } }
@Override public void setResourceAttributes(ResourceAttributes attributes) throws CoreException { }