Listing the repository content

"jean-baptiste lézoray" <[email protected]> Tue, 6 Jun 2006 11:50:55 +0200
Newsgroups gmane.comp.java.netbeans.modules.javacvs.devel
Message-ID <[email protected]>
Hi there

I have a problem for listing the modules of a repository.  In fact I
need to list the repository content (for the user to choose a module
to import).  I've read several times the content of this newsgroup and
I have tried different ways, but I can't get to have the famous list
:-(, so I need a little help !

I first tried to use a CheckoutCommand with a ModuleListBuilder(), but
the result was empty. I've read that this command just lists the
content of the CVSROOT/Modules files.  In my case, that file is empty.
 I notice that Eclipse can list my repository even if that file is
empty so I must also be able to do it (?)

Then I tried with the hack (described in the bug track
http://www.netbeans.org/issues/show_bug.cgi?id=35239 ) to list the
directories in the repository.  Using the same way on a command line,
i get the same informations :
cache:/tmp/justATest# mkdir CVS
cache:/tmp/justATest# vi CVS/Entries
cache:/tmp/justATest# vi CVS/Repository
cache:/tmp/justATest# vi CVS/Root
cache:/tmp/justATest# cvs -n up -d
cvs update: Updating .
cvs update: New directory `CVSROOT' -- ignored
cvs update: New directory `demo' -- ignored
cvs update: New directory `nouveau' -- ignored

In fact, the "-- ignored" directories is the information I need ! But
how can i get those informations ? I can just have a String out of a
MessageEvent (for exemple : "cvs update: New directory `nouveau' --
ignored") but not the directory .... is there a way to do that ?
what's wrong in my code ?

Thanks for helping ! (excuse my poor english ... )

lezoray jb

-------------------------------
Here is a sample of my code :


/*
 * returns the modules list from the specified CVSRoot.
 */
public static Vector<String> getModulesList( CVSRoot cvsRoot )
throws AuthenticationException, CommandException {

    boolean debug = true;

    // Here there is a hack to get the modules list (more Precisely, the
    // repository content) with the javaCVS lib. It is discused in the
    // project newsGroup.
    // We will implement an algorithm described in the JavaCVS bugtrack
    // as #35239 .
    //
    // see bug track: http://www.netbeans.org/issues/show_bug.cgi?id=35239
    // see Newsgroups: gmane.comp.java.netbeans.modules.javacvs.devel
    //
    // TODO a better way to get the modules list....

    Vector<String> modulesNames = new Vector<String>();
    try {

        // Create an empty temporary folder
        File aTempFile = File.createTempFile("cvs-tempDir", "");
        String aTempFileName = aTempFile.getAbsolutePath();
        aTempFile.delete();
        File aTempDir = new File( aTempFileName );
        aTempDir.mkdir();
        if (!debug) aTempDir.deleteOnExit();

        // makes a CVS sub-folder
        File cvsDir = new File( aTempDir, "CVS" );
        cvsDir.mkdir();

        // Create CVS/Entries file with "D\n" content.
        File cvsEntries = new File( cvsDir, "Entries" );
        cvsEntries.createNewFile();
        BufferedWriter out = new BufferedWriter(new FileWriter( cvsEntries ));
        out.write("D\n");
        out.close();

        // Create CVS/Root file with appropriate cvs root.
        File cvsRootF = new File( cvsDir, "Root" );
        cvsRootF.createNewFile();
        out = new BufferedWriter(new FileWriter( cvsRootF ));
        out.write( ":pserver:bob:UDontNeedToKnow@pare-feu:2401/cvs" );
        out.close();

        // Create CVS/Repository file with desired folder.
        File cvsRepository = new File( cvsDir, "Repository" );
        cvsRepository.createNewFile();
        out = new BufferedWriter(new FileWriter( cvsRepository ));
        out.write( "/cvs" );
        out.close();



        // Run "cvs -n update -d" command. It will list the
        // files and folders in the trunk on the server.
        UpdateCommand updt = new UpdateCommand();
        updt.setBuildDirectories( true ); // build directories '-d'

        GlobalOptions go = new GlobalOptions();
        go.setDoNoChanges( true ); // no changes on files '-n'

        Connection con = CvsUtils.getConnection( cvsRoot ); // that's
ok and validated
        Client cli = new Client( con, new StandardAdminHandler());
        cli.setLocalPath( aTempDir.getAbsolutePath() );
        cli.getEventManager().addCVSListener(
            new CVSAdapter() {
            public void messageSent(MessageEvent e) {
                String msg = "### MessageSent \n" +
                        "toString : " + e.toString()  + "\n" +
                        "message  : " + e.getMessage() + "\n" +
                        "Error(s) : " + ((e.isError())?"yes":"no") + "\n" +
                        "Tagged   : " + ((e.isTagged())?"yes":"no") + "\n" +
                        "Source   : " + (e.getSource().toString()) + "\n" +
                        "Tagged   : " + ((e.isTagged())?"yes":"no") + "\n";
                System.err.println( msg );
            }
            public void fileInfoGenerated(FileInfoEvent e)  {
                String msg = "### FileInfoEvent \n";
                System.err.println( msg );
            }
            }

        );
        cli.executeCommand( updt, go );



        System.err.println( "Update has Failed ? : " +
            ((updt.hasFailed())?"true":"False"));
        System.err.println( "client aborted ? : " +
            ((cli.isAborted())?"true":"false"));

        // list that directory : it should contain the modules list
        System.err.println(" list the temp directory :  ");
        File[] fileList = aTempDir.listFiles();
        for (int i=0; i<fileList.length; i++) {
            if (fileList[i].isDirectory()) {
                System.err.println(" * " + fileList[i].getName());
                modulesNames.add( fileList[i].getName() );
            }
        }

    } catch (IOException e) {
        //TODO catch that exception
    } catch (CommandException e) {
        //TODO catch that exception
    }

    return modulesNames; // THAT LIST IS DESEPERATLY EMPTY
}



---------------------
OUTPUT :

### MessageSent
toString : org.netbeans.lib.cvsclient.event.EnhancedMessageEvent[source=org.netbeans.lib.cvsclient.Client@15718f2]
message  :
Error(s) : no
Tagged   : no
Source   : org.netbeans.lib.cvsclient.Client@15718f2
Tagged   : no

### MessageSent
toString : org.netbeans.lib.cvsclient.event.MessageEvent[source=org.netbeans.lib.cvsclient.response.ErrorMessageResponse@13576a2]
message  : cvs update: Updating .
Error(s) : yes
Tagged   : no
Source   : org.netbeans.lib.cvsclient.response.ErrorMessageResponse@13576a2
Tagged   : no

### MessageSent
toString : org.netbeans.lib.cvsclient.event.MessageEvent[source=org.netbeans.lib.cvsclient.response.ErrorMessageResponse@13576a2]
message  : cvs update: New directory `CVSROOT' -- ignored
Error(s) : yes
Tagged   : no
Source   : org.netbeans.lib.cvsclient.response.ErrorMessageResponse@13576a2
Tagged   : no

### MessageSent
toString : org.netbeans.lib.cvsclient.event.MessageEvent[source=org.netbeans.lib.cvsclient.response.ErrorMessageResponse@13576a2]
message  : cvs update: New directory `demo' -- ignored
Error(s) : yes
Tagged   : no
Source   : org.netbeans.lib.cvsclient.response.ErrorMessageResponse@13576a2
Tagged   : no

### MessageSent
toString : org.netbeans.lib.cvsclient.event.MessageEvent[source=org.netbeans.lib.cvsclient.response.ErrorMessageResponse@13576a2]
message  : cvs update: New directory `nouveau' -- ignored
Error(s) : yes
Tagged   : no
Source   : org.netbeans.lib.cvsclient.response.ErrorMessageResponse@13576a2
Tagged   : no

Update has Failed ? : False
client aborted ? : false

 list the temp directory :
 * CVS


-- 
LEZORAY Jean-baptiste,
06.64.86.32.92 / 02.33.58.59.97
Ecole Nationale Superieure d'Ingenieurs de Caen
www.ecole.ensicaen.fr/~lezoray
www.norka.fr.st

-- 
LEZORAY Jean-baptiste,
06.64.86.32.92 / 02.33.58.59.97
Ecole Nationale Superieure d'Ingenieurs de Caen
www.ecole.ensicaen.fr/~lezoray
www.norka.fr.st