Java Code Examples for org.eclipse.core.filesystem.IFileInfo#exists()

The following examples show how to use org.eclipse.core.filesystem.IFileInfo#exists() . 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: BuildSettingWizardPage.java    From sarl with Apache License 2.0 6 votes vote down vote up
private void rememberExisitingFolders(URI projectLocation) {
	this.orginalFolders = new TreeMap<>();

	try {
		final IFileStore[] children = EFS.getStore(projectLocation).childStores(EFS.NONE, null);
		for (int i = 0; i < children.length; i++) {
			final IFileStore child = children[i];
			final IFileInfo info = child.fetchInfo();
			if (info.isDirectory() && info.exists() && !this.orginalFolders.containsKey(info.getName())) {
				this.orginalFolders.put(info.getName(), child);
			}
		}
	} catch (CoreException e) {
		SARLEclipsePlugin.getDefault().log(e);
	}
}
 
Example 2
Source File: NewJavaProjectWizardPageTwo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void rememberExisitingFolders(URI projectLocation) {
	fOrginalFolders= new HashSet<IFileStore>();

	try {
		IFileStore[] children= EFS.getStore(projectLocation).childStores(EFS.NONE, null);
		for (int i= 0; i < children.length; i++) {
			IFileStore child= children[i];
			IFileInfo info= child.fetchInfo();
			if (info.isDirectory() && info.exists() && !fOrginalFolders.contains(child.getName())) {
				fOrginalFolders.add(child);
			}
		}
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}
}
 
Example 3
Source File: CreateFileChange.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
	RefactoringStatus result= new RefactoringStatus();
	IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(fPath);

	URI location= file.getLocationURI();
	if (location == null) {
		result.addFatalError(Messages.format(
			NLSChangesMessages.CreateFileChange_error_unknownLocation,
			BasicElementLabels.getPathLabel(file.getFullPath(), false)));
		return result;
	}

	IFileInfo jFile= EFS.getStore(location).fetchInfo();
	if (jFile.exists()) {
		result.addFatalError(Messages.format(
			NLSChangesMessages.CreateFileChange_error_exists,
			BasicElementLabels.getPathLabel(file.getFullPath(), false)));
		return result;
	}
	return result;
}
 
Example 4
Source File: CreateFileChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
	RefactoringStatus result= new RefactoringStatus();
	IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(fPath);

	URI location= file.getLocationURI();
	if (location == null) {
		result.addFatalError(Messages.format(
			NLSChangesMessages.CreateFileChange_error_unknownLocation,
			BasicElementLabels.getPathLabel(file.getFullPath(), false)));
		return result;
	}

	IFileInfo jFile= EFS.getStore(location).fetchInfo();
	if (jFile.exists()) {
		result.addFatalError(Messages.format(
			NLSChangesMessages.CreateFileChange_error_exists,
			BasicElementLabels.getPathLabel(file.getFullPath(), false)));
		return result;
	}
	return result;
}
 
Example 5
Source File: RefreshHandler.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
void checkLocationDeleted(final IProject project) throws CoreException {
	if (!project.exists()) { return; }
	final IFileInfo location = IDEResourceInfoUtils.getFileInfo(project.getLocationURI());
	if (!location.exists()) {
		final String message = NLS.bind(IDEWorkbenchMessages.RefreshAction_locationDeletedMessage,
				project.getName(), location.toString());

		final MessageDialog dialog = new MessageDialog(WorkbenchHelper.getShell(),
				IDEWorkbenchMessages.RefreshAction_dialogTitle, null, message, MessageDialog.QUESTION,
				new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0) {
			@Override
			protected int getShellStyle() {
				return super.getShellStyle() | SWT.SHEET;
			}
		};
		WorkbenchHelper.run(() -> dialog.open());

		// Do the deletion back in the operation thread
		if (dialog.getReturnCode() == 0) { // yes was chosen
			project.delete(true, true, null);
		}
	}
}
 
Example 6
Source File: FileOpener.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public static IEditorPart openFileInFileSystem(final URI uri) throws PartInitException {
	if (uri == null) { return null; }
	IFileStore fileStore;
	try {
		fileStore = EFS.getLocalFileSystem().getStore(Path.fromOSString(uri.toFileString()));
	} catch (final Exception e1) {
		MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found",
				"The file'" + uri.toString() + "' cannot be found.");
		return null;
	}
	IFileInfo info;
	try {
		info = fileStore.fetchInfo();
	} catch (final Exception e) {
		MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found",
				"The file'" + uri.toString() + "' cannot be found.");
		return null;
	}
	if (!info.exists()) {
		MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found",
				"The file'" + uri.toString() + "' cannot be found.");
	}
	return IDE.openInternalEditorOnFileStore(PAGE, fileStore);
}
 
Example 7
Source File: ManifestUtils.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Inner helper method parsing single manifests with additional semantic analysis.
 */
protected static ManifestParseTree parseManifest(IFileStore manifestFileStore, String targetBase, Analyzer analyzer) throws CoreException, IOException, ParserException, AnalyzerException {

	/* basic sanity checks */
	IFileInfo manifestFileInfo = manifestFileStore.fetchInfo();
	if (!manifestFileInfo.exists() || manifestFileInfo.isDirectory())
		throw new IOException(ManifestConstants.MISSING_OR_INVALID_MANIFEST);

	if (manifestFileInfo.getLength() == EFS.NONE)
		throw new IOException(ManifestConstants.EMPTY_MANIFEST);

	if (manifestFileInfo.getLength() > ManifestConstants.MANIFEST_SIZE_LIMIT)
		throw new IOException(ManifestConstants.MANIFEST_FILE_SIZE_EXCEEDED);

	InputStream inputStream = manifestFileStore.openInputStream(EFS.NONE, null);
	ManifestParseTree manifestTree = null;
	try {
		manifestTree = parseManifest(inputStream, targetBase, analyzer);
	} finally {
		if (inputStream != null) {
			inputStream.close();
		}
	}
	return manifestTree;
}
 
Example 8
Source File: CopyFilesAndFoldersOperation.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks whether the resources with the given names exist.
 *
 * @param resources
 *            IResources to checl
 * @return Multi status with one error message for each missing file.
 */
IStatus checkExist(IResource[] resources) {
    MultiStatus multiStatus = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK, getProblemsMessage(), null);

    for (int i = 0; i < resources.length; i++) {
        IResource resource = resources[i];
        if (resource != null) {
            URI location = resource.getLocationURI();
            String message = null;
            if (location != null) {
                IFileInfo info = IDEResourceInfoUtils.getFileInfo(location);
                if (info == null || info.exists() == false) {
                    if (resource.isLinked()) {
                        message = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_missingLinkTarget,
                                resource.getName());
                    } else {
                        message = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_resourceDeleted,
                                resource.getName());
                    }
                }
            }
            if (message != null) {
                IStatus status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, message, null);
                multiStatus.add(status);
            }
        }
    }
    return multiStatus;
}
 
Example 9
Source File: JarWriter3.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new JarEntry with the passed path and contents, and writes it
 * to the current archive.
 *
 * @param	resource			the file to write
 * @param	path				the path inside the archive
 *
    * @throws	IOException			if an I/O error has occurred
 * @throws	CoreException 		if the resource can-t be accessed
 */
protected void addFile(IFile resource, IPath path) throws IOException, CoreException {
	JarEntry newEntry= new JarEntry(path.toString().replace(File.separatorChar, '/'));
	byte[] readBuffer= new byte[4096];

	if (fJarPackage.isCompressed())
		newEntry.setMethod(ZipEntry.DEFLATED);
		// Entry is filled automatically.
	else {
		newEntry.setMethod(ZipEntry.STORED);
		JarPackagerUtil.calculateCrcAndSize(newEntry, resource.getContents(false), readBuffer);
	}

	long lastModified= System.currentTimeMillis();
	URI locationURI= resource.getLocationURI();
	if (locationURI != null) {
		IFileInfo info= EFS.getStore(locationURI).fetchInfo();
		if (info.exists())
			lastModified= info.getLastModified();
	}

	// Set modification time
	newEntry.setTime(lastModified);

	InputStream contentStream = resource.getContents(false);

	addEntry(newEntry, contentStream);
}
 
Example 10
Source File: JarWriter3.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates the directory entries for the given path and writes it to the
 * current archive.
 *
 * @param resource
 *            the resource for which the parent directories are to be added
 * @param destinationPath
 *            the path to add
 *
 * @throws IOException
 *             if an I/O error has occurred
 * @throws CoreException
 *             if accessing the resource failes
 */
protected void addDirectories(IResource resource, IPath destinationPath) throws IOException, CoreException {
	IContainer parent= null;
	String path= destinationPath.toString().replace(File.separatorChar, '/');
	int lastSlash= path.lastIndexOf('/');
	List<JarEntry> directories= new ArrayList<JarEntry>(2);
	while (lastSlash != -1) {
		path= path.substring(0, lastSlash + 1);
		if (!fDirectories.add(path))
			break;

		parent= resource.getParent();
		long timeStamp= System.currentTimeMillis();
		URI location= parent.getLocationURI();
		if (location != null) {
			IFileInfo info= EFS.getStore(location).fetchInfo();
			if (info.exists())
				timeStamp= info.getLastModified();
		}

		JarEntry newEntry= new JarEntry(path);
		newEntry.setMethod(ZipEntry.STORED);
		newEntry.setSize(0);
		newEntry.setCrc(0);
		newEntry.setTime(timeStamp);
		directories.add(newEntry);

		lastSlash= path.lastIndexOf('/', lastSlash - 1);
	}

	for (int i= directories.size() - 1; i >= 0; --i) {
		fJarOutputStream.putNextEntry(directories.get(i));
	}
}
 
Example 11
Source File: LocalWebServerHttpRequestHandler.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private static IFileInfo getIndex(IFileStore parent) throws CoreException
{
	for (IFileInfo fileInfo : parent.childInfos(EFS.NONE, new NullProgressMonitor()))
	{
		if (fileInfo.exists() && PATTERN_INDEX.matcher(fileInfo.getName()).matches())
		{
			return fileInfo;
		}
	}
	return EFS.getNullFileSystem().getStore(Path.EMPTY).fetchInfo();
}
 
Example 12
Source File: IDEEditputProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public IEditorInput createEditorInput( Object file )
{
	if (file instanceof File)
	{
		File handle = (File)file;
		String fileName = handle.getAbsolutePath( );
		
		IWorkspace space = ResourcesPlugin.getWorkspace( );
		IWorkspaceRoot root = space.getRoot( );
		try
		{
			//IFile[] resources = root.findFilesForLocationURI( new URL("file:///" + fileName ).toURI( ) ); //$NON-NLS-1$
			IFile[] resources = root.findFilesForLocationURI(new File( fileName ).toURI( ) ); //$NON-NLS-1$
			if (resources != null && resources.length > 0)
			{
				IEditorInput input = new FileEditorInput(resources[0]);
				return input;
			}
			else
			{
				IFileStore fileStore =  EFS.getLocalFileSystem().getStore(new Path(fileName));
				IFileInfo fetchInfo = fileStore.fetchInfo();
				if (!fetchInfo.isDirectory() && fetchInfo.exists())
				{
					return new FileStoreEditorInput(fileStore);
				}
			}
		}
		catch(Exception e)
		{
			return null;
		}
	}
	return null;
}
 
Example 13
Source File: ResourceManager.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public boolean validateLocation(final IFile resource) {
	if (!resource.isLinked()) { return true; }
	if (DEBUG.IS_ON()) {
		DEBUG.OUT("Validating link location of " + resource);
	}
	final boolean internal =
			ResourcesPlugin.getWorkspace().validateLinkLocation(resource, resource.getLocation()).isOK();
	if (!internal) { return false; }
	final IFileStore file = EFS.getLocalFileSystem().getStore(resource.getLocation());
	final IFileInfo info = file.fetchInfo();
	return info.exists();
}
 
Example 14
Source File: FileUtils.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a best guess URI based on the target string and an optional URI specifying from where the relative URI
 * should be run. If existingResource is null, then the root of the workspace is used as the relative URI
 *
 * @param target
 *            a String giving the path
 * @param existingResource
 *            the URI of the resource from which relative URIs should be interpreted
 * @author Alexis Drogoul, July 2018
 * @return an URI or null if it cannot be determined.
 */
public static URI getURI(final String target, final URI existingResource) {
	if (target == null) { return null; }
	try {
		final IPath path = Path.fromOSString(target);
		final IFileStore file = EFS.getLocalFileSystem().getStore(path);
		final IFileInfo info = file.fetchInfo();
		if (info.exists()) {
			// We have an absolute file
			final URI fileURI = URI.createFileURI(target);
			return fileURI;
		} else {
			final URI first = URI.createURI(target, false);
			URI root;
			if (!existingResource.isPlatformResource()) {
				root = URI.createPlatformResourceURI(existingResource.toString(), false);
			} else {
				root = existingResource;
			}
			if (root == null) {
				root = WORKSPACE_URI;
			}
			final URI iu = first.resolve(root);
			if (isFileExistingInWorkspace(iu)) { return iu; }
			return null;
		}
	} catch (final Exception e) {
		return null;
	}
}
 
Example 15
Source File: FileUtils.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private static String findOutsideWorkspace(final String fp, final URI modelBase, final boolean mustExist) {
	if (!mustExist) { return fp; }
	final IFileStore file = FILE_SYSTEM.getStore(new Path(fp));
	final IFileInfo info = file.fetchInfo();
	if (info.exists()) {
		final IFile linkedFile = createLinkToExternalFile(fp, modelBase);
		if (linkedFile == null) { return fp; }
		return linkedFile.getLocation().toFile().getAbsolutePath();
	}
	return null;
}
 
Example 16
Source File: XtextDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public long getModificationStamp(Object element) {
	if (isWorkspaceExternalEditorInput(element)) {
		IFileStore fileStore = Adapters.adapt(element, IFileStore.class);
		if (fileStore != null) {
			IFileInfo info = fileStore.fetchInfo();
			if (info.exists()) {
				return info.getLastModified();
			}
		}
		return IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
	} else {
		return super.getModificationStamp(element);
	}
}
 
Example 17
Source File: ProjectContentsLocationArea.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Open an appropriate directory browser
 */
private void handleLocationBrowseButtonPressed()
{

	String selectedDirectory = null;
	String dirName = getPathFromLocationField();

	if (!dirName.equals(IDEResourceInfoUtils.EMPTY_STRING))
	{
		IFileInfo info;
		info = IDEResourceInfoUtils.getFileInfo(dirName);

		if (info == null || !(info.exists()))
			dirName = IDEResourceInfoUtils.EMPTY_STRING;
	}
	else
	{
		String value = getDialogSettings().get(SAVED_LOCATION_ATTR);
		if (value != null)
		{
			dirName = value;
		}
	}

	FileSystemConfiguration config = getSelectedConfiguration();
	if (config == null || config.equals(FileSystemSupportRegistry.getInstance().getDefaultConfiguration()))
	{
		DirectoryDialog dialog = new DirectoryDialog(locationPathField.getShell(), SWT.SHEET);
		dialog.setMessage(IDEWorkbenchMessages.ProjectLocationSelectionDialog_directoryLabel);

		dialog.setFilterPath(dirName);

		selectedDirectory = dialog.open();

	}
	else
	{
		URI uri = getSelectedConfiguration().getContributor().browseFileSystem(dirName, browseButton.getShell());
		if (uri != null)
			selectedDirectory = uri.toString();
	}

	if (selectedDirectory != null)
	{
		updateLocationField(selectedDirectory);
		getDialogSettings().put(SAVED_LOCATION_ATTR, selectedDirectory);
	}
}
 
Example 18
Source File: FileUtils.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isDirectoryOrNullExternalFile(final String path) {
	final IFileStore external = FILE_SYSTEM.getStore(new Path(path));
	final IFileInfo info = external.fetchInfo();
	if (info.isDirectory() || !info.exists()) { return true; }
	return false;
}
 
Example 19
Source File: DocumentUtils.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 4 votes vote down vote up
public static IFileStore getExternalFile(IPath path) {
    IFileStore fileStore = EFS.getLocalFileSystem().getStore(path);
    IFileInfo fileInfo = fileStore.fetchInfo();

    return fileInfo != null && fileInfo.exists() ? fileStore : null;
}
 
Example 20
Source File: CompilationDirector.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
private boolean isUMLFile(IFileStore toCheck) {
    IFileInfo info = toCheck.fetchInfo();
    return info.exists() && !info.isDirectory() && toCheck.getName().endsWith('.' + UMLResource.FILE_EXTENSION);
}