Search in sources :

Example 1 with EntryFile

use of alma.acs.releasedoc.Cvs2clXmlEntry.EntryFile in project ACS by ACS-Community.

the class ProcessCvs2clOutput method run.

void run(String[] args) throws Exception {
    if (args.length < 1) {
        throw new IllegalArgumentException("At least the xml file name must be given.");
    }
    File xmlFile1 = new File(args[args.length - 1]);
    if (!xmlFile1.exists()) {
        System.err.println("File " + xmlFile1.getAbsolutePath() + " does not exist.");
    }
    setOptions(args);
    Cvs2clXmlParser parser = new Cvs2clXmlParser();
    Document doc = parser.parseXml(xmlFile1);
    Set<Cvs2clXmlEntry> entries1 = new HashSet<Cvs2clXmlEntry>();
    storeEntries(doc, entries1);
    // optionally subtract entry sets
    for (File subtractFile : subtractFiles) {
        Document doc2 = parser.parseXml(subtractFile);
        Set<Cvs2clXmlEntry> entries2 = new HashSet<Cvs2clXmlEntry>();
        storeEntries(doc2, entries2);
        entries1.removeAll(entries2);
        System.out.println("Subtracted cvs entries from file " + subtractFile.getAbsolutePath());
    }
    TWikiFormatter formatter = new TWikiFormatter();
    // sorting
    List<Cvs2clXmlEntry> entries2 = null;
    switch(sortBy) {
        case time:
            entries2 = formatter.sortByDate(entries1);
            // formatting
            formatter.printTwiki(entries2);
            break;
        case user:
            entries2 = formatter.sortByAuthor(entries1);
            TWikiFormatter.HeadingInserter hi = new TWikiFormatter.HeadingInserter() {

                boolean needsHeading(Cvs2clXmlEntry entry) {
                    return (lastEntry == null || !lastEntry.getAuthor().equals(entry.getAuthor()));
                }

                String headingText(Cvs2clXmlEntry entry) {
                    return entry.getAuthor();
                }
            };
            formatter.setHeadingInserter(hi);
            // formatting
            formatter.printTwiki(entries2);
            break;
        case file:
            // A separate Cvs2clXmlEntry gets created for every file, and all entries for the same file are put in a map.
            Map<String, List<Cvs2clXmlEntry>> entriesByFileName = new HashMap<String, List<Cvs2clXmlEntry>>();
            // Iterate over all entries, some of which represent a related change on many files which needs to be broken up
            for (Cvs2clXmlEntry compositeEntry : entries1) {
                // Iterate over all files of this entry. We don't care about the common dir, because every file is given with the full path anyway.
                for (Cvs2clXmlEntry.EntryFile file : compositeEntry.getFiles()) {
                    String pathName = file.getPathName();
                    List<Cvs2clXmlEntry> currentFileEntries = null;
                    if (entriesByFileName.containsKey(pathName)) {
                        // reuse entry list, add Cvs2clXmlEntry
                        currentFileEntries = entriesByFileName.get(pathName);
                    } else {
                        currentFileEntries = new ArrayList<Cvs2clXmlEntry>();
                        entriesByFileName.put(pathName, currentFileEntries);
                    }
                    // create a separate Cvs2clXmlEntry for this file
                    Cvs2clXmlEntry singleFileEntry = new Cvs2clXmlEntry(compositeEntry);
                    List<EntryFile> singleFileList = new ArrayList<EntryFile>(1);
                    singleFileList.add(file);
                    singleFileEntry.setFiles(singleFileList);
                    currentFileEntries.add(singleFileEntry);
                }
            }
            List<String> fileNames = new ArrayList<String>(entriesByFileName.keySet());
            Collections.sort(fileNames);
            // 
            if (retainFiles != null) {
                int oldSize = fileNames.size();
                fileNames.retainAll(retainFiles);
                System.out.println("Reduced file list from " + oldSize + " to " + fileNames.size());
            }
            hi = new TWikiFormatter.HeadingInserter() {

                boolean needsHeading(Cvs2clXmlEntry entry) {
                    if (lastEntry == null) {
                        return true;
                    }
                    String nameThis = getRelevantFileName(entry.getFiles().get(0).getPathName());
                    String nameLast = getRelevantFileName(lastEntry.getFiles().get(0).getPathName());
                    return !nameThis.equals(nameLast);
                }

                String headingText(Cvs2clXmlEntry entry) {
                    return getRelevantFileName(entry.getFiles().get(0).getPathName());
                }

                private String getRelevantFileName(String pathName) {
                    int relevantLevels = (pathName.startsWith("ACS/LGPL/CommonSoftware/") ? 4 : 2);
                    String[] nameParts = pathName.split("/");
                    String ret = "";
                    for (int i = 0; i < relevantLevels; i++) {
                        ret += nameParts[i] + "/";
                    }
                    return ret;
                }
            };
            formatter.setHeadingInserter(hi);
            for (String fileName : fileNames) {
                List<Cvs2clXmlEntry> currentFileEntries = formatter.sortByDate(entriesByFileName.get(fileName));
                // @TODO construct a fixed-ordered map first and then pass everything in one call to the formatter
                formatter.printTwikiByFile(fileName, currentFileEntries);
            }
            break;
        default:
            // should never happen, unless someone adds new enum literals
            throw new IllegalStateException("Need to fix this switch statement!");
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) EntryFile(alma.acs.releasedoc.Cvs2clXmlEntry.EntryFile) EntryFile(alma.acs.releasedoc.Cvs2clXmlEntry.EntryFile) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) EntryFile(alma.acs.releasedoc.Cvs2clXmlEntry.EntryFile) HashSet(java.util.HashSet)

Example 2 with EntryFile

use of alma.acs.releasedoc.Cvs2clXmlEntry.EntryFile in project ACS by ACS-Community.

the class TWikiFormatter method printTwikiByCheckin.

void printTwikiByCheckin(Cvs2clXmlEntry entry) {
    if (headingInserter != null) {
        headingInserter.processRecord(entry);
    }
    String output = dateFormat.format(entry.getDate());
    output += "  ";
    output += entry.getAuthor();
    output += LINE_SEPARATOR;
    String wikiFileIndent = getWikiIndentBullet1();
    if (entry.getCommonDir() != null) {
        output += "   * " + entry.getCommonDir();
        output += ": " + LINE_SEPARATOR;
        wikiFileIndent = "   " + wikiFileIndent;
    }
    Iterator<EntryFile> fileIter = entry.getFiles().iterator();
    while (fileIter.hasNext()) {
        EntryFile file = fileIter.next();
        output += wikiFileIndent;
        if (file.getCvsstate().equals("dead")) {
            output += "<strike>" + file.getPathName() + "</strike>";
        } else {
            output += "=" + file.getPathName() + "=";
        }
        output += LINE_SEPARATOR;
    }
    // @TODO perhaps use <blockquote> around the message for indenting, instead of the silly bullet.
    output += "   * " + formatMessage("     ", entry.getMessage()) + LINE_SEPARATOR;
    System.out.println(output);
}
Also used : EntryFile(alma.acs.releasedoc.Cvs2clXmlEntry.EntryFile)

Aggregations

EntryFile (alma.acs.releasedoc.Cvs2clXmlEntry.EntryFile)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Document (org.w3c.dom.Document)1 NodeList (org.w3c.dom.NodeList)1