Skip to content

Package: DepReader

DepReader

nameinstructionbranchcomplexitylinemethod
DepReader()
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createDep(String)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
createModule(String)
M: 0 C: 29
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getDepfile()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
read(String)
M: 0 C: 55
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
splitDepsInParts(String)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
splitFileInLines(String)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
splitLineInParts(String)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
splitModule(String)
M: 0 C: 55
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 14
100%
M: 0 C: 1
100%

Coverage

1: /**
2: *
3: */
4: package kernelmodules;
5:
6: import reader.ReaderException;
7: import scanner.ScannerConstants;
8:
9: /**
10: * @author Hendrik
11: *
12: */
13: public class DepReader {
14:         /**
15:          * The current Dependencyfile.
16:          */
17:         private final DepFile depfile;
18:         /**
19:          * the current depEntry.
20:          */
21:         private DepEntry depEntry;
22:
23:         /**
24:          *
25:          */
26:
27:         public DepReader() {
28:                 super();
29:                 this.depfile = new DepFile();
30:                 this.depEntry = new DepEntry(null);
31:
32:         }
33:
34:         /**
35:          * reads the file.
36:          *
37:          * @param pathToRead
38:          * path to the file to read.
39:          * @throws ReaderException
40:          * if it fails.
41:          */
42:         public void read(final String pathToRead) throws ReaderException {
43:                 final String input = reader.FileReader.read(pathToRead);
44:
45:                 final String[] lines = splitFileInLines(input);
46:•                for (int i = 0; i < lines.length; i++) {
47:                         final String[] line = splitLineInParts(lines[i]);
48:                         int j = 0;
49:•                        while (j < line.length) {
50:                                 createModule(line[j]);
51:                                 j++;
52:                                 final String[] deps = splitDepsInParts(line[j]);
53:                                 int k = 0;
54:•                                while (k < deps.length) {
55:                                         createDep(deps[k]); // Leerer String oder Null?
56:                                         k++;
57:                                 }
58:                                 j++;
59:                         }
60:                 }
61:         }
62:
63:         /**
64:          * split the file in lines.
65:          *
66:          * @param file
67:          * Datei.
68:          * @return List of Lines
69:          */
70:         public String[] splitFileInLines(final String file) {
71:                 return file.split(ScannerConstants.NEWLINE.toString());
72:         }
73:
74:         /**
75:          * split the line in parts.
76:          *
77:          * @param line
78:          * Zeile.
79:          * @return List of Parts
80:          */
81:         public String[] splitLineInParts(final String line) {
82:                 return line.split(ScannerConstants.COLONSIGN.toString());
83:         }
84:
85:         /**
86:          * splits the Dependencies in parts.
87:          *
88:          * @param deps
89:          * dependency
90:          * @return List of Deps
91:          */
92:         public String[] splitDepsInParts(final String deps) {
93:                 return deps.split(ScannerConstants.SPACE.toString());
94:         }
95:
96:         /**
97:          * This function creates a new Module.
98:          *
99:          * @param module
100:          * module as String
101:          */
102:         public void createModule(final String module) {
103:                 final String[] moduleParts = splitModule(module);
104:                 final Module newMod = new Module(moduleParts[0], moduleParts[1]);
105:                 this.depEntry = new DepEntry(newMod);
106:                 this.depfile.addDepEntry(this.depEntry);
107:                 ModMgr.getTheInstance().addModule(newMod);
108:         }
109:
110:         /**
111:          * This function creats a new dependency.
112:          *
113:          * @param dep
114:          * dep as String
115:          */
116:         public void createDep(final String dep) {
117:                 final String[] splitDep = splitModule(dep);
118:                 final Module moduleDep = new Module(splitDep[0], splitDep[1]);
119:                 // TODO: Rekursion Abhängigkeiten von abhängigen Paketen überprüfen
120:                 this.depEntry.addDeps(moduleDep);
121:                 ModMgr.getTheInstance().addModule(moduleDep);
122:         }
123:
124:         /**
125:          * This function split the String Modul in name and path.
126:          *
127:          * @param module
128:          * the module as String
129:          * @return String[0] = name; String[1] = path;
130:          */
131:         protected String[] splitModule(final String module) {
132:                 final String[] parts = module.split(ScannerConstants.SLASH.toString());
133:                 final int nameInt = parts.length - 1;
134:                 final String name = parts[nameInt];
135:                 final StringBuffer buf = new StringBuffer();
136:                 int i = 0;
137:
138:•                while (i < parts.length - 1) {
139:                         buf.append(parts[i]);
140:                         buf.append(ScannerConstants.SLASH.toString());
141:                         i++;
142:                 }
143:                 final String path = buf.toString();
144:
145:                 final String[] returnArray = new String[2];
146:                 returnArray[0] = name;
147:                 returnArray[1] = path;
148:                 return returnArray;
149:         }
150:
151:         /**
152:          * @return the depfile
153:          */
154:         protected DepFile getDepfile() {
155:                 return this.depfile;
156:         }
157: }