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

The following examples show how to use org.eclipse.core.runtime.IPath#makeAbsolute() . 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: JarImportWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the target path to be used for the updated classpath entry.
 *
 * @param entry
 *            the classpath entry
 * @return the target path, or <code>null</code>
 * @throws CoreException
 *             if an error occurs
 */
private IPath getTargetPath(final IClasspathEntry entry) throws CoreException {
	final URI location= getLocationURI(entry);
	if (location != null) {
		final URI target= getTargetURI(location);
		if (target != null) {
			IPath path= URIUtil.toPath(target);
			if (path != null) {
				final IPath workspace= ResourcesPlugin.getWorkspace().getRoot().getLocation();
				if (workspace.isPrefixOf(path)) {
					path= path.removeFirstSegments(workspace.segmentCount());
					path= path.setDevice(null);
					path= path.makeAbsolute();
				}
			}
			return path;
		}
	}
	return null;
}
 
Example 2
Source File: DefaultPathsForInterpreterInfo.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a Set of the root paths of all projects (and the workspace root itself).
 * @return A HashSet of root paths.
 */
public static HashSet<IPath> getRootPaths() {
    HashSet<IPath> rootPaths = new HashSet<IPath>();
    if (SharedCorePlugin.inTestMode()) {
        return rootPaths;
    }
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IPath rootLocation = root.getLocation().makeAbsolute();

    rootPaths.add(rootLocation);

    IProject[] projects = root.getProjects();
    for (IProject iProject : projects) {
        IPath location = iProject.getLocation();
        if (location != null) {
            IPath abs = location.makeAbsolute();
            if (!rootLocation.isPrefixOf(abs)) {
                rootPaths.add(abs);
            }
        }
    }
    return rootPaths;
}
 
Example 3
Source File: GitCloneTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get list of clones for the given workspace or path. When <code>path</code> is
 * not <code>null</code> the result is narrowed to clones under the <code>path</code>.
 *
 * @param workspaceId the workspace ID. Must be null if path is provided.
 * @param path path under the workspace starting with project ID. Must be null if workspaceId is provided.
 * @return the request
 */
static WebRequest listGitClonesRequest(String workspaceId, IPath path) {
	assertTrue(workspaceId == null && path != null || workspaceId != null && path == null);
	String requestURI = SERVER_LOCATION + GIT_SERVLET_LOCATION + Clone.RESOURCE + '/';
	if (workspaceId != null) {
		requestURI += "workspace/" + workspaceId;
	} else if (path != null) {
		requestURI += "path" + (path.isAbsolute() ? path : path.makeAbsolute());
	}
	WebRequest request = new GetMethodWebRequest(requestURI);
	request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1");
	setAuthentication(request);
	return request;
}
 
Example 4
Source File: TraceValidateAndImportOperation.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Extract all file system elements (File) to destination folder (typically
 * workspace/TraceProject/.traceImport)
 */
private void extractAllArchiveFiles(List<TraceFileSystemElement> fileSystemElements, IFolder destFolder, IPath baseSourceContainerPath, IProgressMonitor progressMonitor) throws InterruptedException, CoreException, InvocationTargetException {
    SubMonitor subMonitor = SubMonitor.convert(progressMonitor, fileSystemElements.size());
    ListIterator<TraceFileSystemElement> fileSystemElementsIter = fileSystemElements.listIterator();
    while (fileSystemElementsIter.hasNext()) {
        ModalContext.checkCanceled(subMonitor);

        SubMonitor elementProgress = subMonitor.newChild(1);
        TraceFileSystemElement element = fileSystemElementsIter.next();
        elementProgress.setTaskName(Messages.ImportTraceWizard_ExamineOperationTaskName + " " + element.getFileSystemObject().getAbsolutePath()); //$NON-NLS-1$
        File archiveFile = (File) element.getFileSystemObject().getRawFileSystemObject();
        boolean isArchiveFileElement = element.getFileSystemObject() instanceof FileFileSystemObject && ArchiveUtil.isArchiveFile(archiveFile);
        if (isArchiveFileElement) {
            elementProgress = SubMonitor.convert(elementProgress, 4);
            IPath makeAbsolute = baseSourceContainerPath.makeAbsolute();
            IPath relativeToSourceContainer = new Path(element.getFileSystemObject().getAbsolutePath()).makeRelativeTo(makeAbsolute);
            IFolder folder = safeCreateExtractedFolder(destFolder, relativeToSourceContainer, elementProgress.newChild(1));
            extractArchiveToFolder(archiveFile, folder, elementProgress.newChild(1));

            // Delete original archive, we don't want to import this, just
            // the extracted content
            IFile fileRes = destFolder.getFile(relativeToSourceContainer);
            fileRes.delete(true, elementProgress.newChild(1));
            IPath newPath = destFolder.getFullPath().append(relativeToSourceContainer);
            // Rename extracted folder (.extract) to original archive name
            folder.move(newPath, true, elementProgress.newChild(1));
            folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(newPath);
            elementProgress.subTask(""); //$NON-NLS-1$

            // Create the new import provider and root element based on
            // the newly extracted temporary folder
            FileSystemObjectImportStructureProvider importStructureProvider = new FileSystemObjectImportStructureProvider(FileSystemStructureProvider.INSTANCE, null);
            IFileSystemObject rootElement = importStructureProvider.getIFileSystemObject(new File(folder.getLocation().toOSString()));
            TraceFileSystemElement newElement = TraceFileSystemElement.createRootTraceFileElement(rootElement, importStructureProvider);
            List<TraceFileSystemElement> extractedChildren = new ArrayList<>();
            newElement.getAllChildren(extractedChildren);
            extractAllArchiveFiles(extractedChildren, folder, folder.getLocation(), progressMonitor);
        }
    }
}
 
Example 5
Source File: HostingTest.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
@Test
// Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=382760 
public void testDisallowedSiteAccess() throws SAXException, IOException, JSONException, URISyntaxException, CoreException {
	UserInfo userBObject = createUser("userB", "userB");
	String userB = userBObject.getUniqueId();

	// User "test": create file in test's workspace
	final String filename = "foo.html";
	final String fileContent = "<html><body>This is a test file</body></html>";
	WebResponse createdFile = createFileOnServer("", filename, fileContent);
	URL fileLocation = createdFile.getURL();
	IPath filepath = new Path(fileLocation.getPath());
	filepath = filepath.removeFirstSegments(new Path(FILE_SERVLET_LOCATION).segmentCount()); // chop off leading /file/
	filepath = filepath.removeLastSegments(1); // chop off trailing /foo.html
	filepath = filepath.makeAbsolute();
	filepath = filepath.addTrailingSeparator();
	String parentFolder = filepath.toString();

	// User B: Give access to test's workspace
	String bWorkspaceId = workspaceId;
	AuthorizationService.addUserRight(userBObject.getUniqueId(), "/workspace/" + bWorkspaceId);
	AuthorizationService.addUserRight(userBObject.getUniqueId(), "/workspace/" + bWorkspaceId + "/*");

	// User B: create a site against B's workspace that exposes a file in test's workspace
	final String siteName = "My hosted site";
	final String filePath = parentFolder; //"/" + filename;
	final String mountAt = "/"; //"/file.html";
	final JSONArray mappings = makeMappings(new String[][] {{mountAt, filePath}});

	WebRequest createSiteReq = getCreateSiteRequest(siteName, bWorkspaceId, mappings, null);
	setAuthentication(createSiteReq, userB, userB);
	WebResponse createSiteResp = webConversation.getResponse(createSiteReq);
	assertEquals(HttpURLConnection.HTTP_CREATED, createSiteResp.getResponseCode());
	JSONObject siteObject = new JSONObject(createSiteResp.getText());

	// User B: Start the site
	String location = siteObject.getString(ProtocolConstants.HEADER_LOCATION);
	siteObject = startSite(location, userB, userB);

	final JSONObject hostingStatus = siteObject.getJSONObject(SiteConfigurationConstants.KEY_HOSTING_STATUS);
	final String hostedURL = hostingStatus.getString(SiteConfigurationConstants.KEY_HOSTING_STATUS_URL);

	// Attempt to access file on user B's site, should fail
	WebRequest getFileReq = new GetMethodWebRequest(hostedURL + mountAt);
	WebResponse getFileResp = webConversation.getResponse(getFileReq);
	assertEquals(HttpURLConnection.HTTP_FORBIDDEN, getFileResp.getResponseCode());
}
 
Example 6
Source File: ClasspathModifierQueries.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Constructor gets the desired output location
 * of the project
 *
 * @param outputLocation desired output location for the
 * project. It is possible that the desired output location
 * equals the current project's output location (for example if
 * it is not intended to change the output location at this time).
 */
public OutputFolderQuery(IPath outputLocation) {
    if (outputLocation != null)
        fDesiredOutputLocation= outputLocation.makeAbsolute();
}