Java Code Examples for org.eclipse.core.runtime.Path#segment()

The following examples show how to use org.eclipse.core.runtime.Path#segment() . 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: GitRemoteHandlerV1.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
private boolean handleDelete(HttpServletRequest request, HttpServletResponse response, String path) throws CoreException, IOException, URISyntaxException,
		JSONException, ServletException {
	Path p = new Path(path);
	if (p.segment(1).equals("file")) { //$NON-NLS-1$
		// expected path: /gitapi/remote/{remote}/file/{path}
		String remoteName = p.segment(0);

		File gitDir = GitUtils.getGitDir(p.removeFirstSegments(1));
		Repository db = null;
		try {
			db = FileRepositoryBuilder.create(gitDir);
			StoredConfig config = db.getConfig();
			config.unsetSection(ConfigConstants.CONFIG_REMOTE_SECTION, remoteName);
			config.save();
			// TODO: handle result
			return true;
		} finally {
			if (db != null) {
				db.close();
			}
		}
	}
	return false;
}
 
Example 2
Source File: NodeJSDeploymentPlanner.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
protected String getApplicationName(IFileStore contentLocation) throws UnsupportedEncodingException {
	
	IFileStore rootStore = OrionConfiguration.getRootLocation();
	Path relativePath = new Path(URLDecoder.decode(contentLocation.toURI().toString(), "UTF8").substring(rootStore.toURI().toString().length()));
	if (relativePath.segmentCount() < 4) {
		// not a change to a file in a project
		return null;
	}
	
	String projectDirectory = relativePath.segment(3);
	projectDirectory = projectDirectory.replaceFirst(" \\| ", " --- ");
	String[] folderNameParts = projectDirectory.split(" --- ", 2);
	if (folderNameParts.length > 1)
		return folderNameParts[1];
	return folderNameParts[0];
}
 
Example 3
Source File: GenericDeploymentPlanner.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
protected String getApplicationName(IFileStore contentLocation) throws UnsupportedEncodingException {
	
	IFileStore rootStore = OrionConfiguration.getRootLocation();
	Path relativePath = new Path(URLDecoder.decode(contentLocation.toURI().toString(), "UTF8").substring(rootStore.toURI().toString().length()));
	if (relativePath.segmentCount() < 4) {
		// not a change to a file in a project
		return null;
	}
	
	String projectDirectory = relativePath.segment(3);
	projectDirectory = projectDirectory.replaceFirst(" \\| ", " --- ");
	String[] folderNameParts = projectDirectory.split(" --- ", 2);
	if (folderNameParts.length > 1)
		return folderNameParts[1];
	return folderNameParts[0];
}
 
Example 4
Source File: SerializableClasspathEntry.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
private IPath restoreSourcePath(IPath baseDirectory, IPath sourceBaseDirectory) {
  Path path = new Path(sourceAttachmentPath);
  if (path.segmentCount() == 0) {
    return path;
  }

  switch (path.segment(0)) {
    case SOURCE_REPO_RELATIVE_PREFIX:
      return PathUtil.makePathAbsolute(path.removeFirstSegments(1), sourceBaseDirectory);
    case BINARY_REPO_RELATIVE_PREFIX:
      return PathUtil.makePathAbsolute(path.removeFirstSegments(1), baseDirectory);
    default:
      // Unknown prefix, use path only if valid
      if (path.toFile().exists()) {
        return path;
      } else {
        return null;
      }
  }
}
 
Example 5
Source File: PushJob.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public PushJob(String userRunningTask, CredentialsProvider credentials, Path path, String srcRef, boolean tags, boolean force) {
	super(userRunningTask, true, (GitCredentialsProvider) credentials);
	this.path = path;
	this.remote = path.segment(0);
	this.branch = GitUtils.decode(path.segment(1));
	this.srcRef = srcRef;
	this.tags = tags;
	this.force = force;
	setFinalMessage(NLS.bind("Pushing {0} done", path.segment(0)));
	setTaskExpirationTime(TimeUnit.DAYS.toMillis(7));
}
 
Example 6
Source File: NodeJSDeploymentPlanner.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
protected String getApplicationHost(IFileStore contentLocation) throws UnsupportedEncodingException {

		IFileStore rootStore = OrionConfiguration.getRootLocation();
		Path relativePath = new Path(URLDecoder.decode(contentLocation.toURI().toString(), "UTF8").substring(rootStore.toURI().toString().length()));
		if (relativePath.segmentCount() < 4) {
			// not a change to a file in a project
			return null;
		}
		
		String folderName = relativePath.segment(3);
		folderName = folderName.replaceFirst(" \\| ", " --- ");
		return ManifestUtils.slugify(folderName);
	}
 
Example 7
Source File: GenericDeploymentPlanner.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
protected String getApplicationHost(IFileStore contentLocation) throws UnsupportedEncodingException {

		IFileStore rootStore = OrionConfiguration.getRootLocation();
		Path relativePath = new Path(URLDecoder.decode(contentLocation.toURI().toString(), "UTF8").substring(rootStore.toURI().toString().length()));
		if (relativePath.segmentCount() < 4) {
			// not a change to a file in a project
			return null;
		}
		
		String folderName = relativePath.segment(3);
		folderName = folderName.replaceFirst(" \\| ", " --- ");
		return ManifestUtils.slugify(folderName);
	}
 
Example 8
Source File: DirectoryHandlerV1.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
private boolean handleDelete(HttpServletRequest request, HttpServletResponse response, IFileStore dir) throws JSONException, CoreException, ServletException, IOException {
	Path path = new Path(request.getPathInfo());
	dir.delete(EFS.NONE, null);
	if (path.segmentCount() == 2) {
		// The folder is a project, remove the metadata
		OrionConfiguration.getMetaStore().deleteProject(path.segment(0), path.segment(1));
	} else if (path.segmentCount() == 1) {
		// The folder is a workspace, remove the metadata
		String workspaceId = path.segment(0);
		OrionConfiguration.getMetaStore().deleteWorkspace(request.getRemoteUser(), workspaceId);
	}
	return true;
}