1 19 20 package org.netbeans.modules.versioning.system.cvss; 21 22 import org.netbeans.lib.cvsclient.admin.StandardAdminHandler; 23 import org.netbeans.lib.cvsclient.admin.AdminHandler; 24 import org.netbeans.lib.cvsclient.admin.Entry; 25 import org.netbeans.lib.cvsclient.command.GlobalOptions; 26 import org.netbeans.modules.versioning.util.Utils; 27 import org.openide.filesystems.FileUtil; 28 29 import java.io.*; 30 import java.util.*; 31 32 38 class CvsLiteAdminHandler implements AdminHandler { 39 40 static final String INVALID_METADATA_MARKER = "invalid-metadata"; 42 private static final String INVALID_METADATA_MARKER_PATH = CvsVersioningSystem.FILENAME_CVS + "/" + INVALID_METADATA_MARKER; 44 private StandardAdminHandler stdHandler; 45 46 public CvsLiteAdminHandler() { 47 this.stdHandler = new StandardAdminHandler(); 48 } 49 50 private void checkForInvalidMetadata(File dir) { 51 File marker = new File(dir, INVALID_METADATA_MARKER_PATH); 52 if (marker.exists()) { 53 Utils.deleteRecursively(marker.getParentFile()); 54 } 55 } 56 57 public void updateAdminData(String localDirectory, String repositoryPath, 58 Entry entry, GlobalOptions globalOptions) 59 throws IOException { 60 checkForInvalidMetadata(new File(localDirectory)); 61 stdHandler.updateAdminData(localDirectory, repositoryPath, entry, globalOptions); 62 } 63 64 public Entry getEntry(File file) throws IOException { 65 checkForInvalidMetadata(file.getParentFile()); 66 return stdHandler.getEntry(file); 67 } 68 69 public boolean exists(File file) { 70 if (file.exists()) return true; 71 if (CvsVersioningSystem.FILENAME_CVS.equals(file.getName())) file = file.getParentFile(); return false; 73 } 74 75 public Iterator<Entry> getEntries(File directory) throws IOException { 76 checkForInvalidMetadata(directory); 77 if (new File(directory, CvsVersioningSystem.FILENAME_CVS).isDirectory()) { 78 return stdHandler.getEntries(directory); 79 } 80 directory = FileUtil.normalizeFile(directory); 81 return stdHandler.getEntries(directory); 82 } 83 84 public Entry[] getEntriesAsArray(File directory) 85 throws IOException { 86 checkForInvalidMetadata(directory); 87 List<Entry> entries = new ArrayList<Entry>(); 88 for (Iterator<Entry> i = getEntries(directory); i.hasNext(); ) { 89 entries.add(i.next()); 90 } 91 return entries.toArray(new Entry[entries.size()]); 92 } 93 94 public void setEntry(File file, Entry entry) throws IOException { 95 checkForInvalidMetadata(file.getParentFile()); 96 File adminDir = new File(file.getParentFile(), CvsVersioningSystem.FILENAME_CVS); 98 createAdminDirs(adminDir); 99 stdHandler.setEntry(file, entry); 100 } 101 102 108 private void createAdminDirs(File adminDir) throws IOException { 109 if (!adminDir.exists()) { 110 if (adminDir.getParentFile() != null && adminDir.getParentFile().getParentFile() != null) { 111 createAdminDirs(new File(adminDir.getParentFile().getParentFile(), CvsVersioningSystem.FILENAME_CVS)); 112 } 113 } 114 } 115 116 public String getRepositoryForDirectory(String directory, String repository) 117 throws IOException { 118 119 checkForInvalidMetadata(new File(directory)); 120 122 File dirFile = new File(directory); 123 if (dirFile.exists()) return stdHandler.getRepositoryForDirectory(directory, repository); 124 125 return stdHandler.getRepositoryForDirectory(directory, repository); 126 } 127 128 public void removeEntry(File file) throws IOException { 129 File parent = file.getParentFile(); 130 checkForInvalidMetadata(parent); 131 stdHandler.removeEntry(file); 132 } 133 134 public Set getAllFiles(File directory) throws IOException { 135 checkForInvalidMetadata(directory); 136 return stdHandler.getAllFiles(directory); 138 } 139 140 public String getStickyTagForDirectory(File directory) { 141 checkForInvalidMetadata(directory); 142 return stdHandler.getStickyTagForDirectory(directory); 143 } 144 } 145 | Popular Tags |