1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.job.history.internal; |
21 |
|
|
22 |
|
import java.io.BufferedWriter; |
23 |
|
import java.io.File; |
24 |
|
import java.io.FileReader; |
25 |
|
import java.io.FileWriter; |
26 |
|
import java.io.IOException; |
27 |
|
import java.io.Reader; |
28 |
|
import java.io.StringReader; |
29 |
|
import java.io.Writer; |
30 |
|
import java.util.List; |
31 |
|
|
32 |
|
import javax.inject.Singleton; |
33 |
|
|
34 |
|
import org.xwiki.component.annotation.Component; |
35 |
|
import org.xwiki.extension.job.history.ExtensionJobHistoryRecord; |
36 |
|
import org.xwiki.extension.job.history.ExtensionJobHistorySerializer; |
37 |
|
import org.xwiki.job.internal.xstream.SafeXStream; |
38 |
|
|
39 |
|
import com.thoughtworks.xstream.XStream; |
40 |
|
|
41 |
|
|
42 |
|
@link |
43 |
|
|
44 |
|
@version |
45 |
|
@since |
46 |
|
|
47 |
|
@Component |
48 |
|
@Singleton |
|
|
| 35% |
Uncovered Elements: 13 (20) |
Complexity: 11 |
Complexity Density: 0.85 |
|
49 |
|
public class DefaultExtensionJobHistorySerializer implements ExtensionJobHistorySerializer |
50 |
|
{ |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
private XStream xstream = new SafeXStream(); |
55 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
0 |
@Override... |
57 |
|
public String serialize(ExtensionJobHistoryRecord record) |
58 |
|
{ |
59 |
0 |
return this.xstream.toXML(record); |
60 |
|
} |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
42 |
@Override... |
63 |
|
public void write(ExtensionJobHistoryRecord record, Writer writer) |
64 |
|
{ |
65 |
42 |
this.xstream.toXML(record, writer); |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 3 |
Complexity Density: 0.75 |
|
68 |
42 |
@Override... |
69 |
|
public void append(ExtensionJobHistoryRecord record, File historyFile) throws IOException |
70 |
|
{ |
71 |
42 |
historyFile.getParentFile().mkdirs(); |
72 |
42 |
try (BufferedWriter writer = new BufferedWriter(new FileWriter(historyFile, true))) { |
73 |
42 |
write(record, writer); |
74 |
|
} |
75 |
|
} |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
0 |
@Override... |
78 |
|
public List<ExtensionJobHistoryRecord> deserialize(String serializedRecords) |
79 |
|
{ |
80 |
0 |
return this.read(new StringReader(serializedRecords)); |
81 |
|
} |
82 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
83 |
0 |
@SuppressWarnings("unchecked")... |
84 |
|
@Override |
85 |
|
public List<ExtensionJobHistoryRecord> read(Reader reader) |
86 |
|
{ |
87 |
0 |
Reader listReader = new CompositeReader(new StringReader("<list>"), reader, new StringReader("</list>")); |
88 |
0 |
return (List<ExtensionJobHistoryRecord>) this.xstream.fromXML(listReader); |
89 |
|
} |
90 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 1 |
|
91 |
0 |
@Override... |
92 |
|
public List<ExtensionJobHistoryRecord> read(File historyFile) throws IOException |
93 |
|
{ |
94 |
0 |
try (FileReader reader = new FileReader(historyFile)) { |
95 |
0 |
return read(reader); |
96 |
|
} |
97 |
|
} |
98 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
99 |
0 |
@Override... |
100 |
|
public List<ExtensionJobHistoryRecord> clone(List<ExtensionJobHistoryRecord> records) |
101 |
|
{ |
102 |
0 |
return deserialize(this.xstream.toXML(records)); |
103 |
|
} |
104 |
|
} |