Coverage report

  %line %branch
nl.toolforge.karma.core.vc.cvsimpl.ExtClient
0% 
0% 

 1  
 package nl.toolforge.karma.core.vc.cvsimpl;
 2  
 
 3  
 import nl.toolforge.core.util.file.MyFileUtils;
 4  
 import nl.toolforge.karma.core.KarmaRuntimeException;
 5  
 import nl.toolforge.karma.core.cmd.CommandException;
 6  
 import nl.toolforge.karma.core.cmd.CommandResponse;
 7  
 import nl.toolforge.karma.core.cmd.CommandResponseHandler;
 8  
 import org.apache.tools.ant.BuildException;
 9  
 import org.apache.tools.ant.Project;
 10  
 import org.apache.tools.ant.helper.ProjectHelperImpl;
 11  
 import org.netbeans.lib.cvsclient.command.Command;
 12  
 
 13  
 import java.io.BufferedReader;
 14  
 import java.io.BufferedWriter;
 15  
 import java.io.File;
 16  
 import java.io.FileWriter;
 17  
 import java.io.IOException;
 18  
 import java.io.InputStreamReader;
 19  
 
 20  
 /**
 21  
  * Quick hack to support the CVS <code>ext</code> protocol. This implementation uses the Ant task, not anything
 22  
  * native, unfortunately.
 23  
  *
 24  
  * @author D.A. Smedes
 25  
  * @version $Id: ExtClient.java,v 1.2 2004/11/02 23:57:07 asmedes Exp $
 26  
  */
 27  0
 public final class ExtClient {
 28  
 
 29  0
   private CommandResponse response = new CommandResponse();
 30  
 
 31  
   public void setHandler(CommandResponseHandler handler) {
 32  0
     response.addCommandResponseListener(handler);
 33  0
   }
 34  
 
 35  0
   private LogParser listener = null;
 36  
 
 37  
   public void runCommand(Command command, File contextDirectory, CVSRepository location) throws CVSException {
 38  
 
 39  0
     if (listener == null) {
 40  0
       throw new KarmaRuntimeException("No listener registered for this client.");
 41  
     }
 42  
 
 43  
     // todo hmm, this mechanism doesn't integrate with the commandresponse mechanism
 44  
     //
 45  0
     listener.setOutputPrintStream(System.out);
 46  0
     listener.setMessageOutputLevel(Project.MSG_INFO);
 47  
 
 48  
     // Configure underlying ant to run a command.
 49  
     //
 50  0
     Project project = new Project();
 51  0
     project.addBuildListener(listener);
 52  0
     project.init();
 53  
 
 54  
     // The ping thingie doesn't work through a proxy.
 55  
     //
 56  
 
 57  
 //    if (!Ping.ping(location.getHost(), 22, 3000)) {
 58  
 //      throw new CVSException(LocationException.CONNECTION_EXCEPTION, new Object[]{location.getId()});
 59  
 //    } else {
 60  
 
 61  0
     ProjectHelperImpl helper = new ProjectHelperImpl();
 62  
     try {
 63  0
       helper.parse(project, getBuildFile("ext-support.xml"));
 64  0
     } catch (IOException e) {
 65  0
       throw new KarmaRuntimeException("Cannot find ext-support.xml");
 66  0
     }
 67  
 
 68  0
     project.setProperty("cvsroot", location.getCVSRoot());
 69  0
     project.setProperty("command", command.getCVSCommand());
 70  0
     project.setProperty("dest", contextDirectory.getPath());
 71  
 
 72  
     try {
 73  0
       project.executeTarget("run");
 74  0
     } catch (BuildException e) {
 75  0
       throw new CVSException(e, CommandException.BUILD_FAILED);
 76  0
     }
 77  
 //    }
 78  0
   }
 79  
 
 80  
   private final File getBuildFile(String buildFile) throws IOException {
 81  
 
 82  0
     File tmp = null;
 83  
 
 84  0
     tmp = MyFileUtils.createTempDirectory();
 85  
 
 86  0
     ClassLoader loader = this.getClass().getClassLoader();
 87  
 
 88  0
     BufferedReader in =
 89  
         new BufferedReader(class="keyword">new InputStreamReader(loader.getResourceAsStream("ant" + File.separator + buildFile)));
 90  0
     BufferedWriter out =
 91  
         new BufferedWriter(class="keyword">new FileWriter(class="keyword">new File(tmp, buildFile)));
 92  
 
 93  
     String str;
 94  0
     while ((str = in.readLine()) != null) {
 95  0
       out.write(str);
 96  
     }
 97  0
     out.close();
 98  0
     in.close();
 99  
 
 100  
     // Return a temp reference to the file
 101  
     //
 102  0
     return new File(tmp, buildFile);
 103  
   }
 104  
 
 105  
   public void addCVSListener(LogParser listener) {
 106  0
     this.listener = listener;
 107  0
   }
 108  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.