alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */


package org.netbeans.modules.changelog;

/**
 *
 * @author  Milos Kleint, ralph krueger
 */
import org.netbeans.modules.javacvs.events.CommandDisplayerAdapter;
import org.netbeans.modules.javacvs.commands.*;
import org.netbeans.modules.cvsclient.*;

import org.apache.regexp.RE;
import org.apache.regexp.RESyntaxException;


import org.netbeans.lib.cvsclient.command.DefaultFileInfoContainer;
import org.netbeans.lib.cvsclient.command.FileInfoContainer;
import org.netbeans.lib.cvsclient.command.log.LogInformation;
import java.util.*;
import java.io.*;
import org.openide.filesystems.*;
import org.openide.*;
import org.openide.loaders.*;
import org.openide.util.*;
import javax.swing.*;
import java.awt.Dialog;
import java.awt.event.*;

public class ChangeLogDisplayer extends CommandDisplayerAdapter {
    
    private static final String INITIAL_REV = "Initial revision"; //NOI18N
    private static final String WAS_ADDED_ON_BRANCH = "was initially added on branch"; //NOI18N
    
    private int commandCount = 0;
    private int finishedCommandCount = 0;
    private long revisionsNumber = 0;
    private boolean errorsOccured = false;
    
    private HashMap fileObjectMap;
    
    private RE messageRE = null;
    
    private ChangeLogProcessor processor;
    
    /** Creates new ChangeLogDisplayer */
    public ChangeLogDisplayer(ChangeLogProcessor proces) {
        fileObjectMap = new HashMap(10);
        processor = proces;
    }
    
    
    /**
     * adds fileobjects to a map of selected fileobjects for this action.
     * Is needed to convert correctly the resulting files back to
     * fileobjects.
     */ 
    public void addFileObjects(FileObject[] fos) {
        if (fos != null) {
            for (int i=0; i < fos.length; i++) {
                File file = FileSystemCommand.toFile(fos[i]);
                if (file != null) {
                    fileObjectMap.put(file, fos[i]);
                }
            }
        }
    }

    public synchronized void setNumberOfCommands(int number) {
        commandCount = number;
    }
    
    public int getNumberOfCommand() {
        return commandCount;
    }
    
    
    public synchronized void showFinishedCommand() {
//        System.out.println("finished 1 status command..");
        finishedCommandCount = finishedCommandCount + 1;
        if (finishedCommandCount == commandCount) {
            showDialog();
        }
    }
    
    public synchronized void showExecutionFailed(Exception exception) {
        errorsOccured = true;
        System.out.println("exc=" + exception);
        exception.printStackTrace();
        finishedCommandCount = finishedCommandCount + 1;
        if (finishedCommandCount == commandCount) {
            showDialog();
        }
    }

    public synchronized void showStartCommand() {
        
    }
    
    private java.util.List extractBranches(LogInformation info) {
        LinkedList list = new LinkedList();
        if (info.getAllSymbolicNames() != null) {
            Iterator it = info.getAllSymbolicNames().iterator();
            while (it.hasNext()) {
                LogInformation.SymName name = (LogInformation.SymName)it.next();
                // performance related condition??
                if (name.getRevision().indexOf(".0") > 0) { 
                    int[] arr = ChangeLogUtils.convertRevisionToIntArray(name.getRevision());
                    if (arr[arr.length - 2] == 0) {
                        // needs to be performance improved!!!!
                        
                        name.setRevision(ChangeLogUtils.convertIntArrayToRevision(arr).intern());
                        list.add(name);
                    }
                }
            }
        }
        return list;
    }
    
    public synchronized void showFileInfoGenerated(FileInfoContainer info) {
        if (info.getClass().equals(LogInformation.class)) {
            LogInformation lInfo = (LogInformation)info;
            LogInfoRevision.LogInfoHeader header = createHeader(lInfo);
            List branchList = extractBranches(lInfo);
            boolean include = true;
            Iterator it =lInfo.getRevisionList().iterator();
            while (it.hasNext()) {
                include = true;
                LogInformation.Revision rev = (LogInformation.Revision)it.next();
                // don't include revision 1.1 created on background when
                // the file is added on the branch..
                if (rev.getState() != null &&
                    rev.getMessage() != null &&
                    rev.getNumber() != null &&
                    rev.getState().equals("dead") && //NOI18N
                    rev.getNumber().equals("1.1") && //NOI18N
                    rev.getMessage().indexOf(WAS_ADDED_ON_BRANCH) > 0) {
                        continue;
                }
                // don't include the revision created during import command.
                // not sure if the condition here is bulletproof.
                if (rev.getMessage() != null &&
                    rev.getNumber() != null &&
                    rev.getNumber().equals("1.1") && //NOI18N
                    rev.getMessage().indexOf(INITIAL_REV) >= 0) {
                        continue;
                }
                if (processor.messageMatchesFilterPattern(rev.getMessage())) {
                    LogInfoRevision revision = createRevision(rev, header);
                    revision.setBranch(findBranchInSymNamesList(branchList, revision.getNumber()));
                    processor.addRevision(revision, rev.getMessage());
                }
            }
        }
    }

    /**
     * TODO:
     * can be optimized by first sorting from longest to shortest branch number..
     */
    private String findBranchInSymNamesList(List list, String revisionNumber) {
        Iterator it = list.iterator();
        if (revisionNumber.indexOf('.') == revisionNumber.lastIndexOf('.')) {
            return null;
        }
        String branch = null;
        String longestMatch = "";
        while (it.hasNext()) {
            LogInformation.SymName name = (LogInformation.SymName)it.next();
            if (revisionNumber.startsWith(name.getRevision())) {
                if (name.getRevision().length() > longestMatch.length()) {
                    branch = name.getName();
                    longestMatch = name.getRevision();
                }
            }
        }
        return branch;
    }
    
    private void showDialog() {
        processor.finishProcessing();
    }
    
    
    
    
    private LogInfoRevision.LogInfoHeader createHeader(LogInformation info) {
        LogInfoRevision.LogInfoHeader header = new LogInfoRevision.LogInfoHeader();
        header.setAccessList(info.getAccessList());
        header.setBranch(info.getBranch());
        header.setDescription(info.getDescription());
        header.setFile(info.getFile());
        header.setHeadRevision(info.getHeadRevision());
        header.setKeywordSubstitution(info.getKeywordSubstitution());
        header.setLocks(info.getLocks());
        header.setRepositoryFilename(info.getRepositoryFilename());
        header.setSelectedRevisions(info.getSelectedRevisions());
        header.setTotalRevisions(info.getTotalRevisions());
        return header;
    }
    
    private LogInfoRevision createRevision(LogInformation.Revision jcvsRev, 
                                           LogInfoRevision.LogInfoHeader header) {
        LogInfoRevision rev = new LogInfoRevision(header.getFile());
        rev.setAuthor(jcvsRev.getAuthor());
//        rev.setBranches(jcvsRev.getBranches());
        rev.setDate(jcvsRev.getDate());
        rev.setLines(jcvsRev.getLines());
        rev.setLogInfoHeader(header);
        rev.setNumber(jcvsRev.getNumber());
        rev.setState(jcvsRev.getState());
        return rev;
    }
        
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.