本文整理匯總了Java中org.eclipse.core.resources.ResourcesPlugin.getWorkspace方法的典型用法代碼示例。如果您正苦於以下問題:Java ResourcesPlugin.getWorkspace方法的具體用法?Java ResourcesPlugin.getWorkspace怎麽用?Java ResourcesPlugin.getWorkspace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.core.resources.ResourcesPlugin
的用法示例。
在下文中一共展示了ResourcesPlugin.getWorkspace方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setGW4ENature
import org.eclipse.core.resources.ResourcesPlugin; //導入方法依賴的package包/類
/**
* Set the GW4E Nature to the passed project
*
* @param project
* @return
* @throws CoreException
*/
public static IStatus setGW4ENature(IProject project) throws CoreException {
IProjectDescription description = project.getDescription();
String[] natures = description.getNatureIds();
String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
// add our id
newNatures[natures.length] = GW4ENature.NATURE_ID;
// validate the natures
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IStatus status = workspace.validateNatureSet(newNatures);
if (status.getCode() == IStatus.OK) {
description.setNatureIds(newNatures);
project.setDescription(description, null);
}
return status;
}
示例2: importProject
import org.eclipse.core.resources.ResourcesPlugin; //導入方法依賴的package包/類
private static IProject importProject(File probandsFolder, String projectName, boolean prepareDotProject)
throws Exception {
File projectSourceFolder = new File(probandsFolder, projectName);
if (!projectSourceFolder.exists()) {
throw new IllegalArgumentException("proband not found in " + projectSourceFolder);
}
if (prepareDotProject) {
prepareDotProject(projectSourceFolder);
}
IProgressMonitor monitor = new NullProgressMonitor();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProjectDescription newProjectDescription = workspace.newProjectDescription(projectName);
IProject project = workspace.getRoot().getProject(projectName);
project.create(newProjectDescription, monitor);
project.open(monitor);
if (!project.getLocation().toFile().exists()) {
throw new IllegalArgumentException("test project correctly created in " + project.getLocation());
}
IOverwriteQuery overwriteQuery = new IOverwriteQuery() {
@Override
public String queryOverwrite(String file) {
return ALL;
}
};
ImportOperation importOperation = new ImportOperation(project.getFullPath(), projectSourceFolder,
FileSystemStructureProvider.INSTANCE, overwriteQuery);
importOperation.setCreateContainerStructure(false);
importOperation.run(monitor);
return project;
}
示例3: dispose
import org.eclipse.core.resources.ResourcesPlugin; //導入方法依賴的package包/類
@Override
public void dispose() {
selectionProvider.removeSelectionChangedListener(selectionChangedListener);
selectionProvider = null;
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.removeResourceChangeListener(openAction);
workspace.removeResourceChangeListener(closeAction);
workspace.removeResourceChangeListener(closeUnrelatedAction);
super.dispose();
}
示例4: scheduleBuildIfNecessary
import org.eclipse.core.resources.ResourcesPlugin; //導入方法依賴的package包/類
/**
* Schedules a build with the given projects. Does nothing if the {@link Platform platform} is not running, or the
* iterable of projects is empty.
*
* @param toUpdate
* an iterable of projects to build.
*/
public void scheduleBuildIfNecessary(final Iterable<IProject> toUpdate) {
if (Platform.isRunning() && !Iterables.isEmpty(toUpdate)) {
final Workspace workspace = (Workspace) ResourcesPlugin.getWorkspace();
final IBuildConfiguration[] projectsToReBuild = from(asList(workspace.getBuildOrder()))
.filter(config -> Iterables.contains(toUpdate, config.getProject()))
.toArray(IBuildConfiguration.class);
if (!Arrays2.isEmpty(projectsToReBuild)) {
new RebuildWorkspaceProjectsJob(projectsToReBuild).schedule();
}
}
}
示例5: toIFolder
import org.eclipse.core.resources.ResourcesPlugin; //導入方法依賴的package包/類
/**
* Return the passed parameters (a file) as an IFolder
*
* @param file
* @return
*/
public static IFolder toIFolder(File file) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IPath location = Path.fromOSString(file.getAbsolutePath());
IFile ifile = workspace.getRoot().getFileForLocation(location);
return workspace.getRoot().getFolder(ifile.getFullPath());
}
示例6: errorIsInProblemView
import org.eclipse.core.resources.ResourcesPlugin; //導入方法依賴的package包/類
public boolean errorIsInProblemView (String expected) throws CoreException {
System.out.println("XXXXXXXXX errorIsInProblemView >"+expected+"<");
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IResource resource = workspace.getRoot();
IMarker[] markers = resource.findMarkers(null, true, IResource.DEPTH_INFINITE);
for (IMarker m : markers) {
String msg = (String)m.getAttribute(IMarker.MESSAGE);
System.out.println(">"+msg+"<");
if (expected.equalsIgnoreCase(msg.trim())) return true;
}
return false;
}
示例7: addNature
import org.eclipse.core.resources.ResourcesPlugin; //導入方法依賴的package包/類
private void addNature(IProject project) throws CoreException{
if(!project.hasNature(ProjectNature.NATURE_ID)){
IProjectDescription description = project.getDescription();
String[] prevNatures = description.getNatureIds();
String[] newNatures = new String[prevNatures.length + 3];
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
newNatures[prevNatures.length] = ProjectNature.NATURE_ID;
newNatures[prevNatures.length + 1] = JavaCore.NATURE_ID;
newNatures[prevNatures.length + 2] = ORG_ECLIPSE_M2E_CORE_MAVEN2_NATURE;
// validate the natures
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IStatus status = workspace.validateNatureSet(newNatures);
ICommand javaBuildCommand= description.newCommand();
javaBuildCommand.setBuilderName("org.eclipse.jdt.core.javabuilder");
ICommand mavenBuildCommand= description.newCommand();
mavenBuildCommand.setBuilderName("org.eclipse.m2e.core.maven2Builder");
ICommand[] iCommand = {javaBuildCommand, mavenBuildCommand};
description.setBuildSpec(iCommand);
// only apply new nature, if the status is ok
if (status.getCode() == IStatus.OK) {
description.setNatureIds(newNatures);
project.setDescription(description, null);
}
logger.debug("Project nature added");
}
}
示例8: deleteProjectPluginResource
import org.eclipse.core.resources.ResourcesPlugin; //導入方法依賴的package包/類
public void deleteProjectPluginResource(boolean deleteContent, String projectName) throws CoreException {
cacheIProject.remove(projectName);
IWorkspace myWorkspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot myWorkspaceRoot = myWorkspace.getRoot();
IProject resourceProject = myWorkspaceRoot.getProject(projectName);
if (resourceProject.exists()) {
resourceProject.delete(deleteContent, false, null);
}
}
示例9: toIFile
import org.eclipse.core.resources.ResourcesPlugin; //導入方法依賴的package包/類
/**
* Return the passed parameters (a file) as an IFile
*
* @param file
* @return
*/
public static IFile toIFile(File file) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IPath location = Path.fromOSString(file.getAbsolutePath());
IFile ifile = workspace.getRoot().getFileForLocation(location);
return ifile;
}
示例10: validateFullResourcePath
import org.eclipse.core.resources.ResourcesPlugin; //導入方法依賴的package包/類
/**
* @param resourcePath
* @return
*/
protected boolean validateFullResourcePath(IPath resourcePath,Problem pb) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IStatus result = workspace.validatePath(resourcePath.toString(),
IResource.FOLDER);
if (!result.isOK()) {
pb.raiseProblem(result.getMessage(), Problem.PROBLEM_PATH_INVALID);
return false;
}
return true;
}
示例11: validate
import org.eclipse.core.resources.ResourcesPlugin; //導入方法依賴的package包/類
private void validate() {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
// check whether the project name is empty
String projectName = projectData.projectName;
if (projectName == null || projectName.trim().isEmpty()) {
setErrorMessage("Project name must not be empty");
setPageComplete(false);
return;
}
// check whether the project name is valid
final IStatus projectNameStatus = workspace.validateName(projectName, IResource.PROJECT);
if (!projectNameStatus.isOK()) {
setErrorMessage(projectNameStatus.getMessage());
setPageComplete(false);
return;
}
// check whether the project with the name already exists
IProject handle = workspace.getRoot().getProject(projectData.projectName);
if (handle.exists()) {
setErrorMessage("A project with name '" + projectData.projectName + "' already exists in the workspace");
setPageComplete(false);
return;
}
// check whether the location is empty
String location = projectData.projectLocation;
if (location == null || location.isEmpty()) {
setErrorMessage("Enter a location for the project.");
setPageComplete(false);
return;
}
// check whether the location is a syntactically correct path
if (!Path.EMPTY.isValidPath(location)) {
setErrorMessage("Invalid project contents directory");
setPageComplete(false);
return;
}
IPath projectPath = null;
if (!useDefaultsButton.getSelection()) {
projectPath = Path.fromOSString(location);
if (!projectPath.toFile().exists()) {
if (!canCreate(projectPath.toFile())) {
setErrorMessage("Cannot create project content at the given external location.");
setPageComplete(false);
return;
}
}
}
// check whether the location is valid
final IStatus locationStatus = workspace.validateProjectLocation(handle, projectPath);
if (!locationStatus.isOK()) {
setErrorMessage(locationStatus.getMessage());
setPageComplete(false);
return;
}
setErrorMessage(null);
setPageComplete(true);
}
示例12: isValid
import org.eclipse.core.resources.ResourcesPlugin; //導入方法依賴的package包/類
@Override
public boolean isValid(ILaunchConfiguration config) {
setErrorMessage(null);
setMessage(null);
IWorkspace workspace = ResourcesPlugin.getWorkspace();
String modelName = _modelLocationText.getText().trim();
if (modelName.length() > 0) {
IResource modelIResource = workspace.getRoot().findMember(modelName);
if (modelIResource == null || !modelIResource.exists()) {
setErrorMessage(NLS.bind(LauncherMessages.SequentialMainTab_model_doesnt_exist, new String[] {modelName}));
return false;
}
if (modelName.equals("/")) {
setErrorMessage(LauncherMessages.SequentialMainTab_Model_not_specified);
return false;
}
if (! (modelIResource instanceof IFile)) {
setErrorMessage(NLS.bind(LauncherMessages.SequentialMainTab_invalid_model_file, new String[] {modelName}));
return false;
}
}
if (modelName.length() == 0) {
setErrorMessage(LauncherMessages.SequentialMainTab_Model_not_specified);
return false;
}
String languageName = _languageCombo.getText().trim();
if (languageName.length() == 0) {
setErrorMessage(LauncherMessages.SequentialMainTab_Language_not_specified);
return false;
}
else if(MelangeHelper.getEntryPoints(languageName).isEmpty()){
setErrorMessage(LauncherMessages.SequentialMainTab_Language_main_methods_dont_exist);
return false;
}
String mainMethod = _entryPointMethodText.getText().trim();
if (mainMethod.length() == 0) {
setErrorMessage(LauncherMessages.SequentialMainTab_Language_main_method_not_selected);
return false;
}
String rootElement = _entryPointModelElementText.getText().trim();
if (rootElement.length() == 0) {
setErrorMessage(LauncherMessages.SequentialMainTab_Language_root_element_not_selected);
return false;
}
String[] params =MelangeHelper.getParametersType(mainMethod);
String firstParam = MelangeHelper.lastSegment(params[0]);
String rootEClass = getModel().getEObject(rootElement).eClass().getName();
if( !(params.length == 1 && firstParam.equals(rootEClass)) ){
setErrorMessage(LauncherMessages.SequentialMainTab_Language_incompatible_root_and_main);
return false;
}
return true;
}
示例13: getWorkspace
import org.eclipse.core.resources.ResourcesPlugin; //導入方法依賴的package包/類
public static IWorkspace getWorkspace() {
return ResourcesPlugin.getWorkspace();
}
示例14: build
import org.eclipse.core.resources.ResourcesPlugin; //導入方法依賴的package包/類
/**
* Start a build on given project or workspace using given options.
*
* @param javaProject Project which must be (full) build or null if all
* workspace has to be built.
* @param options Options used while building
*/
void build(final IJavaProject javaProject, Hashtable options, boolean noWarning) throws IOException, CoreException {
if (DEBUG)
System.out.print("\tstart build...");
JavaCore.setOptions(options);
if (PRINT)
System.out.println("JavaCore options: " + options);
// Build workspace if no project
if (javaProject == null) {
// single measure
ENV.fullBuild();
} else {
if (PRINT)
System.out.println("Project options: " + javaProject.getOptions(false));
IWorkspaceRunnable compilation = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
ENV.fullBuild(javaProject.getPath());
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.run(compilation, null/* don't take any lock */, IWorkspace.AVOID_UPDATE, null/*
* no
* progress
* available
* here
*/);
}
// Verify markers
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IMarker[] markers = workspaceRoot.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
List resources = new ArrayList();
List messages = new ArrayList();
int warnings = 0;
for (int i = 0, length = markers.length; i < length; i++) {
IMarker marker = markers[i];
switch (((Integer) marker.getAttribute(IMarker.SEVERITY)).intValue()) {
case IMarker.SEVERITY_ERROR:
resources.add(marker.getResource().getName());
messages.add(marker.getAttribute(IMarker.MESSAGE));
break;
case IMarker.SEVERITY_WARNING:
warnings++;
if (noWarning) {
resources.add(marker.getResource().getName());
messages.add(marker.getAttribute(IMarker.MESSAGE));
}
break;
}
}
workspaceRoot.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
// Assert result
int size = messages.size();
if (size > 0) {
StringBuffer debugBuffer = new StringBuffer();
for (int i = 0; i < size; i++) {
debugBuffer.append(resources.get(i));
debugBuffer.append(":\n\t");
debugBuffer.append(messages.get(i));
debugBuffer.append('\n');
}
System.out.println("Unexpected ERROR marker(s):\n" + debugBuffer.toString());
System.out.println("--------------------");
String target = javaProject == null ? "workspace" : javaProject.getElementName();
// assertEquals("Found "+size+" unexpected errors while building "+target,
// 0, size);
}
if (DEBUG)
System.out.println("done");
}
示例15: removeSaveParticipant
import org.eclipse.core.resources.ResourcesPlugin; //導入方法依賴的package包/類
/**
*
*/
private void removeSaveParticipant() {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.removeResourceChangeListener(listener);
}