1 | |
package net.sf.statsvn.util.svnkit; |
2 | |
|
3 | |
import java.io.File; |
4 | |
import java.io.IOException; |
5 | |
|
6 | |
import net.sf.statcvs.input.LogSyntaxException; |
7 | |
import net.sf.statsvn.output.SvnConfigurationOptions; |
8 | |
import net.sf.statsvn.util.ISvnProcessor; |
9 | |
import net.sf.statsvn.util.SvnInfoUtils; |
10 | |
import net.sf.statsvn.util.SvnVersionMismatchException; |
11 | |
|
12 | |
import org.tmatesoft.svn.core.SVNDepth; |
13 | |
import org.tmatesoft.svn.core.SVNException; |
14 | |
import org.tmatesoft.svn.core.wc.SVNClientManager; |
15 | |
import org.tmatesoft.svn.core.wc.xml.SVNXMLInfoHandler; |
16 | |
import org.xml.sax.Attributes; |
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
public class SvnKitInfo extends SvnInfoUtils { |
26 | |
|
27 | |
protected static class SvnKitInfoHandler extends SvnInfoUtils.SvnInfoHandler { |
28 | |
|
29 | |
public SvnKitInfoHandler(SvnInfoUtils infoUtils) { |
30 | 0 | super(infoUtils); |
31 | 0 | } |
32 | |
|
33 | |
protected boolean isRootFolder(Attributes attributes) { |
34 | 0 | String path = attributes.getValue("path"); |
35 | |
|
36 | 0 | return (path.equals(".") || new File(path).equals(((SvnKitInfo) getInfoUtils()).getCheckoutDirectory())) |
37 | |
&& attributes.getValue("kind").equals("dir"); |
38 | |
} |
39 | |
|
40 | |
} |
41 | |
|
42 | |
public SvnKitInfo(ISvnProcessor processor) { |
43 | 0 | super(processor); |
44 | 0 | } |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
public synchronized void checkRepoRootAvailable() throws SvnVersionMismatchException { |
54 | |
|
55 | |
try { |
56 | 0 | loadInfo(true); |
57 | 0 | if (getRootUrl() != null) |
58 | 0 | return; |
59 | 0 | } catch (Exception e) { |
60 | 0 | SvnConfigurationOptions.getTaskLogger().info(e.getMessage()); |
61 | 0 | } |
62 | |
|
63 | 0 | throw new SvnVersionMismatchException(SVN_REPO_ROOT_NOTFOUND); |
64 | |
} |
65 | |
|
66 | |
public File getCheckoutDirectory() { |
67 | 0 | return getSvnKitProcessor().getCheckoutDirectory(); |
68 | |
} |
69 | |
|
70 | |
public SVNClientManager getManager() { |
71 | 0 | return getSvnKitProcessor().getManager(); |
72 | |
} |
73 | |
|
74 | |
public SvnKitProcessor getSvnKitProcessor() { |
75 | 0 | return (SvnKitProcessor) getProcessor(); |
76 | |
} |
77 | |
|
78 | |
protected void handleSvnException(SVNException ex) throws IOException { |
79 | 0 | String msg = "svn info " + ex.getMessage(); |
80 | 0 | SvnConfigurationOptions.getTaskLogger().error(msg); |
81 | 0 | throw new IOException(msg); |
82 | |
} |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
protected void loadInfo(final boolean bRootOnly) throws LogSyntaxException, IOException { |
95 | 0 | if (isQueryNeeded(true )) { |
96 | 0 | clearCache(); |
97 | |
|
98 | |
try { |
99 | 0 | SVNXMLInfoHandler handler = new SVNXMLInfoHandler(new SvnKitInfoHandler(this)); |
100 | 0 | handler.setTargetPath(getCheckoutDirectory()); |
101 | 0 | getManager().getWCClient().doInfo(getCheckoutDirectory(), null, null, SVNDepth.fromRecurse(!bRootOnly), null, |
102 | |
handler); |
103 | 0 | } catch (SVNException e) { |
104 | 0 | handleSvnException(e); |
105 | 0 | } |
106 | |
} |
107 | 0 | } |
108 | |
|
109 | |
} |