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

The following examples show how to use org.eclipse.core.resources.IProject#refreshLocal() . 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: CodewindEclipseApplication.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void buildComplete() {
	IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
   	if (project != null && project.isAccessible()) {
   		Job job = new Job(NLS.bind(Messages.RefreshResourceJobLabel, project.getName())) {
			@Override
			protected IStatus run(IProgressMonitor monitor) {
				try {
					project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
		            return Status.OK_STATUS;
				} catch (Exception e) {
					Logger.logError("An error occurred while refreshing the resource: " + project.getLocation()); //$NON-NLS-1$
					return new Status(IStatus.ERROR, CodewindCorePlugin.PLUGIN_ID,
							NLS.bind(Messages.RefreshResourceError, project.getLocation()), e);
				}
			}
		};
		job.setPriority(Job.LONG);
		job.schedule();
   	}
}
 
Example 2
Source File: ExampleImporter.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public IProject importExample(ExampleData edata, IProgressMonitor monitor) {
	try {
		IProjectDescription original = ResourcesPlugin.getWorkspace()
				.loadProjectDescription(new Path(edata.getProjectDir().getAbsolutePath()).append("/.project"));
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(edata.getProjectDir().getName());

		IProjectDescription clone = ResourcesPlugin.getWorkspace().newProjectDescription(original.getName());
		clone.setBuildSpec(original.getBuildSpec());
		clone.setComment(original.getComment());
		clone.setDynamicReferences(original.getDynamicReferences());
		clone.setNatureIds(original.getNatureIds());
		clone.setReferencedProjects(original.getReferencedProjects());
		if (project.exists()) {
			return project;
		}
		project.create(clone, monitor);
		project.open(monitor);

		@SuppressWarnings("unchecked")
		List<IFile> filesToImport = FileSystemStructureProvider.INSTANCE.getChildren(edata.getProjectDir());
		ImportOperation io = new ImportOperation(project.getFullPath(), edata.getProjectDir(),
				FileSystemStructureProvider.INSTANCE, new IOverwriteQuery() {

					@Override
					public String queryOverwrite(String pathString) {
						return IOverwriteQuery.ALL;
					}

				}, filesToImport);
		io.setOverwriteResources(true);
		io.setCreateContainerStructure(false);
		io.run(monitor);
		project.refreshLocal(IProject.DEPTH_INFINITE, monitor);
		return project;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 3
Source File: AbstractAcuteTest.java    From aCute with Eclipse Public License 2.0 6 votes vote down vote up
/**
 *
 * @param projectName the name that will be used as prefix for the project, and that will be used to find
 * the content of the project from the plugin "projects" folder
 * @throws IOException
 * @throws CoreException
 * @throws InterruptedException
 */
protected IProject provisionProject(String projectName) throws IOException, CoreException, InterruptedException {
	URL url = FileLocator.find(Platform.getBundle("org.eclipse.acute.tests"), Path.fromPortableString("projects/" + projectName), Collections.emptyMap());
	url = FileLocator.toFileURL(url);
	File folder = new File(url.getFile());
	if (folder != null && folder.exists()) {
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName + "_" + getClass().getName() + "_" + System.currentTimeMillis());
		project.create(new NullProgressMonitor());
		this.provisionedProjects.put(projectName, project);
		FileUtils.copyDirectory(folder, project.getLocation().toFile());
		// workaround for https://github.com/OmniSharp/omnisharp-node-client/issues/265
		ProcessBuilder dotnetRestoreBuilder = new ProcessBuilder(AcutePlugin.getDotnetCommand(), "restore");
		dotnetRestoreBuilder.directory(project.getLocation().toFile());
		assertEquals(0, dotnetRestoreBuilder.start().waitFor());
		project.open(new NullProgressMonitor());
		project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
		return project;
	} else {
		return null;
	}
}
 
Example 4
Source File: XLIFFEditorImplWithNatTable.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 释放编辑器,同时释放其他相关资源。
 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
 */
public void dispose() {
	// 当该编辑器被释放资源时,检查该编辑器是否被保存,并且是否是同时打开多个文件,若成立,则删除合并打开所产生的临时文件--robert 2012-03-30
	if (!isStore && isMultiFile()) {
		try {
			IEditorInput input = getEditorInput();
			IProject multiProject = ResourceUtil.getResource(input).getProject();
			ResourceUtil.getResource(input).delete(true, null);
			multiProject.refreshLocal(IResource.DEPTH_INFINITE, null);

			CommonFunction.refreshHistoryWhenDelete(input);
		} catch (CoreException e) {
			LOGGER.error("", e);
			e.printStackTrace();
		}
	}

	if (titleImage != null && !titleImage.isDisposed()) {
		titleImage.dispose();
		titleImage = null;
	}
	if (table != null && !table.isDisposed()) {
		table.dispose();
		table = null;
	}

	if (statusLineImage != null && !statusLineImage.isDisposed()) {
		statusLineImage.dispose();
		statusLineImage = null;
	}
	handler = null;
	JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
	NattableUtil.getInstance(this).releaseResource();
	super.dispose();
	System.gc();
}
 
Example 5
Source File: WorkspaceDiagnosticsHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBadLocationException() throws Exception {
	//import project
	importProjects("eclipse/hello");
	IProject project = getProject("hello");
	IFile iFile = project.getFile("/src/test1/A.java");
	File file = iFile.getRawLocation().toFile();
	assertTrue(file.exists());
	iFile = project.getFile("/src/test1/A1.java");
	File destFile = iFile.getRawLocation().toFile();
	assertFalse(destFile.exists());
	FileUtils.copyFile(file, destFile, false);
	String uri = destFile.toPath().toUri().toString();
	project.refreshLocal(IResource.DEPTH_INFINITE, null);
	waitForBackgroundJobs();
	ArgumentCaptor<PublishDiagnosticsParams> captor = ArgumentCaptor.forClass(PublishDiagnosticsParams.class);
	verify(connection, atLeastOnce()).publishDiagnostics(captor.capture());
	List<PublishDiagnosticsParams> allCalls = captor.getAllValues();
	Collections.reverse(allCalls);
	projectsManager.setConnection(client);
	Optional<PublishDiagnosticsParams> param = allCalls.stream().filter(p -> p.getUri().equals(uri)).findFirst();
	assertTrue(param.isPresent());
	List<Diagnostic> diags = param.get().getDiagnostics();
	assertEquals(diags.toString(), 2, diags.size());
	Optional<Diagnostic> d = diags.stream().filter(p -> p.getMessage().equals("The type A is already defined")).findFirst();
	assertTrue(d.isPresent());
	Diagnostic diag = d.get();
	assertTrue(diag.getRange().getStart().getLine() >= 0);
	assertTrue(diag.getRange().getStart().getCharacter() >= 0);
	assertTrue(diag.getRange().getEnd().getLine() >= 0);
	assertTrue(diag.getRange().getEnd().getCharacter() >= 0);
}
 
Example 6
Source File: ModelExportTestUtils.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
public static void initialize() throws CoreException, IOException, InterruptedException {
	String projectPath = new File(TEST_PROJECT_PATH).getCanonicalPath();
	IProjectDescription description = ResourcesPlugin.getWorkspace()
			.loadProjectDescription(new Path(projectPath + Path.SEPARATOR + PROJECT_FILE));
	IProject genericProject = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
	if (!genericProject.exists()) {
		genericProject.create(description, null);
	}
	genericProject.open(null);
	project = JavaCore.create(genericProject);
	genericProject.refreshLocal(IProject.DEPTH_INFINITE, null);
}
 
Example 7
Source File: AbstractBaseAction.java    From erflute with Apache License 2.0 5 votes vote down vote up
protected void refreshProject() {
    final IFile iFile = ((IFileEditorInput) getEditorPart().getEditorInput()).getFile();
    final IProject project = iFile.getProject();
    try {
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (final CoreException e) {
        Activator.showExceptionDialog(e);
    }
}
 
Example 8
Source File: TexlipseBuilder.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
    * Clean the temporary files.
    * 
    * @see IncrementalProjectBuilder.clean
    */
   @Override
protected void clean(IProgressMonitor monitor) throws CoreException {

       IProject project = getProject();
       final ProjectFileTracking fileTracking = new ProjectFileTracking(project);
       final OutputFileManager fileManager = new OutputFileManager(project, fileTracking);

       BuilderRegistry.clearConsole();

       // reset session variables
       TexlipseProperties.setSessionProperty(project, TexlipseProperties.SESSION_LATEX_RERUN, null);
       TexlipseProperties.setSessionProperty(project, TexlipseProperties.SESSION_BIBTEX_RERUN, null);
       TexlipseProperties.setSessionProperty(project, TexlipseProperties.BIBFILES_CHANGED, null);

       // check main file
       String mainFile = TexlipseProperties.getProjectProperty(project, TexlipseProperties.MAINFILE_PROPERTY);
       if (mainFile == null || mainFile.length() == 0) {
           // main tex file not set -> nothing builded -> nothing to clean
           return;
       }

       fileManager.cleanTempFiles(monitor);
       fileManager.cleanOutputFile(monitor);

       monitor.subTask(TexlipsePlugin.getResourceString("builderSubTaskCleanMarkers"));

       this.deleteMarkers(project);
       project.refreshLocal(IProject.DEPTH_INFINITE, monitor);
	monitor.done();
}
 
Example 9
Source File: FlexMavenPackagedProjectStagingDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testStage_springBoot() throws IOException, CoreException {
  Map<String, IProject> projects =
      ProjectUtils.importProjects(
          getClass(), "test-projects/spring-boot-test.zip", false /* checkBuildErrors */, null);
  assertEquals(1, projects.size());

  IProject project = projects.values().iterator().next();
  IPath safeWorkDirectory = project.getFolder("safe-work-directory").getLocation();
  IPath stagingDirectory = project.getFolder("staging-result").getLocation();
  IPath appEngineDirectory = project.getFolder("src/main/appengine").getLocation();

  StagingDelegate delegate =
      new FlexMavenPackagedProjectStagingDelegate(project, appEngineDirectory);
  IStatus status = delegate.stage(stagingDirectory, safeWorkDirectory,
      null, null, new NullProgressMonitor());
  assertTrue(status.isOK());

  project.refreshLocal(IResource.DEPTH_INFINITE, null);
  assertTrue(project.getFolder("target").exists());
  assertTrue(project.getFile("target/customized-final-artifact-name.jar").exists());
  assertTrue(stagingDirectory.append("app.yaml").toFile().exists());
  assertTrue(stagingDirectory.append("customized-final-artifact-name.jar").toFile().exists());

  project.delete(true, null);
}
 
Example 10
Source File: XLIFFEditorImplWithNatTable.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 释放编辑器,同时释放其他相关资源。
 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
 */
public void dispose() {
	// 当该编辑器被释放资源时,检查该编辑器是否被保存,并且是否是同时打开多个文件,若成立,则删除合并打开所产生的临时文件--robert 2012-03-30
	if (!isStore && isMultiFile()) {
		try {
			IEditorInput input = getEditorInput();
			IProject multiProject = ResourceUtil.getResource(input).getProject();
			ResourceUtil.getResource(input).delete(true, null);
			multiProject.refreshLocal(IResource.DEPTH_INFINITE, null);

			CommonFunction.refreshHistoryWhenDelete(input);
		} catch (CoreException e) {
			LOGGER.error("", e);
			e.printStackTrace();
		}
	}

	if (titleImage != null && !titleImage.isDisposed()) {
		titleImage.dispose();
		titleImage = null;
	}
	if (table != null && !table.isDisposed()) {
		table.dispose();
		table = null;
	}

	if (statusLineImage != null && !statusLineImage.isDisposed()) {
		statusLineImage.dispose();
		statusLineImage = null;
	}
	handler = null;
	JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
	NattableUtil.getInstance(this).releaseResource();
	super.dispose();
	System.gc();
}
 
Example 11
Source File: AbstractWorkbenchTestCase.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a junit.jar file in the project.
 */
protected void createJunitJar(NullProgressMonitor monitor, IProject project) throws CoreException {
    String junitJarLocatioon = project.getLocation().toOSString() +
            "/junit.jar";
    File junitJarFile = new File(junitJarLocatioon);
    if (!junitJarFile.exists()) {
        FileUtils.copyFile(TestDependent.TEST_PYDEV_PLUGIN_LOC
                +
                "tests_completions/org/python/pydev/editor/codecompletion/revisited/javaintegration/junit.jar",
                junitJarLocatioon);
    }
    project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
 
Example 12
Source File: SARLProjectConfigurator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Refresh the project file hierarchy.
 *
 * @param project the project.
 * @param monitor the progress monitor.
 */
@SuppressWarnings("static-method")
protected void safeRefresh(IProject project, IProgressMonitor monitor) {
	try {
		project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
	} catch (CoreException exception) {
		SARLEclipsePlugin.getDefault().log(exception);
	}
}
 
Example 13
Source File: ExportToTestDataDialog.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
private void refreshProject() {
	IFile file = ((IFileEditorInput) editorPart.getEditorInput()).getFile();
	IProject project = file.getProject();

	try {
		project.refreshLocal(IResource.DEPTH_INFINITE, null);

	} catch (CoreException e) {
		Activator.showExceptionDialog(e);
	}
}
 
Example 14
Source File: DefaultSCTWorkspaceAccess.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void refreshProject(String projectName) {
	try {
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
		if (project != null && project.isAccessible())
			project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
	} catch (CoreException e) {
		throw new RuntimeException(e);
	}
}
 
Example 15
Source File: ExportGhidraModuleWizard.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Exports the given Ghidra module project to an extension zip file.
 *  
 * @param javaProject The Ghidra module project to export.
 * @param gradleDistribution The Gradle distribution to use to export.
 * @param monitor The monitor to use during export.
 * @throws InvocationTargetException if an error occurred during export.
 */
private void export(IJavaProject javaProject, GradleDistribution gradleDistribution,
		IProgressMonitor monitor)
		throws InvocationTargetException {
	try {
		IProject project = javaProject.getProject();
		info("Exporting " + project.getName());
		monitor.beginTask("Exporting " + project.getName(), 2);

		// Get path to Ghidra installation directory
		String ghidraInstallDirPath = project.getFolder(
			GhidraProjectUtils.GHIDRA_FOLDER_NAME).getLocation().toOSString();
		
		// Get project's java.  Gradle should use the same version.
		// TODO: It's more correct to get this from the project's classpath, since Ghidra's
		// saved Java home can change from launch to launch.  
		GhidraApplicationLayout ghidraLayout = new GhidraApplicationLayout(new File(ghidraInstallDirPath));
		File javaHomeDir = new JavaConfig(
			ghidraLayout.getApplicationInstallationDir().getFile(false)).getSavedJavaHome();
		if(javaHomeDir == null) {
			throw new IOException("Failed to get the Java home associated with the project.  " +
				"Perform a \"Link Ghidra\" operation on the project and try again.");
		}

		// Setup the Gradle build attributes
		List<String> tasks = new ArrayList<>();
		String workingDir = project.getLocation().toOSString();
		String gradleDist = gradleDistribution.toString();
		String gradleUserHome = "";
		String javaHome = javaHomeDir.getAbsolutePath();
		List<String> jvmArgs = new ArrayList<>();
		List<String> gradleArgs =
			Arrays.asList(new String[] { "-PGHIDRA_INSTALL_DIR=" + ghidraInstallDirPath });
		boolean showExecutionView = false;
		boolean showConsoleView = true;
		boolean overrideWorkspaceSettings = true;
		boolean isOffline = true;
		boolean isBuildScansEnabled = false;
		GradleRunConfigurationAttributes gradleAttributes =
			new GradleRunConfigurationAttributes(tasks, workingDir, gradleDist, gradleUserHome,
				javaHome, jvmArgs, gradleArgs, showExecutionView, showConsoleView,
				overrideWorkspaceSettings, isOffline, isBuildScansEnabled);

		// Launch Gradle
		GradleLaunchConfigurationManager lm = CorePlugin.gradleLaunchConfigurationManager();
		ILaunchConfiguration lc = lm.getOrCreateRunConfiguration(gradleAttributes);
		lc.launch(ILaunchManager.RUN_MODE, monitor, true, true);
		lc.delete();

		monitor.worked(1);

		project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
		monitor.worked(1);

		info("Finished exporting " + project.getName());
	}
	catch (IOException | ParseException | CoreException e) {
		throw new InvocationTargetException(e);
	}
	finally {
		monitor.done();
	}
}
 
Example 16
Source File: VibeLauncherTester.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <p>
 * This operation sets up the workspace. 
 * </p>
 */
@BeforeClass
public static void beforeTests() {

	// Local Declarations
	IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	IProject project = null;
	String separator = System.getProperty("file.separator");
	String userDir = System.getProperty("user.home") + separator
			+ "ICETests" + separator + "caebatTesterWorkspace";
	// Enable Debugging
	System.setProperty("DebugICE", "");

	// Setup the project
	try {
		// Get the project handle
		IPath projectPath = new Path(userDir + separator + ".project");
		// Create the project description
		IProjectDescription desc = ResourcesPlugin.getWorkspace()
		                    .loadProjectDescription(projectPath);
		// Get the project handle and create it
		project = workspaceRoot.getProject(desc.getName());
		// Create the project if it doesn't exist
		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, null);
	} catch (CoreException e) {
		// Catch exception for creating the project
		e.printStackTrace();
		fail();
	}

	// Set the global project reference.
	projectSpace = project;

	return;
}
 
Example 17
Source File: CoreTester.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * This operation checks that the second create() operation functions
 * properly.
 *
 * @throws CoreException
 *             Thrown if the project file cannot be deleted.
 */
@Test
public void checkCreateInMultipleProjects() throws CoreException {
	// Create a builder for the test
	FakeGeometryBuilder fakeGeometryBuilder = new FakeGeometryBuilder();
	IProject project = getProject("default2");

	// Register the ItemBuilder
	iCECore.registerItem(fakeGeometryBuilder);

	// Reset the persistence provider
	fakePersistenceProvider.reset();

	// Create the item
	String name = fakeGeometryBuilder.getItemName();

	String idString = iCECore.createItem(name, project);
	int id = Integer.parseInt(idString);
	assertTrue(id > 0);
	assertTrue(fakePersistenceProvider.itemPersisted());

	// Check the project space for the process output file created by the
	// new Item. The actual XML file of the Item will not be stored here
	// because I am using a fake persistence provider. (It is a unit test,
	// after all.) However, if the Item is correctly receiving the new
	// project, the persistence provider should be called and the Item
	// should be storing its process output file there.
	String fileName = "Inigo_Montoya_" + id + "_processOutput.txt";
	// Refresh the project space, just in case.
	project.refreshLocal(IResource.DEPTH_INFINITE, null);
	IFile file = project.getFile(fileName);

	// Clean up the file
	file.delete(true, null);

	// Delete the Item from the Core to give the next test a clean slate.
	iCECore.deleteItem(String.valueOf(id));

	// Reset the persistence provider for the next test
	fakePersistenceProvider.reset();

	return;
}
 
Example 18
Source File: VerySimpleBuilder.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
    IProject toBuild = getProject();

    // mark all referencing as needing rebuild
    for (IProject referencing : toBuild.getReferencingProjects())
        referencing.touch(monitor);

    // build location context
    IFileStore storeToBuild = EFS.getStore(toBuild.getLocationURI());
    LocationContext context = new LocationContext(storeToBuild);
    context.addSourcePath(storeToBuild, null);
    for (IProject referenced : toBuild.getReferencedProjects()) {
        URI referencedLocation = referenced.getLocationURI();
        if (referencedLocation != null) {
            IFileStore modelPathEntry = EFS.getStore(referencedLocation);
            context.addRelatedPath(modelPathEntry);
        }
    }

    removeMarkers(toBuild);
    IProblem[] problems = FrontEnd.getCompilationDirector().compile(null, null, context,
            ICompilationDirector.FULL_BUILD, monitor);
    toBuild.refreshLocal(IResource.DEPTH_INFINITE, null);
    Arrays.sort(problems, new Comparator<IProblem>() {
        public int compare(IProblem o1, IProblem o2) {
            if ((o1 instanceof InternalProblem) || (o2 instanceof InternalProblem)) {
                if (!(o1 instanceof InternalProblem))
                    return 1;
                if (!(o2 instanceof InternalProblem))
                    return -1;
                return 0;
            }
            int fileNameDelta = ((IFileStore) o1.getAttribute(IProblem.FILE_NAME)).toURI().compareTo(
                    ((IFileStore) o2.getAttribute(IProblem.FILE_NAME)).toURI());
            if (fileNameDelta != 0)
                return fileNameDelta;
            int lineNo1 = getLineNumber(o1);
            int lineNo2 = getLineNumber(o2);
            return lineNo1 - lineNo2;
        }

    });
    createMarkers(toBuild, problems);
    return null;
}
 
Example 19
Source File: JReFrameworker.java    From JReFrameworker with MIT License 4 votes vote down vote up
public static IStatus createProject(String projectName, IPath projectPath, IProgressMonitor monitor, BuildFile.Target... targets) throws CoreException, IOException, URISyntaxException, TransformerException, ParserConfigurationException, SAXException {
	IProject project = null;
	
	try {
		monitor.beginTask("Create JReFrameworker Runtime Project", 2);
		
		// create the empty eclipse project
		monitor.setTaskName("Creating Eclipse project...");
		project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
		File projectDirectory = new File(projectPath.toFile().getCanonicalPath() + File.separatorChar + project.getName()).getCanonicalFile();
		
		File runtimesDirectory = new File(projectDirectory.getCanonicalPath() + File.separatorChar + BUILD_DIRECTORY);
		runtimesDirectory.mkdirs();
		
		IJavaProject jProject = createProject(projectName, projectPath, project, monitor);
		monitor.worked(1);
		if (monitor.isCanceled()){
			return Status.CANCEL_STATUS;
		}
		
		BuildFile buildFile = BuildFile.createBuildFile(jProject);
		for(BuildFile.Target target : targets){
			buildFile.addTarget(target);
		}
		
		// copy runtimes and configure project classpath
		monitor.setTaskName("Configuring project classpath...");
		configureProjectClasspath(jProject);
		monitor.worked(1);
		if (monitor.isCanceled()){
			return Status.CANCEL_STATUS;
		}
		
		return Status.OK_STATUS;
	} finally {
		if (project != null && project.exists()){
			project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
		}
		monitor.done();
	}
}
 
Example 20
Source File: AddProjectToSessionWizard.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns all modified resources (either changed or deleted) for the current project mapping.
 *
 * <p><b>Important:</b> Do not call this inside the SWT Thread. This is a long running operation !
 */
private Map<String, FileListDiff> getModifiedResources(
    final Map<String, IProject> projectMapping, final IProgressMonitor monitor)
    throws CoreException {

  final Map<String, FileListDiff> modifiedResources = new HashMap<String, FileListDiff>();

  final ISarosSession session = sessionManager.getSession();

  // FIXME the wizard should handle the case that the session may stop in
  // the meantime !

  if (session == null) throw new IllegalStateException("no session running");

  final SubMonitor subMonitor =
      SubMonitor.convert(
          monitor, "Searching for files that will be modified...", projectMapping.size());

  for (final Entry<String, IProject> entry : projectMapping.entrySet()) {

    final String projectID = entry.getKey();
    final IProject project = entry.getValue();

    final IReferencePoint adaptedProject = ResourceAdapterFactory.create(entry.getValue());

    if (!session.isShared(adaptedProject)) project.refreshLocal(IResource.DEPTH_INFINITE, null);

    final FileList localFileList;

    try {
      localFileList =
          FileListFactory.createFileList(
              adaptedProject,
              checksumCache,
              ProgressMonitorAdapterFactory.convert(
                  subMonitor.newChild(1, SubMonitor.SUPPRESS_ALL_LABELS)));
    } catch (IOException e) {
      Throwable cause = e.getCause();

      if (cause instanceof CoreException) throw (CoreException) cause;

      throw new CoreException(
          new org.eclipse.core.runtime.Status(
              IStatus.ERROR, Saros.PLUGIN_ID, "failed to compute local file list", e));
    }

    final ResourceNegotiationData data = negotiation.getResourceNegotiationData(projectID);

    final FileListDiff diff = FileListDiff.diff(localFileList, data.getFileList());

    if (!diff.getRemovedFolders().isEmpty()
        || !diff.getRemovedFiles().isEmpty()
        || !diff.getAlteredFiles().isEmpty()) {
      modifiedResources.put(project.getName(), diff);
    }
  }

  return modifiedResources;
}