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

The following examples show how to use org.eclipse.core.resources.IProject#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: CommandState.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, String> getCurrentState() {
	Map<String, String> map = new HashMap<String, String>(1);
	boolean enableOption = false;
	Preferences preferences = InstanceScope.INSTANCE.getNode("com.hybris.hyeclipse.preferences");
	String platformHomeStr = preferences.get("platform_home", null);
	if (platformHomeStr == null) {
		IProject platformProject = ResourcesPlugin.getWorkspace().getRoot().getProject("platform");
		IPath platformProjectPath = platformProject.getLocation();
		if (platformProjectPath != null) {
			enableOption = true;
		}
	}
	else {
		enableOption = true;
	}
	
	if (enableOption) {
		map.put(ID, ENABLED);
	}
	else {
		map.put(ID, DISABLED);
	}
	return map;
}
 
Example 2
Source File: RepositoryProviderOperation.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Retgurn the scheduling rule to be obtained before work
 * begins on the given provider. By default, it is the provider's project.
 * This can be changed by subclasses.
 * @param provider
 * @return
 */
protected ISchedulingRule getSchedulingRule(SVNTeamProvider provider) {
	IResourceRuleFactory ruleFactory = provider.getRuleFactory();
	HashSet rules = new HashSet();
	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	for (int i = 0; i < resources.length; i++) {			
		IResource[] pathResources = SVNWorkspaceRoot.getResourcesFor(new Path(resources[i].getLocation().toOSString()), false);
		for (IResource pathResource : pathResources) {
			IProject resourceProject = pathResource.getProject();				
			rules.add(ruleFactory.modifyRule(resourceProject));
			if (resourceProject.getLocation() != null) {
				// Add nested projects
				for (IProject project : projects) {
					if (project.getLocation() != null) {
						if (!project.getLocation().equals(resourceProject.getLocation()) && resourceProject.getLocation().isPrefixOf(project.getLocation())) {
							rules.add(ruleFactory.modifyRule(project));
						}
					}
				}	
			}
		}
	}
	return MultiRule.combine((ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]));
}
 
Example 3
Source File: JarWriter.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: 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 5
Source File: PlatformHomePropertyTester.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean test(Object arg0, String arg1, Object[] arg2, Object arg3) {
	
	boolean enableOption = false;
	Preferences preferences = InstanceScope.INSTANCE.getNode("com.hybris.hyeclipse.preferences");
	String platformHomeStr = preferences.get("platform_home", null);
	if (platformHomeStr == null) {
		IProject platformProject = ResourcesPlugin.getWorkspace().getRoot().getProject("platform");
		IPath platformProjectPath = platformProject.getLocation();
		if (platformProjectPath != null) {
			enableOption = true;
		}
	}
	else {
		enableOption = true;
	}
	
	return enableOption;
}
 
Example 6
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 7
Source File: CargoTools.java    From corrosion with Eclipse Public License 2.0 5 votes vote down vote up
public static void ensureDotCargoImportedAsProject(IProgressMonitor monitor) throws CoreException {
	File cargoFolder = new File(System.getProperty("user.home") + "/.cargo"); //$NON-NLS-1$ //$NON-NLS-2$
	if (!cargoFolder.exists()) {
		return;
	}
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	for (IProject project : workspace.getRoot().getProjects()) {
		if (!project.isOpen() && project.getName().startsWith(".cargo")) { //$NON-NLS-1$
			project.open(monitor);
		}
		IPath location = project.getLocation();
		if (location != null) {
			File projectFolder = location.toFile().getAbsoluteFile();
			if (cargoFolder.getAbsolutePath().startsWith(projectFolder.getAbsolutePath())) {
				return; // .cargo already imported
			}
		}
	}
	// No .cargo folder available in workspace
	String projectName = ".cargo"; //$NON-NLS-1$
	while (workspace.getRoot().getProject(projectName).exists()) {
		projectName += '_';
	}
	IProjectDescription description = workspace.newProjectDescription(projectName);
	description.setLocation(Path.fromOSString(cargoFolder.getAbsolutePath()));
	IProject cargoProject = workspace.getRoot().getProject(projectName);
	cargoProject.create(description, monitor);
	cargoProject.open(monitor);
}
 
Example 8
Source File: LangLaunchConfigurationDelegate.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
protected EclipseProcessLauncher getValidLaunchInfo(
		ILaunchConfiguration configuration, CompositeBuildTargetSettings buildTargetSettings)
		throws CommonException, CoreException {
	
	IProject project = buildTargetSettings.getBuildTargetSupplier().getValidProject();
	
	String workingDirectoryString = evaluateStringVars(
		configuration.getAttribute(LaunchConstants.ATTR_WORKING_DIRECTORY, (String) null));

	IPath workingDirectory = workingDirectoryString == null ? 
			project.getLocation() : 
			new Path(workingDirectoryString);
	
	Location programLoc = buildTarget.getValidExecutableLocation(); // not null
	
	String programArguments = configuration.getAttribute(LaunchConstants.ATTR_PROGRAM_ARGUMENTS, "");
	String commandLine = programLoc.toString() + " " + programArguments;
	
	Map<String, String> configEnv = configuration.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, 
		new HashMap<>(0));
	boolean appendEnv = configuration.getAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, true);
	
	CommandInvocation programInvocation = new CommandInvocation(commandLine, new HashMap2<>(configEnv), appendEnv);
	
	return new EclipseProcessLauncher(
		project, 
		programLoc,
		workingDirectory, 
		programInvocation,
		LaunchConstants.PROCESS_TYPE_ID
	);
}
 
Example 9
Source File: ProjectConfigerFactory.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public static ProjectConfiger getProjectConfiger(IProject project) {
	ProjectConfiger configer = confgerMap.get(project.getName());
	if (configer == null) {
		String projectFile = project.getLocation() + System.getProperty("file.separator") + ".config";
		try {
			configer = new ProjectConfiger(projectFile);
			confgerMap.put(project.getName(), configer);
		} catch (IOException e) {
			logger.error(Messages.getString("file.ProjectConfigerFactory.logger1") + projectFile, e);
			return null;
		}
	}
	return configer;
}
 
Example 10
Source File: ProjectValidationPage.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ProjectValidationPage(CodewindConnection connection, IProject project) {
	super(Messages.ProjectValidationPageName);
	setTitle(Messages.ProjectValidationPageTitle);
	setDescription(Messages.ProjectValidationPageDescription);
	this.connection = connection;
	this.project = project;
	if (project != null) {
		this.projectPath = project.getLocation();
	}
}
 
Example 11
Source File: ProjectConfigerFactory.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public static ProjectConfiger getProjectConfiger(IProject project) {
	ProjectConfiger configer = confgerMap.get(project.getName());
	if (configer == null) {
		String projectFile = project.getLocation() + System.getProperty("file.separator") + ".config";
		try {
			configer = new ProjectConfiger(projectFile);
			confgerMap.put(project.getName(), configer);
		} catch (IOException e) {
			logger.error(Messages.getString("file.ProjectConfigerFactory.logger1") + projectFile, e);
			return null;
		}
	}
	return configer;
}
 
Example 12
Source File: EclipseProjectImporter.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void importDir(java.nio.file.Path dir, IProgressMonitor m) {
	SubMonitor monitor = SubMonitor.convert(m, 4);
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	IPath dotProjectPath = new Path(dir.resolve(DESCRIPTION_FILE_NAME).toAbsolutePath().toString());
	IProjectDescription descriptor;
	try {
		descriptor = workspace.loadProjectDescription(dotProjectPath);
		String name = descriptor.getName();
		if (!descriptor.hasNature(JavaCore.NATURE_ID)) {
			return;
		}
		IProject project = workspace.getRoot().getProject(name);
		if (project.exists()) {
			IPath existingProjectPath = project.getLocation();
			existingProjectPath = fixDevice(existingProjectPath);
			dotProjectPath = fixDevice(dotProjectPath);
			if (existingProjectPath.equals(dotProjectPath.removeLastSegments(1))) {
				project.open(IResource.NONE, monitor.newChild(1));
				project.refreshLocal(IResource.DEPTH_INFINITE, monitor.newChild(1));
				return;
			} else {
				project = findUniqueProject(workspace, name);
				descriptor.setName(project.getName());
			}
		}
		project.create(descriptor, monitor.newChild(1));
		project.open(IResource.NONE, monitor.newChild(1));
	} catch (CoreException e) {
		JavaLanguageServerPlugin.log(e.getStatus());
		throw new RuntimeException(e);
	} finally {
		monitor.done();
	}
}
 
Example 13
Source File: DeleteResourceAndCloseEditorAction.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
protected Control createCustomArea(Composite parent) {
	Composite composite = new Composite(parent, SWT.NONE);
	composite.setLayout(new GridLayout());
	String text1;
	if (projects.length == 1) {
		IProject project = (IProject) projects[0];
		if (project == null || project.getLocation() == null) {
			text1 = IDEWorkbenchMessages.DeleteResourceAction_deleteContentsN;
		} else {
			text1 = NLS.bind(IDEWorkbenchMessages.DeleteResourceAction_deleteContents1, project.getLocation()
					.toOSString());
		}
	} else {
		text1 = IDEWorkbenchMessages.DeleteResourceAction_deleteContentsN;
	}
	
	Label tipLbl = new Label(composite, SWT.NONE);
	tipLbl.setFont(parent.getFont());
	tipLbl.setText(text1);
	deleteContent = true;

	Label detailsLabel = new Label(composite, SWT.LEFT);
	detailsLabel.setText(IDEWorkbenchMessages.DeleteResourceAction_deleteContentsDetails);
	detailsLabel.setFont(parent.getFont());
	// indent the explanatory label
	GridData data = new GridData();
	data.horizontalIndent = IDialogConstants.INDENT;
	detailsLabel.setLayoutData(data);
	// add a listener so that clicking on the label selects the
	// corresponding radio button.
	// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=172574
	// Add a spacer label
	new Label(composite, SWT.LEFT);

	


	return composite;
}
 
Example 14
Source File: FindBugsWorker.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Checks the given absolute path and convert it to relative path if it is
 * relative to the given project or workspace. This representation can be
 * used to store filter paths in user preferences file
 *
 * @param filePath
 *            absolute OS file path
 * @param project
 *            might be null
 * @return filter file path as stored in preferences which matches given
 *         path
 */
public static IPath toFilterPath(String filePath, IProject project) {
    IPath path = new Path(filePath);
    IPath commonPath;
    if (project != null) {
        commonPath = project.getLocation();
        IPath relativePath = getRelativePath(path, commonPath);
        if (!relativePath.equals(path)) {
            return relativePath;
        }
    }
    commonPath = ResourcesPlugin.getWorkspace().getRoot().getLocation();
    return getRelativePath(path, commonPath);
}
 
Example 15
Source File: IDETypeScriptRepositoryManager.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
public IPath getPath(String path, IProject project) {
	if (path.startsWith(PROJECT_LOC_TOKEN)) {
		// ${project_loc:node_modules/typescript
		String projectPath = path.substring(PROJECT_LOC_TOKEN.length(),
				path.endsWith(END_TOKEN) ? path.length() - 1 : path.length());
		IPath location = project.getLocation();
		return location != null ? location.append(projectPath) : null;
	} else if (path.startsWith(WORKSPACE_LOC_TOKEN)) {
		String wsPath = path.substring(WORKSPACE_LOC_TOKEN.length(),
				path.endsWith(END_TOKEN) ? path.length() - 1 : path.length());
		return ResourcesPlugin.getWorkspace().getRoot().getLocation().append(wsPath);
	}
	return null;
}
 
Example 16
Source File: BaseValidationTest.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test06_runQuickFix() throws Exception {
	IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
	runQuickFix(project);
	// Validation should get run again automatically when the quick fix is complete and
	// this should clear the marker
	waitForMarkersCleared(project);
	// Check that the dockerfile is there
	IPath path = project.getLocation();
	path = path.append(srcPath);
	assertTrue("The dockerfile should be regenerated", path.toFile().exists());
}
 
Example 17
Source File: Util.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public static IPath getAbsoluteFileSystemPath(IPath workspaceRelativePath) {
  assert (workspaceRelativePath.segmentCount() > 0);
  String projectName = workspaceRelativePath.segment(0);

  IProject project = Util.getWorkspaceRoot().getProject(projectName);
  assert (project.exists());

  IPath projectFileSystemPath = project.getLocation();
  IPath projectRelativePath = workspaceRelativePath.removeFirstSegments(1);
  return projectFileSystemPath.append(projectRelativePath);
}
 
Example 18
Source File: BindProjectWizard.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public BindProjectWizard(CodewindConnection connection, IProject project) {
	super();
	this.connection = connection;
	this.project = project;
	if (project != null) {
		this.projectPath = project.getLocation();
	}
	setNeedsProgressMonitor(true);
	setDefaultPageImageDescriptor(CodewindUIPlugin.getImageDescriptor(CodewindUIPlugin.CODEWIND_BANNER));
	setHelpAvailable(false);
}
 
Example 19
Source File: ProjectTestsUtils.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Imports the given yarn workspace project as an Eclipse project into the Eclipse workspace. Also imports (by
 * reference) those projects located in the subfolder 'packages' for which the given predicate returns
 * <code>true</code>.
 *
 * @param libraryManager
 *            library manager instance.
 * @param parentFolder
 *            folder containing the test data.
 * @param yarnProjectName
 *            name of the folder containing the yarn workspace project.
 * @param packagesToImport
 *            predicate telling whether a given package contained in the 'packages' subfolder of the yarn workspace
 *            should be imported as well (the predicate's argument is the package name).
 * @param n4jsLibs
 *            names of N4JS libraries to install from the local <code>n4js-libs</code> top-level folder (see
 *            {@link N4jsLibsAccess#installN4jsLibs(Path, boolean, boolean, boolean, N4JSProjectName...)}).
 * @return yarn workspace project
 */
public static IProject importYarnWorkspace(LibraryManager libraryManager, File parentFolder,
		N4JSProjectName yarnProjectName,
		Predicate<N4JSProjectName> packagesToImport, Collection<N4JSProjectName> n4jsLibs) throws CoreException {
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	IProject yarnProject = ProjectTestsUtils.importProject(parentFolder, yarnProjectName);

	IPath yarnPath = yarnProject.getLocation();
	IPath yarnPackagesPath = yarnPath.append("packages");
	for (String yarnPackageName : yarnPackagesPath.toFile().list()) {
		IPath packagePath = yarnPackagesPath.append(yarnPackageName);
		if (yarnPackageName.startsWith("@")) {
			for (String scopedPackageName : packagePath.toFile().list()) {
				IPath scopedPackagePath = packagePath.append(scopedPackageName);
				if (packagesToImport.apply(new N4JSProjectName(yarnPackageName + '/' + scopedPackageName))) {
					importProjectNotCopy(workspace, scopedPackagePath.toFile(), new NullProgressMonitor());
				}
			}
		} else {
			if (packagesToImport.apply(new N4JSProjectName(yarnPackageName))) {
				importProjectNotCopy(workspace, packagePath.toFile(), new NullProgressMonitor());
			}
		}
	}

	if (!n4jsLibs.isEmpty()) {
		try {
			N4jsLibsAccess.installN4jsLibs(
					yarnPackagesPath.toFile().toPath(),
					true, false, false,
					n4jsLibs.toArray(new N4JSProjectName[0]));
			yarnProject.refreshLocal(IResource.DEPTH_INFINITE, null);
		} catch (IOException e) {
			throw new RuntimeException("unable to install n4js-libs from local checkout", e);
		}
	}

	if (libraryManager != null) {
		waitForAllJobs();
		libraryManager.runNpmYarnInstall(new PlatformResourceURI(yarnProject), new NullProgressMonitor());
	}
	waitForAllJobs();
	waitForAutoBuild();
	return yarnProject;
}
 
Example 20
Source File: WebAppProjectProperties.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the location last selected as a WAR output directory. If no WAR outputs directory has been chosen for this
 * project, the project root directory is returned.
 */
public static IPath getLastUsedWarOutLocationOrProjectLocation(IProject project) {
  IPath path = getLastUsedWarOutLocation(project);
  return path != null ? path : project.getLocation();
}