/** * Determines the sticky information for a given file. If the file is new then it returns its * parent directory's sticky info, if any. * * @param file file to examine * @return String sticky information for a file (without leading N, D or T specifier) or null */ public static String getSticky(File file) { if (file == null) return null; FileInformation info = CvsVersioningSystem.getInstance().getStatusCache().getStatus(file); if (info.getStatus() == FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY) { return getSticky(file.getParentFile()); } else if (info.getStatus() == FileInformation.STATUS_NOTVERSIONED_EXCLUDED) { return null; } if (file.isDirectory()) { String std = CvsVersioningSystem.getInstance().getAdminHandler().getStickyTagForDirectory(file); if (std != null) { std = std.substring(1); } return std; } Entry entry = info.getEntry(file); if (entry != null) { String stickyInfo = null; if (entry.getTag() != null) stickyInfo = entry.getTag(); // NOI18N else if (entry.getDate() != null) stickyInfo = entry.getDateFormatted(); // NOI18N return stickyInfo; } return null; }
/** * @return <code>true</code> if * <ul> * <li>the project != null and * <li>the project contains at least one CVS versioned source group * </ul> * otherwise <code>false</code>. * @param checkStatus if set to true, cache.getStatus is called and can take significant amount of * time */ public static boolean isVersionedProject(Project project, boolean checkStatus) { if (project != null) { FileStatusCache cache = CvsVersioningSystem.getInstance().getStatusCache(); Sources sources = ProjectUtils.getSources(project); SourceGroup[] sourceGroups = sources.getSourceGroups(Sources.TYPE_GENERIC); for (int j = 0; j < sourceGroups.length; j++) { SourceGroup sourceGroup = sourceGroups[j]; File f = FileUtil.toFile(sourceGroup.getRootFolder()); if (f != null) { if (checkStatus && (cache.getStatus(f).getStatus() & FileInformation.STATUS_MANAGED) != 0) { return true; } else if (!checkStatus && CvsVersioningSystem.isManaged(f)) { return true; } } } } return false; }
/** * Computes path of this file to repository root. * * @param file a file * @return String path of this file in repsitory. If this path does not describe a versioned file, * this method returns an empty string */ public static String getRelativePath(File file) { String postfix = ""; for (file = file.getParentFile(); file != null && !file.exists(); file = file.getParentFile()) { postfix = "/" + file.getName() + postfix; } if (file == null) return ""; try { return CvsVersioningSystem.getInstance() .getAdminHandler() .getRepositoryForDirectory(file.getAbsolutePath(), "") .substring(1) + postfix; // NOI18N } catch (IOException e) { return ""; // NOI18N } }
/** * Determines all files and folders that belong to a given project and adds them to the supplied * Collection. * * @param filteredFiles destination collection of Files * @param project project to examine */ public static void addProjectFiles( Collection filteredFiles, Collection rootFiles, Collection rootFilesExclusions, Project project) { FileStatusCache cache = CvsVersioningSystem.getInstance().getStatusCache(); Sources sources = ProjectUtils.getSources(project); SourceGroup[] sourceGroups = sources.getSourceGroups(Sources.TYPE_GENERIC); for (int j = 0; j < sourceGroups.length; j++) { SourceGroup sourceGroup = sourceGroups[j]; FileObject srcRootFo = sourceGroup.getRootFolder(); File rootFile = FileUtil.toFile(srcRootFo); try { getCVSRootFor(rootFile); } catch (IOException e) { // the folder is not under a versioned root continue; } rootFiles.add(rootFile); boolean containsSubprojects = false; FileObject[] rootChildren = srcRootFo.getChildren(); Set projectFiles = new HashSet(rootChildren.length); for (int i = 0; i < rootChildren.length; i++) { FileObject rootChildFo = rootChildren[i]; if (CvsVersioningSystem.FILENAME_CVS.equals(rootChildFo.getNameExt())) continue; File child = FileUtil.toFile(rootChildFo); // #67900 Added special treatment for .cvsignore files if (sourceGroup.contains(rootChildFo) || CvsVersioningSystem.FILENAME_CVSIGNORE.equals(rootChildFo.getNameExt())) { // TODO: #60516 deep scan is required here but not performed due to performace reasons projectFiles.add(child); } else { int status = cache.getStatus(child).getStatus(); if (status != FileInformation.STATUS_NOTVERSIONED_EXCLUDED) { rootFilesExclusions.add(child); containsSubprojects = true; } } } if (containsSubprojects) { filteredFiles.addAll(projectFiles); } else { filteredFiles.add(rootFile); } } }
/** * Returns the widest possible versioned context for the given file, the outter boundary is the * file's Project. * * @param file a file * @return Context a context */ public static Context getProjectContext(Project project, File file) { Context context = Utils.getProjectsContext(new Project[] {project}); if (context.getRootFiles().length == 0) { // the project itself is not versioned, try to search in the broadest context possible FileStatusCache cache = CvsVersioningSystem.getInstance().getStatusCache(); for (; ; ) { File parent = file.getParentFile(); assert parent != null; if ((cache.getStatus(parent).getStatus() & FileInformation.STATUS_IN_REPOSITORY) == 0) { Set<File> files = new HashSet<File>(1); files.add(file); context = new Context(files, files, Collections.emptySet()); break; } file = parent; } } return context; }
/** * Semantics is similar to {@link org.openide.windows.TopComponent#getActivatedNodes()} except * that this method returns File objects instead od Nodes. Every node is examined for Files it * represents. File and Folder nodes represent their underlying files or folders. Project nodes * are represented by their source groups. Other logical nodes must provide FileObjects in their * Lookup. * * @param nodes null (then taken from windowsystem, it may be wrong on editor tabs #66700). * @param includingFileStatus if any activated file does not have this CVS status, an empty array * is returned * @param includingFolderStatus if any activated folder does not have this CVS status, an empty * array is returned * @param onlyCachedStatus if set to true, only cached status will be considered * @return File [] array of activated files, or an empty array if any of examined files/folders * does not have given status */ public static Context getCurrentContext( Node[] nodes, int includingFileStatus, int includingFolderStatus, boolean onlyCachedStatus) { Context context = getCurrentContext(nodes); FileStatusCache cache = CvsVersioningSystem.getInstance().getStatusCache(); File[] files = context.getRootFiles(); for (int i = 0; i < files.length; i++) { File file = files[i]; FileInformation fi = onlyCachedStatus ? cache.getCachedStatus(file) : cache.getStatus(file); int status = fi == null ? FileInformation.STATUS_VERSIONED_UPTODATE : fi.getStatus(); if (file.isDirectory()) { if ((status & includingFolderStatus) == 0) return Context.Empty; } else { if ((status & includingFileStatus) == 0) return Context.Empty; } } // if there are no exclusions, we may safely return this context because filtered files == root // files if (context.getExclusions().isEmpty()) return context; // in this code we remove files from filteredFiles to NOT include any files that do not have // required status // consider a freeform project that has 'build' in filteredFiles, the Branch action would try to // branch it // so, it is OK to have BranchAction enabled but the context must be a bit adjusted here Set<File> filteredFiles = new HashSet<File>(Arrays.asList(context.getFiles())); Set<File> rootFiles = new HashSet<File>(Arrays.asList(context.getRootFiles())); Set<File> rootFileExclusions = new HashSet<File>(context.getExclusions()); for (Iterator<File> i = filteredFiles.iterator(); i.hasNext(); ) { File file = i.next(); if (file.isDirectory()) { if ((cache.getStatus(file).getStatus() & includingFolderStatus) == 0) i.remove(); } else { if ((cache.getStatus(file).getStatus() & includingFileStatus) == 0) i.remove(); } } return new Context(filteredFiles, rootFiles, rootFileExclusions); }