/plugins/SVNPlugin/tags/0.5/trunk/src/ise/plugin/svn/command/Delete.java

# · Java · 100 lines · 49 code · 16 blank · 35 comment · 8 complexity · d2056faf64dde4816019366c6082375d MD5 · raw file

  1. /*
  2. Copyright (c) 2007, Dale Anson
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without modification,
  5. are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright notice,
  9. this list of conditions and the following disclaimer in the documentation
  10. and/or other materials provided with the distribution.
  11. * Neither the name of the author nor the names of its contributors
  12. may be used to endorse or promote products derived from this software without
  13. specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  21. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. package ise.plugin.svn.command;
  26. import java.io.*;
  27. import java.util.*;
  28. import org.tmatesoft.svn.core.wc.ISVNOptions;
  29. import org.tmatesoft.svn.core.wc.SVNClientManager;
  30. import org.tmatesoft.svn.cli.command.SVNCommandEventProcessor;
  31. import org.tmatesoft.svn.core.SVNException;
  32. import org.tmatesoft.svn.core.wc.SVNWCClient;
  33. import org.tmatesoft.svn.core.wc.SVNWCUtil;
  34. import ise.plugin.svn.data.DeleteData;
  35. import ise.plugin.svn.data.DeleteResults;
  36. public class Delete {
  37. public DeleteResults delete( DeleteData data ) throws CommandInitializationException, SVNException {
  38. // validate data values
  39. if ( data.getPaths() == null ) {
  40. return null; // nothing to do
  41. }
  42. if ( data.getOut() == null ) {
  43. throw new CommandInitializationException( "Invalid output stream." );
  44. }
  45. if ( data.getErr() == null ) {
  46. data.setErr( data.getOut() );
  47. }
  48. // convert paths to Files
  49. List<String> paths = data.getPaths();
  50. File[] localPaths = new File[ paths.size() ];
  51. for ( int i = 0; i < paths.size(); i++ ) {
  52. localPaths[ i ] = new File( paths.get( i ) );
  53. // check for file existence?
  54. }
  55. // use default svn config options
  56. ISVNOptions options = SVNWCUtil.createDefaultOptions( true );
  57. // use the svnkit client manager
  58. SVNClientManager clientManager = SVNClientManager.newInstance( options, data.getUsername(), data.getPassword() );
  59. // get a commit client
  60. SVNWCClient client = clientManager.getWCClient();
  61. // set an event handler so that messages go to the commit data streams for display
  62. client.setEventHandler( new SVNCommandEventProcessor( data.getOut(), data.getErr(), false ) );
  63. // actually do the deletes(s)
  64. PrintStream out = data.getOut();
  65. DeleteResults results = new DeleteResults();
  66. for ( String path : paths ) {
  67. try {
  68. File file = new File(path);
  69. client.doDelete( file, data.getForce(), data.getDeleteFiles(), data.getDryRun() );
  70. results.addPath(path);
  71. }
  72. catch ( Exception e ) {
  73. out.println( e.getMessage() );
  74. results.addErrorPath(path, e.getMessage());
  75. }
  76. }
  77. out.flush();
  78. out.close();
  79. return results;
  80. }
  81. }