Java Code Examples for org.eclipse.core.resources.IResource#getModificationStamp()
The following examples show how to use
org.eclipse.core.resources.IResource#getModificationStamp() .
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: ProjectFileTracking.java From texlipse with Eclipse Public License 1.0 | 6 votes |
/** * Recursively scans the given container for files and adds them to the * given map, along with their time stamps. This does not list the * folders it recurses into. * * @param container container to scan for files * @param nameMap map of file paths to put the files and time stamps into * @param monitor progress monitor * @throws CoreException if an error occurs */ private void recursiveScanFiles(final IContainer container, final Map<IPath, Long> nameMap, IProgressMonitor monitor) throws CoreException { IResource[] res = container.members(); for (IResource current : res) { if (current instanceof IFolder) { if (!excludeFolders.contains(current)) { // Recurse into subfolders IFolder subFolder = (IFolder) current; recursiveScanFiles(subFolder, nameMap, monitor); } } else if (!isProjectFile(current.getName())) { Long timestamp = new Long(current.getModificationStamp()); nameMap.put(current.getProjectRelativePath(), timestamp); } monitor.worked(1); } }
Example 2
Source File: FileMetaDataProvider.java From gama with GNU General Public License v3.0 | 6 votes |
private <T extends IGamaFileMetaData> T readMetadata(final IResource file, final Class<T> clazz, final boolean includeOutdated) { T result = null; final long modificationStamp = file.getModificationStamp(); try { final String s = (String) file.getSessionProperty(CACHE_KEY); if (s != null) { // s = GZIP.decompress(s); result = GamaFileMetaData.from(s, modificationStamp, clazz, includeOutdated); } if (!clazz.isInstance(result)) { return null; } } catch (final Exception ignore) { DEBUG.ERR("Error loading metadata for " + file.getName() + " : " + ignore.getMessage()); } return result; }
Example 3
Source File: PyChange.java From Pydev with Eclipse Public License 1.0 | 6 votes |
public long getModificationStamp(IResource resource) { if (!(resource instanceof IFile)) { return resource.getModificationStamp(); } IFile file = (IFile) resource; ITextFileBuffer buffer = getBuffer(file); if (buffer == null) { return file.getModificationStamp(); } else { IDocument document = buffer.getDocument(); if (document instanceof IDocumentExtension4) { return ((IDocumentExtension4) document).getModificationStamp(); } else { return file.getModificationStamp(); } } }
Example 4
Source File: RenamePackageChange.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void addStamps(Map<IResource, Long> stamps, ICompilationUnit[] units) { for (int i= 0; i < units.length; i++) { IResource resource= units[i].getResource(); long stamp= IResource.NULL_STAMP; if (resource != null && (stamp= resource.getModificationStamp()) != IResource.NULL_STAMP) { stamps.put(resource, Long.valueOf(stamp)); } } }
Example 5
Source File: RenamePackageChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void addStamps(Map<IResource, Long> stamps, ICompilationUnit[] units) { for (int i= 0; i < units.length; i++) { IResource resource= units[i].getResource(); long stamp= IResource.NULL_STAMP; if (resource != null && (stamp= resource.getModificationStamp()) != IResource.NULL_STAMP) { stamps.put(resource, new Long(stamp)); } } }
Example 6
Source File: AnalysisBuilderVisitor.java From Pydev with Eclipse Public License 1.0 | 5 votes |
@Override public void visitRemovedResource(IResource resource, ICallback0<IDocument> document, IProgressMonitor monitor) { PythonNature nature = getPythonNature(resource); if (nature == null) { return; } if (resource.getType() == IResource.FOLDER) { //We don't need to explicitly treat any folder (just its children -- such as __init__ and submodules) return; } if (!isFullBuild()) { //on a full build, it'll already remove all the info String moduleName; try { moduleName = getModuleName(resource, nature); } catch (MisconfigurationException e) { Log.log(e); return; } long documentTime = this.getDocumentTime(); if (documentTime == -1) { Log.log("Warning: The document time in the visitor for remove is -1. Changing for current time. " + "Resource: " + resource + ". Module name: " + moduleName); documentTime = System.currentTimeMillis(); } long resourceModificationStamp = resource.getModificationStamp(); final IAnalysisBuilderRunnable runnable = AnalysisBuilderRunnableFactory.createRunnable(moduleName, nature, isFullBuild(), false, AnalysisBuilderRunnable.ANALYSIS_CAUSE_BUILDER, documentTime, resourceModificationStamp); if (runnable == null) { //It may be null if the document version of the new one is lower than one already active. return; } execRunnable(moduleName, runnable, false); } }
Example 7
Source File: MoveCompilationUnitChange.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Override Change doPerformReorg(IProgressMonitor pm) throws CoreException, OperationCanceledException { String name; String newName= getNewName(); if (newName == null) { name= getCu().getElementName(); } else { name= newName; } // get current modification stamp long currentStamp= IResource.NULL_STAMP; IResource resource= getCu().getResource(); if (resource != null) { currentStamp= resource.getModificationStamp(); } IPackageFragment destination= getDestinationPackage(); fUndoable= !destination.exists() || !destination.getCompilationUnit(name).exists(); IPackageFragment[] createdPackages= null; if (!destination.exists()) { IPackageFragmentRoot packageFragmentRoot= (IPackageFragmentRoot) destination.getParent(); createdPackages= createDestination(packageFragmentRoot, destination, pm); } // perform the move and restore modification stamp getCu().move(destination, null, newName, true, pm); if (fStampToRestore != IResource.NULL_STAMP) { ICompilationUnit moved= destination.getCompilationUnit(name); IResource movedResource= moved.getResource(); if (movedResource != null) { movedResource.revertModificationStamp(fStampToRestore); } } if (fDeletePackages != null) { for (int i= fDeletePackages.length - 1; i >= 0; i--) { fDeletePackages[i].delete(true, pm); } } if (fUndoable) { return new MoveCompilationUnitChange(destination, getCu().getElementName(), getOldPackage(), currentStamp, createdPackages); } else { return null; } }
Example 8
Source File: XdsRenameResourceChange.java From xds-ide with Eclipse Public License 1.0 | 4 votes |
public Change perform(IProgressMonitor pm) throws CoreException { try { pm.beginTask(RefactoringCoreMessages.RenameResourceChange_progress_description, 1); IResource resource= getResource(); File absoluteFile = ResourceUtils.getAbsoluteFile(resource); IPath destPath = renamedResourcePath(resource.getRawLocation(), fNewName); boolean isLinked = resource.isLinked(); long currentStamp= resource.getModificationStamp(); IPath newPath= renamedResourcePath(fResourcePath, fNewName); IFile destIFile = ResourceUtils.getWorkspaceRoot().getFile(newPath); Change undoDeleteChange = null; if (destIFile.exists()) { // handle rename conflict DeleteResourceChange deleteChange = new DeleteResourceChange(destIFile.getFullPath(), true); undoDeleteChange = deleteChange.perform(pm); } resource.move(newPath, IResource.SHALLOW, pm); if (isLinked) { File dest = destPath.toFile(); FileUtils.deleteQuietly(dest); absoluteFile.renameTo(dest); // get the resource again since after move resource can be inadequate IWorkspaceRoot workspaceRoot = ResourceUtils.getWorkspaceRoot(); resource = workspaceRoot.getFile(newPath); ((IFile)resource).createLink(destPath, IResource.REPLACE, new NullProgressMonitor()); } if (fStampToRestore != IResource.NULL_STAMP) { IResource newResource= ResourcesPlugin.getWorkspace().getRoot().findMember(newPath); newResource.revertModificationStamp(fStampToRestore); } String oldName= fResourcePath.lastSegment(); XdsRenameResourceChange undoRenameChange = new XdsRenameResourceChange(newPath, oldName, currentStamp); if (undoDeleteChange == null) { return undoRenameChange; } else { return new CompositeChange(getName(), new Change[]{undoRenameChange, undoDeleteChange}); // constructing undo changes } } finally { pm.done(); } }
Example 9
Source File: MoveCompilationUnitChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override Change doPerformReorg(IProgressMonitor pm) throws CoreException, OperationCanceledException { String name; String newName= getNewName(); if (newName == null) name= getCu().getElementName(); else name= newName; // get current modification stamp long currentStamp= IResource.NULL_STAMP; IResource resource= getCu().getResource(); if (resource != null) { currentStamp= resource.getModificationStamp(); } IPackageFragment destination= getDestinationPackage(); fUndoable= !destination.exists() || !destination.getCompilationUnit(name).exists(); IPackageFragment[] createdPackages= null; if (!destination.exists()) { IPackageFragmentRoot packageFragmentRoot= (IPackageFragmentRoot) destination.getParent(); createdPackages= createDestination(packageFragmentRoot, destination, pm); } // perform the move and restore modification stamp getCu().move(destination, null, newName, true, pm); if (fStampToRestore != IResource.NULL_STAMP) { ICompilationUnit moved= destination.getCompilationUnit(name); IResource movedResource= moved.getResource(); if (movedResource != null) { movedResource.revertModificationStamp(fStampToRestore); } } if (fDeletePackages != null) { for (int i= fDeletePackages.length - 1; i >= 0; i--) { fDeletePackages[i].delete(true, pm); } } if (fUndoable) { return new MoveCompilationUnitChange(destination, getCu().getElementName(), getOldPackage(), currentStamp, createdPackages); } else { return null; } }
Example 10
Source File: PyChange.java From Pydev with Eclipse Public License 1.0 | 4 votes |
private void initializeResource(IResource resource) { fKind = RESOURCE; fDirty = false; fReadOnly = isReadOnly(resource); fModificationStamp = resource.getModificationStamp(); }
Example 11
Source File: PyRenameResourceChange.java From Pydev with Eclipse Public License 1.0 | 4 votes |
@Override public Change perform(IProgressMonitor pm) throws CoreException { try { pm.beginTask(getName(), 1); IResource resource = getResource(); long currentStamp = resource.getModificationStamp(); IContainer destination = target != null ? target : getDestination(resource, fInitialName, fNewName, pm); IResource[] createdFiles = createDestination(destination); IPath newPath; boolean copyChildrenInsteadOfMove = false; if (resource.getType() == IResource.FILE) { //Renaming file newPath = destination.getFullPath().append(FullRepIterable.getLastPart(fNewName) + ".py"); } else { //Renaming folder newPath = destination.getFullPath().append(FullRepIterable.getLastPart(fNewName)); IPath fullPath = resource.getFullPath(); if (fullPath.isPrefixOf(newPath)) { copyChildrenInsteadOfMove = true; } } if (copyChildrenInsteadOfMove) { IContainer container = (IContainer) resource; IResource[] members = container.members(true); //Note: get the members before creating the target. IFolder folder = container.getFolder(new Path(newPath.lastSegment())); IFile initFile = container.getFile(new Path("__init__.py")); folder.create(IResource.NONE, true, null); createdFiles = ArrayUtils.concatArrays(createdFiles, new IResource[] { folder }); for (IResource member : members) { member.move(newPath.append(member.getFullPath().lastSegment()), IResource.SHALLOW, pm); } initFile.create(new ByteArrayInputStream(new byte[0]), IResource.NONE, null); } else { //simple move resource.move(newPath, IResource.SHALLOW, pm); } if (fStampToRestore != IResource.NULL_STAMP) { IResource newResource = ResourcesPlugin.getWorkspace().getRoot().findMember(newPath); newResource.revertModificationStamp(fStampToRestore); } for (IResource r : this.fCreatedFiles) { r.delete(true, null); } //The undo command return new PyRenameResourceChange(newPath, fNewName, fInitialName, fComment, currentStamp, createdFiles); } finally { pm.done(); } }
Example 12
Source File: PyDevBuilderVisitor.java From Pydev with Eclipse Public License 1.0 | 4 votes |
private static String getModuleNameCacheKey(IResource resource) { return MODULE_NAME_CACHE + resource.getModificationStamp(); }