1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.testdoc.core.adapter;
17
18 import java.io.File;
19 import java.io.IOException;
20 import java.net.URI;
21
22 import javax.annotation.processing.Filer;
23 import javax.lang.model.element.Element;
24 import javax.tools.FileObject;
25 import javax.tools.StandardLocation;
26
27 import de.smartics.testdoc.core.doc.FileHelper;
28 import de.smartics.testdoc.core.doc.Type;
29
30
31
32
33
34
35
36 public class FilerExportAdapter extends AbstractFileBasedExportAdapter
37 {
38
39
40
41
42
43
44
45
46
47 private final Filer filer;
48
49
50
51
52
53
54
55
56 public FilerExportAdapter(final Filer filer)
57 {
58 this.filer = filer;
59 }
60
61
62
63
64
65
66
67
68
69
70
71 @Override
72 protected File[] createFileRefs(final Type testCaseType)
73 throws IllegalStateException
74 {
75 try
76 {
77 final FileObject fileObject =
78 filer.createResource(StandardLocation.SOURCE_OUTPUT,
79 "de.smartics.testdoc.ser", testCaseType.toString() + ".ser",
80 (Element[]) null);
81 final File file = createFile(fileObject);
82 final File dir = file.getParentFile();
83 return createFileRefs(testCaseType, dir);
84 }
85 catch (IOException e)
86 {
87 throw new IllegalStateException(
88 "Cannot create file object to for test case type '" + testCaseType
89 + "'.");
90 }
91 }
92
93 private File createFile(final FileObject fileObject)
94 {
95 final URI uri = fileObject.toUri();
96 try
97 {
98 final File file = new File(uri);
99 return file;
100 }
101 catch (final IllegalArgumentException e)
102 {
103 throw new IllegalStateException("Cannot create file with URI '" + uri
104 + "'.", e);
105 }
106 }
107
108 @Override
109 protected File createFileRef(final Type testCaseType, final Type uutType)
110 {
111 try
112 {
113 final FileObject fileObject =
114 filer.createResource(StandardLocation.SOURCE_OUTPUT,
115 "de.smartics.testdoc.ser", testCaseType.toString() + '-'
116 + uutType.toString() + ".ser",
117 (Element[]) null);
118 final File file = new File(fileObject.toUri());
119 FileHelper.provideDir(file.getParentFile());
120 return file;
121 }
122 catch (final IOException e)
123 {
124 throw new IllegalStateException(
125 "Cannot create file object to for test case type '" + testCaseType
126 + " and UUT type '" + uutType + "'.");
127 }
128 }
129
130
131
132 }