org.eclipse.core.internal.resources.Workspace Java Examples

The following examples show how to use org.eclipse.core.internal.resources.Workspace. 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: BuildManagerAccess.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Enforce a build.
 */
public static void needBuild() {
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	if (workspace instanceof Workspace) {
		BuildManager buildManager = ((Workspace) workspace).getBuildManager();
		try {
			requestRebuild.invoke(buildManager);
			Object job = autoBuildJob.get(buildManager);
			forceBuild.invoke(job);
		} catch (SecurityException | IllegalAccessException | IllegalArgumentException
				| InvocationTargetException e) {
			throw new RuntimeException(e);
		}

	} else {
		throw new RuntimeException("Unexpected workspace implementation");
	}
}
 
Example #2
Source File: BuildCancellationTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void build(IBuildContext context, IProgressMonitor monitor) throws CoreException {
	super.build(context, monitor);
	if(isExternalInterrupt) {
		try {
			// simulate a workspace operation that interrupts the auto build like in
			// {@link Workspace#prepareOperation(org.eclipse.core.runtime.jobs.ISchedulingRule, IProgressMonitor)}
			BuildManager buildManager = ((Workspace) ResourcesPlugin.getWorkspace()).getBuildManager();
			Field field0 = buildManager.getClass().getDeclaredField("autoBuildJob");
			field0.setAccessible(true);
			Object autoBuildJob = field0.get(buildManager);
			Field field1 = autoBuildJob.getClass().getDeclaredField("interrupted");
			field1.setAccessible(true);
			field1.set(autoBuildJob, true);
			isExternalInterrupt = false;
		} catch(Exception exc) {
			throw new RuntimeException(exc);
		}
	}
	if(cancelException != null) 
		throw cancelException;
}
 
Example #3
Source File: BuildManagerAccess.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Obtain the configured Xtext builder for the given project, if any.
 */
public static XtextBuilder findBuilder(IProject project) {
	try {
		if (project.isAccessible()) {
			Project casted = (Project) project;
			IBuildConfiguration activeBuildConfig = casted.getActiveBuildConfig();
			for (ICommand command : casted.internalGetDescription().getBuildSpec(false)) {
				if (XtextBuilder.BUILDER_ID.equals(command.getBuilderName())) {
					IWorkspace workspace = ResourcesPlugin.getWorkspace();
					if (workspace instanceof Workspace) {
						BuildManager buildManager = ((Workspace) workspace).getBuildManager();
						XtextBuilder result = (XtextBuilder) getBuilder.invoke(buildManager, activeBuildConfig, command, -1,
								new MultiStatus(Activator.PLUGIN_ID, 0, null, null));
						return result;
					}
				}
			}
		}
		return null;
	} catch (IllegalAccessException | InvocationTargetException | CoreException e) {
		throw new RuntimeException(e);
	}
}
 
Example #4
Source File: BuildManagerAccess.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Enforce a build.
 */
public static void requestBuild() {
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	if (workspace instanceof Workspace) {
		BuildManager buildManager = ((Workspace) workspace).getBuildManager();
		try {
			requestRebuild.invoke(buildManager);
			Object job = autoBuildJob.get(buildManager);
			forceBuild.invoke(job);
		} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
			throw new RuntimeException(e);
		}
	} else {
		throw new RuntimeException("Unexpected workspace implementation");
	}
}
 
Example #5
Source File: WorkspaceLockAccess.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public Result isWorkspaceLockedByCurrentThread(IWorkspace workspace) {
	try {
		WorkManager workManager = ((Workspace) workspace).getWorkManager();
		if (workManager.isLockAlreadyAcquired()) {
			return Result.YES;
		}
		return Result.NO;
	} catch (CoreException e) { // may be thrown during shutdown when the workmanager is no longer available
		return Result.SHUTDOWN;
	}
}
 
Example #6
Source File: AbstractGWTPluginTestCase.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static File createFile(IPath workspaceRelativeAbsPathOfFile, String contents) throws CoreException {
  // TODO: Convert to ResouceUtils.createFile
  Workspace workspace = (Workspace) ResourcesPlugin.getWorkspace();
  File file = (File) workspace.newResource(workspaceRelativeAbsPathOfFile, IResource.FILE);
  ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(contents.getBytes());
  file.create(byteArrayInputStream, false, null);
  JobsUtilities.waitForIdle();
  return file;
}
 
Example #7
Source File: BuildUtil.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Synchronous run of a builder with the given name on the given project.
 * 
 * @param project
 * @param kind
 *            See {@link IncrementalProjectBuilder} for the available types.
 * @param builderName
 * @param args
 * @param monitor
 * @return A status indicating if the build succeeded or failed
 */
public static IStatus syncBuild(IProject project, int kind, String builderName, Map args, IProgressMonitor monitor)
{
	try
	{
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
		BuildManager buildManager = ((Workspace) workspace).getBuildManager();
		return buildManager.build(new BuildConfiguration(project), kind, builderName, args, monitor);
	}
	catch (IllegalStateException e)
	{
		return new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, "Error while getting the Workspace", e); //$NON-NLS-1$
	}
}
 
Example #8
Source File: MockedFile.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public MockedFile(IPath path, Workspace container) {
	super(path, container);
}
 
Example #9
Source File: RebuildingXtextBuilder.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Like the super implementation, except the build is not triggered if
 * both toBeDeleted and toBeUpdated are empty. {@inheritDoc}
 */
@SuppressWarnings("nls")
@Override
protected void doBuild(final ToBeBuilt toBeBuilt, final IProgressMonitor monitor, final BuildType type) throws CoreException {
  if (toBeBuilt.getToBeDeleted().size() != 0 || toBeBuilt.getToBeUpdated().size() != 0) {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Starting " + type.name() + " build:" + "\ndeleted(" + toBeBuilt.getToBeDeleted().size() + ")=" + toBeBuilt.getToBeDeleted().toString()
          + "\nupdated(" + toBeBuilt.getToBeUpdated().size() + ")=" + toBeBuilt.getToBeUpdated().toString());
    }

    SubMonitor progress = SubMonitor.convert(monitor, 1 + 1 + 1); // build + participant + rebuild

    ResourceSet resourceSet = getResourceSetProvider().get(getProject());
    resourceSet.getLoadOptions().put(ResourceDescriptionsProvider.NAMED_BUILDER_SCOPE, Boolean.TRUE);
    if (resourceSet instanceof ResourceSetImpl && ((ResourceSetImpl) resourceSet).getURIResourceMap() == null) {
      ((ResourceSetImpl) resourceSet).setURIResourceMap(Maps.<URI, Resource> newHashMap());
    }
    BuildData buildData = new BuildData(getProject().getName(), resourceSet, toBeBuilt, queuedBuildData);
    ImmutableList<Delta> deltas = builderState.update(buildData, progress.newChild(1));
    if (participant != null) {
      final BuildContext buildContext = new BuildContext(this, resourceSet, deltas, type);
      // remember the current workspace tree
      final ElementTree oldTree = ((Workspace) ResourcesPlugin.getWorkspace()).getElementTree();
      oldTree.immutable();
      participant.build(buildContext, progress.newChild(1));
      if (buildContext.isRebuildRequired() && rebuilds++ <= 2) {
        final ElementTree newTree = ((Workspace) ResourcesPlugin.getWorkspace()).getElementTree();
        newTree.immutable();
        final ResourceDelta generatedDelta = ResourceDeltaFactory.computeDelta((Workspace) ResourcesPlugin.getWorkspace(), oldTree, newTree, getProject().getFullPath(), -1);
        // rebuild the generated delta
        ResourcesPlugin.getWorkspace().checkpoint(false);
        incrementalBuild(generatedDelta, progress.newChild(1));
      }
    } else {
      progress.worked(2);
    }
    resourceSet.getResources().clear();
    resourceSet.eAdapters().clear();
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Build done.");
    }
  } else if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Ignoring empty " + type.name() + " build.");
  }
}
 
Example #10
Source File: WebServerCorePlugin.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Save state of server configurations
 */
public void saveServerConfigurations()
{
	new DelayedSnapshotJob(((Workspace) ResourcesPlugin.getWorkspace()).getSaveManager()).schedule();
}
 
Example #11
Source File: WorkspaceJob.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public WorkspaceJob(String name, IWorkspace workspace) {
    super(name);
    this.workspace = (Workspace) workspace;
}