Skip to content

Package: MainImond

MainImond

nameinstructionbranchcomplexitylinemethod
readIntegerConsoleInput()
M: 31 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
readStringConsoleInput()
M: 22 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
receiveCommandsRun(String, String)
M: 161 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 26 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package update.remote.imond;
2:
3: import java.io.BufferedReader;
4: import java.io.IOException;
5: import java.io.InputStreamReader;
6: import java.nio.charset.Charset;
7:
8: /**
9: * This is the main class for updating the router with imond.
10: *
11: * @author Patrick Kriegel
12: *
13: */
14: // TODO: ACHTUNG, da die Klasse nicht vollständig zu sein scheint, werden die PMD-Warnungen dieser
15: // Klasse vorerst ignoriert,
16: // WICHTIG: Wenn die Klasse fertig ist, bitte die folgenden beiden Zeilen wieder löschen!!!!!
17: // This will suppress all the PMD warnings in this class
18: @SuppressWarnings({ "PMD", "unused" })
19: public final class MainImond {
20:
21:         /**
22:          * UTF-8.
23:          */
24:         private static final String UTF_8 = "UTF-8";
25:
26:         /**
27:          * This is the constructor. No side-effects.
28:          */
29:         private MainImond() {
30:         }
31:
32:         /**
33:          * This attribute represents the server ip for the connection.
34:          */
35:         private static String server = "";
36:         /**
37:          * This attribute represents the password for the connection.
38:          */
39:         private static String password = "";
40:         /**
41:          * This attribute represents the port for the connection.
42:          */
43:         private static int port = 0000;
44:         /**
45:          * This attribute represents the value if the user will update again (true) or not (false).
46:          */
47:         private static Boolean updateAgain = true;
48:         /**
49:          * This attribute represents the SynchronizeCommunication for the communication with imond.
50:          */
51:         private static final SynchronizeCommunication SYNCHRONIZECOMMUNICATION =
52:                         new SynchronizeCommunication();
53:         /**
54:          * This attribute represents the SynchronizeLogic for the communication with imond.
55:          */
56:         private static final SynchronizeLogic SYNCHRONIZELOGIC =
57:                         new SynchronizeLogic(SYNCHRONIZECOMMUNICATION);
58:         /**
59:          * buildPath.
60:          */
61:         private static String buildPath = "";
62:
63:         // /**
64:         // * This method runs the program. It connects to the router and queries the password. It
65:         // * instructs the imond to receive the update file.
66:         // *
67:         // * @param args
68:         // * the args
69:         // * @throws CommunicationException
70:         // * If the connection failed.
71:         // * @throws IOException
72:         // * Exception, if there are problems with reading files.
73:         // */
74:         // public static void main(final String[] args) throws CommunicationException, IOException {
75:         //
76:         // try {
77:         // System.out.println(ImondConstants.WELCOME);
78:         // System.out.println(ImondConstants.SERVER);
79:         // server = readStringConsoleInput();
80:         // } catch (final Exception e) {
81:         // throw new CommunicationException(ImondConstants.EME_IPREADPROBLEM + e);
82:         // }
83:         //
84:         // try {
85:         // System.out.println(ImondConstants.PORT);
86:         // port = readIntegerConsoleInput();
87:         // } catch (final Exception e) {
88:         // throw new CommunicationException(ImondConstants.EME_PORTREADPROBLEM + e);
89:         // }
90:         //
91:         // try {
92:         // SYNCHRONIZECOMMUNICATION.connect(server, port);
93:         // System.out.println(ImondConstants.SOCKETSUCCESFULLY);
94:         // } catch (final Exception e) {
95:         // throw new CommunicationException(ImondConstants.EME_IPORPORTWRONG + e);
96:         // }
97:         //
98:         // final String checkPassNeeded = SYNCHRONIZECOMMUNICATION.pass();
99:         // final StringTokenizer st = new StringTokenizer(checkPassNeeded, ImondConstants.SPACE);
100:         // st.nextToken();
101:         // final String result = st.nextToken().trim();
102:         //
103:         // if (Integer.parseInt(result) != ImondConstants.FOUR) {
104:         // try {
105:         // System.out.println(ImondConstants.PASSWORD);
106:         // password = readStringConsoleInput();
107:         // } catch (final Exception e) {
108:         // throw new CommunicationException(ImondConstants.EME_PASSWORDREADPROBLEM + e);
109:         // }
110:         //
111:         // try {
112:         // SYNCHRONIZELOGIC.authenticate(password);
113:         // System.out.println(ImondConstants.AUTHENTICATIONSUCCESSFULLY);
114:         // } catch (final Exception e) {
115:         // throw new CommunicationException(ImondConstants.EME_AUTHENTICATIONPROBLEM + e);
116:         // }
117:         // }
118:         //
119:         // while (updateAgain) {
120:         //
121:         // try {
122:         // System.out.println(ImondConstants.FILEOFBUILDPATH);
123:         // buildPath = readStringConsoleInput();
124:         // } catch (final Exception e) {
125:         // throw new CommunicationException(ImondConstants.EME_FILESIZEREADPROBLEM + e);
126:         // }
127:         //
128:         // receiveCommandsRun(buildPath, password);
129:         //
130:         // try {
131:         // System.out.println(ImondConstants.UPDATEAGAIN);
132:         // final String decision = readStringConsoleInput();
133:         // if (ImondConstants.Y.equals(decision)) {
134:         // updateAgain = true;
135:         // } else if (ImondConstants.N.equals(decision)) {
136:         // updateAgain = false;
137:         // } else {
138:         // throw new CommunicationException(ImondConstants.EME_UPDATEAGAINWRONGCHAR);
139:         // }
140:         // } catch (final Exception e) {
141:         // throw new CommunicationException(ImondConstants.EME_UPDATEAGAINREADPROBLEM + e);
142:         // }
143:         // }
144:         //
145:         // try {
146:         // SYNCHRONIZECOMMUNICATION.disconnect();
147:         // System.out.println(ImondConstants.DISCONNECTSUCCESFULLY);
148:         // } catch (final Exception e) {
149:         // throw new CommunicationException(ImondConstants.EME_DISCONNECTPROBLEM + e);
150:         // }
151:         //
152:         // }
153:
154:         /**
155:          * This method reads the string input.
156:          *
157:          * @return input
158:          */
159:         private static String readStringConsoleInput() {
160:                 String input = "";
161:
162:                 try {
163:                         final BufferedReader in =
164:                                         new BufferedReader(new InputStreamReader(System.in, Charset.forName(UTF_8)));
165:                         input = in.readLine();
166:                 } catch (final IOException e) {
167:                         System.out.println(ImondConstants.EME_INPUTNOTRAEDABLE);
168:                 }
169:                 return input;
170:
171:         }
172:
173:         /**
174:          * This method reads the integer input.
175:          *
176:          * @return input
177:          */
178:         private static Integer readIntegerConsoleInput() {
179:                 String input = "";
180:                 Integer portnumber = 0;
181:                 try {
182:                         final BufferedReader bufferedReader =
183:                                         new BufferedReader(new InputStreamReader(System.in, Charset.forName(UTF_8)));
184:
185:•                        if (bufferedReader != null) {
186:                                 input = bufferedReader.readLine();
187:                         }
188:                         portnumber = Integer.parseInt(input);
189:                 } catch (final IOException e) {
190:                         System.out.println(ImondConstants.EME_INPUTNOTRAEDABLE);
191:                 }
192:                 return portnumber;
193:         }
194:
195:         /**
196:          * This method runs the receive method of SynchronizeCommunication for all files, which are
197:          * necessary for /boot/ on fli4l.
198:          *
199:          * @param buildPathLocal
200:          * Source of the files.
201:          * @param passwordLocal
202:          * password for fli4l.
203:          * @throws CommunicationException
204:          * Exception, if there are problems with sending the data.
205:          * @throws IOException
206:          * Exception, if there are problems with reading files.
207:          */
208:         private static void receiveCommandsRun(final String buildPathLocal,
209:                         final String passwordLocal) throws CommunicationException, IOException {
210:                 final String fileOptImg = buildPathLocal + ImondConstants.OPT_IMG;
211:                 final String fileKernel = buildPathLocal + ImondConstants.KERNEL;
212:                 final String fileRootfs = buildPathLocal + ImondConstants.ROOTFS_IMG;
213:                 final String fileRccfg = buildPathLocal + ImondConstants.RC_CFG;
214:                 final String fileSyslinux = buildPathLocal + ImondConstants.SYSLINUX_CFG;
215:
216:                 try {
217:                         SYNCHRONIZECOMMUNICATION.receiveFile(ImondConstants.BOOT_OPT_IMG, fileOptImg,
218:                                         passwordLocal);
219:                 } catch (final CommunicationException e) {
220:                         throw new CommunicationException(ImondConstants.EME_RECEIVEFILEERRORPARTONE
221:                                         + fileOptImg + ImondConstants.EME_RECEIVEFILEERRORPARTTWO + e);
222:                 }
223:
224:                 try {
225:                         SYNCHRONIZECOMMUNICATION.receiveFile(ImondConstants.BOOT_KERNEL, fileKernel,
226:                                         passwordLocal);
227:                 } catch (final CommunicationException e) {
228:                         throw new CommunicationException(ImondConstants.EME_RECEIVEFILEERRORPARTONE
229:                                         + fileKernel + ImondConstants.EME_RECEIVEFILEERRORPARTTWO + e);
230:                 }
231:
232:                 try {
233:                         SYNCHRONIZECOMMUNICATION.receiveFile(ImondConstants.BOOT_ROOTFS_IMG, fileRootfs,
234:                                         passwordLocal);
235:                 } catch (final CommunicationException e) {
236:                         throw new CommunicationException(ImondConstants.EME_RECEIVEFILEERRORPARTONE
237:                                         + fileRootfs + ImondConstants.EME_RECEIVEFILEERRORPARTTWO + e);
238:                 }
239:
240:                 try {
241:                         SYNCHRONIZECOMMUNICATION.receiveFile(ImondConstants.BOOT_RC_CFG, fileRccfg,
242:                                         passwordLocal);
243:                 } catch (final CommunicationException e) {
244:                         throw new CommunicationException(ImondConstants.EME_RECEIVEFILEERRORPARTONE
245:                                         + fileRccfg + ImondConstants.EME_RECEIVEFILEERRORPARTTWO + e);
246:                 }
247:                 try {
248:                         SYNCHRONIZECOMMUNICATION.receiveFile(ImondConstants.BOOT_SYSLINUX_CFG, fileSyslinux,
249:                                         passwordLocal);
250:                 } catch (final CommunicationException e) {
251:                         throw new CommunicationException(ImondConstants.EME_RECEIVEFILEERRORPARTONE
252:                                         + fileSyslinux + ImondConstants.EME_RECEIVEFILEERRORPARTTWO + e);
253:                 }
254:
255:         }
256: }