Java Code Examples for org.eclipse.core.filesystem.IFileStore#isParentOf()

The following examples show how to use org.eclipse.core.filesystem.IFileStore#isParentOf() . 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: SdkUtils.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean isInsideSdkLibraryDefinitions(Sdk sdk, IFileStore fileStore) {
	if (sdk == null || fileStore == null) {
		return false;
	}
	String sdkHomePath = sdk.getSdkHomePath();
	if (sdkHomePath != null) {
		File sdkHomeDir = new File(sdkHomePath);
		if (sdkHomeDir.isDirectory()) {
			IFileStore sdkHomeFileStore = ResourceUtils.toFileStore(sdkHomeDir);
			if (sdkHomeFileStore != null) {
				return sdkHomeFileStore.isParentOf(fileStore);
			}
		}
	}
	return false;
}
 
Example 2
Source File: IndexFilterManager.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * isFilteredItem
 * 
 * @param item
 * @return
 */
public boolean isFilteredItem(IFileStore item)
{
	if (item != null)
	{
		for (IFileStore candidate : getFilteredItems())
		{
			if (candidate.equals(item) || candidate.isParentOf(item))
			{
				return true;
			}
		}
	}

	return false;
}
 
Example 3
Source File: GitIgnoreHandlerV1.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
private boolean handlePut(HttpServletRequest request, HttpServletResponse response, IPath filePath) throws JSONException, IOException, ServletException,
		CoreException {

	JSONObject toIgnore = OrionServlet.readJSONRequest(request);
	JSONArray paths = toIgnore.optJSONArray(ProtocolConstants.KEY_PATH);

	if (paths.length() < 1)
		return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST,
				"No paths to insert into .gitignore", null));

	/* remove /file */
	IFileStore projectStore = NewFileServlet.getFileStore(null, filePath.removeFirstSegments(1));

	for (int i = 0; i < paths.length(); ++i) {

		IPath path = new Path(paths.getString(i));
		IFileStore pathStore = projectStore.getFileStore(path);
		IFileStore gitignoreStore = pathStore.getParent().getFileStore(new Path(DOT_GIT_IGNORE));

		if (!pathStore.fetchInfo().exists() || !projectStore.isParentOf(gitignoreStore)) {
			String msg = NLS.bind("Invalid path: {0}", EncodingUtils.encodeForHTML(path.toString()));
			ServerStatus status = new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null);
			return statusHandler.handleRequest(request, response, status);
		}

		/* update the .gitignore file */
		appendGitignore(gitignoreStore, pathStore.getName());
	}

	return true;
}
 
Example 4
Source File: EFSUtils.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the path of this file relative to the parent
 * 
 * @param file
 * @param obsoleted
 *            TODO
 * @return
 * @throws CoreException
 * @deprecated
 */
public static String getRelativePath(IFileStore parent, IFileStore file, Object obsoleted)
{
	if (parent.equals(file) || parent.isParentOf(file))
	{
		String rootFile = getAbsolutePath(parent);
		String childFile = getAbsolutePath(file);
		if (rootFile != null && childFile != null)
		{
			return childFile.substring(rootFile.length());
		}
	}
	return null;
}
 
Example 5
Source File: EFSUtils.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * getRelativePath
 * 
 * @param parentFileStore
 * @param childFileStore
 * @return
 */
public static IPath getRelativePath(IFileStore parentFileStore, IFileStore childFileStore)
{
	if (parentFileStore.isParentOf(childFileStore))
	{
		IPath parentPath = Path.fromPortableString(parentFileStore.toURI().getPath());
		IPath childPath = Path.fromPortableString(childFileStore.toURI().getPath());
		return childPath.makeRelativeTo(parentPath);
	}
	return null;
}
 
Example 6
Source File: IndexFilterManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * addFilterItem
 * 
 * @param IFileStore
 */
public void addFilterItem(IFileStore item)
{
	if (item == null)
	{
		return;
	}

	// only add if this item isn't being filtered already
	if (!isFilteredItem(item))
	{
		// remove any pre-existing file stores that are children of the
		// item we're about to add
		Set<IFileStore> toRemove = new HashSet<IFileStore>(this._filteredItems.size());

		for (IFileStore candidate : this._filteredItems)
		{
			if (item.isParentOf(candidate))
			{
				toRemove.add(candidate);
			}
		}

		this._filteredItems.removeAll(toRemove);

		// add new item to our list
		this._filteredItems.add(item);
	}
}
 
Example 7
Source File: CopyFilesAndFoldersOperation.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks whether the destination is valid for copying the source file
 * stores.
 * <p>
 * Note this method is for internal use only. It is not API.
 * </p>
 * <p>
 * TODO Bug 117804. This method has been renamed to avoid a bug in the
 * Eclipse compiler with regards to visibility and type resolution when
 * linking.
 * </p>
 *
 * @param destination
 *            the destination container
 * @param sourceStores
 *            the source IFileStore
 * @return an error message, or <code>null</code> if the path is valid
 */
private String validateImportDestinationInternal(IContainer destination, IFileStore[] sourceStores) {
    if (!isAccessible(destination)) {
        return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_destinationAccessError;
    }

    IFileStore destinationStore;
    try {
        destinationStore = EFS.getStore(destination.getLocationURI());
    } catch (CoreException exception) {
        IDEWorkbenchPlugin.log(exception.getLocalizedMessage(), exception);
        return NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_internalError,
                exception.getLocalizedMessage());
    }
    for (int i = 0; i < sourceStores.length; i++) {
        IFileStore sourceStore = sourceStores[i];
        IFileStore sourceParentStore = sourceStore.getParent();

        if (sourceStore != null) {
            if (destinationStore.equals(sourceStore)
                    || (sourceParentStore != null && destinationStore.equals(sourceParentStore))) {
                return NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_importSameSourceAndDest,
                        sourceStore.getName());
            }
            // work around bug 16202. replacement for
            // sourcePath.isPrefixOf(destinationPath)
            IFileStore destinationParent = destinationStore.getParent();
            if (sourceStore.isParentOf(destinationParent)) {
                return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_destinationDescendentError;
            }

        }
    }
    return null;
}
 
Example 8
Source File: InheritanceUtils.java    From orion.server with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * @param sandbox The file store used to limit manifest inheritance, i.e. each parent manifest has to be a
 *  transitive child of the sandbox.
 * @param current Manifest file store used to fetch the manifest contents.
 * @param parent  Parent manifest file store path.
 * @return whether the parent manifest is within the given sandbox or not.
 */
public static boolean isWithinSandbox(IFileStore sandbox, IFileStore current, IPath parent) {
	return sandbox.isParentOf(current.getParent().getFileStore(parent));
}