/bundles/plugins-trunk/SVNPlugin/src/ise/plugin/svn/data/SVNData.java

# · Java · 275 lines · 150 code · 32 blank · 93 comment · 16 complexity · 3bbab7262c25dc4098c119c81d1da158 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.data;
  26. import java.io.*;
  27. import java.lang.reflect.Field;
  28. import java.util.*;
  29. import ise.plugin.svn.io.ConsolePrintStream;
  30. import ise.plugin.svn.library.PasswordHandler;
  31. import ise.plugin.svn.library.PrivilegedAccessor;
  32. /**
  33. * Base class to contain data to pass to the various subversion commands.
  34. */
  35. public class SVNData implements Serializable {
  36. private static final long serialVersionUID = 42L;
  37. private transient ConsolePrintStream out;
  38. private transient ConsolePrintStream err;
  39. private List<String> paths;
  40. private boolean pathsAreUrls = false;
  41. private String username = null;
  42. private String password = null;
  43. private boolean recursive = false;
  44. private boolean force = false;
  45. private boolean dryRun = false;
  46. private boolean remote = true;
  47. public SVNData() {}
  48. public SVNData( ConsolePrintStream out,
  49. ConsolePrintStream err,
  50. List<String> paths,
  51. String username,
  52. String password,
  53. boolean recursive ) {
  54. this.out = out;
  55. this.err = err;
  56. this.paths = paths;
  57. this.username = username;
  58. this.password = password;
  59. this.recursive = recursive;
  60. }
  61. /**
  62. * Returns the value of out.
  63. */
  64. public ConsolePrintStream getOut() {
  65. return out;
  66. }
  67. /**
  68. * Sets the value of out.
  69. * @param out The value to assign out.
  70. */
  71. public void setOut( ConsolePrintStream out ) {
  72. this.out = out;
  73. }
  74. /**
  75. * Returns the value of err.
  76. */
  77. public ConsolePrintStream getErr() {
  78. return err;
  79. }
  80. /**
  81. * Sets the value of err.
  82. * @param err The value to assign err.
  83. */
  84. public void setErr( ConsolePrintStream err ) {
  85. this.err = err;
  86. }
  87. /**
  88. * Returns the value of paths.
  89. */
  90. public List<String> getPaths() {
  91. return new ArrayList<String>( paths );
  92. }
  93. /**
  94. * Sets the value of paths.
  95. * @param paths The value to assign paths.
  96. */
  97. public void setPaths( List<String> paths ) {
  98. this.paths = paths;
  99. }
  100. public void addPath( String path ) {
  101. if ( paths == null ) {
  102. paths = new ArrayList<String>();
  103. }
  104. paths.add( path );
  105. }
  106. public boolean pathsAreURLs() {
  107. return pathsAreUrls;
  108. }
  109. public void setPathsAreURLs( boolean b ) {
  110. pathsAreUrls = b;
  111. }
  112. /**
  113. * Returns the value of username, returns null if previously set to empty string.
  114. */
  115. public String getUsername() {
  116. return username == null || username.length() == 0 ? null : username;
  117. }
  118. /**
  119. * Sets the value of username.
  120. * @param username The value to assign username.
  121. */
  122. public void setUsername( String username ) {
  123. this.username = username;
  124. }
  125. /**
  126. * Returns the value of password, returns null if previously set to empty string.
  127. */
  128. public String getPassword() {
  129. return password == null || password.length() == 0 ? null : password;
  130. }
  131. public String getDecryptedPassword() {
  132. return PasswordHandler.decryptPassword( password );
  133. }
  134. /**
  135. * Sets the value of encrypted password.
  136. * @param password The value to assign password.
  137. */
  138. public void setPassword( String password ) {
  139. this.password = password;
  140. }
  141. /**
  142. * Returns the value of recursive.
  143. */
  144. public boolean getRecursive() {
  145. return recursive;
  146. }
  147. /**
  148. * Sets the value of recursive.
  149. * @param recursive The value to assign recursive.
  150. */
  151. public void setRecursive( boolean recursive ) {
  152. this.recursive = recursive;
  153. }
  154. /**
  155. * Returns the value of force.
  156. */
  157. public boolean getForce() {
  158. return force;
  159. }
  160. /**
  161. * Sets the value of force.
  162. * @param force The value to assign force.
  163. */
  164. public void setForce( boolean force ) {
  165. this.force = force;
  166. }
  167. /**
  168. * Returns the value of dryRun.
  169. */
  170. public boolean getDryRun() {
  171. return dryRun;
  172. }
  173. /**
  174. * Sets the value of dryRun.
  175. * @param dryRun The value to assign dryRun.
  176. */
  177. public void setDryRun( boolean dryRun ) {
  178. this.dryRun = dryRun;
  179. }
  180. /**
  181. * Returns the value of remote.
  182. */
  183. public boolean getRemote() {
  184. return remote;
  185. }
  186. /**
  187. * Set whether this data represents about a working copy or a remote/repository
  188. * copy of a file or directory.
  189. */
  190. public void setRemote( boolean b ) {
  191. remote = b;
  192. }
  193. public String toString() {
  194. StringBuffer sb = new StringBuffer();
  195. try {
  196. sb.append( this.getClass().getName() ).append( '[' );
  197. Field[] fields = this.getClass().getDeclaredFields();
  198. for ( Field field : fields ) {
  199. sb.append( field.getName() ).append( '=' ).append( PrivilegedAccessor.getValue( this, field.getName() ) ).append( ',' );
  200. }
  201. sb.append( ']' );
  202. }
  203. catch ( Exception e ) {
  204. e.printStackTrace();
  205. }
  206. return sb.toString();
  207. }
  208. public static String toString( Object data ) {
  209. if ( data == null ) {
  210. return "null";
  211. }
  212. StringBuffer sb = new StringBuffer();
  213. try {
  214. sb.append( data.getClass().getName() ).append( '\n' );
  215. Field[] fields = data.getClass().getDeclaredFields();
  216. List<String> fieldNames = new ArrayList<String>();
  217. for ( Field field : fields ) {
  218. fieldNames.add( field.getName() );
  219. }
  220. Collections.sort( fieldNames );
  221. int longest = 0;
  222. for ( String name : fieldNames ) {
  223. if ( name.length() > longest ) {
  224. longest = name.length();
  225. }
  226. }
  227. String padding = " ";
  228. for ( String name : fieldNames ) {
  229. if ( "password".equals( name ) ) {
  230. continue;
  231. }
  232. sb.append( '\t' ).append( padding.substring( 0, longest - name.length() ) ).append( name ).append( ": " ).append( PrivilegedAccessor.getValue( data, name ) ).append( '\n' );
  233. }
  234. }
  235. catch ( Exception e ) {
  236. e.printStackTrace();
  237. }
  238. return sb.toString();
  239. }
  240. }