Change so that if the cvslib fails to connect, then fall back to using the cvs executable.

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@114252 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
epugh committed 2003-10-29 16:23:33 +00:00
1 parent 6c4f5a2fa3
commit 9d69059623
5 files changed
+253 -142

No files matched your search

@@ -7,22 +7,21 @@ package org.apache.maven.cvslib;
* Copyright (c) 2002 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The end-user documentation included with the redistribution, if any,
* must include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if and
* wherever such third-party acknowledgments normally appear.
* 4. The names "Apache" and "Apache Software Foundation" and "Apache Maven"
* must not be used to endorse or promote products derived from this software
* without prior written permission. For written permission, please contact
* apache@apache.org.
* 5. Products derived from this software may not be called "Apache", "Apache
* modification, are permitted provided that the following conditions are met: 1.
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. The end-user documentation
* included with the redistribution, if any, must include the following
* acknowledgment: "This product includes software developed by the Apache
* Software Foundation (http://www.apache.org/)." Alternately, this
* acknowledgment may appear in the software itself, if and wherever such
* third-party acknowledgments normally appear. 4. The names "Apache" and
* "Apache Software Foundation" and "Apache Maven" must not be used to endorse
* or promote products derived from this software without prior written
* permission. For written permission, please contact apache@apache.org. 5.
* Products derived from this software may not be called "Apache", "Apache
* Maven", nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
@@ -65,7 +64,6 @@ import org.apache.tools.ant.types.Commandline;
* A CVS implementation of the {@link org.apache.maven.changelog.ChangeLog}
* interface.
*
*
* @author Glenn McAllister
* @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
* @author <a href="mailto:jeff.martin@synamic.co.uk">Jeff Martin</a>
@@ -91,10 +89,10 @@ class CvsChangeLogGenerator extends AbstractChangeLogGenerator
public static final int POS_SCM_MODULE = 5;
/**
* Execute cvslib client driving the given parser.
* @todo Currently the output from the logListener is a String, which is
* then converted to an InputStream. The output of logListener really should
* be an input stream.
* Execute cvslib client driving the given parser. @todo Currently the
* output from the logListener is a String, which is then converted to an
* InputStream. The output of logListener really should be an input stream.
*
* @param parser A {@link ChangeLogParser parser}to process the scm
* output.
* @return A collection of {@link ChangeLogEntry entries}parsed from the
@@ -121,14 +119,29 @@ class CvsChangeLogGenerator extends AbstractChangeLogGenerator
}
clParser = parser;
CvsConnection connection = new CvsConnection();
String[] args = getScmLogCommand().getArguments();
CvsLogListener logListener = new CvsLogListener();
CvsConnection.processCommand(args, this.changeLogExecutor.getBasedir().toString(), logListener);
try
{
CvsConnection.processCommand(
args,
this.changeLogExecutor.getBasedir().toString(),
logListener);
entries =
clParser.parse(
new ByteArrayInputStream(
logListener.getStdout().toString().getBytes()));
}
catch (IllegalArgumentException iae)
{
entries = super.getEntries(parser);
}
catch (Exception e){
LOG.error(e);
}
entries = clParser.parse(new ByteArrayInputStream(logListener.getStdout().toString().getBytes()));
return entries;
}
/**
@@ -1,58 +1,47 @@
package org.apache.maven.cvslib;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
/*
* ==================================================================== The
* Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The end-user documentation included with the redistribution, if any,
* must include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if and
* wherever such third-party acknowledgments normally appear.
* 4. The names "Apache" and "Apache Software Foundation" and "Apache Maven"
* must not be used to endorse or promote products derived from this software
* without prior written permission. For written permission, please contact
* apache@apache.org.
* 5. Products derived from this software may not be called "Apache", "Apache
* Maven", nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/> .
*
* ====================================================================
*/
@@ -80,47 +69,46 @@ import org.netbeans.lib.cvsclient.event.CVSListener;
/**
* A Cvs connection that simulates a command line interface.
*
*
* @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
*/
public class CvsConnection
{
/** Log */
private static final Log LOG =
LogFactory.getLog(CvsConnection.class);
private static final Log LOG = LogFactory.getLog(CvsConnection.class);
/**
* The path to the repository on the server
*/
* The path to the repository on the server
*/
private String repository;
/**
* The local path to use to perform operations (the top level)
*/
* The local path to use to perform operations (the top level)
*/
private String localPath;
/**
* The connection to the server
*/
* The connection to the server
*/
private Connection connection;
/**
* The client that manages interactions with the server
*/
* The client that manages interactions with the server
*/
private Client client;
/**
* The global options being used. GlobalOptions are only global for a
* particular command.
*/
* The global options being used. GlobalOptions are only global for a
* particular command.
*/
private GlobalOptions globalOptions;
/**
* Execute a configured CVS command
*
* @param command the command to execute
* @throws CommandException if there is an error running the command
*/
* Execute a configured CVS command
*
* @param command the command to execute
* @throws CommandException if there is an error running the command
*/
public void executeCommand(Command command)
throws CommandException, AuthenticationException
{
@@ -143,8 +131,8 @@ public class CvsConnection
}
/**
* Creates the connection and the client and connects.
*/
* Creates the connection and the client and connects.
*/
private void connect(CVSRoot root, String password)
throws IllegalArgumentException, AuthenticationException
{
@@ -168,13 +156,12 @@ public class CvsConnection
}
}
/**
* Obtain the CVS root, either from the -D option cvs.root or from the CVS
* directory
*
* @return the CVSRoot string
*/
* Obtain the CVS root, either from the -D option cvs.root or from the CVS
* directory
*
* @return the CVSRoot string
*/
private static String getCVSRoot(String workingDir)
{
String root = null;
@@ -219,12 +206,12 @@ public class CvsConnection
}
/**
* Process global options passed into the application
*
* @param args the argument list, complete
* @param globalOptions the global options structure that will be passed to
* the command
*/
* Process global options passed into the application
*
* @param args the argument list, complete
* @param globalOptions the global options structure that will be passed to
* the command
*/
private static int processGlobalOptions(
String[] args,
GlobalOptions globalOptions)
@@ -247,12 +234,12 @@ public class CvsConnection
}
/**
* Lookup the password in the .cvspass file. This file is looked for in the
* user.home directory if the option cvs.passfile is not set
*
* @param CVSRoot the CVS root for which the password is being searched
* @return the password, scrambled
*/
* Lookup the password in the .cvspass file. This file is looked for in the
* user.home directory if the option cvs.passfile is not set
*
* @param CVSRoot the CVS root for which the password is being searched
* @return the password, scrambled
*/
private static String lookupPassword(String cvsRoot)
{
File passFile =
@@ -298,23 +285,22 @@ public class CvsConnection
}
if (password == null)
{
LOG.error(
"Didn't find password for CVSROOT '" + cvsRoot + "'.");
LOG.error("Didn't find password for CVSROOT '" + cvsRoot + "'.");
}
return password;
}
/**
* Process the CVS command passed in args[] array with all necessary
* options. The only difference from main() method is, that this method
* does not exit the JVM and provides command output.
*
* @param args The command with options
*/
* Process the CVS command passed in args[] array with all necessary
* options. The only difference from main() method is, that this method
* does not exit the JVM and provides command output.
*
* @param args The command with options
*/
public static boolean processCommand(
String[] args,
String localPath,
CVSListener listener)
CVSListener listener) throws Exception
{
// Set up the CVSRoot. Note that it might still be null after this
@@ -385,7 +371,6 @@ public class CvsConnection
return false;
}
String password = null;
if (CVSRoot.METHOD_PSERVER.equals(root.getMethod()))
@@ -412,20 +397,13 @@ public class CvsConnection
// command. This is the case for command-line CVS but not
// usually for GUI front-ends
cvsCommand.setLocalPath(localPath);
try
{
cvsCommand.connect(root, password);
cvsCommand.addListener(listener);
cvsCommand.executeCommand(c);
}
catch (Exception t)
{
LOG.error("Error: " + t,t);
return false;
}
cvsCommand.connect(root, password);
cvsCommand.addListener(listener);
cvsCommand.executeCommand(c);
return true;
}
}
@@ -65,7 +65,7 @@ import junit.framework.TestCase;
/**
* @author <a href="bwalding@jakarta.org">Ben Walding</a>
* @version $Id: CvsChangeLogGeneratorTest.java,v 1.7 2003/10/29 14:40:37 epugh Exp $
* @version $Id: CvsChangeLogGeneratorTest.java,v 1.8 2003/10/29 16:23:33 epugh Exp $
*/
class ExposeGenerator extends CvsChangeLogGenerator
{
@@ -78,7 +78,7 @@ class ExposeGenerator extends CvsChangeLogGenerator
/**
* @author <a href="bwalding@jakarta.org">Ben Walding</a>
* @version $Id: CvsChangeLogGeneratorTest.java,v 1.7 2003/10/29 14:40:37 epugh Exp $
* @version $Id: CvsChangeLogGeneratorTest.java,v 1.8 2003/10/29 16:23:33 epugh Exp $
*/
public class CvsChangeLogGeneratorTest extends TestCase
{
@@ -128,7 +128,11 @@ public class CvsChangeLogGeneratorTest extends TestCase
new Test(
"scm|cvs|local|local|D:/home/cvspublic|maven",
"cvs|-d|D:/home/cvspublic|log",
null)};
null),
new Test(
"scm:cvs:extssh:someuser@cvs.apache.org:/home/cvs:maven",
"cvs|-d|:extssh:someuser@cvs.apache.org:/home/cvs|log",
null)};
public void testParse() throws Throwable
{
@@ -0,0 +1,112 @@
package org.apache.maven.cvslib;
/*
* ==================================================================== The
* Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: 1.
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. The end-user documentation
* included with the redistribution, if any, must include the following
* acknowledgment: "This product includes software developed by the Apache
* Software Foundation (http://www.apache.org/)." Alternately, this
* acknowledgment may appear in the software itself, if and wherever such
* third-party acknowledgments normally appear. 4. The names "Apache" and
* "Apache Software Foundation" and "Apache Maven" must not be used to endorse
* or promote products derived from this software without prior written
* permission. For written permission, please contact apache@apache.org. 5.
* Products derived from this software may not be called "Apache", "Apache
* Maven", nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/> .
*/
import java.io.File;
import junit.framework.TestCase;
/**
* Test cases for {@link CvsLogListener}
*
* @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
* @version $Id: CvsConnectionTest.java,v 1.1 2003/10/29 16:23:33 epugh Exp $
*/
public class CvsConnectionTest extends TestCase
{
/**
* Create a test with the given name
*
* @param testName the name of the test
*/
public CvsConnectionTest(String testName)
{
super(testName);
}
/**
* Test of making a pserver connection.
*
* @throws Exception when there is an unexpected problem
*/
public void testConnectWithPServer() throws Exception
{
ExposeGenerator eg = new ExposeGenerator();
eg.setConnection(
"scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven");
String args[] = eg.getScmLogCommand().getArguments();
File f = new File(".").getAbsoluteFile();
String localPath = f.toString();
CvsLogListener listener = new CvsLogListener();
CvsConnection.processCommand(args, localPath, listener);
assertTrue(listener.getStdout().length() > 0);
}
/**
* Test of making an ssh connection
*
* @throws Exception when there is an unexpected problem
*/
public void testConnectWithExtSSH() throws Exception
{
ExposeGenerator eg = new ExposeGenerator();
eg.setConnection(
"scm:cvs:extssh:pugh@80.38.99.24:/home/pugh/cvsroot:parsys");
String args[] = eg.getScmLogCommand().getArguments();
File f = new File(".").getAbsoluteFile();
String localPath = f.toString();
CvsLogListener listener = new CvsLogListener();
try
{
CvsConnection.processCommand(args, localPath, listener);
fail("should have thrown exception");
}
catch (IllegalArgumentException e)
{
// good
}
}
}
+4
View File
@@ -8,6 +8,10 @@
<body>
<release version="1.4-dev" date="in cvs">
<action dev="epugh" type="update">
If, using the cvslib, fails, then fall back to using
the command line call to the cvs executable.
</action>
<action dev="epugh" type="update">
Added java based CVS library using cvslib. Removed
requirement for cvs executable.