/** * Tries to delete an open project containing an irremovable file. Works only for Linux with * natives. */ public void testDeleteOpenProjectLinux() { if (!(Platform.getOS().equals(Platform.OS_LINUX) && isReadOnlySupported())) return; IProject project = null; File projectRoot = null; IFolder folder = null; try { IWorkspace workspace = getWorkspace(); project = workspace.getRoot().getProject(getUniqueString()); folder = project.getFolder("a_folder"); IFile file1 = folder.getFile("file1.txt"); IFile file2 = project.getFile("file2.txt"); ensureExistsInWorkspace(new IResource[] {file1, file2}, true); projectRoot = project.getLocation().toFile(); // marks folder as read-only so its files cannot be deleted on Linux setReadOnly(folder, true); IFile projectFile = project.getFile(".project"); assertTrue("1.2", projectFile.exists()); assertTrue("1.3", projectFile.isSynchronized(IResource.DEPTH_INFINITE)); try { project.delete(IResource.FORCE, getMonitor()); fail("2.0 - should have failed"); } catch (CoreException ce) { // success - a file couldn't be removed } assertTrue("2.1", project.exists()); assertTrue("2.2", file1.exists()); assertTrue("2.3", !file2.exists()); assertTrue("2.5", folder.exists()); assertTrue("2.6", projectFile.exists()); assertTrue("2.7", project.isSynchronized(IResource.DEPTH_INFINITE)); setReadOnly(folder, false); assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE)); try { project.delete(IResource.FORCE, getMonitor()); } catch (CoreException ce) { ce.printStackTrace(); fail("4.0", ce); } assertTrue("5.1", !project.exists()); assertTrue("5.2", !file1.exists()); assertTrue("5.3", file1.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("5.4", project.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("6.0", !projectRoot.exists()); } finally { if (folder != null && folder.exists()) setReadOnly(folder, false); if (projectRoot != null) ensureDoesNotExistInFileSystem(projectRoot); } }
/** Tries to delete a folder containing an unremovable file. Works only for Windows. */ public void testDeleteFolderWindows() { if (!isWindows()) return; IProject project = null; InputStream input = null; File projectRoot = null; try { IWorkspace workspace = getWorkspace(); project = workspace.getRoot().getProject(getUniqueString()); IFolder folder = project.getFolder("a_folder"); IFile file1 = folder.getFile("file1.txt"); IFile file3 = folder.getFile("file3.txt"); ensureExistsInWorkspace(new IResource[] {file1, file3}, true); projectRoot = project.getLocation().toFile(); // opens a file so it cannot be removed on Windows try { input = file1.getContents(); } catch (CoreException ce) { ce.printStackTrace(); fail("1.0"); } try { folder.delete(IResource.FORCE, getMonitor()); fail("2.0 - should have failed"); } catch (CoreException ce) { // success - a file couldn't be removed } assertTrue("2.2", file1.exists()); assertTrue("2.4", !file3.exists()); assertTrue("2.5", folder.exists()); assertTrue("2.7", folder.isSynchronized(IResource.DEPTH_INFINITE)); assertClose(input); assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE)); try { folder.delete(IResource.FORCE, getMonitor()); } catch (CoreException ce) { ce.printStackTrace(); fail("4.0", ce); } assertTrue("5.1", !file1.exists()); assertTrue("5.2", !folder.exists()); assertTrue("5.3", file1.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("5.4", folder.isSynchronized(IResource.DEPTH_INFINITE)); } finally { try { assertClose(input); } finally { if (projectRoot != null) ensureDoesNotExistInFileSystem(projectRoot); } } }
/** * This method should be called only if isRelevant returns true; Makes simple check if this java * file contains annotation Name. * * @param resource * @return */ public boolean isLikelyComponentSource(IFile f) { if (!f.isSynchronized(IFile.DEPTH_ZERO) || !f.exists()) return false; XModel model = InnerModelHelper.createXModel(f.getProject()); if (model == null) return false; XModelObject o = EclipseResourceUtil.getObjectByResource(model, f); return (o != null) && (LibraryScanner.isTLDFile(o) || LibraryScanner.isFaceletTaglibFile(o) || LibraryScanner.isFacesConfigFile(o)); }
/** * Constructs include path from one module to another. * * @param from - module to construct include path from. * @param to - module to construct include path to. * @return constructed include path */ public static ConstructedIncludePath constructIncludePath(IModule from, IModule to) { IBuildPath fromBuildPath = from.getBuildPath(); IBuildPath toBuildPath = to.getBuildPath(); Set<IBuildPath> fromDependencies = fromBuildPath.getDependencies(); if (fromDependencies.equals(toBuildPath)) { String includePath = constructPathFromRoot(to); return new ConstructedIncludePath(includePath, null, null); } // if "from" build-path directly depends from "to" build-path if (fromDependencies.contains(toBuildPath)) { String includePath = constructPathFromRoot(to); return new ConstructedIncludePath(includePath, null, null); } else { // for local modules using its project-based build-path instead of native module build-path if (to instanceof LocalModule) { IFile file = ((LocalModule) to).getFile(); if (!file.isSynchronized(1)) { try { file.refreshLocal(1, new NullProgressMonitor()); if (file.exists()) { IProject project = file.getProject(); IBuildPath projectBuildPath = BuildPathManager.getInstance().getBuildPathByResource(project); if (projectBuildPath != null) { IModule alternativeToModule = projectBuildPath.getModule(file); if (alternativeToModule != null) { String includePath = constructPathFromRoot(alternativeToModule); return new ConstructedIncludePath(includePath, fromBuildPath, projectBuildPath); } } } } catch (CoreException e) { IdeLog.logWarning( PHPEditorPlugin.getDefault(), "PHP Refactoring - Error while constructing an include-path (constructIncludePath)", //$NON-NLS-1$ e, PHPEditorPlugin.DEBUG_SCOPE); } } } // in other case, using original build-paths for reporting unsatisfied state String includePath = constructPathFromRoot(to); return new ConstructedIncludePath(includePath, fromBuildPath, toBuildPath); } }
private static IEditorInput convertFileInput(IFileEditorInput input) { IFileEditorInput fi = (IFileEditorInput) input; IFile f = fi.getFile(); if (f != null && !f.isSynchronized(IResource.DEPTH_INFINITE)) { try { f.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { // ignore } } XModelObject o = EclipseResourceUtil.getObjectByResource(f); if (o == null) { o = EclipseResourceUtil.createObjectForResource(f); } return (o == null || o.getFileType() != XModelObject.FILE) ? input : new XModelObjectEditorInput(getMainObject(o)); }
protected boolean isValid(IResource resource) throws CoreException { if (resource instanceof IFile) { IFile file = (IFile) resource; if (!file.isSynchronized(0)) { // In case the resource has been updated, refresh it file.refreshLocal(0, null); } if (file.getContentDescription() != null && file.getContentDescription().getContentType() != null && KickstartFormMemoryModel.KICKSTART_FORM_CONTENT_TYPE.equals( file.getContentDescription().getContentType().getId())) { return true; } } else if (resource instanceof IFolder) { return !resource.isDerived() && !resource.isHidden(); } return false; }
/** Tries to delete an open project containing an unremovable file. Works only for Windows. */ public void testDeleteOpenProjectWindows() { if (!(isWindows())) return; IProject project = null; InputStream input = null; File projectRoot = null; try { IWorkspace workspace = getWorkspace(); project = workspace.getRoot().getProject(getUniqueString()); IFolder folder = project.getFolder("a_folder"); IFile file1 = folder.getFile("file1.txt"); IFile file2 = project.getFile("file2.txt"); IFile file3 = folder.getFile("file3.txt"); IFile projectFile = project.getFile(new Path(".project")); ensureExistsInWorkspace(new IResource[] {file1, file2, file3}, true); projectRoot = project.getLocation().toFile(); assertExistsInFileSystem("0.0", file1); assertExistsInFileSystem("0.1", file2); assertExistsInFileSystem("0.2", file3); assertExistsInFileSystem("0.3", folder); assertExistsInFileSystem("0.4", projectFile); // opens a file so it cannot be removed on Windows try { input = file1.getContents(); } catch (CoreException ce) { ce.printStackTrace(); fail("1.0"); } assertTrue("1.2", projectFile.exists()); assertTrue("1.3", projectFile.isSynchronized(IResource.DEPTH_INFINITE)); try { project.delete(IResource.FORCE, getMonitor()); fail("2.0 - should have failed"); } catch (CoreException ce) { // success - a file couldn't be removed } // Delete is best-case so check all the files. // Do a check on disk and in the workspace in case something is out of sync. assertExistsInWorkspace("2.1.1", project); assertExistsInFileSystem("2.1.2", project); assertExistsInWorkspace("2.2.1", file1); assertExistsInFileSystem("2.2.2", file1); assertTrue("2.2.3", file1.isSynchronized(IResource.DEPTH_INFINITE)); assertDoesNotExistInWorkspace("2.3.1", file2); assertDoesNotExistInFileSystem("2.3.2", file2); assertTrue("2.3.3", file2.isSynchronized(IResource.DEPTH_INFINITE)); assertDoesNotExistInWorkspace("2.4.1", file3); assertDoesNotExistInFileSystem("2.4.2", file3); assertTrue("2.4.3", file3.isSynchronized(IResource.DEPTH_INFINITE)); assertExistsInWorkspace("2.5.1", folder); assertExistsInFileSystem("2.5.2", folder); assertTrue("2.5.3", folder.isSynchronized(IResource.DEPTH_INFINITE)); assertExistsInWorkspace("2.6.1", projectFile); assertExistsInFileSystem("2.6.2", projectFile); assertTrue("2.6.3", projectFile.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("2.7.0", project.isSynchronized(IResource.DEPTH_ZERO)); assertTrue("2.7.1", project.isSynchronized(IResource.DEPTH_INFINITE)); assertClose(input); assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE)); try { project.delete(IResource.FORCE, getMonitor()); } catch (CoreException e) { fail("4.0", e); } assertTrue("5.1", !project.exists()); assertTrue("5.2", !file1.exists()); assertTrue("5.3", file1.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("5.4", project.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("6.0", !projectRoot.exists()); } finally { try { assertClose(input); } finally { if (projectRoot != null) ensureDoesNotExistInFileSystem(projectRoot); } } }
/** * TODO: this is probably not the best way to do things. This one test validates most of the * functionality in tools.ui. However, starting and stopping a workbench takes a lot of time and * we need a project to run the service creation tests so... * * <p>Tests the creation of a SwitchYard project: project, pom.xml, switchyard.xml creation. * * <p>Test dependency update operation. * * <p>Tests the creation of a new SwitchYard service. * * @throws Exception if an error occurs or test fails. */ public void testCreateSwitchYardProjectOperation() throws Exception { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject newProjectHandle = workspace.getRoot().getProject(CreateSwitchYardProjectTest.class.getSimpleName()); String packageName = "test.package_name"; String groupId = "test.project.group"; String version = "0.0.1-SNAPSHOT"; String runtimeVersion = "0.5.0.Final"; assertTrue("Project already exists.", !newProjectHandle.exists()); final NewSwitchYardProjectMetaData projectMetaData = new NewSwitchYardProjectMetaData(); projectMetaData.setNewProjectHandle(newProjectHandle); projectMetaData.setPackageName(packageName); projectMetaData.setGroupId(groupId); projectMetaData.setProjectVersion(version); projectMetaData.setRuntimeVersion(runtimeVersion); projectMetaData.setComponents( Collections.singleton( SwitchYardComponentExtensionManager.instance().getRuntimeComponentExtension())); IWorkspaceRunnable op = new CreateSwitchYardProjectOperation(projectMetaData, null); workspace.run(op, new NullProgressMonitor()); waitForJobs(); newProjectHandle.build(IncrementalProjectBuilder.FULL_BUILD, monitor); waitForJobs(); assertNoErrors(newProjectHandle); // TODO: change true to false once SWITCHYARD-469 is corrected assertTrue( "Project contains errors", newProjectHandle.findMaxProblemSeverity(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE) < IMarker.SEVERITY_ERROR); IFile switchyardFile = newProjectHandle.getFile("src/main/resources/META-INF/switchyard.xml"); assertTrue("Failed to create switchyard.xml", switchyardFile.exists()); assertTrue( "switchyard.xml file is out of sync after project creation", switchyardFile.isSynchronized(IFile.DEPTH_ZERO)); IFile pomFile = newProjectHandle.getFile("pom.xml"); assertTrue("Failed to create pom.xml", pomFile.exists()); assertTrue( "pom.xml file is out of sync after project creation", pomFile.isSynchronized(IFile.DEPTH_ZERO)); IFacetedProject fp = ProjectFacetsManager.create(newProjectHandle, false, new NullProgressMonitor()); assertNotNull("Project is not a faceted project.", fp); assertTrue( "switchyard.core facet not configured on project", fp.hasProjectFacet(ProjectFacetsManager.getProjectFacet("switchyard.core"))); assertTrue( "jst.utility facet not configured on project", fp.hasProjectFacet(ProjectFacetsManager.getProjectFacet("jst.utility"))); assertTrue( "java facet not configured on project", fp.hasProjectFacet(ProjectFacetsManager.getProjectFacet("java"))); // Test project update op = new AbstractSwitchYardProjectOperation( null, Collections.singleton( SwitchYardComponentExtensionManager.instance() .getComponentExtension("org.switchyard.components:switchyard-component-bpm")), true, "Testing SwitchYard project update", null) { @Override protected IProject getProject() { return newProjectHandle; } @Override protected void execute(IProgressMonitor monitor) throws CoreException { monitor.done(); } }; workspace.run(op, new NullProgressMonitor()); waitForJobs(); newProjectHandle.build(IncrementalProjectBuilder.FULL_BUILD, monitor); waitForJobs(); assertNoErrors(newProjectHandle); assertTrue("Failed to update pom.xml", pomFile.exists()); assertTrue( "pom.xml file is out of sync after project update", pomFile.isSynchronized(IFile.DEPTH_ZERO)); assertXMLFilesMatch( "pom dependency update failed", pomFile, "test-data/validation/add_dependency_pom.xml"); // test new bean service and test class IFile testServiceFile = newProjectHandle .getFolder("src/main/java") .getFolder(packageName.replace('.', '/')) .getFile("TestService.java"); testServiceFile.create( CreateSwitchYardProjectTest.class .getClassLoader() .getResourceAsStream("test-data/source/TestService.java"), true, new NullProgressMonitor()); // the project needs to be built or we can't create the service test class newProjectHandle.build(IncrementalProjectBuilder.FULL_BUILD, monitor); waitForJobs(); NewBeanServiceClassWizardPage newBeanPage = new NewBeanServiceClassWizardPage(); newBeanPage.init(new StructuredSelection(testServiceFile)); assertTrue( "NewBeanServiceClassWizardPage is not initialized correctly.", newBeanPage.isPageComplete()); NewServiceTestClassWizardPage newTestPage = new NewServiceTestClassWizardPage(); newTestPage.init(new StructuredSelection(testServiceFile)); newTestPage.setServiceContract(newBeanPage.getServiceContract(), false); assertTrue( "NewServiceTestClassWizardPage is not initialized correctly.", newTestPage.isPageComplete()); op = new CreateBeanServiceOperation(newBeanPage, newTestPage, null); workspace.run(op, new NullProgressMonitor()); waitForJobs(); newProjectHandle.build(IncrementalProjectBuilder.FULL_BUILD, monitor); waitForJobs(); assertNoErrors(newProjectHandle); assertTrue("switchyard.xml missing after bean service creation", switchyardFile.exists()); assertTrue( "switchyard.xml file is out of sync after bean service creation", switchyardFile.isSynchronized(IFile.DEPTH_ZERO)); assertXMLFilesMatch( "bean service creation failed", switchyardFile, "test-data/validation/create_service_switchyard.xml"); assertTrue("pom.xml missing after bean service creation", pomFile.exists()); assertTrue( "pom.xml file is out of sync after bean service creation", pomFile.isSynchronized(IFile.DEPTH_ZERO)); assertXMLFilesMatch( "bean service creation failed", pomFile, "test-data/validation/create_service_pom.xml"); IFile testServiceImplFile = newProjectHandle .getFolder("src/main/java") .getFolder(packageName.replace('.', '/')) .getFile("TestServiceBean.java"); IFile testServiceTestFile = newProjectHandle .getFolder("src/test/java") .getFolder(packageName.replace('.', '/')) .getFile("TestServiceTest.java"); assertTrue("TestServiceBean missing after bean service creation", testServiceImplFile.exists()); assertTrue( "TestServiceBean file is out of sync after bean service creation", testServiceImplFile.isSynchronized(IFile.DEPTH_ZERO)); assertTrue( "testServiceTestFile missing after bean service creation", testServiceTestFile.exists()); assertTrue( "testServiceTestFile file is out of sync after bean service creation", testServiceTestFile.isSynchronized(IFile.DEPTH_ZERO)); // TODO: validate contents of generated files }