Java Code Examples for org.eclipse.core.resources.IFolder#getLocation()

The following examples show how to use org.eclipse.core.resources.IFolder#getLocation() . 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: WebAppUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the same output as
 * {@link WebAppUtilities#getWarOutLocationOrPrompt(IProject)}, except that
 * this does nt prompt the user. <code>null</code> is returned if the path is
 * not found, or if the passed value is not a web app project.
 *
 * @return the set WAR directory path, or null if not found
 */
public static IPath getWarOutLocation(IProject project) {
  ExtensionQuery<IOutputWarDirectoryLocator> extQuery =
      new ExtensionQuery<IOutputWarDirectoryLocator>(CorePlugin.PLUGIN_ID,
          "warOutputDirectoryLocator", "class");
  List<ExtensionQuery.Data<IOutputWarDirectoryLocator>> warOutputDirectoryLocators =
      extQuery.getData();
  for (ExtensionQuery.Data<IOutputWarDirectoryLocator> warOutputDirectoryLocator :
      warOutputDirectoryLocators) {
    IFolder warOutputDir = warOutputDirectoryLocator.getExtensionPointData()
        .getOutputWarDirectory(project);
    if (warOutputDir != null) {
      return warOutputDir.getLocation();
    }
  }

  IPath fileSystemPath = null;
  IFolder warOut = isWebApp(project) ? getManagedWarOut(project) : null;
  if (warOut != null) {
    fileSystemPath = warOut.getLocation();
  }
  return fileSystemPath;
}
 
Example 2
Source File: CordovaPluginManager.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the folder that the plugin with id is installed under the plugins folder.
 * It also uses {@link CordovaPluginRegistryMapper} to check for alternate ids.
 * 
 * @param id
 * @return null or a folder
 * throws CoreException - if <i>plugins</i> folder does not exist
 */
private IFolder getPluginHomeFolder(String id) throws CoreException{
	if(id == null ) return null;
	IFolder plugins = getPluginsFolder();
	if(!plugins.exists()){
		throw new CoreException(new Status(IStatus.ERROR, HybridCore.PLUGIN_ID, "Plugin folder does not exist"));
	}
	IFolder pluginHome = plugins.getFolder(id);
	IPath location = pluginHome.getLocation();
	if(pluginHome.exists() &&  location != null && location.toFile().isDirectory()){
		return pluginHome;
	}
	// try the alternate ID 
	String alternateId = CordovaPluginRegistryMapper.alternateID(id);
	if(alternateId != null ){
		 pluginHome = plugins.getFolder(alternateId);
		 location = pluginHome.getLocation();
		 if(pluginHome.exists() &&  location != null && location.toFile().isDirectory()){
			 return pluginHome;
		 }
	}
	return null;
}
 
Example 3
Source File: FlexExistingDeployArtifactStagingDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws  CoreException {
  IProject project = projectCreator.getProject();
  stagingDirectory = project.getFolder("stagingDirectory").getLocation();

  IFolder appEngineFolder = project.getFolder("appEngineDirectory");
  appEngineFolder.create(true, true, null);
  String appYaml = "runtime: java\n" + 
      "env: flex\n";
  appEngineFolder.getFile("app.yaml")
      .create(new ByteArrayInputStream(appYaml.getBytes(Charsets.UTF_8)), true, null);
  appEngineDirectory = appEngineFolder.getLocation();

}
 
Example 4
Source File: SyntaxProjectsManager.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static IPath[] listAllSourcePaths() throws JavaModelException {
	Set<IPath> classpaths = new HashSet<>();
	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	for (IProject project : projects) {
		if (ProjectsManager.DEFAULT_PROJECT_NAME.equals(project.getName())) {
			continue;
		}
		IJavaProject javaProject = JavaCore.create(project);
		if (javaProject != null && javaProject.exists()) {
			IClasspathEntry[] classpath = javaProject.getRawClasspath();
			for (IClasspathEntry entry : classpath) {
				if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
					IPath path = entry.getPath();
					if (path == null) {
						continue;
					}

					IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
					if (folder.exists() && !folder.isDerived()) {
						IPath location = folder.getLocation();
						if (location != null && !ResourceUtils.isContainedIn(location, classpaths)) {
							classpaths.add(location);
						}
					}
				}
			}
		}
	}

	return classpaths.toArray(new IPath[classpaths.size()]);
}
 
Example 5
Source File: WorkItem.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @return false if no classes was added
 */
private static boolean addClassesForFolder(IFolder folder, Map<IPath, IPath> outLocations, Project fbProject) {
    IPath path = folder.getLocation();
    IPath srcRoot = getMatchingSourceRoot(path, outLocations);
    if (srcRoot == null) {
        return false;
    }
    IPath outputRoot = outLocations.get(srcRoot);
    int firstSegments = path.matchingFirstSegments(srcRoot);
    // add relative path to the output path
    IPath out = outputRoot.append(path.removeFirstSegments(firstSegments));
    File directory = out.toFile();
    return fbProject.addFile(directory.getAbsolutePath());
    // TODO child directories too. Should add preference???
}
 
Example 6
Source File: WebAppProjectValidator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private boolean validateBuildClasspath(IJavaProject javaProject)
    throws CoreException {
  IPath webInfLibFolderLocation = null;

  IFolder webInfLibFolder = WebAppUtilities.getWebInfOut(getProject()).getFolder(
      "lib");

  if (webInfLibFolder.exists()) {
    webInfLibFolderLocation = webInfLibFolder.getLocation();
  }

  IClasspathEntry[] rawClasspaths = javaProject.getRawClasspath();
  boolean isOk = true;
  List<IPath> excludedJars = WebAppProjectProperties.getJarsExcludedFromWebInfLib(javaProject.getProject());

  for (IClasspathEntry rawClasspath : rawClasspaths) {
    rawClasspath = JavaCore.getResolvedClasspathEntry(rawClasspath);
    if (rawClasspath.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
      IPath entryPath = ResourceUtils.resolveToAbsoluteFileSystemPath(rawClasspath.getPath());
      if (excludedJars.contains(entryPath)) {
        continue;
      }

      if (webInfLibFolderLocation == null
          || !webInfLibFolderLocation.isPrefixOf(entryPath)) {
        MarkerUtilities.createQuickFixMarker(PROBLEM_MARKER_ID,
            ProjectStructureOrSdkProblemType.JAR_OUTSIDE_WEBINF_LIB,
            entryPath.toPortableString(), javaProject.getProject(),
            entryPath.toOSString());
        isOk = false;
      }
    }
  }

  return isOk;
}
 
Example 7
Source File: RouteJavaScriptOSGIForESBManager.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
@Override
protected void addResources(ExportFileResource osgiResource, ProcessItem processItem) throws Exception {
    IFolder srcFolder = null;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
        IRunProcessService processService = GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
        ITalendProcessJavaProject talendProcessJavaProject =
                processService.getTalendJobJavaProject(processItem.getProperty());
        if (talendProcessJavaProject != null) {
            srcFolder = talendProcessJavaProject.getExternalResourcesFolder();
        }
    }
    if (srcFolder == null) {
        return;
    }
    IPath srcPath = srcFolder.getLocation();

    // http://jira.talendforge.org/browse/TESB-6437
    // https://jira.talendforge.org/browse/TESB-7893
    Collection<IPath> routeResource = RouteResourceUtil.synchronizeRouteResource(processItem);
    if (routeResource != null) {
        for (IPath path : RouteResourceUtil.synchronizeRouteResource(processItem)) {
            osgiResource
                    .addResource(path.removeLastSegments(1).makeRelativeTo(srcPath).toString(),
                            path.toFile().toURI().toURL());
        }
    }
}
 
Example 8
Source File: HybridMobileEngineManager.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private IFolder getPlatformHomeFolder(String platform) throws CoreException {
	if (platform == null) {
		return null;
	}
	IFolder platforms = getPlatformsFolder();
	if (!platforms.exists()) {
		throw new CoreException(new Status(IStatus.ERROR, HybridCore.PLUGIN_ID, "Platforms folder does not exist"));
	}
	IFolder platformHome = platforms.getFolder(platform);
	IPath location = platformHome.getLocation();
	if (platformHome.exists() && location != null && location.toFile().isDirectory()) {
		return platformHome;
	}
	return null;
}
 
Example 9
Source File: BuildProjectOperation.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private IPath createBuildDestination(IProgressMonitor monitor) throws CoreException {
    monitor.beginTask("Creating target folder...", IProgressMonitor.UNKNOWN);
    IFolder targetFolder = repositoryAccessor.getCurrentRepository().getProject().getFolder("target");
    if (targetFolder.exists()) {
        targetFolder.delete(true, new NullProgressMonitor());
    }
    targetFolder.create(true, true, new NullProgressMonitor());
    targetFolder.getFolder(repositoryAccessor.getCurrentRepository().getName()).create(true, true,
            new NullProgressMonitor());
    monitor.done();
    return targetFolder.getLocation();
}
 
Example 10
Source File: ExternalResourceManager.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
private static final IStatus linkDirectory(IProject p, final IFolder externalsFolder, File directory, IProgressMonitor monitor, boolean filterOutSubfolders) throws CoreException {
	IWorkspace workspace = ResourceUtils.getWorkspace();
	if (workspace == null){
		return Status.OK_STATUS;
	}
	List<File> parts = ResourceUtils.getParts(directory);
	IFolder folder = externalsFolder;
	for (int i = 0; i < parts.size() - 1; i++) {
		File part = parts.get(i);
		folder = folder.getFolder(getName(part));
		if (!folder.exists()) {
			folder.create(IResource.FORCE | IResource.VIRTUAL, true, monitor);
			ResourceUtils.setAbsolutePathOfLinkedResourceAttribute(folder, part.getAbsolutePath());
			ResourceUtils.setSyntheticResourceAttribute(folder);
		}
	}
	
	IFolder linkedFolder = folder.getFolder(directory.getName());
	
	if (linkedFolder.exists() && (linkedFolder.isVirtual() || linkedFolder.getLocation() == null)) { 
		// linkedFolder can be only linked or virtual folder (by the precondition of this method).
		// It can be virtual folder (linkedFolder.getLocation() === null) if lookup directory was added and it was not linked before. 
		
		linkedFolder.delete(true, monitor);
	}
	if (!linkedFolder.exists()){
		Path path = new Path(directory.getAbsolutePath());
		IStatus validateLinkLocationStatus = workspace.validateLinkLocation(linkedFolder, path);
		if (!JavaUtils.areFlagsSet(validateLinkLocationStatus.getSeverity(), IStatus.ERROR | IStatus.CANCEL)){
			linkedFolder.createLink(path, IResource.NONE, monitor);
			if (filterOutSubfolders) {
				ResourceUtils.applyRegexFilter(linkedFolder, IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FOLDERS, ".*", monitor); //$NON-NLS-1$
			}
			ResourceUtils.setAbsolutePathOfLinkedResourceAttribute(linkedFolder, directory.getAbsolutePath());
			ResourceUtils.refreshLocalSync(folder);
		}
		
		return validateLinkLocationStatus;
	}
	
	return Status.OK_STATUS;
}
 
Example 11
Source File: WebAppUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the project default output location
 *
 * @param project
 * @return The absolute path to the resource, check with {@link IResource#exists()}, can be null
 * @throws JavaModelException if unable to find the output location from the project
 */
public static IPath getOutputFolderPath(IJavaProject project) throws JavaModelException {
  IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
  IFolder outputLoc = workspaceRoot.getFolder(project.getOutputLocation());
  return outputLoc.getLocation();
}