1 | /* $Id: ZargoFilePersister.java 19907 2012-12-30 13:06:01Z closettop_nightlybuild $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009-2012 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * tfmorris | |
11 | * Michiel van der Wulp | |
12 | ***************************************************************************** | |
13 | * | |
14 | * Some portions of this file was previously release using the BSD License: | |
15 | */ | |
16 | ||
17 | // Copyright (c) 1996-2008 The Regents of the University of California. All | |
18 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
19 | // software and its documentation without fee, and without a written | |
20 | // agreement is hereby granted, provided that the above copyright notice | |
21 | // and this paragraph appear in all copies. This software program and | |
22 | // documentation are copyrighted by The Regents of the University of | |
23 | // California. The software program and documentation are supplied "AS | |
24 | // IS", without any accompanying services from The Regents. The Regents | |
25 | // does not warrant that the operation of the program will be | |
26 | // uninterrupted or error-free. The end-user understands that the program | |
27 | // was developed for research purposes and is advised not to rely | |
28 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
29 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
30 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
31 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
32 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
33 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
34 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
35 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
36 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
37 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
38 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
39 | ||
40 | package org.argouml.persistence; | |
41 | ||
42 | import java.io.BufferedReader; | |
43 | import java.io.BufferedWriter; | |
44 | import java.io.File; | |
45 | import java.io.FileNotFoundException; | |
46 | import java.io.FileOutputStream; | |
47 | import java.io.FilterInputStream; | |
48 | import java.io.IOException; | |
49 | import java.io.InputStream; | |
50 | import java.io.InputStreamReader; | |
51 | import java.io.OutputStreamWriter; | |
52 | import java.io.PrintWriter; | |
53 | import java.io.Reader; | |
54 | import java.io.UnsupportedEncodingException; | |
55 | import java.io.Writer; | |
56 | import java.net.MalformedURLException; | |
57 | import java.net.URL; | |
58 | import java.util.ArrayList; | |
59 | import java.util.List; | |
60 | import java.util.logging.Level; | |
61 | import java.util.logging.Logger; | |
62 | import java.util.zip.ZipEntry; | |
63 | import java.util.zip.ZipInputStream; | |
64 | import java.util.zip.ZipOutputStream; | |
65 | ||
66 | import org.argouml.application.api.Argo; | |
67 | import org.argouml.application.helpers.ApplicationVersion; | |
68 | import org.argouml.i18n.Translator; | |
69 | import org.argouml.kernel.ProfileConfiguration; | |
70 | import org.argouml.kernel.Project; | |
71 | import org.argouml.kernel.ProjectFactory; | |
72 | import org.argouml.kernel.ProjectMember; | |
73 | import org.argouml.model.Model; | |
74 | import org.argouml.util.FileConstants; | |
75 | import org.argouml.util.ThreadUtils; | |
76 | import org.xml.sax.InputSource; | |
77 | import org.xml.sax.SAXException; | |
78 | ||
79 | /** | |
80 | * To persist to and from zargo (zipped file) storage. | |
81 | * | |
82 | * @author Bob Tarling | |
83 | */ | |
84 | class ZargoFilePersister extends UmlFilePersister { | |
85 | /** | |
86 | * Logger. | |
87 | */ | |
88 | private static final Logger LOG = | |
89 | Logger.getLogger(ZargoFilePersister.class.getName()); | |
90 | ||
91 | /** | |
92 | * The constructor. | |
93 | */ | |
94 | public ZargoFilePersister() { | |
95 | } | |
96 | ||
97 | /* | |
98 | * @see org.argouml.persistence.AbstractFilePersister#getExtension() | |
99 | */ | |
100 | @Override | |
101 | public String getExtension() { | |
102 |
1
1. getExtension : mutated return of Object value for org/argouml/persistence/ZargoFilePersister::getExtension to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return "zargo"; |
103 | } | |
104 | ||
105 | /* | |
106 | * @see org.argouml.persistence.AbstractFilePersister#getDesc() | |
107 | */ | |
108 | @Override | |
109 | protected String getDesc() { | |
110 |
1
1. getDesc : mutated return of Object value for org/argouml/persistence/ZargoFilePersister::getDesc to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Translator.localize("combobox.filefilter.zargo"); |
111 | } | |
112 | ||
113 | /** | |
114 | * It is being considered to save out individual xmi's from individuals | |
115 | * diagrams to make it easier to modularize the output of Argo. | |
116 | * | |
117 | * @param file | |
118 | * The file to write. | |
119 | * @param project | |
120 | * the project to save | |
121 | * @throws SaveException | |
122 | * when anything goes wrong | |
123 | * @throws InterruptedException if the thread is interrupted | |
124 | * | |
125 | * @see org.argouml.persistence.ProjectFilePersister#save( | |
126 | * org.argouml.kernel.Project, java.io.File) | |
127 | */ | |
128 | @Override | |
129 | public void doSave(Project project, File file) throws SaveException, | |
130 | InterruptedException { | |
131 | ||
132 | LOG.log(Level.INFO, "Saving"); | |
133 | /* Retain the previous project file even when the save operation | |
134 | * crashes in the middle. Also create a backup file after saving. */ | |
135 | boolean doSafeSaves = useSafeSaves(); | |
136 | ||
137 | ProgressMgr progressMgr = new ProgressMgr(); | |
138 |
1
1. doSave : removed call to org/argouml/persistence/AbstractFilePersister$ProgressMgr::setNumberOfPhases → NO_COVERAGE |
progressMgr.setNumberOfPhases(4); |
139 |
1
1. doSave : removed call to org/argouml/persistence/AbstractFilePersister$ProgressMgr::nextPhase → NO_COVERAGE |
progressMgr.nextPhase(); |
140 | ||
141 | File lastArchiveFile = new File(file.getAbsolutePath() + "~"); | |
142 | File tempFile = null; | |
143 | ||
144 |
1
1. doSave : negated conditional → NO_COVERAGE |
if (doSafeSaves) { |
145 | try { | |
146 | tempFile = createTempFile(file); | |
147 | } catch (FileNotFoundException e) { | |
148 | throw new SaveException(Translator.localize( | |
149 | "optionpane.save-project-exception-cause1"), e); | |
150 | } catch (IOException e) { | |
151 | throw new SaveException(Translator.localize( | |
152 | "optionpane.save-project-exception-cause2"), e); | |
153 | } | |
154 | } | |
155 | ||
156 | ZipOutputStream stream = null; | |
157 | try { | |
158 | ||
159 |
1
1. doSave : removed call to org/argouml/kernel/Project::setFile → NO_COVERAGE |
project.setFile(file); |
160 |
1
1. doSave : removed call to org/argouml/kernel/Project::setVersion → NO_COVERAGE |
project.setVersion(ApplicationVersion.getVersion()); |
161 |
1
1. doSave : removed call to org/argouml/kernel/Project::setPersistenceVersion → NO_COVERAGE |
project.setPersistenceVersion(PERSISTENCE_VERSION); |
162 | ||
163 | stream = new ZipOutputStream(new FileOutputStream(file)); | |
164 | ||
165 |
1
1. doSave : negated conditional → NO_COVERAGE |
for (ProjectMember projectMember : project.getMembers()) { |
166 |
1
1. doSave : negated conditional → NO_COVERAGE |
if (projectMember.getType().equalsIgnoreCase("xmi")) { |
167 | ||
168 | LOG.log(Level.INFO, | |
169 | "Saving member of type: {0}", | |
170 | projectMember.getType()); | |
171 | ||
172 |
1
1. doSave : removed call to java/util/zip/ZipOutputStream::putNextEntry → NO_COVERAGE |
stream.putNextEntry( |
173 | new ZipEntry(projectMember.getZipName())); | |
174 | MemberFilePersister persister = | |
175 | getMemberFilePersister(projectMember); | |
176 |
1
1. doSave : removed call to org/argouml/persistence/MemberFilePersister::save → NO_COVERAGE |
persister.save(projectMember, stream); |
177 | } | |
178 | } | |
179 | ||
180 |
1
1. doSave : negated conditional → NO_COVERAGE |
if (doSafeSaves) { |
181 | // if save did not raise an exception | |
182 | // and name+"#" exists move name+"#" to name+"~" | |
183 | // this is the correct backup file | |
184 |
1
1. doSave : negated conditional → NO_COVERAGE |
if (lastArchiveFile.exists()) { |
185 | lastArchiveFile.delete(); | |
186 | } | |
187 |
2
1. doSave : negated conditional → NO_COVERAGE 2. doSave : negated conditional → NO_COVERAGE |
if (tempFile.exists() && !lastArchiveFile.exists()) { |
188 | tempFile.renameTo(lastArchiveFile); | |
189 | } | |
190 |
1
1. doSave : negated conditional → NO_COVERAGE |
if (tempFile.exists()) { |
191 | tempFile.delete(); | |
192 | } | |
193 | } | |
194 | ||
195 |
1
1. doSave : removed call to org/argouml/persistence/AbstractFilePersister$ProgressMgr::nextPhase → NO_COVERAGE |
progressMgr.nextPhase(); |
196 | ||
197 | } catch (Exception e) { | |
198 | LOG.log(Level.SEVERE, "Exception occured during save attempt", e); | |
199 | try { | |
200 |
1
1. doSave : negated conditional → NO_COVERAGE |
if (stream != null) { |
201 |
1
1. doSave : removed call to java/util/zip/ZipOutputStream::close → NO_COVERAGE |
stream.close(); |
202 | } | |
203 | } catch (Exception ex) { | |
204 | // Do nothing. | |
205 | } | |
206 | ||
207 |
1
1. doSave : negated conditional → NO_COVERAGE |
if (doSafeSaves) { |
208 | // frank: in case of exception | |
209 | // delete name and mv name+"#" back to name if name+"#" exists | |
210 | // this is the "rollback" to old file | |
211 | file.delete(); | |
212 | tempFile.renameTo(file); | |
213 | } | |
214 | // we have to give a message to user and set the system to unsaved! | |
215 | throw new SaveException(e); | |
216 | } | |
217 | ||
218 | try { | |
219 |
1
1. doSave : removed call to java/util/zip/ZipOutputStream::close → NO_COVERAGE |
stream.close(); |
220 | } catch (IOException ex) { | |
221 | LOG.log(Level.SEVERE, "Failed to close save output writer", ex); | |
222 | } | |
223 | } | |
224 | ||
225 | /* | |
226 | * @see org.argouml.persistence.AbstractFilePersister#isSaveEnabled() | |
227 | */ | |
228 | @Override | |
229 | public boolean isSaveEnabled() { | |
230 |
1
1. isSaveEnabled : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
231 | } | |
232 | ||
233 | /* | |
234 | * @see org.argouml.persistence.ProjectFilePersister#doLoad(java.io.File) | |
235 | */ | |
236 | @Override | |
237 | public Project doLoad(File file) | |
238 | throws OpenException, InterruptedException { | |
239 | ||
240 | ProgressMgr progressMgr = new ProgressMgr(); | |
241 |
1
1. doLoad : removed call to org/argouml/persistence/AbstractFilePersister$ProgressMgr::setNumberOfPhases → NO_COVERAGE |
progressMgr.setNumberOfPhases(3 + UML_PHASES_LOAD); |
242 |
1
1. doLoad : removed call to org/argouml/util/ThreadUtils::checkIfInterrupted → NO_COVERAGE |
ThreadUtils.checkIfInterrupted(); |
243 | ||
244 | int fileVersion; | |
245 | String releaseVersion; | |
246 | try { | |
247 | String argoEntry = getEntryNames(file, ".argo").iterator().next(); | |
248 | URL argoUrl = makeZipEntryUrl(toURL(file), argoEntry); | |
249 | fileVersion = getPersistenceVersion(argoUrl.openStream()); | |
250 | releaseVersion = getReleaseVersion(argoUrl.openStream()); | |
251 | } catch (MalformedURLException e) { | |
252 | throw new OpenException(e); | |
253 | } catch (IOException e) { | |
254 | throw new OpenException(e); | |
255 | } | |
256 | ||
257 | // TODO: The commented code below was commented out by Bob Tarling | |
258 | // in order to resolve bugs 4845 and 4857. Hopefully we can | |
259 | // determine the cause and reintroduce. | |
260 | ||
261 | //boolean upgradeRequired = !checkVersion(fileVersion, releaseVersion) | |
262 | boolean upgradeRequired = true; | |
263 | ||
264 | // Upgrade is in the way for UML2 projects, so we turn it off in that case: | |
265 |
1
1. doLoad : negated conditional → NO_COVERAGE |
if (Model.getFacade().getUmlVersion().charAt(0) == '2') { |
266 | upgradeRequired = false; | |
267 | } | |
268 | ||
269 | LOG.log(Level.INFO, "Loading zargo file of version {0}", fileVersion); | |
270 | ||
271 | final Project p; | |
272 |
1
1. doLoad : negated conditional → NO_COVERAGE |
if (upgradeRequired) { |
273 | File combinedFile = zargoToUml(file, progressMgr); | |
274 | p = super.doLoad(file, combinedFile, progressMgr); | |
275 | } else { | |
276 | p = loadFromZargo(file, progressMgr); | |
277 | } | |
278 | ||
279 |
1
1. doLoad : removed call to org/argouml/persistence/AbstractFilePersister$ProgressMgr::nextPhase → NO_COVERAGE |
progressMgr.nextPhase(); |
280 | ||
281 |
1
1. doLoad : removed call to org/argouml/persistence/PersistenceManager::setProjectURI → NO_COVERAGE |
PersistenceManager.getInstance().setProjectURI(file.toURI(), p); |
282 |
1
1. doLoad : mutated return of Object value for org/argouml/persistence/ZargoFilePersister::doLoad to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return p; |
283 | ||
284 | } | |
285 | ||
286 | private Project loadFromZargo(File file, ProgressMgr progressMgr) | |
287 | throws OpenException { | |
288 | ||
289 | Project p = ProjectFactory.getInstance().createProject(file.toURI()); | |
290 | try { | |
291 |
1
1. loadFromZargo : removed call to org/argouml/persistence/AbstractFilePersister$ProgressMgr::nextPhase → NO_COVERAGE |
progressMgr.nextPhase(); |
292 | ||
293 | // Load .argo project descriptor | |
294 | ArgoParser parser = new ArgoParser(); | |
295 | String argoEntry = getEntryNames(file, ".argo").iterator().next(); | |
296 |
1
1. loadFromZargo : removed call to org/argouml/persistence/ArgoParser::readProject → NO_COVERAGE |
parser.readProject(p, new InputSource(makeZipEntryUrl(toURL(file), |
297 | argoEntry).toExternalForm())); | |
298 | ||
299 | List memberList = parser.getMemberList(); | |
300 | ||
301 | LOG.log(Level.INFO,memberList.size() + " members"); | |
302 | ||
303 | // Load .xmi file before any PGML files | |
304 | // FIXME: the following is loading the model before anything else. | |
305 | // Due to the Zargo containing the profiles, currently we have | |
306 | // removed this hack in UmlFilePersister and I think it should be | |
307 | // removed from here also. | |
308 | String xmiEntry = getEntryNames(file, ".xmi").iterator().next(); | |
309 | MemberFilePersister persister = getMemberFilePersister("xmi"); | |
310 | URL url = makeZipEntryUrl(toURL(file), xmiEntry); | |
311 |
1
1. loadFromZargo : removed call to org/argouml/persistence/MemberFilePersister::load → NO_COVERAGE |
persister.load(p, new InputSource(url.toExternalForm())); |
312 | ||
313 | // Load the rest | |
314 | List<String> entries = getEntryNames(file, null); | |
315 |
1
1. loadFromZargo : negated conditional → NO_COVERAGE |
for (String name : entries) { |
316 |
1
1. loadFromZargo : Replaced integer addition with subtraction → NO_COVERAGE |
String ext = name.substring(name.lastIndexOf('.') + 1); |
317 |
2
1. loadFromZargo : negated conditional → NO_COVERAGE 2. loadFromZargo : negated conditional → NO_COVERAGE |
if (!"argo".equals(ext) && !"xmi".equals(ext)) { |
318 | persister = getMemberFilePersister(ext); | |
319 | ||
320 | LOG.log(Level.INFO, | |
321 | "Loading member with " | |
322 | + persister.getClass().getName()); | |
323 | ||
324 | url = makeZipEntryUrl(toURL(file), name); | |
325 |
1
1. loadFromZargo : removed call to org/argouml/persistence/MemberFilePersister::load → NO_COVERAGE |
persister.load(p, new InputSource(url.toExternalForm())); |
326 | } | |
327 | } | |
328 | ||
329 |
1
1. loadFromZargo : removed call to org/argouml/persistence/AbstractFilePersister$ProgressMgr::nextPhase → NO_COVERAGE |
progressMgr.nextPhase(); |
330 |
1
1. loadFromZargo : removed call to org/argouml/util/ThreadUtils::checkIfInterrupted → NO_COVERAGE |
ThreadUtils.checkIfInterrupted(); |
331 |
1
1. loadFromZargo : removed call to org/argouml/kernel/Project::postLoad → NO_COVERAGE |
p.postLoad(); |
332 |
1
1. loadFromZargo : mutated return of Object value for org/argouml/persistence/ZargoFilePersister::loadFromZargo to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return p; |
333 | } catch (InterruptedException e) { | |
334 |
1
1. loadFromZargo : mutated return of Object value for org/argouml/persistence/ZargoFilePersister::loadFromZargo to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
335 | } catch (MalformedURLException e) { | |
336 | throw new OpenException(e); | |
337 | } catch (IOException e) { | |
338 | throw new OpenException(e); | |
339 | } catch (SAXException e) { | |
340 | throw new OpenException(e); | |
341 | } | |
342 | } | |
343 | ||
344 | private URL toURL(File file) throws MalformedURLException { | |
345 |
1
1. toURL : mutated return of Object value for org/argouml/persistence/ZargoFilePersister::toURL to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return file.toURI().toURL(); |
346 | } | |
347 | ||
348 | ||
349 | private File zargoToUml(File file, ProgressMgr progressMgr) | |
350 | throws OpenException, InterruptedException { | |
351 | ||
352 | File combinedFile = null; | |
353 | try { | |
354 | combinedFile = File.createTempFile("combinedzargo_", ".uml"); | |
355 | LOG.log(Level.INFO, | |
356 | "Combining old style zargo sub files " | |
357 | + "into new style uml file {0}", | |
358 | combinedFile.getAbsolutePath()); | |
359 | ||
360 |
1
1. zargoToUml : removed call to java/io/File::deleteOnExit → NO_COVERAGE |
combinedFile.deleteOnExit(); |
361 | ||
362 | String encoding = Argo.getEncoding(); | |
363 | FileOutputStream stream = new FileOutputStream(combinedFile); | |
364 | PrintWriter writer = | |
365 | new PrintWriter(new BufferedWriter( | |
366 | new OutputStreamWriter(stream, encoding))); | |
367 | ||
368 |
1
1. zargoToUml : removed call to java/io/PrintWriter::println → NO_COVERAGE |
writer.println("<?xml version = \"1.0\" " + "encoding = \"" |
369 | + encoding + "\" ?>"); | |
370 | ||
371 |
1
1. zargoToUml : removed call to org/argouml/persistence/ZargoFilePersister::copyArgo → NO_COVERAGE |
copyArgo(file, encoding, writer); |
372 | ||
373 |
1
1. zargoToUml : removed call to org/argouml/persistence/AbstractFilePersister$ProgressMgr::nextPhase → NO_COVERAGE |
progressMgr.nextPhase(); |
374 | ||
375 |
1
1. zargoToUml : removed call to org/argouml/persistence/ZargoFilePersister::copyMember → NO_COVERAGE |
copyMember(file, "profile", encoding, writer); |
376 | ||
377 |
1
1. zargoToUml : removed call to org/argouml/persistence/ZargoFilePersister::copyXmi → NO_COVERAGE |
copyXmi(file, encoding, writer); |
378 | ||
379 |
1
1. zargoToUml : removed call to org/argouml/persistence/ZargoFilePersister::copyDiagrams → NO_COVERAGE |
copyDiagrams(file, encoding, writer); |
380 | ||
381 | // Copy the todo items after the model and diagrams so that | |
382 | // any model elements or figs that the todo items refer to | |
383 | // will exist before creating critics. | |
384 |
1
1. zargoToUml : removed call to org/argouml/persistence/ZargoFilePersister::copyMember → NO_COVERAGE |
copyMember(file, "todo", encoding, writer); |
385 | ||
386 |
1
1. zargoToUml : removed call to org/argouml/persistence/AbstractFilePersister$ProgressMgr::nextPhase → NO_COVERAGE |
progressMgr.nextPhase(); |
387 | ||
388 |
1
1. zargoToUml : removed call to java/io/PrintWriter::println → NO_COVERAGE |
writer.println("</uml>"); |
389 |
1
1. zargoToUml : removed call to java/io/PrintWriter::close → NO_COVERAGE |
writer.close(); |
390 | LOG.log(Level.INFO, "Completed combining files"); | |
391 | } catch (IOException e) { | |
392 | throw new OpenException(e); | |
393 | } | |
394 |
1
1. zargoToUml : mutated return of Object value for org/argouml/persistence/ZargoFilePersister::zargoToUml to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return combinedFile; |
395 | } | |
396 | ||
397 | ||
398 | private void copyArgo(File file, String encoding, PrintWriter writer) | |
399 | throws IOException, MalformedURLException, OpenException, | |
400 | UnsupportedEncodingException { | |
401 | ||
402 | int pgmlCount = getPgmlCount(file); | |
403 | boolean containsToDo = containsTodo(file); | |
404 | boolean containsProfile = containsProfile(file); | |
405 | ||
406 | // first read the .argo file from Zip | |
407 | ZipInputStream zis = | |
408 | openZipStreamAt(toURL(file), FileConstants.PROJECT_FILE_EXT); | |
409 | ||
410 |
1
1. copyArgo : negated conditional → NO_COVERAGE |
if (zis == null) { |
411 | throw new OpenException( | |
412 | "There is no .argo file in the .zargo"); | |
413 | } | |
414 | ||
415 | String line; | |
416 | BufferedReader reader = | |
417 | new BufferedReader(new InputStreamReader(zis, encoding)); | |
418 | // Keep reading till we hit the <argo> tag | |
419 | String rootLine; | |
420 |
1
1. copyArgo : negated conditional → NO_COVERAGE |
do { |
421 | rootLine = reader.readLine(); | |
422 |
1
1. copyArgo : negated conditional → NO_COVERAGE |
if (rootLine == null) { |
423 | throw new OpenException( | |
424 | "Can't find an <argo> tag in the argo file"); | |
425 | } | |
426 | } while(!rootLine.startsWith("<argo")); | |
427 | ||
428 | ||
429 | // Get the version from the tag. | |
430 | String version = getVersion(rootLine); | |
431 |
1
1. copyArgo : removed call to java/io/PrintWriter::println → NO_COVERAGE |
writer.println("<uml version=\"" + version + "\">"); |
432 |
1
1. copyArgo : removed call to java/io/PrintWriter::println → NO_COVERAGE |
writer.println(rootLine); |
433 | LOG.log(Level.INFO, "Transfering argo contents"); | |
434 | int memberCount = 0; | |
435 |
1
1. copyArgo : negated conditional → NO_COVERAGE |
while ((line = reader.readLine()) != null) { |
436 |
1
1. copyArgo : negated conditional → NO_COVERAGE |
if (line.trim().startsWith("<member")) { |
437 |
1
1. copyArgo : Changed increment from 1 to -1 → NO_COVERAGE |
++memberCount; |
438 | } | |
439 |
2
1. copyArgo : negated conditional → NO_COVERAGE 2. copyArgo : negated conditional → NO_COVERAGE |
if (line.trim().equals("</argo>") && memberCount == 0) { |
440 | LOG.log(Level.INFO, "Inserting member info"); | |
441 |
1
1. copyArgo : removed call to java/io/PrintWriter::println → NO_COVERAGE |
writer.println("<member type='xmi' name='.xmi' />"); |
442 |
3
1. copyArgo : changed conditional boundary → NO_COVERAGE 2. copyArgo : Changed increment from 1 to -1 → NO_COVERAGE 3. copyArgo : negated conditional → NO_COVERAGE |
for (int i = 0; i < pgmlCount; ++i) { |
443 |
1
1. copyArgo : removed call to java/io/PrintWriter::println → NO_COVERAGE |
writer.println("<member type='pgml' name='.pgml' />"); |
444 | } | |
445 |
1
1. copyArgo : negated conditional → NO_COVERAGE |
if (containsToDo) { |
446 |
1
1. copyArgo : removed call to java/io/PrintWriter::println → NO_COVERAGE |
writer.println("<member type='todo' name='.todo' />"); |
447 | } | |
448 |
1
1. copyArgo : negated conditional → NO_COVERAGE |
if (containsProfile) { |
449 | String type = ProfileConfiguration.EXTENSION; | |
450 |
1
1. copyArgo : removed call to java/io/PrintWriter::println → NO_COVERAGE |
writer.println("<member type='" + type + "' name='." |
451 | + type + "' />"); | |
452 | } | |
453 | } | |
454 |
1
1. copyArgo : removed call to java/io/PrintWriter::println → NO_COVERAGE |
writer.println(line); |
455 | } | |
456 | ||
457 | LOG.log(Level.INFO, "Member count = {0}", memberCount); | |
458 | ||
459 |
1
1. copyArgo : removed call to java/util/zip/ZipInputStream::close → NO_COVERAGE |
zis.close(); |
460 |
1
1. copyArgo : removed call to java/io/BufferedReader::close → NO_COVERAGE |
reader.close(); |
461 | } | |
462 | ||
463 | private void copyXmi(File file, String encoding, PrintWriter writer) | |
464 | throws IOException, MalformedURLException, | |
465 | UnsupportedEncodingException { | |
466 | ||
467 | ZipInputStream zis = openZipStreamAt(toURL(file), ".xmi"); | |
468 | BufferedReader reader = new BufferedReader( | |
469 | new InputStreamReader(zis, encoding)); | |
470 | // Skip 1 lines | |
471 | reader.readLine(); | |
472 | ||
473 |
1
1. copyXmi : removed call to org/argouml/persistence/ZargoFilePersister::readerToWriter → NO_COVERAGE |
readerToWriter(reader, writer); |
474 | ||
475 |
1
1. copyXmi : removed call to java/util/zip/ZipInputStream::close → NO_COVERAGE |
zis.close(); |
476 |
1
1. copyXmi : removed call to java/io/BufferedReader::close → NO_COVERAGE |
reader.close(); |
477 | } | |
478 | ||
479 | ||
480 | private void copyDiagrams(File file, String encoding, PrintWriter writer) | |
481 | throws IOException { | |
482 | ||
483 | // Loop round loading the diagrams | |
484 | ZipInputStream zis = new ZipInputStream(toURL(file).openStream()); | |
485 | SubInputStream sub = new SubInputStream(zis); | |
486 | ||
487 | ZipEntry currentEntry = null; | |
488 |
1
1. copyDiagrams : negated conditional → NO_COVERAGE |
while ((currentEntry = sub.getNextEntry()) != null) { |
489 |
1
1. copyDiagrams : negated conditional → NO_COVERAGE |
if (currentEntry.getName().endsWith(".pgml")) { |
490 | ||
491 | BufferedReader reader = new BufferedReader( | |
492 | new InputStreamReader(sub, encoding)); | |
493 | String firstLine = reader.readLine(); | |
494 |
1
1. copyDiagrams : negated conditional → NO_COVERAGE |
if (firstLine.startsWith("<?xml")) { |
495 | // Skip the 2 lines | |
496 | //<?xml version="1.0" encoding="UTF-8" ?> | |
497 | //<!DOCTYPE pgml SYSTEM "pgml.dtd"> | |
498 | reader.readLine(); | |
499 | } else { | |
500 |
1
1. copyDiagrams : removed call to java/io/PrintWriter::println → NO_COVERAGE |
writer.println(firstLine); |
501 | } | |
502 | ||
503 |
1
1. copyDiagrams : removed call to org/argouml/persistence/ZargoFilePersister::readerToWriter → NO_COVERAGE |
readerToWriter(reader, writer); |
504 |
1
1. copyDiagrams : removed call to org/argouml/persistence/ZargoFilePersister$SubInputStream::close → NO_COVERAGE |
sub.close(); |
505 |
1
1. copyDiagrams : removed call to java/io/BufferedReader::close → NO_COVERAGE |
reader.close(); |
506 | } | |
507 | } | |
508 |
1
1. copyDiagrams : removed call to java/util/zip/ZipInputStream::close → NO_COVERAGE |
zis.close(); |
509 | } | |
510 | ||
511 | ||
512 | private void copyMember(File file, String tag, String outputEncoding, | |
513 | PrintWriter writer) throws IOException, MalformedURLException, | |
514 | UnsupportedEncodingException { | |
515 | ||
516 | ZipInputStream zis = openZipStreamAt(toURL(file), "." + tag); | |
517 | ||
518 |
1
1. copyMember : negated conditional → NO_COVERAGE |
if (zis != null) { |
519 | InputStreamReader isr = new InputStreamReader(zis, outputEncoding); | |
520 | BufferedReader reader = new BufferedReader(isr); | |
521 | ||
522 | String firstLine = reader.readLine(); | |
523 |
1
1. copyMember : negated conditional → NO_COVERAGE |
if (firstLine.startsWith("<?xml")) { |
524 | // Skip the 2 lines | |
525 | //<?xml version="1.0" encoding="UTF-8" ?> | |
526 | //<!DOCTYPE todo SYSTEM "todo.dtd" > | |
527 | reader.readLine(); | |
528 | } else { | |
529 |
1
1. copyMember : removed call to java/io/PrintWriter::println → NO_COVERAGE |
writer.println(firstLine); |
530 | } | |
531 | ||
532 |
1
1. copyMember : removed call to org/argouml/persistence/ZargoFilePersister::readerToWriter → NO_COVERAGE |
readerToWriter(reader, writer); |
533 | ||
534 |
1
1. copyMember : removed call to java/util/zip/ZipInputStream::close → NO_COVERAGE |
zis.close(); |
535 |
1
1. copyMember : removed call to java/io/BufferedReader::close → NO_COVERAGE |
reader.close(); |
536 | } | |
537 | } | |
538 | ||
539 | ||
540 | private void readerToWriter( | |
541 | Reader reader, | |
542 | Writer writer) throws IOException { | |
543 | ||
544 | int ch; | |
545 |
1
1. readerToWriter : negated conditional → NO_COVERAGE |
while ((ch = reader.read()) != -1) { |
546 |
1
1. readerToWriter : negated conditional → NO_COVERAGE |
if (ch == 0xFFFF) { |
547 | LOG.log(Level.INFO, "Stripping out 0xFFFF from save file"); | |
548 |
1
1. readerToWriter : negated conditional → NO_COVERAGE |
} else if (ch == 8) { |
549 | LOG.log(Level.INFO, "Stripping out 0x8 from save file"); | |
550 | } else { | |
551 |
1
1. readerToWriter : removed call to java/io/Writer::write → NO_COVERAGE |
writer.write(ch); |
552 | } | |
553 | } | |
554 | } | |
555 | ||
556 | /** | |
557 | * Open a ZipInputStream to the first file found with a given extension. | |
558 | * | |
559 | * @param url | |
560 | * The URL of the zip file. | |
561 | * @param ext | |
562 | * The required extension. | |
563 | * @return the zip stream positioned at the required location or null | |
564 | * if the requested extension is not found. | |
565 | * @throws IOException | |
566 | * if there is a problem opening the file. | |
567 | */ | |
568 | private ZipInputStream openZipStreamAt(URL url, String ext) | |
569 | throws IOException { | |
570 | ZipInputStream zis = new ZipInputStream(url.openStream()); | |
571 | ZipEntry entry = zis.getNextEntry(); | |
572 |
2
1. openZipStreamAt : negated conditional → NO_COVERAGE 2. openZipStreamAt : negated conditional → NO_COVERAGE |
while (entry != null && !entry.getName().endsWith(ext)) { |
573 | entry = zis.getNextEntry(); | |
574 | } | |
575 |
1
1. openZipStreamAt : negated conditional → NO_COVERAGE |
if (entry == null) { |
576 |
1
1. openZipStreamAt : removed call to java/util/zip/ZipInputStream::close → NO_COVERAGE |
zis.close(); |
577 |
1
1. openZipStreamAt : mutated return of Object value for org/argouml/persistence/ZargoFilePersister::openZipStreamAt to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
578 | } | |
579 |
1
1. openZipStreamAt : mutated return of Object value for org/argouml/persistence/ZargoFilePersister::openZipStreamAt to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return zis; |
580 | } | |
581 | ||
582 | private InputStream openZipEntry(URL url, String entryName) | |
583 | throws MalformedURLException, IOException { | |
584 |
1
1. openZipEntry : mutated return of Object value for org/argouml/persistence/ZargoFilePersister::openZipEntry to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return makeZipEntryUrl(url, entryName).openStream(); |
585 | } | |
586 | ||
587 | private URL makeZipEntryUrl(URL url, String entryName) | |
588 | throws MalformedURLException { | |
589 | String entryURL = "jar:" + url + "!/" + entryName; | |
590 |
1
1. makeZipEntryUrl : mutated return of Object value for org/argouml/persistence/ZargoFilePersister::makeZipEntryUrl to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new URL(entryURL); |
591 | } | |
592 | ||
593 | /** | |
594 | * A stream of input streams for reading the Zipped file. | |
595 | */ | |
596 | private static class SubInputStream extends FilterInputStream { | |
597 | private ZipInputStream in; | |
598 | ||
599 | /** | |
600 | * The constructor. | |
601 | * | |
602 | * @param z | |
603 | * the zip input stream | |
604 | */ | |
605 | public SubInputStream(ZipInputStream z) { | |
606 | super(z); | |
607 | in = z; | |
608 | } | |
609 | ||
610 | /* | |
611 | * @see java.io.InputStream#close() | |
612 | */ | |
613 | @Override | |
614 | public void close() throws IOException { | |
615 |
1
1. close : removed call to java/util/zip/ZipInputStream::closeEntry → NO_COVERAGE |
in.closeEntry(); |
616 | } | |
617 | ||
618 | /** | |
619 | * Reads the next ZIP file entry and positions stream at the beginning | |
620 | * of the entry data. | |
621 | * | |
622 | * @return the ZipEntry just read | |
623 | * @throws IOException | |
624 | * if an I/O error has occurred | |
625 | */ | |
626 | public ZipEntry getNextEntry() throws IOException { | |
627 |
1
1. getNextEntry : mutated return of Object value for org/argouml/persistence/ZargoFilePersister$SubInputStream::getNextEntry to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return in.getNextEntry(); |
628 | } | |
629 | } | |
630 | ||
631 | private int getPgmlCount(File file) throws IOException { | |
632 |
1
1. getPgmlCount : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return getEntryNames(file, ".pgml").size(); |
633 | } | |
634 | ||
635 | private boolean containsTodo(File file) throws IOException { | |
636 |
2
1. containsTodo : negated conditional → NO_COVERAGE 2. containsTodo : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return !getEntryNames(file, ".todo").isEmpty(); |
637 | } | |
638 | ||
639 | private boolean containsProfile(File file) throws IOException { | |
640 |
2
1. containsProfile : negated conditional → NO_COVERAGE 2. containsProfile : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return !getEntryNames(file, "." + ProfileConfiguration.EXTENSION) |
641 | .isEmpty(); | |
642 | } | |
643 | ||
644 | /** | |
645 | * Get a list of zip file entries which end with the given extension. | |
646 | * If the extension is null, all entries are returned. | |
647 | */ | |
648 | private List<String> getEntryNames(File file, String extension) | |
649 | throws IOException, MalformedURLException { | |
650 | ||
651 | ZipInputStream zis = new ZipInputStream(toURL(file).openStream()); | |
652 | List<String> result = new ArrayList<String>(); | |
653 | ZipEntry entry = zis.getNextEntry(); | |
654 |
1
1. getEntryNames : negated conditional → NO_COVERAGE |
while (entry != null) { |
655 | String name = entry.getName(); | |
656 |
2
1. getEntryNames : negated conditional → NO_COVERAGE 2. getEntryNames : negated conditional → NO_COVERAGE |
if (extension == null || name.endsWith(extension)) { |
657 | result.add(name); | |
658 | } | |
659 | entry = zis.getNextEntry(); | |
660 | } | |
661 |
1
1. getEntryNames : removed call to java/util/zip/ZipInputStream::close → NO_COVERAGE |
zis.close(); |
662 |
1
1. getEntryNames : mutated return of Object value for org/argouml/persistence/ZargoFilePersister::getEntryNames to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return result; |
663 | } | |
664 | ||
665 | ||
666 | } | |
Mutations | ||
102 |
1.1 |
|
110 |
1.1 |
|
138 |
1.1 |
|
139 |
1.1 |
|
144 |
1.1 |
|
159 |
1.1 |
|
160 |
1.1 |
|
161 |
1.1 |
|
165 |
1.1 |
|
166 |
1.1 |
|
172 |
1.1 |
|
176 |
1.1 |
|
180 |
1.1 |
|
184 |
1.1 |
|
187 |
1.1 2.2 |
|
190 |
1.1 |
|
195 |
1.1 |
|
200 |
1.1 |
|
201 |
1.1 |
|
207 |
1.1 |
|
219 |
1.1 |
|
230 |
1.1 |
|
241 |
1.1 |
|
242 |
1.1 |
|
265 |
1.1 |
|
272 |
1.1 |
|
279 |
1.1 |
|
281 |
1.1 |
|
282 |
1.1 |
|
291 |
1.1 |
|
296 |
1.1 |
|
311 |
1.1 |
|
315 |
1.1 |
|
316 |
1.1 |
|
317 |
1.1 2.2 |
|
325 |
1.1 |
|
329 |
1.1 |
|
330 |
1.1 |
|
331 |
1.1 |
|
332 |
1.1 |
|
334 |
1.1 |
|
345 |
1.1 |
|
360 |
1.1 |
|
368 |
1.1 |
|
371 |
1.1 |
|
373 |
1.1 |
|
375 |
1.1 |
|
377 |
1.1 |
|
379 |
1.1 |
|
384 |
1.1 |
|
386 |
1.1 |
|
388 |
1.1 |
|
389 |
1.1 |
|
394 |
1.1 |
|
410 |
1.1 |
|
420 |
1.1 |
|
422 |
1.1 |
|
431 |
1.1 |
|
432 |
1.1 |
|
435 |
1.1 |
|
436 |
1.1 |
|
437 |
1.1 |
|
439 |
1.1 2.2 |
|
441 |
1.1 |
|
442 |
1.1 2.2 3.3 |
|
443 |
1.1 |
|
445 |
1.1 |
|
446 |
1.1 |
|
448 |
1.1 |
|
450 |
1.1 |
|
454 |
1.1 |
|
459 |
1.1 |
|
460 |
1.1 |
|
473 |
1.1 |
|
475 |
1.1 |
|
476 |
1.1 |
|
488 |
1.1 |
|
489 |
1.1 |
|
494 |
1.1 |
|
500 |
1.1 |
|
503 |
1.1 |
|
504 |
1.1 |
|
505 |
1.1 |
|
508 |
1.1 |
|
518 |
1.1 |
|
523 |
1.1 |
|
529 |
1.1 |
|
532 |
1.1 |
|
534 |
1.1 |
|
535 |
1.1 |
|
545 |
1.1 |
|
546 |
1.1 |
|
548 |
1.1 |
|
551 |
1.1 |
|
572 |
1.1 2.2 |
|
575 |
1.1 |
|
576 |
1.1 |
|
577 |
1.1 |
|
579 |
1.1 |
|
584 |
1.1 |
|
590 |
1.1 |
|
615 |
1.1 |
|
627 |
1.1 |
|
632 |
1.1 |
|
636 |
1.1 2.2 |
|
640 |
1.1 2.2 |
|
654 |
1.1 |
|
656 |
1.1 2.2 |
|
661 |
1.1 |
|
662 |
1.1 |