You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractCvsTask.java 25 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "Ant" and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. */
  54. package org.apache.tools.ant.taskdefs;
  55. import java.io.BufferedOutputStream;
  56. import java.io.File;
  57. import java.io.FileOutputStream;
  58. import java.io.IOException;
  59. import java.io.OutputStream;
  60. import java.io.PrintStream;
  61. import java.util.Vector;
  62. import org.apache.tools.ant.BuildException;
  63. import org.apache.tools.ant.Project;
  64. import org.apache.tools.ant.Task;
  65. import org.apache.tools.ant.types.Commandline;
  66. import org.apache.tools.ant.types.Environment;
  67. import org.apache.tools.ant.util.StringUtils;
  68. /**
  69. * original Cvs.java 1.20
  70. *
  71. * NOTE: This implementation has been moved here from Cvs.java with
  72. * the addition of some accessors for extensibility. Another task
  73. * can extend this with some customized output processing.
  74. *
  75. * @author costin@dnt.ro
  76. * @author stefano@apache.org
  77. * @author Wolfgang Werner
  78. * <a href="mailto:wwerner@picturesafe.de">wwerner@picturesafe.de</a>
  79. * @author Kevin Ross
  80. * <a href="mailto:kevin.ross@bredex.com">kevin.ross@bredex.com</a>
  81. *
  82. * @since Ant 1.5
  83. */
  84. public abstract class AbstractCvsTask extends Task {
  85. /**
  86. * Default compression level to use, if compression is enabled via
  87. * setCompression( true ).
  88. */
  89. public static final int DEFAULT_COMPRESSION_LEVEL = 3;
  90. private static final int MAXIMUM_COMRESSION_LEVEL = 9;
  91. private Commandline cmd = new Commandline();
  92. /** list of Commandline children */
  93. private Vector vecCommandlines = new Vector();
  94. /**
  95. * the CVSROOT variable.
  96. */
  97. private String cvsRoot;
  98. /**
  99. * the CVS_RSH variable.
  100. */
  101. private String cvsRsh;
  102. /**
  103. * the package/module to check out.
  104. */
  105. private String cvsPackage;
  106. /**
  107. * the default command.
  108. */
  109. private static final String DEFAULT_COMMAND = "checkout";
  110. /**
  111. * the CVS command to execute.
  112. */
  113. private String command = null;
  114. /**
  115. * suppress information messages.
  116. */
  117. private boolean quiet = false;
  118. /**
  119. * compression level to use.
  120. */
  121. private int compression = 0;
  122. /**
  123. * report only, don't change any files.
  124. */
  125. private boolean noexec = false;
  126. /**
  127. * CVS port
  128. */
  129. private int port = 0;
  130. /**
  131. * CVS password file
  132. */
  133. private File passFile = null;
  134. /**
  135. * the directory where the checked out files should be placed.
  136. */
  137. private File dest;
  138. /** whether or not to append stdout/stderr to existing files */
  139. private boolean append = false;
  140. /**
  141. * the file to direct standard output from the command.
  142. */
  143. private File output;
  144. /**
  145. * the file to direct standard error from the command.
  146. */
  147. private File error;
  148. /**
  149. * If true it will stop the build if cvs exits with error.
  150. * Default is false. (Iulian)
  151. */
  152. private boolean failOnError = false;
  153. /**
  154. * Create accessors for the following, to allow different handling of
  155. * the output.
  156. */
  157. private ExecuteStreamHandler executeStreamHandler;
  158. private OutputStream outputStream;
  159. private OutputStream errorStream;
  160. /** empty no-arg constructor*/
  161. public AbstractCvsTask() {
  162. super();
  163. }
  164. /**
  165. * sets the handler
  166. * @param handler a handler able of processing the output and error streams from the cvs exe
  167. */
  168. public void setExecuteStreamHandler(ExecuteStreamHandler handler) {
  169. this.executeStreamHandler = handler;
  170. }
  171. /**
  172. * find the handler and instantiate it if it does not exist yet
  173. * @return handler for output and error streams
  174. */
  175. protected ExecuteStreamHandler getExecuteStreamHandler() {
  176. if (this.executeStreamHandler == null) {
  177. setExecuteStreamHandler(new PumpStreamHandler(getOutputStream(),
  178. getErrorStream()));
  179. }
  180. return this.executeStreamHandler;
  181. }
  182. /**
  183. * sets a stream to which the output from the cvs executable should be sent
  184. * @param outputStream stream to which the stdout from cvs should go
  185. */
  186. protected void setOutputStream(OutputStream outputStream) {
  187. this.outputStream = outputStream;
  188. }
  189. /**
  190. * access the stream to which the stdout from cvs should go
  191. * if this stream has already been set, it will be returned
  192. * if the stream has not yet been set, if the attribute output
  193. * has been set, the output stream will go to the output file
  194. * otherwise the output will go to ant's logging system
  195. * @return output stream to which cvs'stdout should go to
  196. */
  197. protected OutputStream getOutputStream() {
  198. if (this.outputStream == null) {
  199. if (output != null) {
  200. try {
  201. setOutputStream(new PrintStream(
  202. new BufferedOutputStream(
  203. new FileOutputStream(output
  204. .getPath(),
  205. append))));
  206. } catch (IOException e) {
  207. throw new BuildException(e, getLocation());
  208. }
  209. } else {
  210. setOutputStream(new LogOutputStream(this, Project.MSG_INFO));
  211. }
  212. }
  213. return this.outputStream;
  214. }
  215. /**
  216. * sets a stream to which the stderr from the cvs exe should go
  217. * @param errorStream an output stream willing to process stderr
  218. */
  219. protected void setErrorStream(OutputStream errorStream) {
  220. this.errorStream = errorStream;
  221. }
  222. /**
  223. * access the stream to which the stderr from cvs should go
  224. * if this stream has already been set, it will be returned
  225. * if the stream has not yet been set, if the attribute error
  226. * has been set, the output stream will go to the file denoted by the error attribute
  227. * otherwise the stderr output will go to ant's logging system
  228. * @return output stream to which cvs'stderr should go to
  229. */
  230. protected OutputStream getErrorStream() {
  231. if (this.errorStream == null) {
  232. if (error != null) {
  233. try {
  234. setErrorStream(new PrintStream(
  235. new BufferedOutputStream(
  236. new FileOutputStream(error.getPath(),
  237. append))));
  238. } catch (IOException e) {
  239. throw new BuildException(e, getLocation());
  240. }
  241. } else {
  242. setErrorStream(new LogOutputStream(this, Project.MSG_WARN));
  243. }
  244. }
  245. return this.errorStream;
  246. }
  247. /**
  248. * Sets up the environment for toExecute and then runs it.
  249. * @param toExecute the command line to execute
  250. * @throws BuildException if failonError is set to true and the cvs command fails
  251. */
  252. protected void runCommand(Commandline toExecute) throws BuildException {
  253. // XXX: we should use JCVS (www.ice.com/JCVS) instead of
  254. // command line execution so that we don't rely on having
  255. // native CVS stuff around (SM)
  256. // We can't do it ourselves as jCVS is GPLed, a third party task
  257. // outside of jakarta repositories would be possible though (SB).
  258. Environment env = new Environment();
  259. if (port > 0) {
  260. Environment.Variable var = new Environment.Variable();
  261. var.setKey("CVS_CLIENT_PORT");
  262. var.setValue(String.valueOf(port));
  263. env.addVariable(var);
  264. }
  265. /**
  266. * Need a better cross platform integration with <cvspass>, so
  267. * use the same filename.
  268. */
  269. if (passFile == null) {
  270. File defaultPassFile = new File(
  271. System.getProperty("cygwin.user.home",
  272. System.getProperty("user.home"))
  273. + File.separatorChar + ".cvspass");
  274. if (defaultPassFile.exists()) {
  275. this.setPassfile(defaultPassFile);
  276. }
  277. }
  278. if (passFile != null) {
  279. if (passFile.isFile() && passFile.canRead()) {
  280. Environment.Variable var = new Environment.Variable();
  281. var.setKey("CVS_PASSFILE");
  282. var.setValue(String.valueOf(passFile));
  283. env.addVariable(var);
  284. log("Using cvs passfile: " + String.valueOf(passFile),
  285. Project.MSG_INFO);
  286. } else if (!passFile.canRead()) {
  287. log("cvs passfile: " + String.valueOf(passFile)
  288. + " ignored as it is not readable",
  289. Project.MSG_WARN);
  290. } else {
  291. log("cvs passfile: " + String.valueOf(passFile)
  292. + " ignored as it is not a file",
  293. Project.MSG_WARN);
  294. }
  295. }
  296. if (cvsRsh != null) {
  297. Environment.Variable var = new Environment.Variable();
  298. var.setKey("CVS_RSH");
  299. var.setValue(String.valueOf(cvsRsh));
  300. env.addVariable(var);
  301. }
  302. //
  303. // Just call the getExecuteStreamHandler() and let it handle
  304. // the semantics of instantiation or retrieval.
  305. //
  306. Execute exe = new Execute(getExecuteStreamHandler(), null);
  307. exe.setAntRun(getProject());
  308. if (dest == null) {
  309. dest = getProject().getBaseDir();
  310. }
  311. if (!dest.exists()) {
  312. dest.mkdirs();
  313. }
  314. exe.setWorkingDirectory(dest);
  315. exe.setCommandline(toExecute.getCommandline());
  316. exe.setEnvironment(env.getVariables());
  317. try {
  318. String actualCommandLine = executeToString(exe);
  319. log(actualCommandLine, Project.MSG_VERBOSE);
  320. int retCode = exe.execute();
  321. log("retCode=" + retCode, Project.MSG_DEBUG);
  322. /*Throw an exception if cvs exited with error. (Iulian)*/
  323. if (failOnError && retCode != 0) {
  324. throw new BuildException("cvs exited with error code "
  325. + retCode
  326. + StringUtils.LINE_SEP
  327. + "Command line was ["
  328. + actualCommandLine + "]", getLocation());
  329. }
  330. } catch (IOException e) {
  331. if (failOnError) {
  332. throw new BuildException(e, getLocation());
  333. } else {
  334. log("Caught exception: " + e.getMessage(), Project.MSG_WARN);
  335. }
  336. } catch (BuildException e) {
  337. if (failOnError) {
  338. throw(e);
  339. } else {
  340. Throwable t = e.getException();
  341. if (t == null) {
  342. t = e;
  343. }
  344. log("Caught exception: " + t.getMessage(), Project.MSG_WARN);
  345. }
  346. } catch (Exception e) {
  347. if (failOnError) {
  348. throw new BuildException(e, getLocation());
  349. } else {
  350. log("Caught exception: " + e.getMessage(), Project.MSG_WARN);
  351. }
  352. } finally {
  353. if (outputStream != null) {
  354. try {
  355. outputStream.close();
  356. } catch (IOException e) {
  357. //ignore
  358. }
  359. }
  360. if (errorStream != null) {
  361. try {
  362. errorStream.close();
  363. } catch (IOException e) {
  364. //ignore
  365. }
  366. }
  367. }
  368. }
  369. /**
  370. * do the work
  371. * @throws BuildException if failonerror is set to true and the cvs command fails.
  372. */
  373. public void execute() throws BuildException {
  374. String savedCommand = getCommand();
  375. if (this.getCommand() == null && vecCommandlines.size() == 0) {
  376. // re-implement legacy behaviour:
  377. this.setCommand(AbstractCvsTask.DEFAULT_COMMAND);
  378. }
  379. String c = this.getCommand();
  380. Commandline cloned = null;
  381. if (c != null) {
  382. cloned = (Commandline) cmd.clone();
  383. cloned.createArgument(true).setLine(c);
  384. this.addConfiguredCommandline(cloned, true);
  385. }
  386. try {
  387. for (int i = 0; i < vecCommandlines.size(); i++) {
  388. this.runCommand((Commandline) vecCommandlines.elementAt(i));
  389. }
  390. } finally {
  391. if (cloned != null) {
  392. removeCommandline(cloned);
  393. }
  394. setCommand(savedCommand);
  395. }
  396. }
  397. private String executeToString(Execute execute) {
  398. StringBuffer stringBuffer =
  399. new StringBuffer(Commandline.describeCommand(execute
  400. .getCommandline()));
  401. String newLine = StringUtils.LINE_SEP;
  402. String[] variableArray = execute.getEnvironment();
  403. if (variableArray != null) {
  404. stringBuffer.append(newLine);
  405. stringBuffer.append(newLine);
  406. stringBuffer.append("environment:");
  407. stringBuffer.append(newLine);
  408. for (int z = 0; z < variableArray.length; z++) {
  409. stringBuffer.append(newLine);
  410. stringBuffer.append("\t");
  411. stringBuffer.append(variableArray[z]);
  412. }
  413. }
  414. return stringBuffer.toString();
  415. }
  416. /**
  417. * The CVSROOT variable.
  418. *
  419. * @param root the CVSROOT variable
  420. */
  421. public void setCvsRoot(String root) {
  422. // Check if not real cvsroot => set it to null
  423. if (root != null) {
  424. if (root.trim().equals("")) {
  425. root = null;
  426. }
  427. }
  428. this.cvsRoot = root;
  429. }
  430. /**
  431. * access the the CVSROOT variable
  432. * @return CVSROOT
  433. */
  434. public String getCvsRoot() {
  435. return this.cvsRoot;
  436. }
  437. /**
  438. * The CVS_RSH variable.
  439. *
  440. * @param rsh the CVS_RSH variable
  441. */
  442. public void setCvsRsh(String rsh) {
  443. // Check if not real cvsrsh => set it to null
  444. if (rsh != null) {
  445. if (rsh.trim().equals("")) {
  446. rsh = null;
  447. }
  448. }
  449. this.cvsRsh = rsh;
  450. }
  451. /**
  452. * access the CVS_RSH variable
  453. * @return the CVS_RSH variable
  454. */
  455. public String getCvsRsh() {
  456. return this.cvsRsh;
  457. }
  458. /**
  459. * Port used by CVS to communicate with the server.
  460. *
  461. * @param port port of CVS
  462. */
  463. public void setPort(int port) {
  464. this.port = port;
  465. }
  466. /**
  467. * access the port of CVS
  468. * @return the port of CVS
  469. */
  470. public int getPort() {
  471. return this.port;
  472. }
  473. /**
  474. * Password file to read passwords from.
  475. *
  476. * @param passFile password file to read passwords from
  477. */
  478. public void setPassfile(File passFile) {
  479. this.passFile = passFile;
  480. }
  481. /**
  482. * find the password file
  483. * @return password file
  484. */
  485. public File getPassFile() {
  486. return this.passFile;
  487. }
  488. /**
  489. * The directory where the checked out files should be placed.
  490. *
  491. * @param dest directory where the checked out files should be placed
  492. */
  493. public void setDest(File dest) {
  494. this.dest = dest;
  495. }
  496. /**
  497. * get the file where the checked out files should be placed
  498. *
  499. * @return directory where the checked out files should be placed
  500. */
  501. public File getDest() {
  502. return this.dest;
  503. }
  504. /**
  505. * The package/module to operate upon.
  506. *
  507. * @param p package or module to operate upon
  508. */
  509. public void setPackage(String p) {
  510. this.cvsPackage = p;
  511. }
  512. /**
  513. * access the package or module to operate upon
  514. *
  515. * @return package/module
  516. */
  517. public String getPackage() {
  518. return this.cvsPackage;
  519. }
  520. /**
  521. * The tag of the package/module to operate upon.
  522. * @param p tag
  523. */
  524. public void setTag(String p) {
  525. // Check if not real tag => set it to null
  526. if (p != null && p.trim().length() > 0) {
  527. addCommandArgument("-r");
  528. addCommandArgument(p);
  529. }
  530. }
  531. /**
  532. * This needs to be public to allow configuration
  533. * of commands externally.
  534. * @param arg command argument
  535. */
  536. public void addCommandArgument(String arg) {
  537. this.addCommandArgument(cmd, arg);
  538. }
  539. /**
  540. * add a command line argument to an external command
  541. *
  542. * I do not understand what this method does in this class ???
  543. * particulary not why it is public ????
  544. * AntoineLL July 23d 2003
  545. *
  546. * @param c command line to which one argument should be added
  547. * @param arg argument to add
  548. */
  549. public void addCommandArgument(Commandline c, String arg) {
  550. c.createArgument().setValue(arg);
  551. }
  552. /**
  553. * Use the most recent revision no later than the given date.
  554. * @param p a date as string in a format that the CVS executable can understand
  555. * see man cvs
  556. */
  557. public void setDate(String p) {
  558. if (p != null && p.trim().length() > 0) {
  559. addCommandArgument("-D");
  560. addCommandArgument(p);
  561. }
  562. }
  563. /**
  564. * The CVS command to execute.
  565. *
  566. * This should be deprecated, it is better to use the Commandline class ?
  567. * AntoineLL July 23d 2003
  568. *
  569. * @param c a command as string
  570. */
  571. public void setCommand(String c) {
  572. this.command = c;
  573. }
  574. /**
  575. * accessor to a command line as string
  576. *
  577. * This should be deprecated
  578. * AntoineLL July 23d 2003
  579. *
  580. * @return command line as string
  581. */
  582. public String getCommand() {
  583. return this.command;
  584. }
  585. /**
  586. * If true, suppress informational messages.
  587. * @param q if true, suppress informational messages
  588. */
  589. public void setQuiet(boolean q) {
  590. quiet = q;
  591. }
  592. /**
  593. * If true, report only and don't change any files.
  594. *
  595. * @param ne if true, report only and do not change any files.
  596. */
  597. public void setNoexec(boolean ne) {
  598. noexec = ne;
  599. }
  600. /**
  601. * The file to direct standard output from the command.
  602. * @param output a file to which stdout should go
  603. */
  604. public void setOutput(File output) {
  605. this.output = output;
  606. }
  607. /**
  608. * The file to direct standard error from the command.
  609. *
  610. * @param error a file to which stderr should go
  611. */
  612. public void setError(File error) {
  613. this.error = error;
  614. }
  615. /**
  616. * Whether to append output/error when redirecting to a file.
  617. * @param value true indicated you want to append
  618. */
  619. public void setAppend(boolean value) {
  620. this.append = value;
  621. }
  622. /**
  623. * Stop the build process if the command exits with
  624. * a return code other than 0.
  625. * Defaults to false.
  626. * @param failOnError stop the build process if the command exits with
  627. * a return code other than 0
  628. */
  629. public void setFailOnError(boolean failOnError) {
  630. this.failOnError = failOnError;
  631. }
  632. /**
  633. * Configure a commandline element for things like cvsRoot, quiet, etc.
  634. * @param c the command line which will be configured
  635. * if the commandline is initially null, the function is a noop
  636. * otherwise the function append to the commandline arguments concerning
  637. * <ul>
  638. * <li>
  639. * cvs package
  640. * </li>
  641. * <li>
  642. * compression
  643. * </li>
  644. * <li>
  645. * quiet
  646. * </li>
  647. * <li>cvsroot</li>
  648. * <li>noexec</li>
  649. * </ul>
  650. */
  651. protected void configureCommandline(Commandline c) {
  652. if (c == null) {
  653. return;
  654. }
  655. c.setExecutable("cvs");
  656. if (cvsPackage != null) {
  657. c.createArgument().setLine(cvsPackage);
  658. }
  659. if (this.compression > 0 && this.compression <= MAXIMUM_COMRESSION_LEVEL) {
  660. c.createArgument(true).setValue("-z" + this.compression);
  661. }
  662. if (quiet) {
  663. c.createArgument(true).setValue("-q");
  664. }
  665. if (noexec) {
  666. c.createArgument(true).setValue("-n");
  667. }
  668. if (cvsRoot != null) {
  669. c.createArgument(true).setLine("-d" + cvsRoot);
  670. }
  671. }
  672. /**
  673. * remove a particular command from a vector of command lines
  674. * @param c command line which should be removed
  675. */
  676. protected void removeCommandline(Commandline c) {
  677. vecCommandlines.removeElement(c);
  678. }
  679. /**
  680. * Adds direct command-line to execute.
  681. * @param c command line to execute
  682. */
  683. public void addConfiguredCommandline(Commandline c) {
  684. this.addConfiguredCommandline(c, false);
  685. }
  686. /**
  687. * Configures and adds the given Commandline.
  688. * @param c commandline to insert
  689. * @param insertAtStart If true, c is
  690. * inserted at the beginning of the vector of command lines
  691. */
  692. public void addConfiguredCommandline(Commandline c,
  693. boolean insertAtStart) {
  694. if (c == null) {
  695. return;
  696. }
  697. this.configureCommandline(c);
  698. if (insertAtStart) {
  699. vecCommandlines.insertElementAt(c, 0);
  700. } else {
  701. vecCommandlines.addElement(c);
  702. }
  703. }
  704. /**
  705. * If set to a value 1-9 it adds -zN to the cvs command line, else
  706. * it disables compression.
  707. * @param level compression level 1 to 9
  708. */
  709. public void setCompressionLevel(int level) {
  710. this.compression = level;
  711. }
  712. /**
  713. * If true, this is the same as compressionlevel="3".
  714. *
  715. * @param usecomp If true, turns on compression using default
  716. * level, AbstractCvsTask.DEFAULT_COMPRESSION_LEVEL.
  717. */
  718. public void setCompression(boolean usecomp) {
  719. setCompressionLevel(usecomp
  720. ? AbstractCvsTask.DEFAULT_COMPRESSION_LEVEL : 0);
  721. }
  722. }