| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package nl.toolforge.karma.core.vc.cvsimpl; |
| 20 |
|
|
| 21 |
|
import nl.toolforge.karma.core.KarmaRuntimeException; |
| 22 |
|
import nl.toolforge.karma.core.module.Module; |
| 23 |
|
import org.apache.tools.ant.DirectoryScanner; |
| 24 |
|
import org.netbeans.lib.cvsclient.CVSRoot; |
| 25 |
|
import org.netbeans.lib.cvsclient.admin.Entry; |
| 26 |
|
import org.netbeans.lib.cvsclient.admin.StandardAdminHandler; |
| 27 |
|
|
| 28 |
|
import java.io.BufferedReader; |
| 29 |
|
import java.io.File; |
| 30 |
|
import java.io.FileInputStream; |
| 31 |
|
import java.io.FileNotFoundException; |
| 32 |
|
import java.io.FilenameFilter; |
| 33 |
|
import java.io.IOException; |
| 34 |
|
import java.io.InputStreamReader; |
| 35 |
|
import java.util.ArrayList; |
| 36 |
|
import java.util.Arrays; |
| 37 |
|
import java.util.Iterator; |
| 38 |
|
import java.util.List; |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
public final class AdminHandler { |
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
260 |
private Module module = null; |
| 52 |
|
|
| 53 |
260 |
private List newStuff = new ArrayList(); |
| 54 |
260 |
private List changedStuff = new ArrayList(); |
| 55 |
260 |
private List removedStuff = new ArrayList(); |
| 56 |
|
|
| 57 |
260 |
private FilenameFilter filter = new FilenameFilter() { |
| 58 |
|
|
| 59 |
|
public boolean accept(File dir, String name) { |
| 60 |
|
return !name.matches(".WORKING|.DYNAMIC|.STATIC|.module.info|CVS|.cvsignore") && name.matches("[^\\~]+"); |
| 61 |
|
} |
| 62 |
|
}; |
| 63 |
|
|
| 64 |
260 |
public AdminHandler(Module module) { |
| 65 |
260 |
this.module = module; |
| 66 |
260 |
} |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
public void administrate() { |
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
0 |
DirectoryScanner scanner = new DirectoryScanner(); |
| 77 |
0 |
scanner.setBasedir(module.getBaseDir()); |
| 78 |
0 |
scanner.setExcludes(new String[]{"**/CVS"}); |
| 79 |
0 |
scanner.scan(); |
| 80 |
0 |
String[] moduleDirectories = scanner.getIncludedDirectories(); |
| 81 |
|
|
| 82 |
0 |
for (int i = 0; i < moduleDirectories.length; i++) { |
| 83 |
|
|
| 84 |
0 |
StandardAdminHandler h = new StandardAdminHandler(); |
| 85 |
|
try { |
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
0 |
Entry[] dirEntries = h.getEntriesAsArray(new File(module.getBaseDir(), moduleDirectories[i])); |
| 90 |
0 |
List entryNames = getEntryNames(dirEntries); |
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
0 |
List dirFiles = Arrays.asList(new File(module.getBaseDir(), moduleDirectories[i]).list(filter)); |
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
0 |
for (Iterator k = dirFiles.iterator(); k.hasNext();) { |
| 99 |
0 |
String item = (String) k.next(); |
| 100 |
0 |
if (!entryNames.contains(item)) { |
| 101 |
0 |
if (moduleDirectories[i].equals("")) { |
| 102 |
0 |
newStuff.add(item); |
| 103 |
|
} else { |
| 104 |
0 |
newStuff.add(new File(moduleDirectories[i], item).getPath()); |
| 105 |
|
} |
| 106 |
|
} |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
0 |
for (int j = 0; j < dirEntries.length; j++) { |
| 112 |
|
|
| 113 |
0 |
Entry entry = dirEntries[j]; |
| 114 |
0 |
File fileEntry = new File(module.getBaseDir(), entry.getName()); |
| 115 |
0 |
if (entry.isUserFileToBeRemoved()) { |
| 116 |
0 |
if (moduleDirectories[i].equals("")) { |
| 117 |
0 |
removedStuff.add(entry.getName()); |
| 118 |
|
} else { |
| 119 |
0 |
removedStuff.add(new File(moduleDirectories[i], entry.getName()).getPath()); |
| 120 |
|
} |
| 121 |
0 |
} else if (fileEntry.isFile() && (entry.getLastModclass="keyword">ified() == null ? 0 : entry.getLastModclass="keyword">ified().getTime()) != fileEntry.lastModclass="keyword">ified()) { |
| 122 |
0 |
if (moduleDirectories[i].equals("")) { |
| 123 |
0 |
changedStuff.add(entry.getName()); |
| 124 |
|
} else { |
| 125 |
0 |
changedStuff.add(new File(moduleDirectories[i], entry.getName()).getPath()); |
| 126 |
|
} |
| 127 |
|
} |
| 128 |
|
|
| 129 |
|
} |
| 130 |
0 |
} catch (IOException e) { |
| 131 |
0 |
e.printStackTrace(); |
| 132 |
0 |
} |
| 133 |
|
} |
| 134 |
0 |
} |
| 135 |
|
|
| 136 |
|
private List getEntryNames(Entry[] entries) { |
| 137 |
0 |
List entryList = new ArrayList(); |
| 138 |
0 |
for (int j = 0; j < entries.length; j++) { |
| 139 |
0 |
entryList.add(entries[j].getName()); |
| 140 |
|
} |
| 141 |
0 |
return entryList; |
| 142 |
|
} |
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
| 150 |
|
public List getNewStuff() { |
| 151 |
0 |
return newStuff; |
| 152 |
|
} |
| 153 |
|
|
| 154 |
|
public boolean hasNewStuff() { |
| 155 |
0 |
return newStuff.size() > 0; |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
|
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
|
public List getChangedStuff() { |
| 165 |
0 |
return changedStuff; |
| 166 |
|
} |
| 167 |
|
|
| 168 |
|
public boolean hasChangedStuff() { |
| 169 |
0 |
return changedStuff.size() > 0; |
| 170 |
|
} |
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
public List getRemovedStuff() { |
| 179 |
0 |
return removedStuff; |
| 180 |
|
} |
| 181 |
|
|
| 182 |
|
public boolean hasRemovedStuff() { |
| 183 |
0 |
return removedStuff.size() > 0; |
| 184 |
|
} |
| 185 |
|
|
| 186 |
|
|
| 187 |
|
|
| 188 |
|
|
| 189 |
|
|
| 190 |
|
|
| 191 |
|
|
| 192 |
|
public boolean isEqualLocation() { |
| 193 |
|
|
| 194 |
260 |
if (!module.getBaseDir().exists()) { |
| 195 |
|
|
| 196 |
|
|
| 197 |
260 |
return true; |
| 198 |
|
} |
| 199 |
|
|
| 200 |
0 |
File rootFile = new File(module.getBaseDir(), "CVS/Root"); |
| 201 |
|
|
| 202 |
0 |
String cvsRootString = null; |
| 203 |
|
try { |
| 204 |
0 |
BufferedReader in = new BufferedReader(class="keyword">new InputStreamReader(class="keyword">new FileInputStream(rootFile))); |
| 205 |
|
|
| 206 |
0 |
cvsRootString = in.readLine(); |
| 207 |
0 |
in.close(); |
| 208 |
|
|
| 209 |
0 |
} catch (FileNotFoundException e) { |
| 210 |
|
|
| 211 |
|
|
| 212 |
0 |
return true; |
| 213 |
0 |
} catch (IOException e) { |
| 214 |
0 |
throw new KarmaRuntimeException(e.getMessage()); |
| 215 |
0 |
} |
| 216 |
|
|
| 217 |
0 |
CVSRoot cvsRoot = CVSRoot.parse(cvsRootString); |
| 218 |
|
|
| 219 |
0 |
CVSRepository loc = (CVSRepository) module.getLocation(); |
| 220 |
|
try { |
| 221 |
0 |
return cvsRoot.toString().equals(loc.getCVSRoot()); |
| 222 |
0 |
} catch (CVSException e) { |
| 223 |
0 |
return true; |
| 224 |
|
} |
| 225 |
|
} |
| 226 |
|
} |