如何使用svnkit检查另一个目录中是否存在来自一个目录的特定文件

时间:2014-09-02 04:09:33

标签: java svn svnkit

我正在使用Svnkit,我想知道是否有办法检查另一个目录中是否存在一个目录中的特定文件。
例如:

//svnlocal/projectA/dir1/file2/xxx.java    
//svnlocal/projectB/dir3/file1/xxx.java  

我想找到两个项目中的类似文件,并获取这些类似文件的修订和日期 我已设法获得两个项目的修订和日期 先感谢您!

这是代码。

   import org.tmatesoft.svn.core.wc.SVNWCUtil;

    public class DisplayRep implements Comparator
    {
        public  int compare(Object o1, Object o2) {
            return RangeComparator(o1, o2);
            }



        public static void main(String[] args) {

            String url =null;
            String url2=null;
            String name = null;
            String password =null;
            Scanner ob=new Scanner(System.in);
            System.out.println("Enter the URL for  abc : ");
            url=ob.nextLine(); 
            System.out.println("Enter the URL for pqr : ");
            url2=ob.nextLine(); 
            System.out.println("Enter your Username :");
            name=ob.nextLine();
            System.out.println("Enter your Password :");
            password=ob.nextLine();


            setupLibrary();
            if (args != null) {
                url = (args.length >= 1) ? args[0] : url;
                url2 = (args.length >= 2) ? args[1] : url2;
                name = (args.length >= 3) ? args[2] : name;
                password = (args.length >= 4) ? args[3] : password;
            }
            SVNRepository repository = null;
            SVNRepository   repository2=null;
            try {

                repository2 = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url2));
                repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
            } catch (SVNException svne) {
                System.err
                .println("error while creating an SVNRepository for location '"
                        + url + "': " + svne.getMessage());
                System.exit(1);
            }

            ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(name, password);
            repository.setAuthenticationManager(authManager);

            try{
                SVNNodeKind nodeKind = repository.checkPath("", -1);
                if (nodeKind == SVNNodeKind.NONE) {
                    System.err.println("There is no entry at '" + url + "'.");
                    System.exit(1);
                } else if (nodeKind == SVNNodeKind.FILE) {
                    System.err.println("The entry at '" + url + "' is a file while a directory was expected.");
                    System.exit(1);
                }
                System.out.println("Repository Root  " + repository.getRepositoryRoot(true));
                System.out.println("Repository UUID  " + repository.getRepositoryUUID(true));
                System.out.println("");

                /*
                 * Displays the repository tree at the current path - "" (what means
                 * the path/to/repository directory)
                 */
                listEntries(repository, "");
            } catch (SVNException svne) {
                System.err.println("error while listing entries: "
                        + svne.getMessage());
                System.exit(1);
            }


            ISVNAuthenticationManager authManager2 = SVNWCUtil.createDefaultAuthenticationManager(name, password);
            repository2.setAuthenticationManager(authManager2);

            try{
                SVNNodeKind nodeKind2 = repository2.checkPath("", -1);
                if (nodeKind2 == SVNNodeKind.NONE) {
                    System.err.println("There is no entry at '" + url2 + "'.");
                    System.exit(1);
                } else if (nodeKind2 == SVNNodeKind.FILE) {
                    System.err.println("The entry at '" + url2 + "' is a file while a directory was expected.");
                    System.exit(1);
                }System.out.println("");
                System.out.println("======================================================");
                System.out.println("Repository Root " + repository2.getRepositoryRoot(true));
                System.out.println("Repository UUID  " + repository2.getRepositoryUUID(true));
                System.out.println("");

                listEntries2(repository2, "");
            } catch (SVNException svne) {
                System.err.println("error while listing entries: "
                        + svne.getMessage());
                System.exit(1);
            }
            //=======================================================================
            /*
             * Gets the latest revision number of the repository
             */





            long latestRevision = -1;

            try {
                latestRevision = repository.getLatestRevision();

            } catch (SVNException svne) {
                System.err
                .println("error while fetching the latest repository revision: "
                        + svne.getMessage());
                System.exit(1);
            }
            System.out.println("");
            System.out.println("---------------------------------------------");
            System.out.println("Repository latest revision: " + latestRevision);

            long latestRevision2=-1;
        try{
            latestRevision2 = repository2.getLatestRevision();
            }catch(SVNException svne){
                System.err
                .println("error while fetching the latest repository revision: "
                        + svne.getMessage());
                System.exit(1);

            }
            System.out.println("");
            System.out.println("----------------------------------------");
            System.out.println("Repository2 latest revision: " + latestRevision2);
            System.exit(0);

        }

        /*
         * Initializes the library to work with a repository via 
         * different protocols.
         */
        private static void setupLibrary() {
            DAVRepositoryFactory.setup();
            SVNRepositoryFactoryImpl.setup();
            FSRepositoryFactory.setup();
        }




        static SVNDirEntry entry=null;  
        public static void listEntries(SVNRepository repository, String path)throws SVNException {
            Collection entries = repository.getDir(path, -1, null,
                    (Collection) null);
            Iterator iterator = entries.iterator();
            while (iterator.hasNext()) {
                entry = (SVNDirEntry) iterator.next();

                System.out.println("/" + (path.equals("") ? "" : path + "/")
                        + entry.getName() + " (author: '" + entry.getAuthor()
                        + "'; revision: " + entry.getRevision() + "; date: " + entry.getDate() + ")");



                if (entry.getKind() == SVNNodeKind.DIR) {
                    listEntries(repository, (path.equals("")) ? entry.getName()
                            : path + "/" + entry.getName());
                    }
                  }
                 }

        static SVNDirEntry entry2=null; 
        public static void listEntries2(SVNRepository repository2, String path)throws SVNException {
            Collection entries2 = repository2.getDir(path, -1, null,
                    (Collection) null);
            Iterator iterator = entries2.iterator();
            while (iterator.hasNext()) {
                entry2 = (SVNDirEntry) iterator.next();
                        System.out.println("/" + (path.equals("") ? "" : path + "/")
                        + entry2.getName() + " (author: '" + entry2.getAuthor()
                        + "'; revision: " + entry2.getRevision() + "; date: " + entry2.getDate() + ")");

                /*
                 * Checking up if the entry is a directory.
                 */
                if (entry2.getKind() == SVNNodeKind.DIR) {
                    listEntries2(repository2, (path.equals("")) ? entry2.getName()
                            : path + "/" + entry2.getName());

                    } 
                  }DisplayRep dp = new DisplayRep();
                  dp.compare(entry, entry2);
                 }


        private  int RangeComparator(Object o1, Object o2) {





            System.out.println("");
            System.out.println("in comparator");
            // TODO Auto-generated method stub
            SVNDirEntry r1 = (SVNDirEntry) entry;
            SVNDirEntry r2 = (SVNDirEntry) entry2;
            //boolean r1revisiondate = r2.getRevision() > r1.getRevision(); 

            System.out.println("Node type : "+entry2.getKind());
            if(r2.getRevision()>r1.getRevision())
            {System.out.println(" ");
                System.out.println("abc :"+r2.getRevision()+"   date :"+r2.getDate());
                System.out.println("pqr :"+r1.getRevision()+"  date :"+r1.getDate());
            }
            else {
                System.out.println(" ");
            }
            return 1;

    }
    }

0 个答案:

没有答案