protected void handleApplicationBrowseButton() { IWorkspace workspace = ResourcesPlugin.getWorkspace(); AppSelectionDialog dialog = new AppSelectionDialog(getShell(), workspace.getRoot(), new HtmlWebResourceFilter()); dialog.setTitle("Select a HTML page to launch"); dialog.setInitialPattern(".", FilteredItemsSelectionDialog.FULL_SELECTION); // $NON-NLS-1$ IPath path = new Path(htmlText.getText()); if (workspace.validatePath(path.toString(), IResource.FILE).isOK()) { IFile file = workspace.getRoot().getFile(path); if (file != null && file.exists()) { dialog.setInitialSelections(new Object[] {path}); } } dialog.open(); Object[] results = dialog.getResult(); if ((results != null) && (results.length > 0) && (results[0] instanceof IFile)) { IFile file = (IFile) results[0]; String pathStr = file.getFullPath().toPortableString(); htmlText.setText(pathStr); } }
String findUnsusedProjectName(IWorkspace workspace) { String projectName = "Album " + (++counter); IProject project = workspace.getRoot().getProject(projectName); while (project.exists()) { projectName = "Album " + (++counter); project = workspace.getRoot().getProject(projectName); } return projectName; }
/** * Get the source file as resource in the workspace Does NOT test wether it exists * * @return the source file */ public IFile getSourceAsResource() { IWorkspace workspace = ResourcesPlugin.getWorkspace(); // If the path is in the workspace and absolute, make it relative to the workspace String orgPath = workspace.getRoot().getLocation().toOSString(); String file = getSource(); String sfile = file; // Grr: Win does not care about capitals! // So since I don't know which system i have I have to allow generally both if (file.toLowerCase().startsWith(orgPath.toLowerCase())) sfile = file.substring(orgPath.length()); return workspace.getRoot().getFile(new Path(sfile)); }
public void testSwitchBranchClosesOpenProjectsThatDontExistOnDestinationBranch() throws Throwable { testAddBranch(); assertCurrentBranch("master"); assertSwitchBranch("my_new_branch"); GitIndex index = getRepo().index(); assertTrue("Expected changed file listing to be empty", index.changedFiles().isEmpty()); // Create a new project on this branch! String projectName = "project_on_branch" + System.currentTimeMillis(); File projectDir = getRepo().workingDirectory().append(projectName).toFile(); projectDir.mkdirs(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject project = workspace.getRoot().getProject(projectName); IProjectDescription description = workspace.newProjectDescription(projectName); description.setLocation(getRepo().workingDirectory().append(projectName)); project.create(description, new NullProgressMonitor()); // Commit the project on this branch! index.refresh(new NullProgressMonitor()); // Now there should be a single file that's been changed! List<ChangedFile> changed = index.changedFiles(); assertEquals( "repository changed file listing should contain one entry for new .project file, but does not", 1, changed.size()); // Make sure it's shown as having unstaged changes only and is NEW assertNewUnstagedFile(changed.get(0)); // Stage the new file assertStageFiles(index, changed); assertNewStagedFile(changed.get(0)); assertCommit(index, "Initial commit"); assertSwitchBranch("master"); // Assert that the new project is closed! project = workspace.getRoot().getProject(projectName); assertFalse(project.isOpen()); // assert that there's no .project file stranded there File dotProject = new File(projectDir, IProjectDescription.DESCRIPTION_FILE_NAME); assertFalse(dotProject.exists()); }
/** * Check if model version is changed and rebuild PHP projects if necessary. * * @see PHPCoreConstants.STRUCTURE_VERSION */ private void rebuildProjects() { IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(ID); String modelVersion = preferences.get(PHPCoreConstants.STRUCTURE_VERSION_PREFERENCE, null); if (PHPCoreConstants.STRUCTURE_VERSION.equals(modelVersion)) { return; } preferences.put( PHPCoreConstants.STRUCTURE_VERSION_PREFERENCE, PHPCoreConstants.STRUCTURE_VERSION); try { preferences.flush(); } catch (BackingStoreException e1) { Logger.logException(e1); } IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject[] projects = workspace.getRoot().getProjects(); if (workspace.isAutoBuilding()) { try { for (IProject project : projects) { if (PHPToolkitUtil.isPhpProject(project)) { project.build(IncrementalProjectBuilder.CLEAN_BUILD, null); } } } catch (CoreException e) { Logger.logException(e); } } }
public boolean isInWorkspace() { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IPath defaultDefaultLocation = workspace.getRoot().getLocation(); return defaultDefaultLocation.isPrefixOf(getLocationPath()); }
private IProject initializeWorkspace() { IEclipsePreferences node = new InstanceScope().getNode(ResourcesPlugin.PI_RESOURCES); node.putBoolean(ResourcesPlugin.PREF_AUTO_REFRESH, true); try { node.flush(); } catch (BackingStoreException e) { e.printStackTrace(); } WorkspaceJob job = new WorkspaceJob("init workspace") { @Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { MyPart.this.project = TwitterContentUtil.getOrCreateTwitterDemoProject(workspace, monitor); return Status.OK_STATUS; } }; job.setRule(workspace.getRoot()); job.schedule(); return TwitterContentUtil.getTwitterDemoProject(workspace); }
/** * this will convert the IO file name of the resource bundle to java package name * * @param project * @param value - the io file name * @return - the java package name of the resource bundle */ public static String convertIOToJavaFileName(IProject project, String value) { String rbIOFile = value.substring(value.lastIndexOf("/") + 1); // $NON-NLS-1$ IFile resourceBundleFile = null; IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot wroot = workspace.getRoot(); IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project); for (IClasspathEntry iClasspathEntry : cpEntries) { if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) { IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation(); entryPath = entryPath.append(rbIOFile); resourceBundleFile = wroot.getFileForLocation(entryPath); // System.out.println( "ResourceBundleValidationService.validate():" + resourceBundleFile ); if (resourceBundleFile != null && resourceBundleFile.exists()) { break; } } } String javaName = resourceBundleFile.getProjectRelativePath().toPortableString(); if (javaName.indexOf('.') != -1) { // Strip the extension javaName = value.substring(0, value.lastIndexOf('.')); // Replace all "/" by "." javaName = javaName.replace('/', '.'); } return javaName; }
protected IProject createProject() throws CoreException { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject project = workspace.getRoot().getProject(PROJECT_NAME); project.create(new NullProgressMonitor()); project.open(new NullProgressMonitor()); return project; }
/** * @see org.teiid.designer.core.workspace.ModelWorkspace#createModelProject(java.lang.String, * java.lang.String, org.eclipse.core.runtime.IProgressMonitor) * @since 4.0 */ @Override public ModelProject createModelProject( final String name, final IPath path, final IProgressMonitor monitor) throws CoreException { CoreArgCheck.isNotNull(name); // Check if project already exists if (findModelProject(name) != null) { throw new ModelWorkspaceException( ModelerCore.Util.getString( "ModelWorkspaceImpl.cannotCreateModelProject", name)); // $NON-NLS-1$ } // Validate name final IWorkspace workspace = ModelerCore.getWorkspace(); final IStatus status = workspace.validateName(name, IResource.PROJECT); if (!status.isOK()) { throw new ModelWorkspaceException( new ModelStatusImpl(status.getSeverity(), status.getCode(), status.getMessage())); } // Create new model project final IProject project = workspace.getRoot().getProject(name); final IProjectDescription desc = workspace.newProjectDescription(project.getName()); desc.setLocation(path); desc.setNatureIds(MODEL_NATURES); final IWorkspaceRunnable op = new IWorkspaceRunnable() { @Override public void run(final IProgressMonitor monitor) throws CoreException { project.create(desc, monitor); project.open(monitor); } }; workspace.run(op, monitor); return new ModelProjectImpl(project, this); }
/** * Create temporary build.xml and then erase it after code generation complete * * @param lc * @throws IOException * @throws UnsupportedEncodingException */ protected void createBuildXmlFile(ILaunchConfiguration lc, String fileName) throws UnsupportedEncodingException, IOException { CodeGenXMLFactory codeGenXMLFactory = new CodeGenXMLFactory(lc); String externalPropFileName = CodeGenXMLFactory.getExternalPropFileNameStandard(fileName); codeGenXMLFactory.setExternalPropFileName(externalPropFileName); IWorkspace workspace = ResourcesPlugin.getWorkspace(); if (workspace != null && workspace.getRoot() != null && workspace.getRoot().getLocation() != null) { codeGenXMLFactory.setWorkspacePath(workspace.getRoot().getLocation().toString()); } String buildXml = codeGenXMLFactory.createCodeGenXML(); createFile(fileName, buildXml); final String propFileContentPreSave = codeGenXMLFactory.getPropFileContentPreSave(); createFile(externalPropFileName, propFileContentPreSave); }
/** @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(java.lang.Object) */ public IEditorInput getEditorInput(Object element) { IStorageEditorInput i; AtlStackFrame frame; // String projectName; String fileName; if (element instanceof AtlStackFrame) { frame = (AtlStackFrame) element; if (((AtlDebugTarget) frame.getDebugTarget()).isDisassemblyMode()) return getDisassemblyEditorInput(frame); ILaunchConfiguration configuration = frame.getDebugTarget().getLaunch().getLaunchConfiguration(); try { // TODO Recuperer le nom du fichier sur la stackframe fileName = configuration.getAttribute( AtlLauncherTools.ATLFILENAME, AtlLauncherTools.NULLPARAMETER); IWorkspace wks = ResourcesPlugin.getWorkspace(); IWorkspaceRoot wksroot = wks.getRoot(); i = new FileEditorInput(wksroot.getFile(new Path(fileName))); return i; } catch (CoreException e) { e.printStackTrace(); } } else if (element instanceof AtlBreakpoint) { IMarker marker = ((AtlBreakpoint) element).getMarker(); IFile ifile = (IFile) marker.getResource(); return new FileEditorInput(ifile); } return null; }
@Execute public void execute(IWorkspace workspace, IProgressMonitor monitor) { String projectName = findUnsusedProjectName(workspace); final IProject project = workspace.getRoot().getProject(projectName); final IProjectDescription pd = workspace.newProjectDescription(projectName); try { pd.setLocationURI(new URI(ISemanticFileSystem.SCHEME, null, "/" + projectName, null)); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); return; } try { workspace.run( new IWorkspaceRunnable() { public void run(IProgressMonitor monitor1) throws CoreException { if (!project.exists()) { project.create(pd, monitor1); } if (!project.isOpen()) { project.open(monitor1); RepositoryProvider.map(project, ISemanticFileSystem.SFS_REPOSITORY_PROVIDER); System.out.println("Created at: " + project.getLocationURI()); } } }, monitor); } catch (CoreException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
public List<IProject> getModulesProjects() { Collection<String> modulesPath = info.modulesNameToPath.values(); return modulesPath .stream() .map(path -> workspace.getRoot().getProject(path)) .collect(Collectors.toList()); }
@Override public boolean performFinish() { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final String resourceName = ((AddDemoRESTResourcePage) getPage(AddDemoRESTResourcePage.NAME)).getResourceName(); final String resourceURL = ((AddDemoRESTResourcePage) getPage(AddDemoRESTResourcePage.NAME)).getResourceURL(); IWorkspaceRunnable myRunnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { MyWizard.this.myFolder.addFile( resourceName, URI.create(resourceURL), ISemanticFileSystem.NONE, monitor); MyWizard.this .myFolder .getAdaptedResource() .refreshLocal(IResource.DEPTH_INFINITE, monitor); } }; try { workspace.run(myRunnable, workspace.getRoot(), IWorkspace.AVOID_UPDATE, null); } catch (CoreException e) { MessageDialog.openError( getShell(), Messages.NewDemoRESTResourceWizard_Error_XGRP, e.getMessage()); SemanticResourcesPluginExamples.getDefault().getLog().log(e.getStatus()); return false; } return true; }
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException { searchResult.reset(); IProject[] projects = workspace.getRoot().getProjects(); ResourceSet rs = null; for (IProject curProject : projects) { if (XtextProjectHelper.hasNature(curProject)) { rs = resourceSetProvider.get(curProject); break; } } Iterable<IEObjectDescription> result = doSearch(rs); int i = 0; for (IEObjectDescription ieObjDesc : result) { i++; searchResult.accept(ieObjDesc); } searchResult.finish(); String message = MessageFormat.format( ServiceRepositorySearchMessages.ServiceRepositorySearchViewPage_resultLabel, new Object[] {String.valueOf(i)}); return (monitor.isCanceled()) ? Status.CANCEL_STATUS : new Status(Status.OK, ServiceRepositoryActivator.PLUGIN_ID, message); }
public IFile getNewModelIFile() { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot workspaceRoot = workspace.getRoot(); // IFile newModelFile = (IFile) workspaceRoot.getFileForLocation(newModelPath); IFile newModelFile = (IFile) workspaceRoot.getFile(newModelPath); return newModelFile; }
private void openFileWithDefaultEditor(String projectName, String path) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject project = workspace.getRoot().getProject(projectName); String fileName = path; final IFile fbfile = project.getFile(fileName); Display.getDefault() .asyncExec( new Runnable() { @Override public void run() { IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (activeWindow != null) { IWorkbenchPage page = activeWindow.getActivePage(); if (page != null) { try { IDE.openEditor(page, fbfile); } catch (PartInitException e) { throw new RuntimeException(e); } } } } }); }
public static IFile convert(File file) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IPath location = Path.fromOSString(file.getAbsolutePath()); IFile iFile = workspace.getRoot().getFileForLocation(location); return iFile; }
public static IFile LinkFile(String path) { IWorkspace ws = ResourcesPlugin.getWorkspace(); IProject project = ws.getRoot().getProject("tmp"); if (!project.exists()) try { project.create(null); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (!project.isOpen()) try { project.open(null); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } IPath location = new Path(path); IFile file = project.getFile(location.lastSegment()); try { file.delete(true, null); } catch (CoreException e1) { } try { file.createLink(location, IResource.NONE, null); } catch (CoreException e) { } return file; }
private String getProjectRelaticePath(FileDiff diff) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IPath absolutePath = new Path(db.getWorkDir().getAbsolutePath()).append(diff.path); IResource resource = root.getFileForLocation(absolutePath); return resource.getProjectRelativePath().toString(); }
public void testExpandingResourcePath() throws Exception { URL dotProjectResource = getClass().getResource("/testData/projects/buckminster.test.build_a/.project"); // $NON-NLS assertNotNull("No resource found for .project file", dotProjectResource); dotProjectResource = FileLocator.toFileURL(dotProjectResource); assertNotNull("Unable to resolve .project resource into a file", dotProjectResource); File dotProjectFile = new File(dotProjectResource.toURI()); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject project = workspace.getRoot().getProject("buckminster.test.build_a"); if (!project.isOpen()) { IProgressMonitor monitor = new NullProgressMonitor(); if (!project.exists()) { IProjectDescription projectDesc = workspace.loadProjectDescription(Path.fromOSString(dotProjectFile.getAbsolutePath())); project.create(projectDesc, monitor); } project.open(monitor); } assertTrue("No open project was found after materialization", project.isOpen()); ExpandingProperties<String> properties = new ExpandingProperties<String>(); String projectPath = properties.get("workspace_loc:buckminster.test.build_a"); assertNotNull("workspace_loc:<project name> doesn't resolve existing project", projectPath); assertEquals( "Unexpected physical project location", new File(projectPath), dotProjectFile.getParentFile()); }
/** * Return the project with the given root directory, loading it if it is not already loaded. This * method assumes that there is no conflict with project names. * * @param projectRootDirectory the root directory of the project * @return the project with the given root directory * @throws CoreException * @throws FileNotFoundException if a required file or directory does not exist * @throws IOException if a required file cannot be accessed * @throws SAXException if the .project file is not valid */ public static DartProject loadDartProject(final IPath projectRootDirectory) throws CoreException, FileNotFoundException, IOException, SAXException { final String projectName = getProjectName(projectRootDirectory); final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject project = workspace.getRoot().getProject(projectName); if (!project.exists()) { ResourcesPlugin.getWorkspace() .run( new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { IProjectDescription description = workspace.newProjectDescription(projectName); if (!workspace.getRoot().getLocation().isPrefixOf(projectRootDirectory)) { description.setLocation(projectRootDirectory); } project.create(description, null); project.open(null); } }, null); } DartProject dartProject = DartCore.create(project); // waitForJobs(); return dartProject; }
/** * Creates a new project resource with the selected name. * * <p>In normal usage, this method is invoked after the user has pressed Finish on the wizard; the * enablement of the Finish button implies that all controls on the pages currently contain valid * values. * * @return the created project resource, or <code>null</code> if the project was not created */ IProject createExistingProject() { String projectName = projectNameField.getText(); final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject project = workspace.getRoot().getProject(projectName); if (this.description == null) { this.description = workspace.newProjectDescription(projectName); IPath locationPath = getLocationPath(); // If it is under the root use the default location if (isPrefixOfRoot(locationPath)) { this.description.setLocation(null); } else { this.description.setLocation(locationPath); } } else { this.description.setName(projectName); } // create the new project operation WorkspaceModifyOperation op = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor monitor) throws CoreException { SubMonitor subMonitor = SubMonitor.convert(monitor, 100); project.create(description, subMonitor.split(50)); project.open(IResource.BACKGROUND_REFRESH, subMonitor.split(50)); } }; // run the new project creation operation try { getContainer().run(true, true, op); } catch (InterruptedException e) { return null; } catch (InvocationTargetException e) { // ie.- one of the steps resulted in a core exception Throwable t = e.getTargetException(); if (t instanceof CoreException) { if (((CoreException) t).getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) { MessageDialog.open( MessageDialog.ERROR, getShell(), DataTransferMessages.WizardExternalProjectImportPage_errorMessage, NLS.bind( DataTransferMessages.WizardExternalProjectImportPage_caseVariantExistsError, projectName), SWT.SHEET); } else { ErrorDialog.openError( getShell(), DataTransferMessages.WizardExternalProjectImportPage_errorMessage, null, ((CoreException) t).getStatus()); } } return null; } return project; }
protected void updateConnectionItem() throws CoreException { IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance(); IWorkspaceRunnable operation = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { try { factory.save(connectionItem); closeLockStrategy(); } catch (PersistenceException e) { throw new CoreException( new Status( IStatus.ERROR, "org.talend.metadata.management.ui", "Error when save the connection", e)); } } }; ISchedulingRule schedulingRule = workspace.getRoot(); // the update the project files need to be done in the workspace runnable to avoid all // notification of changes before the end of the modifications. workspace.run(operation, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor()); }
private void openFile(File file, DotGraphView view) { if (view.currentFile == null) { // no workspace file for cur. graph IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path("")); // $NON-NLS-1$ fileStore = fileStore.getChild(file.getAbsolutePath()); if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) { IWorkbenchPage page = view.getSite().getPage(); try { IDE.openEditorOnFileStore(page, fileStore); } catch (PartInitException e) { e.printStackTrace(); } } } else { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IPath location = Path.fromOSString(file.getAbsolutePath()); IFile copy = workspace.getRoot().getFileForLocation(location); IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); if (registry.isSystemExternalEditorAvailable(copy.getName())) { try { view.getViewSite() .getPage() .openEditor(new FileEditorInput(copy), IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); } catch (PartInitException e) { e.printStackTrace(); } } } }
private void stackTracingWasChanged(boolean enabled) { IPreferenceStore store = CxxTestPlugin.getDefault().getPreferenceStore(); String driverFile = store.getString(CxxTestPlugin.CXXTEST_PREF_DRIVER_FILENAME); IExtraOptionsUpdater updater = CxxTestPlugin.getDefault().getExtraOptionsUpdater(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject[] projects = workspace.getRoot().getProjects(); for (IProject project : projects) { if (!project.isOpen()) { continue; } try { if (project.hasNature(CxxTestPlugin.CXXTEST_NATURE)) { IFile driver = project.getFile(driverFile); if (driver != null) { driver.delete(true, null); } updater.updateOptions(project); } } catch (CoreException e) { e.printStackTrace(); } } }
private String getWorkspaceRelativePath(File folder) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IPath rootPath = root.getLocation(); Path path = new Path(folder.getAbsolutePath()); return path.makeRelativeTo(rootPath).toString(); }
/** * Set the folder, in which we will look for files against which to compare other * files-under-test, from its workspace-relative path. CONTRACT: path string is not null or empty. */ public static void setGoldFolder(String workspaceRelativePath) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot workspaceRoot = workspace.getRoot(); IPath rootPath = workspaceRoot.getLocation(); IPath goldPath = rootPath.append(workspaceRelativePath); IFolder gf = workspaceRoot.getFolder(goldPath); setGoldFolder(gf); }
/** * This method will refresh the workspace.If any changes are made in any configuration files * through UI in that case it will refresh the workspace so that user can see the correct/modified * files. * * @param errorTitle * @param errorMessage */ public static void refreshWorkspace(String errorTitle, String errorMessage) { try { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); root.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { PluginUtil.displayErrorDialogAndLog(new Shell(), errorTitle, errorMessage, e); } }