Java Code Examples for org.eclipse.core.runtime.IPath#segment()
The following examples show how to use
org.eclipse.core.runtime.IPath#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: QualifiedNameFinder.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Override public boolean acceptFile(IFile file) throws CoreException { IJavaElement element= JavaCore.create(file); if ((element != null && element.exists())) { return false; } // Only touch text files (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=114153 ): if (! FileBuffers.getTextFileBufferManager().isTextFileLocation(file.getFullPath(), false)) { return false; } IPath path= file.getProjectRelativePath(); String segment= path.segment(0); if (segment != null && (segment.startsWith(".refactorings") || segment.startsWith(".deprecations"))) { return false; } return true; }
Example 2
Source File: GitCommitHandlerV1.java From orion.server with Eclipse Public License 1.0 | 6 votes |
private boolean identifyNewCommitResource(HttpServletRequest request, HttpServletResponse response, Repository db, String newCommit) throws ServletException { try { URI u = getURI(request); IPath p = new Path(u.getPath()); IPath np = new Path("/"); //$NON-NLS-1$ for (int i = 0; i < p.segmentCount(); i++) { String s = p.segment(i); if (i == 2) { s += ".." + GitUtils.encode(newCommit); //$NON-NLS-1$ } np = np.append(s); } if (p.hasTrailingSeparator()) np = np.addTrailingSeparator(); URI nu = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), np.toString(), request.getQueryString(), u.getFragment()); JSONObject result = new JSONObject(); result.put(ProtocolConstants.KEY_LOCATION, nu); OrionServlet.writeJSONResponse(request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT); response.setHeader(ProtocolConstants.HEADER_LOCATION, resovleOrionURI(request, nu).toString()); return true; } catch (Exception e) { return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occurred when identifying a new Commit resource.", e)); } }
Example 3
Source File: SourceAttachmentBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private IPath chooseExtension() { IPath currPath= getFilePath(); if (currPath.segmentCount() == 0) { currPath= fEntry.getPath(); } IPath resolvedPath= getResolvedPath(currPath); File initialSelection= resolvedPath != null ? resolvedPath.toFile() : null; String currVariable= currPath.segment(0); JARFileSelectionDialog dialog= new JARFileSelectionDialog(getShell(), false, true, false); dialog.setTitle(NewWizardMessages.SourceAttachmentBlock_extvardialog_title); dialog.setMessage(NewWizardMessages.SourceAttachmentBlock_extvardialog_description); dialog.setInput(fFileVariablePath.toFile()); dialog.setInitialSelection(initialSelection); if (dialog.open() == Window.OK) { File result= (File) dialog.getResult()[0]; IPath returnPath= Path.fromOSString(result.getPath()).makeAbsolute(); return modifyPath(returnPath, currVariable); } return null; }
Example 4
Source File: WorkspaceResourceHandler.java From orion.server with Eclipse Public License 1.0 | 6 votes |
private boolean handleRemoveProject(HttpServletRequest request, HttpServletResponse response, WorkspaceInfo workspace) throws IOException, JSONException, ServletException { IPath path = new Path(request.getPathInfo()); //format is /workspaceId/project/<projectId> if (path.segmentCount() != 3) return false; String workspaceId = path.segment(0); String projectName = path.segment(2); try { ProjectInfo project = getMetaStore().readProject(workspaceId, projectName); if (project == null) { //nothing to do if project does not exist return true; } removeProject(request.getRemoteUser(), workspace, project); } catch (CoreException e) { ServerStatus error = new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error removing project", e); LogHelper.log(error); return statusHandler.handleRequest(request, response, error); } return true; }
Example 5
Source File: GitDiffHandlerV1.java From orion.server with Eclipse Public License 1.0 | 5 votes |
private boolean identifyNewDiffResource(HttpServletRequest request, HttpServletResponse response) throws ServletException { try { StringWriter writer = new StringWriter(); IOUtilities.pipe(request.getReader(), writer, false, false); JSONObject requestObject = new JSONObject(writer.toString()); URI u = getURI(request); IPath p = new Path(u.getPath()); IPath np = new Path("/"); //$NON-NLS-1$ for (int i = 0; i < p.segmentCount(); i++) { String s = p.segment(i); if (i == 2) { s += ".."; //$NON-NLS-1$ s += GitUtils.encode(requestObject.getString(GitConstants.KEY_COMMIT_NEW)); } np = np.append(s); } if (p.hasTrailingSeparator()) np = np.addTrailingSeparator(); URI nu = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), np.toString(), u.getQuery(), u.getFragment()); JSONObject result = new JSONObject(); result.put(ProtocolConstants.KEY_LOCATION, nu.toString()); OrionServlet.writeJSONResponse(request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT); response.setHeader(ProtocolConstants.HEADER_LOCATION, resovleOrionURI(request, nu).toString()); return true; } catch (Exception e) { return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when identifying a new Diff resource.", e)); } }
Example 6
Source File: EclipseProjectImporter.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private IPath fixDevice(IPath path) { if (path != null && path.getDevice() != null) { return path.setDevice(path.getDevice().toUpperCase()); } if (Platform.OS_WIN32.equals(Platform.getOS()) && path != null && path.toString().startsWith("//")) { String server = path.segment(0); String pathStr = path.toString().replace(server, server.toUpperCase()); return new Path(pathStr); } return path; }
Example 7
Source File: WizardSaveAsPage.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Returns a <code>boolean</code> indicating whether a container name * represents a valid container resource in the workbench. An error message * is stored for future reference if the name does not represent a valid * container. * * @return <code>boolean</code> indicating validity of the container name */ protected boolean validateContainer( ) { IPath path = containerGroup.getContainerFullPath( ); if ( path == null ) { problemType = PROBLEM_CONTAINER_EMPTY; problemMessage = Messages.getString( "WizardSaveAsPage.FolderEmpty" ); //$NON-NLS-1$ return false; } IWorkspace workspace = ResourcesPlugin.getWorkspace( ); String projectName = path.segment( 0 ); if ( projectName == null || !workspace.getRoot( ).getProject( projectName ).exists( ) ) { problemType = PROBLEM_PROJECT_DOES_NOT_EXIST; problemMessage = Messages.getString( "WizardSaveAsPage.NoProject" ); //$NON-NLS-1$ return false; } // path is invalid if any prefix is occupied by a file IWorkspaceRoot root = workspace.getRoot( ); while ( path.segmentCount( ) > 1 ) { if ( root.getFile( path ).exists( ) ) { problemType = PROBLEM_PATH_OCCUPIED; problemMessage = Messages.getFormattedString( "WizardSaveAsPage.PathOccupied", new Object[]{path.makeRelative( )} ); //$NON-NLS-1$ return false; } path = path.removeLastSegments( 1 ); } return true; }
Example 8
Source File: MavenUtils.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Creates a MavenInfo instance based on the path to a Maven artifact in a local repository and * the artifact's group id. * * @param artifactPath the path to the artifact in the user's local repository (e.g., * <code>/home/user/.m2/repository/com/google/gwt/gwt * -user/2.1-SNAPSHOT/gwt-user-2.1-SNAPSHOT.jar</code>) * @param groupId the group id of the artifact (e.g., <code>com.google.gwt</code>) * @return an instance of MavenInfo, or null if one could not be found due to a mismatch between * the group id and the artifact path */ public static MavenInfo create(IPath artifactPath, String groupId) { if (artifactPath == null || artifactPath.isEmpty() || groupId == null || StringUtilities.isEmpty(groupId)) { return null; } IPath groupPath = Path.fromPortableString(groupId.replace('.', '/')); final int numTrailingSegmentsAfterRepositoryBase = NUM_TRAILING_SEGMENTS_AFTER_GROUP_ID + groupPath.segmentCount(); if (artifactPath.segmentCount() <= numTrailingSegmentsAfterRepositoryBase) { return null; } String artifactName = artifactPath.lastSegment(); String version = artifactPath.segment(artifactPath.segmentCount() - VERSION_INDEX_FROM_END_OF_MAVEN_PATH - 1); String artifactId = artifactPath.segment(artifactPath.segmentCount() - ARTIFACTID_INDEX_FROM_END_OF_MAVEN_PATH - 1); if (!artifactPath.removeLastSegments(NUM_TRAILING_SEGMENTS_AFTER_GROUP_ID) .removeTrailingSeparator().toPortableString().endsWith(groupPath.toPortableString())) { return null; } IPath repositoryPath = artifactPath.removeLastSegments(numTrailingSegmentsAfterRepositoryBase); return new MavenInfo(repositoryPath, groupId, artifactId, artifactName, version); }
Example 9
Source File: GitTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
protected JSONObject createProjectOrLink(URI workspaceLocationURI, String projectName, String contentLocation) throws JSONException, IOException, SAXException { JSONObject body = new JSONObject(); if (contentLocation != null) { body.put(ProtocolConstants.KEY_CONTENT_LOCATION, contentLocation); ServletTestingSupport.allowedPrefixes = contentLocation; } WebRequest request = new PostMethodWebRequest(workspaceLocationURI.toString(), IOUtilities.toInputStream(body.toString()), "UTF-8"); if (projectName != null) request.setHeaderField(ProtocolConstants.HEADER_SLUG, projectName); request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1"); setAuthentication(request); WebResponse response = webConversation.getResponse(request); if (response.getResponseCode() != HttpURLConnection.HTTP_CREATED) { String msg = response.getText(); LogHelper.log(new org.eclipse.core.runtime.Status(IStatus.ERROR, "org.eclipse.orion.server.tests", msg)); assertTrue("Unexpected failure cloning: " + msg, false); } JSONObject project = new JSONObject(response.getText()); assertEquals(projectName, project.getString(ProtocolConstants.KEY_NAME)); String projectId = project.optString(ProtocolConstants.KEY_ID, null); assertNotNull(projectId); IPath workspacePath = new Path(workspaceLocationURI.getPath()); String workspaceId = workspacePath.segment(workspacePath.segmentCount() - 1); testProjectBaseLocation = "/" + workspaceId + '/' + projectName; testProjectLocalFileLocation = "/" + project.optString(ProtocolConstants.KEY_ID, null); return project; }
Example 10
Source File: DefaultClasspathFixProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean isNonProjectSpecificContainer(IPath containerPath) { if (containerPath.segmentCount() > 0) { String id= containerPath.segment(0); if (id.equals(JavaCore.USER_LIBRARY_CONTAINER_ID) || id.equals(JavaRuntime.JRE_CONTAINER)) { return true; } } return false; }
Example 11
Source File: PySourceLocatorBase.java From Pydev with Eclipse Public License 1.0 | 5 votes |
@Override protected boolean matchesPath(final Object match, IEditorInput editorInput, IPath localPath) { String matchName = (String) match; String considerName = localPath.segment(localPath.segmentCount() - 1); if (matchName.equals(considerName)) { return true; } return false; }
Example 12
Source File: SourceAttachmentBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IPath getResolvedPath(IPath path) { if (path != null) { String varName= path.segment(0); if (varName != null) { IPath varPath= JavaCore.getClasspathVariable(varName); if (varPath != null) { return varPath.append(path.removeFirstSegments(1)); } } } return null; }
Example 13
Source File: PreferencesServlet.java From orion.server with Eclipse Public License 1.0 | 5 votes |
/** * Returns the metadata object associated with this request. This method controls * exactly what metadata objects are exposed via this service. If there is no matching * metadata object for the request, this method handles the appropriate response * and returns <code>null</code>. * @param req * @param resp */ private MetadataInfo getNode(IPath path, HttpServletRequest req, HttpServletResponse resp) throws ServletException { int segmentCount = path.segmentCount(); String scope = path.segment(0); try { if ("user".equalsIgnoreCase(scope)) { //$NON-NLS-1$ String username = req.getRemoteUser(); if (username == null) { resp.setStatus(HttpServletResponse.SC_FORBIDDEN); return null; } return OrionConfiguration.getMetaStore().readUser(username); } else if ("workspace".equalsIgnoreCase(scope) && segmentCount > 1) { //$NON-NLS-1$ //format is /workspace/{workspaceId} return OrionConfiguration.getMetaStore().readWorkspace(path.segment(1)); } else if ("project".equalsIgnoreCase(scope) && segmentCount > 2) { //$NON-NLS-1$ //format is /project/{workspaceId}/{projectName} return OrionConfiguration.getMetaStore().readProject(path.segment(1), path.segment(2)); } } catch (CoreException e) { handleException(resp, "Internal error obtaining preferences", e, HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return null; } //invalid prefix handleNotFound(req, resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED); return null; }
Example 14
Source File: SARLClasspathContainerTest.java From sarl with Apache License 2.0 | 5 votes |
private static boolean isReferenceLibrary(String reference, IClasspathEntry entry) { IPath path = entry.getPath(); String str = path.lastSegment(); if ("classes".equals(str)) { str = path.segment(path.segmentCount() - 3); return str.equals(reference); } return str.startsWith(reference + "_"); }
Example 15
Source File: CordovaLibraryJsContainerInitializer.java From thym with Eclipse Public License 1.0 | 5 votes |
@Override public Object getComparisonID(IPath containerPath, IJavaScriptProject project) { if (containerPath == null) { return null; } else { return containerPath.segment(0); } }
Example 16
Source File: ExtLibToolingUtil.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
public static boolean isPropertiesOpenInEditor(DesignerProject dproject) { boolean openInEditor = false; IFile ifile = dproject.getProject().getFile("/WebContent/WEB-INF/xsp.properties"); //$NON-NLS-1$ // check if its already open IEditorReference[] er = ExtLibPanelUtil.getActiveWorkbenchPage().getEditorReferences(); for (IEditorReference ref : er) { try { IEditorInput ei = ref.getEditorInput(); IFile f = (IFile)ei.getAdapter(IFile.class); if (null != f) { if (f.equals(ifile)) { openInEditor = true; break; } else { IPath proppath = ifile.getFullPath(); IPath edpath = f.getFullPath(); if (edpath.segmentCount() >= 3 && proppath.segmentCount() > 1) { String[] segs = edpath.segments(); String nsfname = proppath.segment(0); if (StringUtil.equalsIgnoreCase(nsfname, segs[0]) && StringUtil.equalsIgnoreCase("AppProperties", segs[1])) { //$NON-NLS-1$ if (StringUtil.equalsIgnoreCase("database.properties", segs[2])) { //$NON-NLS-1$ openInEditor = true; break; } } } } } } catch(PartInitException pe) { ExtLibToolingLogger.EXT_LIB_TOOLING_LOGGER.warn(pe, "exception trying to find open property editors"); // $NLW-ExtLibToolingUtil.exceptiontryingtofind-1$ } } return openInEditor; }
Example 17
Source File: JavaProject.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * @param path IPath * @return A handle to the package fragment root identified by the given path. * This method is handle-only and the element may or may not exist. Returns * <code>null</code> if unable to generate a handle from the path (for example, * an absolute path that has less than 1 segment. The path may be relative or * absolute. */ public IPackageFragmentRoot getPackageFragmentRoot(IPath path) { if (!path.isAbsolute()) { path = getPath().append(path); } int segmentCount = path.segmentCount(); if (segmentCount == 0) { return null; } if (path.getDevice() != null || JavaModel.getExternalTarget(path, true/*check existence*/) != null) { // external path return getPackageFragmentRoot0(path); } IWorkspaceRoot workspaceRoot = this.project.getWorkspace().getRoot(); IResource resource = workspaceRoot.findMember(path); if (resource == null) { // resource doesn't exist in workspace if (path.getFileExtension() != null) { if (!workspaceRoot.getProject(path.segment(0)).exists()) { // assume it is an external ZIP archive return getPackageFragmentRoot0(path); } else { // assume it is an internal ZIP archive resource = workspaceRoot.getFile(path); } } else if (segmentCount == 1) { // assume it is a project String projectName = path.segment(0); if (getElementName().equals(projectName)) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75814 // default root resource = this.project; } else { // lib being another project resource = workspaceRoot.getProject(projectName); } } else { // assume it is an internal folder resource = workspaceRoot.getFolder(path); } } return getPackageFragmentRoot(resource); }
Example 18
Source File: GitTest.java From orion.server with Eclipse Public License 1.0 | 4 votes |
protected String workspaceIdFromLocation(URI workspaceLocationURI) { IPath path = new Path(workspaceLocationURI.getPath()); return path.segment(path.segmentCount() - 1); }
Example 19
Source File: FilenameDifferentiator.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
private Map<IEditorPart, String> getUnambiguousTitles(Collection<IEditorPart> list) { Map<IEditorPart, IPath> map = new HashMap<IEditorPart, IPath>(); int min = Integer.MAX_VALUE; IPath path; for (IEditorPart part : list) { path = getPath(part); if (path == null) { continue; } min = Math.min(path.segmentCount(), min); map.put(part, path); } // Need to disambiguate the titles! Map<IEditorPart, String> returnMap = new HashMap<IEditorPart, String>(); Set<String> curSegments = new HashSet<String>(); for (int i = 2; i <= min; i++) { returnMap.clear(); curSegments.clear(); for (Map.Entry<IEditorPart, IPath> entry : map.entrySet()) { path = entry.getValue(); String segment = path.segment(path.segmentCount() - i); if (curSegments.contains(segment)) { break; } curSegments.add(segment); String title = path.lastSegment() + SEPARATOR + segment; returnMap.put(entry.getKey(), title); } // They're all unique, return them all! if (curSegments.size() == map.size()) { return returnMap; } } // Something failed! What do we do now? return Collections.emptyMap(); }
Example 20
Source File: SWTUtils.java From APICloud-Studio with GNU General Public License v3.0 | 3 votes |
/** * Finds and caches the image from the complete image path. * * @param computedPath * Represents the complete path of icon (BUNDLE_NAME/ICON_PATH) * @return the image, or null if not found */ public static Image getImage(IPath computedPath) { String bundleSymbolicName = computedPath.segment(0); String iconPath = computedPath.removeFirstSegments(1).toOSString(); return getImage(bundleSymbolicName, iconPath); }