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

The following examples show how to use org.eclipse.core.resources.IProject#isAccessible() . 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: FileMetaDataProvider.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private IGamaFileMetaData getMetaData(final IProject project, final boolean includeOutdated) {
	if (!project.isAccessible()) { return null; }
	final String ct = "project";
	final Class<? extends GamaFileMetaData> infoClass = CLASSES.get(ct);
	if (infoClass == null) { return null; }
	final IGamaFileMetaData data = readMetadata(project, infoClass, includeOutdated);
	if (data == null) {
		try {
			storeMetaData(project, new ProjectInfo(project), false);
		} catch (final CoreException e) {
			e.printStackTrace();
			return null;
		}
	}
	return data;
}
 
Example 2
Source File: TestsRunner.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private static boolean isInteresting(final IProject p) throws CoreException {
	if (p == null || !p.exists() || !p.isAccessible())
		return false;
	// If it is contained in one of the built-in tests projects, return true
	if (p.getDescription().hasNature(WorkbenchHelper.TEST_NATURE))
		return true;
	if (GamaPreferences.Runtime.USER_TESTS.getValue()) {
		// If it is not in user defined projects, return false
		if (p.getDescription().hasNature(WorkbenchHelper.BUILTIN_NATURE))
			return false;
		// We try to find in the project a folder called 'tests'
		final IResource r = p.findMember("tests");
		if (r != null && r.exists() && r.isAccessible() && r.getType() == IResource.FOLDER)
			return true;
	}
	return false;
}
 
Example 3
Source File: ExternalLibraryPreferenceStoreImpl.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Attention: This method needs to be called synchronized using ExternalLibraryBuilder#getRule()
 */
@Override
public IStatus synchronizeNodeModulesFolders() {
	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	List<Path> projectRoots = new LinkedList<>();
	for (IProject project : projects) {
		if (project.isAccessible()) {
			Path path = project.getLocation().toFile().toPath();
			projectRoots.add(path);
		}
	}

	resetDefaults();
	List<Path> locations = nodeModulesDiscoveryHelper.findNodeModulesFolders(projectRoots);
	for (Path location : locations) {
		add(new FileURI(location.toFile()));
	}
	return save(new NullProgressMonitor());
}
 
Example 4
Source File: SourceMapRegistry.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public ISourceMap getSourceMap(IProject project, String platform)
{
	if (project == null || !project.isAccessible())
	{
		IdeLog.logError(CorePlugin.getDefault(),
				"Could not get the sourcemap. The given project was null or not accessible"); //$NON-NLS-1$
		return null;
	}
	lazyLoad();
	String[] natureIds = null;
	try
	{
		natureIds = project.getDescription().getNatureIds();
	}
	catch (CoreException ce)
	{
		IdeLog.logError(CorePlugin.getDefault(), ce);
		return null;
	}

	if (ArrayUtil.isEmpty(natureIds))
	{
		return null;
	}
	return getSourceMap(project, natureIds[0], platform);
}
 
Example 5
Source File: ProblemMarkerManager.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
	IResource res= delta.getResource();
	if (res instanceof IProject && delta.getKind() == IResourceDelta.CHANGED) {
		IProject project= (IProject) res;
		if (!project.isAccessible()) {
			// only track open Java projects
			return false;
		}
	}
	checkInvalidate(delta, res);
	return true;
}
 
Example 6
Source File: XtextProjectHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean hasNature(IProject project) {
	Preconditions.checkNotNull(project);
	try {
		if (project.isAccessible()) {
			return project.hasNature(NATURE_ID);
		}
	} catch (CoreException e) {
		log.error(e.getMessage(), e);
	}
	return false;
}
 
Example 7
Source File: UpdateClasspathJob.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public void updateClasspath() {
	Preferences preferences = JavaLanguageServerPlugin.getPreferencesManager().getPreferences();
	Collection<IPath> rootPaths = preferences.getRootPaths();
	if (rootPaths == null) {
		return;
	}
	for (IPath rootPath: rootPaths) { // Update classpath for all invisible projects
		String invisibleProjectName = ProjectUtils.getWorkspaceInvisibleProjectName(rootPath);
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(invisibleProjectName);
		if (!(project.exists() && project.isAccessible())) {
			continue;
		}
		updateClasspath(JavaCore.create(project), preferences.getReferencedLibraries());
	}
}
 
Example 8
Source File: Tester.java    From aCute with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean isDotnetProject(IProject p) {
	if (p == null || !p.isAccessible()) {
		return false;
	}
	try {
		for (IResource projItem : p.members()) {
			if (projItem.getName().equals("project.json") || projItem.getName().matches("^.*\\.csproj$")) { //$NON-NLS-1$ //$NON-NLS-2$
				return true;
			}
		}
	} catch (CoreException e) {
	}
	return false;
}
 
Example 9
Source File: ProblemMarkerManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean visit(IResourceDelta delta) throws CoreException {
	IResource res= delta.getResource();
	if (res instanceof IProject && delta.getKind() == IResourceDelta.CHANGED) {
		IProject project= (IProject) res;
		if (!project.isAccessible()) {
			// only track open Java projects
			return false;
		}
	}
	checkInvalidate(delta, res);
	return true;
}
 
Example 10
Source File: TraceUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Get the opened (accessible) projects with Tmf nature
 *
 * @return the Tmf projects
 */
public static List<IProject> getOpenedTmfProjects() {
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    List<IProject> tmfProjects = new ArrayList<>();
    for (IProject project : projects) {
        try {
            if (project.isAccessible() && project.getNature(TmfProjectNature.ID) != null && !TmfProjectModelHelper.isShadowProject(project)) {
                tmfProjects.add(project);
            }
        } catch (CoreException e) {
            Activator.getDefault().logError("Error getting opened tmf projects", e); //$NON-NLS-1$
        }
    }
    return tmfProjects;
}
 
Example 11
Source File: ExternalFoldersManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Map getFolders() {
	if (this.folders == null) {
		Map tempFolders = new HashMap();
		IProject project = getExternalFoldersProject();
		try {
			if (!project.isAccessible()) {
				if (project.exists()) {
					// workspace was moved (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=252571 )
					openExternalFoldersProject(project, null/*no progress*/);
				} else {
					// if project doesn't exist, do not open and recreate it as it means that there are no external folders
					return this.folders = Collections.synchronizedMap(tempFolders);
				}
			}
			IResource[] members = project.members();
			for (int i = 0, length = members.length; i < length; i++) {
				IResource member = members[i];
				if (member.getType() == IResource.FOLDER && member.isLinked() && member.getName().startsWith(LINKED_FOLDER_NAME)) {
					IPath externalFolderPath = member.getLocation();
					tempFolders.put(externalFolderPath, member);
				}
			}
		} catch (CoreException e) {
			Util.log(e, "Exception while initializing external folders"); //$NON-NLS-1$
		}
		this.folders = Collections.synchronizedMap(tempFolders);
	}
	return this.folders;
}
 
Example 12
Source File: DefaultResourceUIServiceProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.9
 */
@Override
public boolean isSource(URI uri) {
	if (delegate instanceof IResourceServiceProviderExtension) {
		if (!((IResourceServiceProviderExtension) delegate).isSource(uri))
			return false;
	}
	if (workspace != null) {
		if (uri.isPlatformResource()) {
			String projectName = URI.decode(uri.segment(1));
			IProject project = workspace.getRoot().getProject(projectName);
			return project.isAccessible();
		}
		if (uri.isPlatformPlugin()) {
			return false;
		}
	}
	Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(uri);
	for (Pair<IStorage, IProject> pair : storages) {
		IStorage storage = pair.getFirst();
		if (storage instanceof IFile) {
			return ((IFile)storage).isAccessible();
		} else {
			return false;
		}
	}
	return true;
}
 
Example 13
Source File: JavaSynchronizationContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the projects that used to have changes in the diff tree
 * but have been deleted from the workspace.
 *
 * @param event
 *            the event
 * @return the deleted projects
 */
private Set<IProject> getDeletedProjects(final IDiffChangeEvent event) {
	final Set<IProject> result= new HashSet<IProject>();
	final IPath[] deletions= event.getRemovals();
	for (int index= 0; index < deletions.length; index++) {
		final IPath path= deletions[index];
		if (path.segmentCount() > 0) {
			IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0));
			if (!project.isAccessible())
				result.add(project);
		}
	}
	return result;
}
 
Example 14
Source File: ProjectByResourceProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Return the project context for the given resource.
 */
public IProject getProjectContext(Resource resource) {
	if (resource.getURI().isPlatformResource()) {
		String projectName = URI.decode(resource.getURI().segment(1));
		IProject project = workspace.getRoot().getProject(projectName);
		if (project.exists() && project.isAccessible()) {
			return project;
		} 
	}
	return null;
}
 
Example 15
Source File: ApplicationOverviewEditorPart.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private boolean hasSettingsFile(CodewindApplication app) {
	IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(app.name);
	if (project != null && project.isAccessible()) {
		IFile file = project.getFile(SETTINGS_FILE);
		if (file != null && file.exists()) {
			return true;
		}
	}
	IPath path = app.fullLocalPath.append(SETTINGS_FILE);
	if (path.toFile().exists()) {
		return true;
	}
	return false;
}
 
Example 16
Source File: InvisibleProjectImporter.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static String getPackageName(IPath javaFile, IPath workspaceRoot, String[][] srcPrefixes) {
	IProject project = JavaLanguageServerPlugin.getProjectsManager().getDefaultProject();
	if (project == null || !project.isAccessible()) {
		return "";
	}

	IJavaProject javaProject = JavaCore.create(project);
	return getPackageName(javaFile, workspaceRoot, javaProject, srcPrefixes);
}
 
Example 17
Source File: ProjectUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return true if the project has any GWT facets or natures on it
 */
public static boolean isGwtProject(IProject project) throws CoreException {
  String natureId = "com.gwtplugins.gwt.eclipse.core.gwtNature"; // GWTNature.NATURE_ID
  String facetId = "com.gwtplugins.gwt.facet";
  try {
    return project.isAccessible()
        && (project.hasNature(natureId) || FacetedProjectFramework.hasProjectFacet(project,
            facetId));
  } catch (CoreException e) {
    CorePluginLog.logError(e);
  }
  return false;
}
 
Example 18
Source File: ToBeBuiltComputer.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ToBeBuilt doRemoveProject(IProject project, IProgressMonitor monitor) {
	queuedBuildData.reset(project);
	SubMonitor progress = SubMonitor.convert(monitor, Iterables.size(builderState.getAllResourceDescriptions()) / MONITOR_CHUNK_SIZE + 1);
	ToBeBuilt result = new ToBeBuilt();
	Iterable<IResourceDescription> allResourceDescriptions = builderState.getAllResourceDescriptions();
	int i = 0;
	for (IResourceDescription description : allResourceDescriptions) {
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		Iterable<Pair<IStorage, IProject>> storages = mapper.getStorages(description.getURI());
		boolean onlyOnThisProject = true;
		Iterator<Pair<IStorage, IProject>> iterator = storages.iterator();
		while (iterator.hasNext() && onlyOnThisProject) {
			Pair<IStorage, IProject> storage2Project = iterator.next();
			final IProject second = storage2Project.getSecond();
			final boolean isSameProject = project.equals(second);
			onlyOnThisProject = isSameProject || second == null || !second.isAccessible();
		}
		if (onlyOnThisProject)
			result.getToBeDeleted().add(description.getURI());
		i++;
		if (i % MONITOR_CHUNK_SIZE == 0)
			progress.worked(1);
	}
	return result;
}
 
Example 19
Source File: N4JSProjectExplorerLabelProvider.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Image getImage(final Object element) {

	if (element instanceof WorkingSet) {
		return decorator.decorateImage(WORKING_SET_IMG, element);
	}

	if (element instanceof IFolder) {
		final IFolder folder = (IFolder) element;
		N4JSExternalProject npmProject = helper.getNodeModulesNpmProjectOrNull(folder);

		if (helper.isNodeModulesFolder(folder)) {
			return decorator.decorateImage(LIB_PATH, element);

		} else if (folder.getName().startsWith("@") && helper.isNodeModulesFolder(folder.getParent())) {
			return decorator.decorateImage(LIB_PATH_SCOPED, element);

		} else if (npmProject != null) {
			if (indexSynchronizer.isInIndex(npmProject)) {
				return decorator.decorateImage(EXTERNAL_LIB_PROJECT, element);
			} else {
				return decorator.decorateImage(EXTERNAL_LIB_PROJECT_NOT_BUILT, element);
			}

		} else if (helper.isSourceFolder(folder) || helper.isOutputFolder(folder)) {
			// (temporarily) disabled because #isSourceFolder() and #isOutputFolder() obtain a lock on the workspace
			// (e.g. they call IResource#exists() on IFolder 'element') and this seems to cause performance issues
			// with locks that egit is obtaining for doing cyclic updates (see IDE-2269):
			return decorator.decorateImage(SRC_FOLDER_IMG, element);

		} else if (Files.isSymbolicLink(folder.getLocation().toFile().toPath())) {
			// might be a project from workspace
			URI symLinkUri = URIUtils.toFileUri(folder.getLocation().toFile());
			String n4jsProjectName = ProjectDescriptionUtils.deriveN4JSProjectNameFromURI(symLinkUri);
			String eclipseProjectName = ProjectDescriptionUtils
					.convertN4JSProjectNameToEclipseProjectName(n4jsProjectName);

			IProject iProject = ResourcesPlugin.getWorkspace().getRoot().getProject(eclipseProjectName);
			if (iProject != null && iProject.exists()) {
				if (iProject.isAccessible()) {
					return decorator.decorateImage(PROJECT_IMG, element);
				} else {
					return decorator.decorateImage(PROJECT_CLOSED_IMG, element);
				}
			}

		}
	}

	return delegate.getImage(element);
}
 
Example 20
Source File: LangNature.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isAccessible(IProject project) throws CoreException {
	return project.isAccessible() && project.hasNature(NATURE_ID);
}