Java Code Examples for org.eclipse.core.resources.IProject#findMember()
The following examples show how to use
org.eclipse.core.resources.IProject#findMember() .
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: TexlipseProperties.java From texlipse with Eclipse Public License 1.0 | 6 votes |
/** * Check if the project properties should be read from disk. * * @param project current project * @return true, if the project properties should be read from disk */ public static boolean isProjectPropertiesFileChanged(IProject project) { IResource settingsFile = project.findMember(LATEX_PROJECT_SETTINGS_FILE); if (settingsFile == null) { return false; } Long lastLoadTime = (Long) getSessionProperty(project, SESSION_PROPERTIES_LOAD); if (lastLoadTime == null) { return true; } long timeStamp = settingsFile.getLocalTimeStamp(); return timeStamp > lastLoadTime.longValue(); }
Example 2
Source File: TypeDefinitionsShadowingPluginTest.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Negative test case. * * Imports client, definition and implementation project that declare an invalid type definitions configuration. * * More specifically, the "definesPackage" property of the definition project does not point to the intended * implementation project. As a consequence, the client project cannot make use of any type information on the * implementation project. */ @Test public void testInvalidTypeDefinitionsShadowing() throws CoreException { final File testdataLocation = new File(getResourceUri(PROBANDS, PROBANDS_SUBFOLDER, NEGATIVE_FIXTURE_FOLDER)); ProjectTestsUtils.importYarnWorkspace(libraryManager, testdataLocation, YARN_WORKSPACE_PROJECT); final IProject clientProject = ResourcesPlugin.getWorkspace().getRoot().getProject("Broken_Client"); final IProject definitionProject = ResourcesPlugin.getWorkspace().getRoot().getProject("Broken_Def"); final IProject implProject = ResourcesPlugin.getWorkspace().getRoot().getProject("Impl"); IResourcesSetupUtil.fullBuild(); waitForAutoBuild(); IResource clientModule = clientProject.findMember("src/Client.n4js"); assertIssues("Client module should have compilation issues, as type definitions cannot be resolved", clientModule, "line 2: Import of A cannot be resolved.", "line 6: Couldn't resolve reference to IdentifiableElement 'A'."); assertMarkers("Definition project should not have any markers (no compilation issues)", definitionProject, 0); assertMarkers("Implementation project should not have any markers (no compilation issues)", implProject, 0); }
Example 3
Source File: JarWriter2.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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: JarWriter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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 5
Source File: ImportedProjectNamePluginTest.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Tests the following project name configuration. * * <pre> * File System: eclipse * Package.json: eclipse * Eclipse: eclipse-other * </pre> */ @Test public void testDifferentEclipseName() throws CoreException { // workspace setup final IProject testProject = ProjectTestsUtils.createProjectWithLocation(projectsRoot, "eclipse", "eclipse-other"); configureProjectWithXtext(testProject); waitForAutoBuild(); // obtain package.json resource final IResource packageJsonResource = testProject.findMember(IN4JSProject.PACKAGE_JSON); // assert project name markers assertHasNoMarker(packageJsonResource, IssueCodes.PKGJ_PACKAGE_NAME_MISMATCH); assertHasMarker(packageJsonResource, IssueCodes.PKGJ_PROJECT_NAME_ECLIPSE_MISMATCH); // tear down testProject.delete(false, true, new NullProgressMonitor()); }
Example 6
Source File: ImportedProjectNamePluginTest.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Tests the following project name configuration. * * <pre> * File System: all-match * Package.json: all-match * Eclipse: all-match * </pre> */ @Test public void testAllNamesMatch() throws CoreException { // workspace setup final IProject testProject = ProjectTestsUtils.createProjectWithLocation(projectsRoot, "all-match", "all-match"); configureProjectWithXtext(testProject); waitForAutoBuild(); // obtain package.json resource final IResource packageJsonResource = testProject.findMember(IN4JSProject.PACKAGE_JSON); // assert project name markers assertHasNoMarker(packageJsonResource, IssueCodes.PKGJ_PACKAGE_NAME_MISMATCH); assertHasNoMarker(packageJsonResource, IssueCodes.PKGJ_PROJECT_NAME_ECLIPSE_MISMATCH); // tear down testProject.delete(false, true, new NullProgressMonitor()); }
Example 7
Source File: TestsRunner.java From gama with GNU General Public License v3.0 | 6 votes |
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 8
Source File: TestabilityReportLaunchListener.java From testability-explorer with Apache License 2.0 | 5 votes |
private IResource getAbsolutePathFromJavaFile(String completeClassName, List<IPath> sourceFolderPaths, IProject project) { String path = completeClassName.replaceAll("\\.", "/"); for (IPath sourceFolderPath : sourceFolderPaths) { IPath totalPath = sourceFolderPath.append(path + ".java"); if (project.exists(totalPath)) { return project.findMember(totalPath); } } return null; }
Example 9
Source File: RefactoringModifications.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected IFile getClasspathFile(IResource resource) { IProject project= resource.getProject(); if (project == null) return null; IResource result= project.findMember(".classpath"); //$NON-NLS-1$ if (result instanceof IFile) return (IFile)result; return null; }
Example 10
Source File: AddSourceFolderWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IFolder chooseFolder(String title, String message, IPath initialPath) { Class<?>[] acceptedClasses= new Class[] { IFolder.class }; ISelectionStatusValidator validator= new TypedElementSelectionValidator(acceptedClasses, false); ViewerFilter filter= new TypedViewerFilter(acceptedClasses, null); ILabelProvider lp= new WorkbenchLabelProvider(); ITreeContentProvider cp= new WorkbenchContentProvider(); IProject currProject= fNewElement.getJavaProject().getProject(); ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(getShell(), lp, cp) { @Override protected Control createDialogArea(Composite parent) { Control result= super.createDialogArea(parent); PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IJavaHelpContextIds.BP_CHOOSE_EXISTING_FOLDER_TO_MAKE_SOURCE_FOLDER); return result; } }; dialog.setValidator(validator); dialog.setTitle(title); dialog.setMessage(message); dialog.addFilter(filter); dialog.setInput(currProject); dialog.setComparator(new ResourceComparator(ResourceComparator.NAME)); IResource res= currProject.findMember(initialPath); if (res != null) { dialog.setInitialSelection(res); } if (dialog.open() == Window.OK) { return (IFolder) dialog.getFirstResult(); } return null; }
Example 11
Source File: RefactoringModifications.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
protected IFile getClasspathFile(IResource resource) { IProject project= resource.getProject(); if (project == null) { return null; } IResource result= project.findMember(".classpath"); //$NON-NLS-1$ if (result instanceof IFile) { return (IFile)result; } return null; }
Example 12
Source File: AbstractUml2SolidityLaunchConfigurationTab.java From uml2solidity with Eclipse Public License 1.0 | 5 votes |
/** * @param configuration * @param resourceName * @return * @throws CoreException */ protected IResource findResource(ILaunchConfiguration configuration, String resourceName) throws CoreException { String model = configuration.getAttribute(GenerateUml2Solidity.MODEL_URI, ""); Path path = new Path(model); IResource findMember = ResourcesPlugin.getWorkspace().getRoot().findMember(path); if (findMember instanceof IFile) { IFile f = (IFile) findMember; IProject project = f.getProject(); IResource member = project.findMember(resourceName); return member; } return null; }
Example 13
Source File: JdtClasspathUriResolver.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private URI findResourceInProjectRoot(IJavaProject javaProject, String path, Set<String> visited) throws CoreException { boolean includeAll = visited.isEmpty(); if (visited.add(javaProject.getElementName())) { IProject project = javaProject.getProject(); IResource resourceFromProjectRoot = project.findMember(path); if (resourceFromProjectRoot != null && resourceFromProjectRoot.exists()) { return createPlatformResourceURI(resourceFromProjectRoot); } for(IClasspathEntry entry: javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { if (includeAll || entry.isExported()) { IResource referencedProject = project.getWorkspace().getRoot().findMember(entry.getPath()); if (referencedProject != null && referencedProject.getType() == IResource.PROJECT) { IJavaProject referencedJavaProject = JavaCore.create((IProject) referencedProject); if (referencedJavaProject.exists()) { URI result = findResourceInProjectRoot(referencedJavaProject, path, visited); if (result != null) { return result; } } } break; } } } } return null; }
Example 14
Source File: StorageAwareTrace.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected AbsoluteURI resolvePath(IProject project, SourceRelativeURI path) { String decodedPath = URI.decode(path.getURI().toString()); IResource candidate = project.findMember(decodedPath); if (candidate != null && candidate.exists()) return new AbsoluteURI(URI.createPlatformResourceURI(project.getFullPath() + "/" + decodedPath, true)); return null; }
Example 15
Source File: TypeScriptBuildPath.java From typescript.java with MIT License | 5 votes |
private static IPath toTsconfigFilePath(IPath path, IProject project) { if (path.isEmpty()) { return path.append(FileUtils.TSCONFIG_JSON); } if (project.exists(path)) { IResource resource = project.findMember(path); if (resource.getType() == IResource.FOLDER) { return path.append(FileUtils.TSCONFIG_JSON); } } return path; }
Example 16
Source File: IsDartProjectPropertyTester.java From dartboard with Eclipse Public License 2.0 | 5 votes |
@Override public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (IS_DART_PROJECT_PROPERTY.equals(property)) { IResource resource = Adapters.adapt(receiver, IResource.class); if (resource == null) { return false; } IProject project = resource.getProject(); if (project == null) { return false; } if (project.findMember(GlobalConstants.PUBSPEC_YAML) != null) { return true; } try { for (IResource res : project.members()) { if ("dart".equals(res.getFileExtension())) { //$NON-NLS-1$ return true; } } } catch (CoreException e) { LOG.log(DartLog.createError("Couldn't list members of project " + project.getName(), e)); //$NON-NLS-1$ } } return false; }
Example 17
Source File: ClearCacheOnCleanPluginUITest.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Tests if the {@link MultiCleartriggerCache} is cleared when a 'Clean Build' is triggered. */ @Test public void testClearOnCleanBuild() throws CoreException { File prjDir = new File(PROBANDS); IProject project = ProjectTestsUtils.importProject(prjDir, PROJECT_NAME); IResource resourceABC = project.findMember("src/ABC.n4js"); IFile fileABC = ResourcesPlugin.getWorkspace().getRoot().getFile(resourceABC.getFullPath()); assertTrue(fileABC.exists()); IResourcesSetupUtil.fullBuild(); waitForAutoBuild(); syncExtAndBuild(); assertNoIssues(); // use key of API_IMPL_MAPPING SupplierWithPostAction testSupplier = new SupplierWithPostAction(); assertTrue(testSupplier.postActionTriggerCount == 0); cache.clear(MultiCleartriggerCache.CACHE_KEY_API_IMPL_MAPPING); // cache should be empty Object test = cache.get(testSupplier, MultiCleartriggerCache.CACHE_KEY_API_IMPL_MAPPING); assertTrue(testSupplier.postActionTriggerCount == 1); assertTrue("test".equals(test)); // cache should contain key cache.get(testSupplier, MultiCleartriggerCache.CACHE_KEY_API_IMPL_MAPPING); assertTrue(testSupplier.postActionTriggerCount == 1); assertTrue("test".equals(test)); // cleanBuild should clear the cache and set a new instance of ApiImplMappings IResourcesSetupUtil.cleanBuild(); waitForAutoBuild(); test = cache.get(testSupplier, MultiCleartriggerCache.CACHE_KEY_API_IMPL_MAPPING); assertTrue(test instanceof ApiImplMapping); }
Example 18
Source File: IsFlutterProjectPropertyTester.java From dartboard with Eclipse Public License 2.0 | 5 votes |
@Override public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (IS_FLUTTER_PROJECT_PROPERTY.equalsIgnoreCase(property)) { IResource resource = Adapters.adapt(receiver, IResource.class); if (resource == null) { return false; } IProject project = resource.getProject(); if (project == null) { return false; } IResource pubspec = project.findMember(GlobalConstants.PUBSPEC_YAML); if (pubspec == null) { return false; } File pubspecFile = pubspec.getRawLocation().toFile(); CharSource pubspecContent = Files.asCharSource(pubspecFile, Charset.defaultCharset()); try { for (String line : pubspecContent.readLines()) { if (FLUTTER_SDK.matcher(line).matches()) { return true; } } } catch (IOException e) { LOG.log(DartLog.createError("Could not open pubspec.yaml", e)); } } return false; }
Example 19
Source File: PythonPathNature.java From Pydev with Eclipse Public License 1.0 | 4 votes |
/** * @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: ExampleModelOpener.java From statecharts with Eclipse Public License 1.0 | 4 votes |
protected void openExampleReadme(IProject project) throws PartInitException { IResource indexFile = project.findMember(ExampleData.DESC_FILE); if (indexFile != null) { IDE.openEditor(getPage(), (IFile) indexFile, true); } }