Java Code Examples for org.eclipse.core.resources.IProject#getFile()
The following examples show how to use
org.eclipse.core.resources.IProject#getFile() .
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: MavenProjectImporterTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testDeleteClasspath() throws Exception { String name = "salut"; importProjects("maven/" + name); IProject project = getProject(name); assertIsJavaProject(project); assertIsMavenProject(project); IFile dotClasspath = project.getFile(IJavaProject.CLASSPATH_FILE_NAME); File file = dotClasspath.getRawLocation().toFile(); assertTrue(file.exists()); file.delete(); projectsManager.fileChanged(file.toPath().toUri().toString(), CHANGE_TYPE.DELETED); project = getProject(name); IFile bin = project.getFile("bin"); assertFalse(bin.getRawLocation().toFile().exists()); assertTrue(dotClasspath.exists()); }
Example 2
Source File: ProjectUtils.java From XPagesExtensionLibrary with Apache License 2.0 | 6 votes |
public static void copyFilesIntoProject(final IProject project, final String folder, final List<String> fileList) throws Exception { try { for (String file : fileList) { FileInputStream fis = new FileInputStream(file); try { String libFile = new File(file).getName(); IFile libFileProj = project.getFile(folder + "/" + libFile); libFileProj.create(fis, true, null); } finally { StreamUtil.close(fis); } } } catch (Exception e) { throw new Exception("Could not copy JARs into project", e); // $NLX-ProjectUtils.Couldnotcopyjarsintoproject-1$ } }
Example 3
Source File: TestYaml.java From wildwebdeveloper with Eclipse Public License 2.0 | 6 votes |
@Test public void testFalseDetectionAsKubernetes() throws Exception { IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject("p"); p.create(new NullProgressMonitor()); p.open(new NullProgressMonitor()); IFile file = p.getFile("blah.yaml"); file.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor()); IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); ITextEditor editor = (ITextEditor)IDE.openEditor(activePage, file, true); IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); document.set("name: a\ndescrition: b"); boolean markerFound = new DisplayHelper() { @Override protected boolean condition() { try { return file.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO).length > 0; } catch (CoreException e) { return false; } } }.waitForCondition(activePage.getWorkbenchWindow().getShell().getDisplay(), 3000); assertFalse(Arrays.stream(file.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO)).map(Object::toString).collect(Collectors.joining("\n")), markerFound); }
Example 4
Source File: ViewerManager.java From texlipse with Eclipse Public License 1.0 | 6 votes |
/** * Determines the Resource which should be shown. Respects partial builds. * @return * @throws CoreException */ public static IResource getOuputResource(IProject project) throws CoreException { String outFileName = TexlipseProperties.getOutputFileName(project); if (outFileName == null || outFileName.length() == 0) { throw new CoreException(TexlipsePlugin.stat("Empty output file name.")); } // find out the directory where the file should be IContainer outputDir = null; // String fmtProp = TexlipseProperties.getProjectProperty(project, // TexlipseProperties.OUTPUT_FORMAT); // if (registry.getFormat().equals(fmtProp)) { outputDir = TexlipseProperties.getProjectOutputDir(project); /* } else { String base = outFileName.substring(0, outFileName.lastIndexOf('.') + 1); outFileName = base + registry.getFormat(); outputDir = TexlipseProperties.getProjectTempDir(project); }*/ if (outputDir == null) { outputDir = project; } IResource resource = outputDir.findMember(outFileName); return resource != null ? resource : project.getFile(outFileName); }
Example 5
Source File: SideBySideNonYarnProjectsInstallNpmPluginUITest.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Install the same npm package in two independent projects. * * <pre> * 2) P1, P2 in Eclipse workspace; no dependency between P1, P2; P1 -> lodash; P2 -> lodash * a) full build -> errors in both projects * b) run "npm install" in P1 -> error of P1 gone * </pre> */ @Test public void installSamepNpmInTwoIndependentProjects() throws CoreException { File prjDir = new File(getResourceUri(PROBANDS, SAME_NPM_SUBFOLDER)); IProject prjP1 = ProjectTestsUtils.importProject(prjDir, new N4JSProjectName("P1")); IProject prjP2 = ProjectTestsUtils.importProject(prjDir, new N4JSProjectName("P2")); IResourcesSetupUtil.fullBuild(); waitForAutoBuild(); IFile pkgJsonP1 = prjP1.getFile(getResourceName(N4JSGlobals.PACKAGE_JSON)); IFile pkgJsonP2 = prjP2.getFile(getResourceName(N4JSGlobals.PACKAGE_JSON)); assertIssues(pkgJsonP1, "line 15: Project does not exist with project ID: n4js-runtime.", "line 16: Project does not exist with project ID: lodash."); assertIssues(pkgJsonP2, "line 15: Project does not exist with project ID: n4js-runtime.", "line 16: Project does not exist with project ID: lodash."); FileURI prjP1URI = new PlatformResourceURI(prjP1).toFileURI(); String lodashVersion = getDependencyVersion(prjP1URI, "lodash"); libraryManager.installNPM(new N4JSProjectName("n4js-runtime"), prjP1URI, new NullProgressMonitor()); libraryManager.installNPM(new N4JSProjectName("lodash"), lodashVersion, prjP1URI, new NullProgressMonitor()); waitForAutoBuild(); assertIssues(pkgJsonP1); // No errors in P1 anymore assertIssues(pkgJsonP2, "line 15: Project does not exist with project ID: n4js-runtime.", "line 16: Project does not exist with project ID: lodash."); }
Example 6
Source File: GHOLD_45_CheckIgnoreAnnotationAtClassLevel_PluginUITest.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Runs a test module with one single class annotated with {@code Ignore} at class level. */ @Test public void testModuleWithIgnoredClass() { final IProject project = ProjectTestsUtils.getProjectByName(PROJECT_NAME); assertTrue("Project is not accessible.", project.isAccessible()); final IFile module = project.getFile("test/X2.n4js"); assertTrue("Module is not accessible.", module.isAccessible()); runTestWaitResult(module); final String[] expected = EMPTY_ARRAY; final String[] actual = getConsoleContentLines(); assertArrayEquals(expected, actual); }
Example 7
Source File: XtendBuilderParticipantTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
/** * https://bugs.eclipse.org/bugs/show_bug.cgi?id=400193 */ @Test public void testSourceRelativeOutput() throws Exception { IProject project = testHelper.getProject(); String srcFolder = "/foo/bar/bug"; JavaProjectSetupUtil.addSourceFolder(JavaCore.create(project), srcFolder); String path = srcFolder + "/Foo.xtend"; String fullFileName = project.getName() + path; IFile sourceFile = testHelper.createFileImpl(fullFileName, "class Foo {}"); assertTrue(sourceFile.exists()); waitForBuild(); IFile generatedFile = project.getFile("foo/bar/xtend-gen/Foo.java"); assertTrue(generatedFile.exists()); IFile traceFile = testHelper.getProject().getFile("foo/bar/xtend-gen/.Foo.java._trace"); assertTrue(traceFile.exists()); IFile classFile = testHelper.getProject().getFile("/bin/Foo.class"); assertTrue(classFile.exists()); List<IPath> traceFiles = traceMarkers.findTraceFiles(sourceFile); assertTrue(traceFiles.contains(traceFile.getFullPath())); sourceFile.delete(false, new NullProgressMonitor()); waitForBuild(); assertFalse(generatedFile.exists()); assertFalse(traceFile.exists()); }
Example 8
Source File: TimeOffsetTest.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Before public void setUp() throws CoreException { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT); if (!project.exists()) { project.create(null); } project.open(null); fResource = project.getFile(RESOURCE); if (!fResource.exists()) { final InputStream source = new ByteArrayInputStream(new byte[0]); fResource.create(source, true, null); } fResource.setPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER, fResource.getParent().getLocation().toOSString()); }
Example 9
Source File: CanConvertToHybridTester.java From thym with Eclipse Public License 1.0 | 5 votes |
/** * Checks if a project can be converted to {@link HybridProject}. * * @param project * @return */ public static boolean canConvert(IProject project){ boolean configExist = false; for(IPath path: PlatformConstants.CONFIG_PATHS){ IFile config = project.getFile(path); if(config.exists()){ configExist = true; break; } } IFolder wwwFile = project.getFolder(PlatformConstants.DIR_WWW); return configExist && wwwFile.exists(); }
Example 10
Source File: WarPublisherTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Test public void testPublishWar() throws CoreException { IProject project = projectCreator.withFacets(WebFacetUtils.WEB_31).getProject(); IFile war = project.getFile("my-app.war"); IPath tempDirectory = project.getFolder("temp").getLocation(); IStatus[] result = WarPublisher.publishWar(project, war.getLocation(), tempDirectory, monitor); assertEquals(0, result.length); war.refreshLocal(IResource.DEPTH_ZERO, monitor); assertTrue(war.exists()); }
Example 11
Source File: JDTUtilsTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testFakeCompilationUnit() throws Exception { String tempDir = System.getProperty("java.io.tmpdir"); File dir = new File(tempDir, "/test/src/org/eclipse"); dir.mkdirs(); File file = new File(dir, "Test.java"); file.createNewFile(); URI uri = file.toURI(); JDTUtils.resolveCompilationUnit(uri); IProject project = WorkspaceHelper.getProject(ProjectsManager.DEFAULT_PROJECT_NAME); IFile iFile = project.getFile("/src/org/eclipse/Test.java"); assertTrue(iFile.getFullPath().toString() + " doesn't exist.", iFile.exists()); Path path = Paths.get(tempDir + "/test"); Files.walk(path, FileVisitOption.FOLLOW_LINKS).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); }
Example 12
Source File: ReviewMarkerManager.java From git-appraise-eclipse with Eclipse Public License 1.0 | 5 votes |
/** * Adds a marker for the given comment, assuming it has a location attached. */ private void markComment( TaskRepository taskRepository, TaskAttribute commentAttr, String taskId) { IProject project = AppraisePluginUtils.getProjectForRepository(taskRepository); String filePath = getFilePath(commentAttr); IResource resource = project; if (filePath != null) { resource = project.getFile(filePath); if (resource == null || !resource.exists()) { return; } } try { IMarker marker = resource.createMarker(AppraiseUiPlugin.REVIEW_TASK_MARKER_ID); marker.setAttribute(IMarker.MESSAGE, getMessage(commentAttr)); marker.setAttribute(IMarker.TRANSIENT, true); if (filePath != null) { marker.setAttribute(IMarker.LINE_NUMBER, getLineNumber(commentAttr)); } marker.setAttribute(IMarker.USER_EDITABLE, false); TaskAttribute authorAttribute = commentAttr.getMappedAttribute(TaskAttribute.COMMENT_AUTHOR); if (authorAttribute != null) { marker.setAttribute( ReviewMarkerAttributes.REVIEW_AUTHOR_MARKER_ATTRIBUTE, authorAttribute.getValue()); } marker.setAttribute( ReviewMarkerAttributes.REVIEW_DATETIME_MARKER_ATTRIBUTE, commentAttr.getMappedAttribute(TaskAttribute.COMMENT_DATE).getValue()); marker.setAttribute( ReviewMarkerAttributes.REVIEW_ID_MARKER_ATTRIBUTE, getCommentId(commentAttr)); marker.setAttribute( ReviewMarkerAttributes.REVIEW_RESOLVED_MARKER_ATTRIBUTE, getResolvedDisplayText(commentAttr)); marker.setAttribute("TaskId", taskId); } catch (CoreException e) { AppraiseUiPlugin.logError("Failed to create marker at " + filePath, e); } }
Example 13
Source File: ProjectArtifactHandler.java From developer-studio with Apache License 2.0 | 5 votes |
protected IFile getTargetArchive(IProject project, String version, String ext) throws Exception { String finalName = String.format("%s.%s", project.getName() + "_" + version, ext); IFolder binaries = project.getFolder("target"); if (!binaries.exists()) { binaries.create(true, true, getProgressMonitor()); binaries.setHidden(true); } IFile archive = project.getFile("target" + File.separator + finalName); return archive; }
Example 14
Source File: XbaseResourceForEditorInputFactoryTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testValidationIsDisabled_01() throws Exception { IProject project = workspace.getRoot().getProject("simpleProject"); project.create(null); project.open(null); IFile file = project.getFile("Hello.xtext"); InputStream stream = new InputStream() { @Override public int read() throws IOException { return -1; } }; file.create(stream, true, null); assertTrue(isValidationDisabled(file)); }
Example 15
Source File: ArtifactProjectDeleteParticipant.java From developer-studio with Apache License 2.0 | 5 votes |
/** * This method gets executed before the refactoring gets executed on * original file which means this method is executed before the actual * project is deleted from the workspace. If you have any task need to run * before the project is deleted, you need to generate Changes for those * tasks in this method. */ @Override public Change createPreChange(IProgressMonitor arg0) throws CoreException, OperationCanceledException { CompositeChange deleteChange = new CompositeChange("Delete Artifact Project"); IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (IProject project : projects) { if (project.isOpen() && project.hasNature("org.wso2.developerstudio.eclipse.distribution.project.nature")) { try { IFile pomFile = project.getFile(POM_XML); MavenProject mavenProject = ProjectRefactorUtils.getMavenProject(project); Dependency projectDependency = ProjectRefactorUtils.getDependencyForTheProject(originalProject); if (mavenProject != null) { List<?> dependencies = mavenProject.getDependencies(); if (projectDependency != null) { for (Iterator<?> iterator = dependencies.iterator(); iterator.hasNext();) { Dependency dependency = (Dependency) iterator.next(); if (ProjectRefactorUtils.isDependenciesEqual(projectDependency, dependency)) { deleteChange.add(new MavenConfigurationFileDeleteChange(project.getName(), pomFile, originalProject)); } } } } } catch (Exception e) { log.error("Error occured while trying to generate the Refactoring", e); } } } return deleteChange; }
Example 16
Source File: ClientTemplate.java From neoscada with Eclipse Public License 1.0 | 5 votes |
private void addResource ( final IProject project, final String name, final InputStream stream, final IProgressMonitor monitor ) throws CoreException { try { final String[] toks = name.split ( "\\/" ); //$NON-NLS-1$ IContainer container = project; for ( int i = 0; i < toks.length - 1; i++ ) { final IFolder folder = container.getFolder ( new Path ( toks[i] ) ); if ( !folder.exists () ) { folder.create ( true, true, null ); } container = folder; } final IFile file = project.getFile ( name ); if ( file.exists () ) { file.setContents ( stream, IResource.FORCE, monitor ); } else { file.create ( stream, true, monitor ); } } finally { try { stream.close (); } catch ( final IOException e ) { } } monitor.done (); }
Example 17
Source File: NewTypeScriptProjectWizard.java From typescript.java with MIT License | 5 votes |
private IFile generateJsonFile(Object jsonObject, IPath path, IProject project) throws InvocationTargetException { Gson gson = new GsonBuilder().setPrettyPrinting().create(); String content = gson.toJson(jsonObject); IFile file = project.getFile(path); try { if (file.exists()) { file.setContents(IOUtils.toInputStream(content), 1, new NullProgressMonitor()); } else { file.create(IOUtils.toInputStream(content), 1, new NullProgressMonitor()); } } catch (CoreException e) { throw new InvocationTargetException(e); } return file; }
Example 18
Source File: ProjectConfigurationWorkingCopy.java From eclipse-cs with GNU Lesser General Public License v2.1 | 5 votes |
/** * Store the audit configurations to the persistent state storage. */ private void storeToPersistence(ProjectConfigurationWorkingCopy config) throws CheckstylePluginException { try { Document docu = writeProjectConfig(config); byte[] data = XMLUtil.toByteArray(docu); InputStream pipeIn = new ByteArrayInputStream(data); // create or overwrite the .checkstyle file IProject project = config.getProject(); IFile file = project.getFile(ProjectConfigurationFactory.PROJECT_CONFIGURATION_FILE); if (!file.exists()) { file.create(pipeIn, true, null); file.refreshLocal(IResource.DEPTH_INFINITE, null); } else { if (file.isReadOnly()) { ResourceAttributes attrs = ResourceAttributes.fromFile(file.getFullPath().toFile()); attrs.setReadOnly(true); file.setResourceAttributes(attrs); } file.setContents(pipeIn, true, true, null); } config.getLocalCheckConfigWorkingSet().store(); } catch (Exception e) { CheckstylePluginException.rethrow(e, NLS.bind(Messages.errorWritingCheckConfigurations, e.getLocalizedMessage())); } }
Example 19
Source File: CSVReaderTester.java From ice with Eclipse Public License 1.0 | 4 votes |
/** * @throws java.lang.Exception */ @BeforeClass public static void setUpBeforeClass() throws Exception { // Get the file separator used on this system, which is different across // OSes. String separator = System.getProperty("file.separator"); // Create the path for the reflectivity file in the ICE tests directory String userHome = System.getProperty("user.home"); IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = null; String projectName = "CSVLoaderTesterWorkspace"; String filename = "getSpecRefSqrdMod_q841.csv"; IPath projectPath = new Path(userHome + separator + "ICETests" + separator + projectName + separator + ".project"); // Setup the project try { // Create the project description IProjectDescription desc = ResourcesPlugin.getWorkspace() .loadProjectDescription(projectPath); // Get the project handle and create it project = workspaceRoot.getProject(desc.getName()); if (!project.exists()) { project.create(desc, new NullProgressMonitor()); } // Open the project if it is not already open if (project.exists() && !project.isOpen()) { project.open(new NullProgressMonitor()); } // Refresh the workspace project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); // Create the IFile handle for the csv file testFile = project.getFile(filename); } catch (CoreException e) { // Catch exception for creating the project e.printStackTrace(); fail(); } // Create the reader reader = new CSVReader(); return; }
Example 20
Source File: PyEditTitleTestWorkbench.java From Pydev with Eclipse Public License 1.0 | 4 votes |
public void testEditorTitle() throws Exception { NullProgressMonitor monitor = new NullProgressMonitor(); IProject project = createProject(monitor, "pydev_title_project"); IFile myFile = project.getFile("my_file.py"); myFile.create(new ByteArrayInputStream("".getBytes()), true, monitor); IFolder folder = project.getFolder("folder"); folder.create(true, true, null); IFile file2 = folder.getFile("my_file.py"); file2.create(new ByteArrayInputStream("".getBytes()), true, monitor); project.refreshLocal(IResource.DEPTH_INFINITE, monitor); PyEdit editor2 = null; PyEdit editor = null; try { editor = (PyEdit) PyOpenEditor.doOpenEditor(myFile); final PyEdit editorRef = editor; String partName = editor.getPartName(); assertEquals("my_file", partName); editor2 = (PyEdit) PyOpenEditor.doOpenEditor(file2); final PyEdit editor2final = editor2; //We may wait until 10 seconds for the condition to happen (we must not keep the ui-thread //otherwise it won't work). goToManual(10000, new ICallback<Boolean, Object>() { @Override public Boolean call(Object arg) { return "my_file (pydev_title_project)".equals(editorRef.getPartName()) && "my_file (folder)".equals(editor2final.getPartName()); } }); } finally { if (editor2 != null) { editor2.close(false); } if (editor != null) { editor.close(false); } } }