1 | |
package net.sf.statsvn.util.svnkit; |
2 | |
|
3 | |
import java.io.File; |
4 | |
import java.io.IOException; |
5 | |
import java.util.ArrayList; |
6 | |
import java.util.List; |
7 | |
|
8 | |
import net.sf.statsvn.output.SvnConfigurationOptions; |
9 | |
import net.sf.statsvn.util.ISvnProcessor; |
10 | |
import net.sf.statsvn.util.SvnPropgetUtils; |
11 | |
|
12 | |
import org.tmatesoft.svn.core.SVNDepth; |
13 | |
import org.tmatesoft.svn.core.SVNException; |
14 | |
import org.tmatesoft.svn.core.SVNProperty; |
15 | |
import org.tmatesoft.svn.core.SVNURL; |
16 | |
import org.tmatesoft.svn.core.wc.ISVNPropertyHandler; |
17 | |
import org.tmatesoft.svn.core.wc.SVNClientManager; |
18 | |
import org.tmatesoft.svn.core.wc.SVNPropertyData; |
19 | |
import org.tmatesoft.svn.core.wc.SVNRevision; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | 0 | public class SvnKitPropget extends SvnPropgetUtils { |
28 | |
|
29 | |
protected class SvnKitPropertyHandler implements ISVNPropertyHandler { |
30 | |
|
31 | |
protected List binaryFiles; |
32 | |
SvnKitPropget propgetUtils; |
33 | |
|
34 | 0 | public SvnKitPropertyHandler(SvnKitPropget propgetUtils, List binaryFiles) { |
35 | 0 | this.binaryFiles = binaryFiles; |
36 | 0 | this.propgetUtils = propgetUtils; |
37 | 0 | } |
38 | |
|
39 | |
protected List getBinaryFiles() { |
40 | 0 | return binaryFiles; |
41 | |
} |
42 | |
|
43 | |
protected SvnKitPropget getPropgetUtils() { |
44 | 0 | return propgetUtils; |
45 | |
} |
46 | |
|
47 | |
public void handleProperty(File file, SVNPropertyData data) throws SVNException { |
48 | 0 | if (isBinary(data)) { |
49 | 0 | String relativePath = file.getAbsoluteFile().getAbsolutePath().substring( |
50 | |
getPropgetUtils().getCheckoutDirectory().getAbsoluteFile().getAbsolutePath().length()+1); |
51 | 0 | binaryFiles.add(relativePath.replace(File.separatorChar, '/')); |
52 | |
} |
53 | 0 | } |
54 | |
|
55 | |
public void handleProperty(long revision, SVNPropertyData data) throws SVNException { |
56 | |
|
57 | 0 | } |
58 | |
|
59 | |
public void handleProperty(SVNURL url, SVNPropertyData data) throws SVNException { |
60 | 0 | if (getPropgetUtils().isBinary(data)) { |
61 | 0 | String path = getPropgetUtils().getProcessor().getInfoProcessor().urlToRelativePath(url.toString()); |
62 | |
|
63 | 0 | binaryFiles.add(path.replace(File.separatorChar, '/')); |
64 | |
} |
65 | 0 | } |
66 | |
|
67 | |
} |
68 | |
|
69 | |
public SvnKitPropget(ISvnProcessor processor) { |
70 | 0 | super(processor); |
71 | 0 | } |
72 | |
|
73 | |
public List getBinaryFiles() { |
74 | 0 | if (binaryFiles == null) { |
75 | |
|
76 | 0 | binaryFiles = new ArrayList(); |
77 | |
try { |
78 | |
|
79 | 0 | getManager().getWCClient().doGetProperty(getCheckoutDirectory(), SVNProperty.MIME_TYPE, SVNRevision.WORKING, SVNRevision.WORKING, |
80 | |
SVNDepth.INFINITY, new SvnKitPropertyHandler(this, binaryFiles), null); |
81 | 0 | } catch (SVNException e) { |
82 | |
try { |
83 | 0 | handleSvnException(e); |
84 | 0 | } catch (IOException ex) { |
85 | 0 | } |
86 | 0 | } |
87 | |
} |
88 | |
|
89 | 0 | return binaryFiles; |
90 | |
} |
91 | |
|
92 | |
public File getCheckoutDirectory() { |
93 | 0 | return getSvnKitProcessor().getCheckoutDirectory(); |
94 | |
} |
95 | |
|
96 | |
public SVNClientManager getManager() { |
97 | 0 | return getSvnKitProcessor().getManager(); |
98 | |
} |
99 | |
|
100 | |
public SvnKitProcessor getSvnKitProcessor() { |
101 | 0 | return (SvnKitProcessor) getProcessor(); |
102 | |
} |
103 | |
|
104 | |
protected void handleSvnException(SVNException ex) throws IOException { |
105 | 0 | String msg = "svn propget " + ex.getMessage(); |
106 | 0 | SvnConfigurationOptions.getTaskLogger().error(msg); |
107 | 0 | throw new IOException(msg); |
108 | |
} |
109 | |
|
110 | |
protected boolean isBinary(SVNPropertyData data) { |
111 | 0 | return data != null && (data.getValue().toString().equals("application/octet-stream") || data.getValue().toString().indexOf("text/") < 0); |
112 | |
} |
113 | |
|
114 | |
public boolean isBinaryFile(final String revision, final String filename) { |
115 | |
try { |
116 | |
|
117 | 0 | SVNPropertyData data = getManager().getWCClient().doGetProperty(new File(filename), SVNProperty.MIME_TYPE, SVNRevision.parse(revision), |
118 | |
SVNRevision.parse(revision)); |
119 | 0 | return isBinary(data); |
120 | 0 | } catch (SVNException e) { |
121 | |
try { |
122 | 0 | handleSvnException(e); |
123 | 0 | } catch (IOException ex) { |
124 | 0 | } |
125 | 0 | return false; |
126 | |
} |
127 | |
} |
128 | |
} |
129 | |
|