Java Code Examples for org.eclipse.core.runtime.IPath#uptoSegment()

The following examples show how to use org.eclipse.core.runtime.IPath#uptoSegment() . 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: Commit.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
protected URI createDiffLocation(String toRefId, String fromRefId, String path) throws URISyntaxException {
	IPath diffPath = new Path(GitServlet.GIT_URI).append(Diff.RESOURCE);

	// diff range format is [fromRef..]toRef
	String diffRange = ""; //$NON-NLS-1$
	if (fromRefId != null)
		diffRange = fromRefId + ".."; //$NON-NLS-1$
	diffRange += toRefId;
	diffPath = diffPath.append(diffRange);

	// clone location is of the form /gitapi/clone/file/{workspaceId}/{projectName}[/{path}]
	IPath clonePath = new Path(cloneLocation.getPath()).removeFirstSegments(2);
	if (path == null) {
		diffPath = diffPath.append(clonePath);
	} else if (isRoot) {
		diffPath = diffPath.append(clonePath).append(path);
	} else {
		// need to start from the project root
		// project path is of the form /file/{workspaceId}/{projectName}
		IPath projectRoot = clonePath.uptoSegment(3);
		diffPath = diffPath.append(projectRoot).append(path);
	}

	return new URI(cloneLocation.getScheme(), cloneLocation.getAuthority(), diffPath.toString(), null, null);
}
 
Example 2
Source File: ProjectUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static Map<IPath, Set<String>> groupGlobsByPrefix(IPath base, Set<String> globs) {
	Map<IPath, Set<String>> groupedPatterns = new HashMap<>();
	for (String glob: globs) {
		IPath pattern = resolveGlobPath(base, glob); // Resolve to absolute path
		int prefixLength = 0;
		while (prefixLength < pattern.segmentCount()) {
			// org.codehaus.plexus.util.DirectoryScanner only supports * and ?
			// and does not handle escaping, so break on these two special chars
			String segment = pattern.segment(prefixLength);
			if (segment.contains("*") || segment.contains("?")) {
				break;
			}
			prefixLength += 1;
		}
		IPath prefix = pattern.uptoSegment(prefixLength);
		IPath remain = pattern.removeFirstSegments(prefixLength).setDevice(null);
		if (!groupedPatterns.containsKey(prefix)) {
			groupedPatterns.put(prefix, new LinkedHashSet<>());
		}
		groupedPatterns.get(prefix).add(remain.toOSString());
	}
	return groupedPatterns;
}
 
Example 3
Source File: SarlClassPathDetector.java    From sarl with Apache License 2.0 6 votes vote down vote up
private IPath findSarlSourceFolder(IPath path) {
	for (final IPath sourceFolder : this.sourceFolders.keySet()) {
		if (sourceFolder.isPrefixOf(path)) {
			return sourceFolder;
		}
	}
	final IPath projectPath = path.uptoSegment(1);
	final IPath stdSarl = projectPath.append(this.standardSarlSourceFolder);
	if (stdSarl.isPrefixOf(path)) {
		return stdSarl;
	}
	final IPath testSarl = projectPath.append(this.testSarlSourceFolder);
	if (testSarl.isPrefixOf(path)) {
		return testSarl;
	}
	return null;
}
 
Example 4
Source File: Log.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
private Remote findRemote(String refName) throws URISyntaxException {
	Assert.isLegal(refName.startsWith(Constants.R_REMOTES), NLS.bind("Expected Ref starting with {0} was {1}", Constants.R_REMOTES, refName));
	IPath remoteNameCandidate = new Path(refName).removeFirstSegments(2);
	List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(getConfig());
	for (int i = 1; i < remoteNameCandidate.segmentCount(); i++) {
		for (RemoteConfig remoteConfig : remoteConfigs) {
			IPath uptoSegment = remoteNameCandidate.uptoSegment(i);
			if (remoteConfig.getName().equals(uptoSegment.toString()))
				return new Remote(cloneLocation, db, remoteConfig.getName());
		}
	}
	Assert.isTrue(false, NLS.bind("Could not find Remote for {0}", refName));
	return null;
}
 
Example 5
Source File: ClassPathDetector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IPath getFolderPath(IPath packPath, IPath relpath) {
	int remainingSegments= packPath.segmentCount() - relpath.segmentCount();
	if (remainingSegments >= 0) {
		IPath common= packPath.removeFirstSegments(remainingSegments);
		if (common.equals(relpath)) {
			return packPath.uptoSegment(remainingSegments);
		}
	}
	return null;
}
 
Example 6
Source File: SarlClassPathDetector.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the folder path.
 *
 * @param packPath the path to path.
 * @param relpath the relative path.
 * @return the folder path or {@code null} if it cannot be computed.
 */
protected static IPath getFolderPath(IPath packPath, IPath relpath) {
	final int remainingSegments = packPath.segmentCount() - relpath.segmentCount();
	if (remainingSegments >= 0) {
		final IPath common = packPath.removeFirstSegments(remainingSegments);
		if (common.equals(relpath)) {
			return packPath.uptoSegment(remainingSegments);
		}
	}
	return null;
}
 
Example 7
Source File: EditorInputFactory.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates an editor input for the passed file.
 *
 * If forceExternalFile is True, it won't even try to create a FileEditorInput, otherwise,
 * it will try to create it with the most suitable type it can
 * (i.e.: FileEditorInput, FileStoreEditorInput, PydevFileEditorInput, ...)
 */
public static IEditorInput create(File file, boolean forceExternalFile) {
    IPath path = Path.fromOSString(FileUtils.getFileAbsolutePath(file));

    if (!forceExternalFile) {
        //May call again to this method (but with forceExternalFile = true)
        IEditorInput input = new PySourceLocatorBase().createEditorInput(path, false, null, null);
        if (input != null) {
            return input;
        }
    }

    IPath zipPath = new Path("");
    while (path.segmentCount() > 0) {
        if (path.toFile().exists()) {
            break;
        }
        zipPath = new Path(path.lastSegment()).append(zipPath);
        path = path.uptoSegment(path.segmentCount() - 1);
    }

    if (zipPath.segmentCount() > 0 && path.segmentCount() > 0) {
        return new PydevZipFileEditorInput(new PydevZipFileStorage(path.toFile(), zipPath.toPortableString()));
    }

    try {
        URI uri = file.toURI();
        return new FileStoreEditorInput(EFS.getStore(uri));
    } catch (Throwable e) {
        //not always available! (only added in eclipse 3.3)
        return new PydevFileEditorInput(file);
    }
}