package journal.action; import java.io.PrintStream; import java.util.ArrayList; import java.util.List; import java.util.SortedMap; import java.util.TreeMap; import journal.reader.DataJournalEntry; import journal.reader.JournalEntry; import journal.tools.SparseList; public class FilenameAndDirectory extends BaseAction { static class PathLength { SparseList<Integer> list = new SparseList<Integer>(0); void inc(int index ) { list.set(index, list.get(index) + 1); } int get(int index) { return list.get(index); } int size() { return list.size(); } } static class Directory implements Comparable<Directory> { Directory parent = null; String name; int numberOfFiles = 0; int deletedFiles = 0; int numberOfDirectories = 0; int directoryDepth = 0; int level = 0; SortedMap<String, Directory> directories = new TreeMap<String, Directory>(); public Directory(final String name) { this(name, null, 0); } public Directory(final String name, final Directory parent, int level) { this.name = name; this.parent = parent; this.level = level; checkDepth(level); } public Directory addDirectory(final String dir) { if( directories.containsKey(dir)) { return directories.get(dir); } else { Directory d = new Directory(dir, this, level + 1); directories.put(dir, d); numberOfDirectories++; return d; } } public void checkDepth(int l) { if( directoryDepth < l - level) { directoryDepth = l - level; } if( parent != null ) { parent.checkDepth(l); } } public void addFile() { numberOfFiles++; if (parent != null) { parent.addFile(); } } public void addDeleted() { deletedFiles++; if( parent != null ) { parent.addDeleted(); } } public String getFullName() { if( parent == null) { return name; } return parent.getFullName() + "/" + name; } public void dump(PrintStream out) { out.println(this); for ( Directory d : directories.values() ) { d.dump(out); } } @Override public String toString() { StringBuilder b = new StringBuilder(); b.append(getFullName()); b.append("\tdepth = "); b.append(directoryDepth); b.append("\tlevel = "); b.append(level); b.append("\tdirs = "); b.append(numberOfDirectories); b.append("\tfiles = "); b.append(numberOfFiles); b.append("\tdeleted = "); b.append(deletedFiles); return b.toString(); } @Override public int compareTo(Directory arg) { return name.compareTo(arg.name); } @Override public int hashCode() { return name.hashCode(); } @Override public boolean equals(Object arg) { Directory other = (Directory) arg; return name.equals(other.name); } } PathLength pathLength = new PathLength(); Directory root = new Directory("/"); List<String> noDigest = new ArrayList<String>(); public void start() throws Exception { super.start(); } public void help() { } public void finish() throws Exception { for( int i = 0; i < pathLength.size(); i++ ) { out.println("Length " + i + " : " + pathLength.get(i)); } out.println("\nDirectory structure:"); root.dump(out); if( noDigest.size() > 0) { out.println("\nNo Digest for the following revisions : "); for( String rev : noDigest) { out.println(rev); } } } public String[] parseArgs(String[] args) { return args; } public void putValue(JournalEntry entry) throws Exception { DataJournalEntry dataEntry = (DataJournalEntry) entry; if (dataEntry.getTableName().equals("db.rev")) { String depotFile = (String) dataEntry.getValue("dfile"); short action = (Short) dataEntry.getValue("action"); if (options.isCaseInsensitive()) { depotFile = depotFile.toLowerCase(); } String[] dirNames = depotFile.substring(2).split("/"); Directory d = root; for ( int i = 0; i < dirNames.length - 1; i++ ) { d = d.addDirectory(dirNames[i]); } if( action != 2 ) { int len = depotFile.length(); pathLength.inc(len); d.addFile(); } else { d.addDeleted(); } if( dataEntry.getValue("digest").equals("") || (Long)dataEntry.getValue("size") == -1L ) { StringBuilder rev = new StringBuilder((String) dataEntry.getValue("dfile")); rev.append('#'); rev.append(dataEntry.getValue("rev")); rev.append(" digest = "); rev.append(dataEntry.getValue("digest")); rev.append(" filesize = "); rev.append(dataEntry.getValue("size")); noDigest.add(rev.toString()); } } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 24773 | Norman Morse |
Moving journalReader from sven's private branch to perforce_software. This is because journalReader is used in the perfsplit test harness, and should be updated over time. Merging //guest/sven_erik_knop/java/JournalReader/... to //guest/perforce_software/journalReader/... |
||
//guest/sven_erik_knop/java/JournalReader/src/journal/action/FilenameAndDirectory.java | |||||
#3 | 8023 | Sven Erik Knop |
Complete rewrite of the configuration file, now based on an ini-file format. The ini file has a general [reader] section for settings like verbose, outputFile, case-sensitivity and so on. It also allows to set up a range of Actions and Filters. The section name here is the fully classified class name, followed by settings for the particular actions. An example will make this clearer: ================================================================ [reader] verbose=true [journal.action.UserRenamer] fileName=user.txt patch=True outputFile=user.out [journal.action.ClientRenamer] fileName=client.txt outputFile=client.out patch=true ================================================================ I will provide more example set-ups in the near future. Filters are classes implementing journal.action.Filter (soon to be journal.filter.Filter) which can be chained together and are all executed before the actions. Actions are applied in order that they are given in the config file. |
||
#2 | 8020 | Sven Erik Knop | Replace public Option attributes with setters and getters. | ||
#1 | 7527 | Sven Erik Knop |
JournalReader, now in its proper place. Documentation to follow. |