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

The following examples show how to use org.eclipse.core.runtime.IPath#removeFirstSegments() . 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: NewSarlFileWizardPage.java    From sarl with Apache License 2.0 6 votes vote down vote up
private static IPath determinePackageName(IPath path) {
	if (path != null) {
		final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0));
		try {
			if (project != null && project.hasNature(JavaCore.NATURE_ID)) {
				final IJavaProject javaProject = JavaCore.create(project);
				for (final IClasspathEntry entry : javaProject.getRawClasspath()) {
					if (entry.getPath().isPrefixOf(path)) {
						return path.removeFirstSegments(entry.getPath().segmentCount());
					}
				}
			}
		} catch (Exception e) {
			// Ignore the exceptions since they are not useful (hopefully)
		}
	}
	return null;
}
 
Example 2
Source File: SuperDevModeSrcArgumentProcessor.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Get the class path entries that are the source.
 *
 * @param javaProject the java project.
 * @param entry classpath entry value.
 * @return the path.
 */
private String getPathIfDir(IJavaProject javaProject, IClasspathEntry entry) {
  IPath p = entry.getPath();

  String projectName = javaProject.getProject().getName();

  String path = null;
  // src directories don't have an output
  // cpe source are src,test directories
  if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
      && (entry.getOutputLocation() == null || (entry.getOutputLocation() != null && !entry
          .getOutputLocation().lastSegment().toString().equals("test-classes")))) {
    String dir = p.toString();
    // if the base segment has the project name,
    // lets remove that so its relative to project
    if (dir.contains(projectName)) {
      IPath relative = p.removeFirstSegments(1);
      path = relative.toString();
    }
  }

  return path;
}
 
Example 3
Source File: JarWriter3.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void registerInWorkspaceIfNeeded() {
	IPath jarPath= fJarPackage.getAbsoluteJarLocation();
	IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
	for (int i= 0; i < projects.length; i++) {
		IProject project= projects[i];
		// The Jar is always put into the local file system. So it can only be
		// part of a project if the project is local as well. So using getLocation
		// is currently save here.
		IPath projectLocation= project.getLocation();
		if (projectLocation != null && projectLocation.isPrefixOf(jarPath)) {
			try {
				jarPath= jarPath.removeFirstSegments(projectLocation.segmentCount());
				jarPath= jarPath.removeLastSegments(1);
				IResource containingFolder= project.findMember(jarPath);
				if (containingFolder != null && containingFolder.isAccessible())
					containingFolder.refreshLocal(IResource.DEPTH_ONE, null);
			} catch (CoreException ex) {
				// don't refresh the folder but log the problem
				JavaPlugin.log(ex);
			}
		}
	}
}
 
Example 4
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 5
Source File: JarWriter2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void registerInWorkspaceIfNeeded() {
	IPath jarPath= fJarPackage.getAbsoluteJarLocation();
	IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
	for (int i= 0; i < projects.length; i++) {
		IProject project= projects[i];
		// The Jar is always put into the local file system. So it can only be
		// part of a project if the project is local as well. So using getLocation
		// is currently save here.
		IPath projectLocation= project.getLocation();
		if (projectLocation != null && projectLocation.isPrefixOf(jarPath)) {
			try {
				jarPath= jarPath.removeFirstSegments(projectLocation.segmentCount());
				jarPath= jarPath.removeLastSegments(1);
				IResource containingFolder= project.findMember(jarPath);
				if (containingFolder != null && containingFolder.isAccessible())
					containingFolder.refreshLocal(IResource.DEPTH_ONE, null);
			} catch (CoreException ex) {
				// don't refresh the folder but log the problem
				JavaPlugin.log(ex);
			}
		}
	}
}
 
Example 6
Source File: ViewerManager.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Resolves a relative path from one directory to another.
 * The path is returned as an OS-specific string with
 * a terminating separator.
 * 
 * @param sourcePath a directory to start from 
 * @param outputPath a directory to end up to
 * @return a relative path from sourcePath to outputPath
 */
public static String resolveRelativePath(IPath sourcePath, IPath outputPath) {

    int same = sourcePath.matchingFirstSegments(outputPath);
    if (same == sourcePath.segmentCount()
            && same == outputPath.segmentCount()) {
        return "";
    }
        
    outputPath = outputPath.removeFirstSegments(same);
    sourcePath = sourcePath.removeFirstSegments(same);
    
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < sourcePath.segmentCount(); i++) {
        sb.append("..");
        sb.append(File.separatorChar);
    }
    
    for (int i = 0; i < outputPath.segmentCount(); i++) {
        sb.append(outputPath.segment(i));
        sb.append(File.separatorChar);
    }
    return sb.toString();
}
 
Example 7
Source File: GenerateAll.java    From eip-designer with Apache License 2.0 5 votes vote down vote up
/**
 * Finds the template in the plug-in. Returns the template plug-in URI.
 * 
 * @param bundleID
 *            is the plug-in ID
 * @param relativePath
 *            is the relative path of the template in the plug-in
 * @return the template URI
 * @throws IOException
 * @generated
 */
@SuppressWarnings("unchecked")
private URI getTemplateURI(String bundleID, IPath relativePath) throws IOException {
	Bundle bundle = Platform.getBundle(bundleID);
	if (bundle == null) {
		// no need to go any further
		return URI.createPlatformResourceURI(new Path(bundleID).append(relativePath).toString(), false);
	}
	URL url = bundle.getEntry(relativePath.toString());
	if (url == null && relativePath.segmentCount() > 1) {
		Enumeration<URL> entries = bundle.findEntries("/", "*.emtl", true);
		if (entries != null) {
			String[] segmentsRelativePath = relativePath.segments();
			while (url == null && entries.hasMoreElements()) {
				URL entry = entries.nextElement();
				IPath path = new Path(entry.getPath());
				if (path.segmentCount() > relativePath.segmentCount()) {
					path = path.removeFirstSegments(path.segmentCount() - relativePath.segmentCount());
				}
				String[] segmentsPath = path.segments();
				boolean equals = segmentsPath.length == segmentsRelativePath.length;
				for (int i = 0; equals && i < segmentsPath.length; i++) {
					equals = segmentsPath[i].equals(segmentsRelativePath[i]);
				}
				if (equals) {
					url = bundle.getEntry(entry.getPath());
				}
			}
		}
	}
	URI result;
	if (url != null) {
		result = URI.createPlatformPluginURI(new Path(bundleID).append(new Path(url.getPath())).toString(), false);
	} else {
		result = URI.createPlatformResourceURI(new Path(bundleID).append(relativePath).toString(), false);
	}
	return result;
}
 
Example 8
Source File: GitUtils.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the existing git repositories for the given file path, following the given traversal rule.
 *
 * @param path
 *            expected format /file/{Workspace}/{projectName}[/{path}]
 * @return a map of all git repositories found, or <code>null</code> if the provided path format doesn't match the expected format.
 * @throws CoreException
 */
public static Map<IPath, File> getGitDirs(IPath path, Traverse traverse) throws CoreException {
	IPath p = path.removeFirstSegments(1);// remove /file
	IFileStore fileStore = NewFileServlet.getFileStore(null, p);
	if (fileStore == null)
		return null;
	Map<IPath, File> result = new HashMap<IPath, File>();
	File file = fileStore.toLocalFile(EFS.NONE, null);
	// jgit can only handle a local file
	if (file == null)
		return result;
	switch (traverse) {
	case CURRENT:
		File gitDir = resolveGitDir(file);
		if (gitDir != null) {
			result.put(new Path(""), gitDir); //$NON-NLS-1$
		}
		break;
	case GO_UP:
		getGitDirsInParents(file, result);
		break;
	case GO_DOWN:
		getGitDirsInChildren(file, p, result);
		break;
	}
	return result;
}
 
Example 9
Source File: HostedSiteServlet.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	traceRequest(req);
	String pathInfoString = req.getPathInfo();
	IPath pathInfo = new Path(null /*don't parse host:port as device*/, pathInfoString == null ? "" : pathInfoString); //$NON-NLS-1$
	if (pathInfo.segmentCount() > 0) {
		String hostedHost = pathInfo.segment(0);
		IHostedSite site = HostingActivator.getDefault().getHostingService().get(hostedHost);
		if (site != null) {
			IPath path = pathInfo.removeFirstSegments(1);
			IPath contextPath = new Path(req.getContextPath());
			IPath contextlessPath = path.makeRelativeTo(contextPath).makeAbsolute();
			URI[] mappedPaths;
			try {
				mappedPaths = getMapped(site, contextlessPath, req.getQueryString());
			} catch (URISyntaxException e) {
				String message = "Could not create target URI";
				logger.error(message, e);
				handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, message, e));
				return;
			}
			if (mappedPaths != null) {
				serve(req, resp, site, mappedPaths);
			} else {
				handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, NLS.bind("No mappings matched {0}", path), null));
			}
		} else {
			resp.setHeader("Cache-Control", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$
			String msg = NLS.bind("Hosted site {0} is stopped", hostedHost);
			handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null));
		}
	} else {
		super.doGet(req, resp);
	}
}
 
Example 10
Source File: PreferencesServlet.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the prefix for the preference to be retrieved or manipulated.
 */
private String getPrefix(IPath path) {
	String scope = path.segment(0);
	if ("user".equalsIgnoreCase(scope)) { //$NON-NLS-1$
		//format is /user/prefix
		path = path.removeFirstSegments(1);
	} else if ("workspace".equalsIgnoreCase(scope)) { //$NON-NLS-1$
		//format is /workspace/{workspaceId}/prefix
		path = path.removeFirstSegments(2);
	} else if ("project".equalsIgnoreCase(scope)) { //$NON-NLS-1$
		//format is /project/{workspaceId}/{projectName}/prefix
		path = path.removeFirstSegments(3);
	}
	return path.toString();
}
 
Example 11
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 12
Source File: DynamicWebProjectUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the WebContent folder for a Dynamic Web Project, or null if the
 * project does not have a WebContent folder.
 *
 * @return A project-relative path to the WebContent folder
 */
public static IPath getWebContentFolder(IProject project) {
  IPath path = null;
  IVirtualComponent component = ComponentCore.createComponent(project);
  if (component != null && component.exists()) {
    path = component.getRootFolder().getWorkspaceRelativePath();
    if (project.getFullPath().isPrefixOf(path)) {
      return path.removeFirstSegments(project.getFullPath().segmentCount());
    }
  }

  return null;
}
 
Example 13
Source File: GenerateXml.java    From eip-designer with Apache License 2.0 5 votes vote down vote up
/**
 * Finds the template in the plug-in. Returns the template plug-in URI.
 * 
 * @param bundleID
 *            is the plug-in ID
 * @param relativePath
 *            is the relative path of the template in the plug-in
 * @return the template URI
 * @throws IOException
 * @generated
 */
@SuppressWarnings("unchecked")
private URI getTemplateURI(String bundleID, IPath relativePath) throws IOException {
	Bundle bundle = Platform.getBundle(bundleID);
	if (bundle == null) {
		// no need to go any further
		return URI.createPlatformResourceURI(new Path(bundleID).append(relativePath).toString(), false);
	}
	URL url = bundle.getEntry(relativePath.toString());
	if (url == null && relativePath.segmentCount() > 1) {
		Enumeration<URL> entries = bundle.findEntries("/", "*.emtl", true);
		if (entries != null) {
			String[] segmentsRelativePath = relativePath.segments();
			while (url == null && entries.hasMoreElements()) {
				URL entry = entries.nextElement();
				IPath path = new Path(entry.getPath());
				if (path.segmentCount() > relativePath.segmentCount()) {
					path = path.removeFirstSegments(path.segmentCount() - relativePath.segmentCount());
				}
				String[] segmentsPath = path.segments();
				boolean equals = segmentsPath.length == segmentsRelativePath.length;
				for (int i = 0; equals && i < segmentsPath.length; i++) {
					equals = segmentsPath[i].equals(segmentsRelativePath[i]);
				}
				if (equals) {
					url = bundle.getEntry(entry.getPath());
				}
			}
		}
	}
	URI result;
	if (url != null) {
		result = URI.createPlatformPluginURI(new Path(bundleID).append(new Path(url.getPath())).toString(), false);
	} else {
		result = URI.createPlatformResourceURI(new Path(bundleID).append(relativePath).toString(), false);
	}
	return result;
}
 
Example 14
Source File: RenamePackageProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IResource getRefactoredResource(IResource element) {
	IFolder packageFolder= (IFolder) fPackage.getResource();
	if (packageFolder == null) {
		return element;
	}

	IContainer newPackageFolder= (IContainer) getNewPackage().getResource();

	if (packageFolder.equals(element)) {
		return newPackageFolder;
	}

	IPath packagePath= packageFolder.getProjectRelativePath();
	IPath elementPath= element.getProjectRelativePath();

	if (packagePath.isPrefixOf(elementPath)) {
		if (fRenameSubpackages || (element instanceof IFile && packageFolder.equals(element.getParent()))) {
			IPath pathInPackage= elementPath.removeFirstSegments(packagePath.segmentCount());
			if (element instanceof IFile) {
				return newPackageFolder.getFile(pathInPackage);
			} else {
				return newPackageFolder.getFolder(pathInPackage);
			}
		}
	}
	return element;
}
 
Example 15
Source File: JavaProject.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the XML String encoding of the class path.
 */
protected String encodeClasspath(IClasspathEntry[] classpath, IClasspathEntry[] referencedEntries, IPath outputLocation, boolean indent, Map unknownElements) throws JavaModelException {
	try {
		ByteArrayOutputStream s = new ByteArrayOutputStream();
		OutputStreamWriter writer = new OutputStreamWriter(s, "UTF8"); //$NON-NLS-1$
		XMLWriter xmlWriter = new XMLWriter(writer, this, true/*print XML version*/);

		xmlWriter.startTag(ClasspathEntry.TAG_CLASSPATH, indent);
		for (int i = 0; i < classpath.length; ++i) {
			((ClasspathEntry)classpath[i]).elementEncode(xmlWriter, this.project.getFullPath(), indent, true, unknownElements, false);
		}

		if (outputLocation != null) {
			outputLocation = outputLocation.removeFirstSegments(1);
			outputLocation = outputLocation.makeRelative();
			HashMap parameters = new HashMap();
			parameters.put(ClasspathEntry.TAG_KIND, ClasspathEntry.kindToString(ClasspathEntry.K_OUTPUT));
			parameters.put(ClasspathEntry.TAG_PATH, String.valueOf(outputLocation));
			xmlWriter.printTag(ClasspathEntry.TAG_CLASSPATHENTRY, parameters, indent, true, true);
		}

		if (referencedEntries != null) {
			for (int i = 0; i < referencedEntries.length; ++i) {
				((ClasspathEntry) referencedEntries[i]).elementEncode(xmlWriter, this.project.getFullPath(), indent, true, unknownElements, true);
			}
		}
		
		xmlWriter.endTag(ClasspathEntry.TAG_CLASSPATH, indent, true/*insert new line*/);
		writer.flush();
		writer.close();
		return s.toString("UTF8");//$NON-NLS-1$
	} catch (IOException e) {
		throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION);
	}
}
 
Example 16
Source File: EclipseUtils.java    From developer-studio with Apache License 2.0 4 votes vote down vote up
public static IPath getWorkspaceRelativePath(IPath library) {
	IPath workspacePath = EclipseUtils.getWorkspacePath();
	IPath returnPath = library.removeFirstSegments(workspacePath.segmentCount());
	return returnPath;
}
 
Example 17
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 18
Source File: ImportBirtRuntimeAction.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * handle action to clear some old birt runtime files
 * 
 * @param webContentPath
 * @param monitor
 * @throws Exception
 */
protected void doClearAction( IPath webContentPath, IProgressMonitor monitor )
		throws Exception
{
	// remove the root folder
	IPath webPath = webContentPath;
	if ( webPath.segmentCount( ) > 0 )
		webPath = webPath.removeFirstSegments( 1 );

	// get conflict resources
	Map map = BirtWizardUtil.initConflictResources( null );

	// clear
	Iterator it = map.entrySet( ).iterator( );
	while ( it.hasNext( ) )
	{
		Map.Entry entry = (Map.Entry)it.next( );
		String folder = (String) entry.getKey( );
		if ( folder == null )
			continue;

		// get the target folder
		IPath path = webPath.append( folder );
		IFolder tempFolder = project.getFolder( path );
		if ( tempFolder == null || !tempFolder.exists( ) )
			continue;

		List files = (List) entry.getValue( );
		if ( files == null || files.size( ) <= 0 )
		{
			// delete the whole folder
			tempFolder.delete( true, monitor );
		}
		else
		{
			// delete the defined files
			tempFolder.accept( new LibResourceVisitor( monitor, files ),
					IResource.DEPTH_INFINITE, false );
		}
	}
}
 
Example 19
Source File: PythonPathNature.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @return the project pythonpath with complete paths in the filesystem.
 */
@Override
public String getOnlyProjectPythonPathStr(boolean addExternal) throws CoreException {
    String source = null;
    String external = null;
    String contributed = null;
    IProject project = fProject;
    PythonNature nature = fNature;

    if (project == null || nature == null) {
        return "";
    }

    //Substitute with variables!
    StringSubstitution stringSubstitution = new StringSubstitution(nature);

    source = (String) getProjectSourcePath(true, stringSubstitution, RETURN_STRING_WITH_SEPARATOR);
    if (addExternal) {
        external = getProjectExternalSourcePath(true, stringSubstitution);
    }
    contributed = stringSubstitution.performPythonpathStringSubstitution(getContributedSourcePath(project));

    if (source == null) {
        source = "";
    }
    //we have to work on this one to resolve to full files, as what is stored is the position
    //relative to the project location
    List<String> strings = StringUtils.splitAndRemoveEmptyTrimmed(source, '|');
    FastStringBuffer buf = new FastStringBuffer();

    for (String currentPath : strings) {
        if (currentPath.trim().length() > 0) {
            IPath p = new Path(currentPath);

            if (SharedCorePlugin.inTestMode()) {
                //in tests
                buf.append(currentPath);
                buf.append("|");
                continue;
            }

            boolean found = false;
            p = p.removeFirstSegments(1); //The first segment should always be the project (historically it's this way, but having it relative would be nicer!?!).
            IResource r = project.findMember(p);
            if (r == null) {
                r = project.getFolder(p);
            }
            if (r != null) {
                IPath location = r.getLocation();
                if (location != null) {
                    found = true;
                    buf.append(FileUtils.getFileAbsolutePath(location.toFile()));
                    buf.append("|");
                }
            }
            if (!found) {
                Log.log(IStatus.WARNING, "Unable to find the path " + currentPath + " in the project were it's \n"
                        + "added as a source folder for pydev (project: " + project.getName() + ") member:" + r,
                        null);
            }
        }
    }

    if (external == null) {
        external = "";
    }
    return buf.append("|").append(external).append("|").append(contributed).toString();
}
 
Example 20
Source File: GenerateAll.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Finds the template in the plug-in. Returns the template plug-in URI.
 * 
 * @param bundleID
 *            is the plug-in ID
 * @param relativePath
 *            is the relative path of the template in the plug-in
 * @return the template URI
 * @throws IOException
 * @generated
 */
@SuppressWarnings ( "unused" )
private URI getTemplateURI ( final String bundleID, final IPath relativePath ) throws IOException
{
    final Bundle bundle = Platform.getBundle ( bundleID );
    if ( bundle == null )
    {
        // no need to go any further 
        return URI.createPlatformResourceURI ( new Path ( bundleID ).append ( relativePath ).toString (), false );
    }
    URL url = bundle.getEntry ( relativePath.toString () );
    if ( url == null && relativePath.segmentCount () > 1 )
    {
        final Enumeration<URL> entries = bundle.findEntries ( "/", "*.emtl", true );
        if ( entries != null )
        {
            final String[] segmentsRelativePath = relativePath.segments ();
            while ( url == null && entries.hasMoreElements () )
            {
                final URL entry = entries.nextElement ();
                IPath path = new Path ( entry.getPath () );
                if ( path.segmentCount () > relativePath.segmentCount () )
                {
                    path = path.removeFirstSegments ( path.segmentCount () - relativePath.segmentCount () );
                }
                final String[] segmentsPath = path.segments ();
                boolean equals = segmentsPath.length == segmentsRelativePath.length;
                for ( int i = 0; equals && i < segmentsPath.length; i++ )
                {
                    equals = segmentsPath[i].equals ( segmentsRelativePath[i] );
                }
                if ( equals )
                {
                    url = bundle.getEntry ( entry.getPath () );
                }
            }
        }
    }
    URI result;
    if ( url != null )
    {
        result = URI.createPlatformPluginURI ( new Path ( bundleID ).append ( new Path ( url.getPath () ) ).toString (), false );
    }
    else
    {
        result = URI.createPlatformResourceURI ( new Path ( bundleID ).append ( relativePath ).toString (), false );
    }
    return result;
}