Java Code Examples for org.eclipse.core.resources.IResource.exists()

The following are Jave code examples for showing how to use exists() of the org.eclipse.core.resources.IResource class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: gw4e.project   File: ResourceManager.java   Source Code and License Vote up 7 votes
/**
 * @param folder
 * @param filetorefresh
 * @return
 * @throws CoreException
 * @throws InterruptedException
 */
public static IResource resfreshFileInContainer(IContainer folder, String filetorefresh)
		throws CoreException, InterruptedException {
	final IResource buildfile = find(folder, filetorefresh);
	Job job = new WorkspaceJob("Refresh folders") {
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			if (buildfile != null && buildfile.exists()) {
				try {
					buildfile.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
				} catch (CoreException e) {
					ResourceManager.logException(e);
				}
			}
			return Status.OK_STATUS;
		}
	};
	job.setUser(true);
	job.schedule();

	return buildfile;
}
 
Example 2
Project: ide-plugins   File: ExecuteUploadFunction.java   Source Code and License Vote up 6 votes
private Properties getGradleProperties() {
    Properties gradleProperties = new Properties();
    IResource resource = project.findMember("gradle.properties");
    if (resource != null && resource.exists()) {
        IFile gradlePropertiesFile = (IFile) resource;
        if (gradlePropertiesFile.exists()) {
            try (FileReader gradlePropertiesReader = new FileReader(new File(gradlePropertiesFile.getLocationURI()))) {
                gradleProperties.load(gradlePropertiesReader);
                return gradleProperties;
            } catch (IOException e) {
                e.printStackTrace();
            } 
        }
    } 
    System.out.println("gradle resource not found");
    return null;
}
 
Example 3
Project: pandionj   File: NewPackageWizard.java   Source Code and License Vote up 6 votes
private void doFinish(IPath containerPath, String[] path, IProgressMonitor monitor) throws CoreException {
	monitor.beginTask("Creating package " + String.join(".", path), path.length);
	IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

	IResource resource = root.findMember(containerPath);
	if (!resource.exists() || !(resource instanceof IContainer)) {
		throwCoreException("Container \"" + containerPath + "\" does not exist.");
	}

	IContainer container = (IContainer) resource;
	for(int i = 0; i < path.length; i++) {
		Path p = new Path(path[i]);
		final IFolder folder = container.getFolder(p);
		if(!folder.exists())
			folder.create(true, false, monitor);
		container = container.getFolder(p);
		monitor.worked(1);
	}
}
 
Example 4
Project: ide-plugins   File: ProjectUtils.java   Source Code and License Vote up 5 votes
public static IFile getGradleBuildFile(IContainer project) {
    IResource resource = project.findMember("build.gradle");
        if (resource != null && resource.exists()) {
            return (IFile) resource;
        }
        return null;
}
 
Example 5
Project: ide-plugins   File: ProjectUtils.java   Source Code and License Vote up 5 votes
public static IFile getGradleSettingsFile(IContainer project) {
       IResource resource = project.findMember("settings.gradle");
           if (resource != null && resource.exists()) {
               return (IFile) resource;
           }
           return null;
}
 
Example 6
Project: Equella   File: JPFManifestBuilder.java   Source Code and License Vote up 5 votes
private void cleanProblems(IResource resource, int depth) throws CoreException
{
	if( resource.exists() )
	{
		resource.deleteMarkers(JPFClasspathPlugin.MARKER_ID, true, depth);
	}
}
 
Example 7
Project: bdf2   File: WizardNewFileCreationPage.java   Source Code and License Vote up 5 votes
/**
 * Returns the scheduling rule to use when creating the resource at the
 * given container path. The rule should be the creation rule for the
 * top-most non-existing parent.
 * 
 * @param resource
 *            The resource being created
 * @return The scheduling rule for creating the given resource
 * @since 3.1
 * @deprecated As of 3.3, scheduling rules are provided by the undoable
 *             operation that this page creates and executes.
 */
protected ISchedulingRule createRule(IResource resource) {
	IResource parent = resource.getParent();
	while (parent != null) {
		if (parent.exists()) {
			return resource.getWorkspace().getRuleFactory()
					.createRule(resource);
		}
		resource = parent;
		parent = parent.getParent();
	}
	return resource.getWorkspace().getRoot();
}
 
Example 8
Project: gemoc-studio-modeldebugging   File: LaunchConfigurationMainTab.java   Source Code and License Vote up 4 votes
@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;
}
 
Example 9
Project: gw4e.project   File: SynchronizeBuildPoliciesHandler.java   Source Code and License Vote up 4 votes
public Object execute(ExecutionEvent event) throws ExecutionException {
	boolean autoBuilding = ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
	IWorkbenchWindow aww = HandlerUtil.getActiveWorkbenchWindow(event);
	ISelection sel = HandlerUtil.getCurrentSelection(event);
	if (sel.isEmpty())
		return null;
	if (sel instanceof IStructuredSelection) {

		IStructuredSelection selection = (IStructuredSelection) sel;
		if (selection != null) {
			Object obj = selection.getFirstElement();
			if (obj != null) {
				try {
					IResource selectedResource = null;
					if (obj instanceof IJavaProject) {
						IJavaProject jp = (IJavaProject) obj;
						selectedResource = jp.getProject();
					}
					if (obj instanceof IPackageFragmentRoot) {
						IPackageFragmentRoot pfr = (IPackageFragmentRoot) obj;
						selectedResource = pfr.getCorrespondingResource();
					}
					if (obj instanceof IPackageFragment) {
						IPackageFragment pf = (IPackageFragment) obj;
						selectedResource = pf.getCorrespondingResource();
					}
					if (selectedResource != null && !selectedResource.exists())
						return null;
					// This is where the synchronization is done ...
					ResourceManager.setAutoBuilding(false);
					GraphWalkerContextManager.synchronizeBuildPolicies(selectedResource, aww);
				} catch (Exception e) {
					ResourceManager.logException(e);
				} finally {
					ResourceManager.setAutoBuilding(autoBuilding);
				}
			}
		}
	}
	return null;
}
 
Example 10
Project: gw4e.project   File: ResourceExists.java   Source Code and License Vote up 4 votes
@Override
public boolean test() throws Exception {
	IResource resource = ResourceManager.getResource(path.toString());
	return resource!=null && resource.exists();
}