Java Code Examples for org.eclipse.core.resources.IResource#SHALLOW

The following examples show how to use org.eclipse.core.resources.IResource#SHALLOW . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceUtilTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void createLinkCopyAndVerify(IPath path, String name, boolean isFile, boolean isSymLink, boolean isShallow, boolean isAbsolute) throws IOException, CoreException {
    IResource originialResource = createAndVerifyLink(path, name, isFile, isSymLink);
    originialResource.setPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, PROPERTY_KEY), PROPERTY_VALUE);
    IPath newPath;
    if (isAbsolute) {
        newPath = originialResource.getParent().getFullPath().addTrailingSeparator().append(name + COPY_SUFFIX);
    } else {
        newPath = new Path ("..").append(originialResource.getParent().getName()).append(name + COPY_SUFFIX);
    }
    int flags = IResource.FORCE;
    flags |= (isShallow ? IResource.SHALLOW : 0);
    IResource copyResource = ResourceUtil.copyResource(originialResource, checkNotNull(newPath), flags, null);
    assertNotNull(copyResource);
    assertTrue(copyResource.exists());
    assertTrue(isFileSystemSymbolicLink(copyResource) == (isSymLink && isShallow));
    assertTrue(copyResource.isLinked() == (!isSymLink && isShallow));
    assertTrue(ResourceUtil.isSymbolicLink(copyResource) == ((isSymLink && isShallow) || (!isSymLink && isShallow)));

    Map<QualifiedName, String> persistentProperties = copyResource.getPersistentProperties();
    assertEquals(1, persistentProperties.size());
    for (Map.Entry<QualifiedName, String> entry: persistentProperties.entrySet()) {
        assertEquals(PROPERTY_KEY, entry.getKey().getLocalName());
        assertEquals(Activator.PLUGIN_ID, entry.getKey().getQualifier());
        assertEquals(PROPERTY_VALUE, entry.getValue());
    }
    originialResource.delete(true, null);
    copyResource.delete(true, null);
}
 
Example 2
Source File: TmfCommonProjectElement.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Copy this model element to the destinationPath
 *
 * @param copySuppFiles
 *            Whether to copy supplementary files or not
 * @param copyAsLink
 *            Whether to copy as a link or not
 * @param destinationPath
 *            The path where the element will be copied
 * @return the new Resource object
 * @since 3.3
 */
public IResource copy(final boolean copySuppFiles, final boolean copyAsLink, IPath destinationPath) {
    /* Copy supplementary files first, only if needed */
    if (copySuppFiles) {
        String newElementPath = getDestinationPathRelativeToParent(destinationPath);
        copySupplementaryFolder(newElementPath);
    }
    /* Copy the trace */
    try {
        int flags = IResource.FORCE;
        if (copyAsLink) {
            flags |= IResource.SHALLOW;
        }

        IResource trace = ResourceUtil.copyResource(getResource(), destinationPath, flags, null);

        /* Delete any bookmarks file found in copied trace folder */
        if (trace instanceof IFolder) {
            IFolder folderTrace = (IFolder) trace;
            for (IResource member : folderTrace.members()) {
                String traceTypeId = TmfTraceType.getTraceTypeId(member);
                if (ITmfEventsEditorConstants.TRACE_INPUT_TYPE_CONSTANTS.contains(traceTypeId)
                        || ITmfEventsEditorConstants.EXPERIMENT_INPUT_TYPE_CONSTANTS.contains(traceTypeId)) {
                    member.delete(true, null);
                }
            }
        }
        return trace;
    } catch (CoreException e) {
        Activator.getDefault().logError("Error copying " + getName(), e); //$NON-NLS-1$
    }
    return null;
}
 
Example 3
Source File: PackageFragmentRootReorgChange.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
protected int getResourceUpdateFlags(){
	return IResource.KEEP_HISTORY | IResource.SHALLOW;
}
 
Example 4
Source File: CopyResourceChange.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private int getReorgFlags() {
	return IResource.KEEP_HISTORY | IResource.SHALLOW;
}
 
Example 5
Source File: ResourceUtil.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Copy a resource in the file system.
 *
 * The supplied destination path may be absolute or relative. Absolute paths
 * fully specify the new location for the resource relative to the workspace
 * root, including its project. Relative paths are considered to be relative to
 * the container of the resource being copied.
 *
 * @param resource
 *            the resource in the workspace
 * @param destinationPath
 *            the destination path
 * @param flags
 *            update flags according to IResource.copy(). Note for file system
 *            symbolic links only IResource.SHALLOW is supported
 * @param monitor
 *            the progress monitor or null.
 * @return the copied resource or null
 * @throws CoreException
 *             if an error occurs
 */
public static @Nullable IResource copyResource(@Nullable IResource resource, @Nullable IPath destinationPath, int flags, @Nullable IProgressMonitor monitor) throws CoreException {
    if (resource == null || destinationPath == null) {
        return null;
    }
    SubMonitor subMon = SubMonitor.convert(monitor, 1);
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    boolean isFileSystemSymbolicLink = ResourceUtil.isFileSystemSymbolicLink(resource);
    // make path absolute
    IPath target = destinationPath.isAbsolute() ? destinationPath : resource.getParent().getFullPath().append(destinationPath);
    if (isFileSystemSymbolicLink &&
            ((flags & IResource.SHALLOW) != 0) &&
            ((resource instanceof IFile)
                    || (resource instanceof IFolder))) {
        return copySymlink(resource, checkNotNull(target), checkNotNull(subMon), checkNotNull(workspaceRoot));
    }
    // use eclipse copy
    resource.copy(destinationPath, flags, subMon);
    return workspaceRoot.findMember(target);
}
 
Example 6
Source File: PackageFragmentRootReorgChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected int getResourceUpdateFlags(){
	return IResource.KEEP_HISTORY | IResource.SHALLOW;
}
 
Example 7
Source File: CopyResourceChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private int getReorgFlags() {
	return IResource.KEEP_HISTORY | IResource.SHALLOW;
}
 
Example 8
Source File: RenameSourceFolderChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private int getCoreMoveFlags() {
	if (getResource().isLinked())
		return IResource.SHALLOW;
	else
		return IResource.NONE;
}