/** * Reads an XML file of uml format and extracts the persistence version * number from the root tag. * * @param inputStream the stream point to the XML file * @return The ArgoUML release number * @throws OpenException on any error */ protected String getReleaseVersion(InputStream inputStream) throws OpenException { BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(inputStream, Argo .getEncoding())); String versionLine = reader.readLine(); while (!versionLine.trim().startsWith("<version>")) { versionLine = reader.readLine(); if (versionLine == null) { throw new OpenException( "Failed to find the release <version> tag"); } } versionLine = versionLine.trim(); int end = versionLine.lastIndexOf("</version>"); return versionLine.trim().substring(9, end); } catch (IOException e) { throw new OpenException(e); } catch (NumberFormatException e) { throw new OpenException(e); } finally { try { if (inputStream != null) { inputStream.close(); } if (reader != null) { reader.close(); } } catch (IOException e) { // No more we can do here on failure } } }
private void copyArgo(File file, String encoding, PrintWriter writer) throws IOException, MalformedURLException, OpenException, UnsupportedEncodingException { int pgmlCount = getPgmlCount(file); boolean containsToDo = containsTodo(file); boolean containsProfile = containsProfile(file); // first read the .argo file from Zip ZipInputStream zis = openZipStreamAt(toURL(file), FileConstants.PROJECT_FILE_EXT); if (zis == null) { throw new OpenException( "There is no .argo file in the .zargo"); } String line; BufferedReader reader = new BufferedReader(new InputStreamReader(zis, encoding)); // Keep reading till we hit the <argo> tag String rootLine; do { rootLine = reader.readLine(); if (rootLine == null) { throw new OpenException( "Can't find an <argo> tag in the argo file"); } } while(!rootLine.startsWith("<argo")); // Get the version from the tag. String version = getVersion(rootLine); writer.println("<uml version=\"" + version + "\">"); writer.println(rootLine); LOG.info("Transfering argo contents"); int memberCount = 0; while ((line = reader.readLine()) != null) { if (line.trim().startsWith("<member")) { ++memberCount; } if (line.trim().equals("</argo>") && memberCount == 0) { LOG.info("Inserting member info"); writer.println("<member type='xmi' name='.xmi' />"); for (int i = 0; i < pgmlCount; ++i) { writer.println("<member type='pgml' name='.pgml' />"); } if (containsToDo) { writer.println("<member type='todo' name='.todo' />"); } if (containsProfile) { String type = ProfileConfiguration.EXTENSION; writer.println("<member type='" + type + "' name='." + type + "' />"); } } writer.println(line); } if (LOG.isInfoEnabled()) { LOG.info("Member count = " + memberCount); } zis.close(); reader.close(); }
Clone fragments detected by clone detection tool
File path: /ArgoUML-0.34-src/argouml/src/argouml-app/src/org/argouml/persistence/UmlFilePersister.java File path: /ArgoUML-0.34-src/argouml/src/argouml-app/src/org/argouml/persistence/ZargoFilePersister.java
Method name: String getReleaseVersion(InputStream) Method name: void copyArgo(File, String, PrintWriter)
Number of AST nodes: 7 Number of AST nodes: 4
1
/**
1
private void copyArgo(File file, String encoding, PrintWriter writer)
2
     * Reads an XML file of uml format and extracts the persistence version
2
        throws IOException, MalformedURLException, OpenException,
3
     * number from the root tag.
3
        UnsupportedEncodingException {
4
     * 
4
        
5
     * @param inputStream the stream point to the XML file
5
        int pgmlCount = getPgmlCount(file);
6
     * @return The ArgoUML release number
6
        boolean containsToDo = containsTodo(file);
7
     * @throws OpenException on any error
7
        boolean containsProfile = containsProfile(file);
8
     */
8
9
    protected String getReleaseVersion(InputStream inputStream)
9
        // first read the .argo file from Zip
10
        throws OpenException {
10
        ZipInputStream zis =
11
11
            openZipStreamAt(toURL(file), FileConstants.PROJECT_FILE_EXT);
12
        BufferedReader reader = null;
12
        
13
        try {
13
        if (zis == null) {
14
            reader = new BufferedReader(new InputStreamReader(inputStream, Argo
14
            throw new OpenException(
15
                    .getEncoding()));
15
                    "There is no .argo file in the .zargo");
16
            String versionLine = reader.readLine();
16
        }
17
            while (!versionLine.trim().startsWith("<version>")) {
17
        
18
                versionLine = reader.readLine();
18
        String line;
19
                if (versionLine == null) {
19
        BufferedReader reader = 
20
                    throw new OpenException(
20
            new BufferedReader(new InputStreamReader(zis, encoding));
21
                            "Failed to find the release <version> tag");
21
        // Keep reading till we hit the <argo> tag
22
                }
22
        String rootLine;
23
            }
23
        do {
24
            versionLine = versionLine.trim();
24
            rootLine = reader.readLine();
25
            int end = versionLine.lastIndexOf("</version>");
25
            if (rootLine == null) {
26
            return versionLine.trim().substring(9, end);
26
                throw new OpenException(
27
        } catch (IOException e) {
27
                        "Can't find an <argo> tag in the argo file");
28
            throw new OpenException(e);
28
            }
29
        } catch (NumberFormatException e) {
29
        } while(!rootLine.startsWith("<argo"));
30
            throw new OpenException(e);
30
31
        } finally {
31
32
            try {
32
        // Get the version from the tag.
33
                if (inputStream != null) {
33
        String version = getVersion(rootLine);
34
                    inputStream.close();
34
        writer.println("<uml version=\"" + version + "\">");
35
                }
35
        writer.println(rootLine);
36
                if (reader != null) {
36
        LOG.info("Transfering argo contents");
37
                    reader.close();
37
        int memberCount = 0;
38
                }
38
        while ((line = reader.readLine()) != null) {
39
            } catch (IOException e) {
39
            if (line.trim().startsWith("<member")) {
40
                // No more we can do here on failure
40
                ++memberCount;
41
            }
41
            }
42
        }
42
            if (line.trim().equals("</argo>") && memberCount == 0) {
43
    }
43
                LOG.info("Inserting member info");
44
                writer.println("<member type='xmi' name='.xmi' />");
45
                for (int i = 0; i < pgmlCount; ++i) {
46
                    writer.println("<member type='pgml' name='.pgml' />");
47
                }
48
                if (containsToDo) {
49
                    writer.println("<member type='todo' name='.todo' />");
50
                }
51
                if (containsProfile) {
52
                    String type = ProfileConfiguration.EXTENSION;
53
                    writer.println("<member type='" + type + "' name='."
54
                            + type + "' />");
55
                }
56
            }
57
            writer.println(line);
58
        }
59
        if (LOG.isInfoEnabled()) {
60
            LOG.info("Member count = " + memberCount);
61
        }
62
        zis.close();
63
        reader.close();
64
    }
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements8
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)0.0
    Similarity Score1.000
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    5
    while (!versionLine.trim().startsWith("<version>"))
    5
    while (!versionLine.trim().startsWith("<version>"))
    13
    do while(!rootLine.startsWith("<argo"))
    Differences
    Expression1Expression2Difference
    """LITERAL_VALUE_MISMATCH
    versionLine.trim()rootLineTYPE_COMPATIBLE_REPLACEMENT
    13
    do while(!rootLine.startsWith("<argo"))
    6
    versionLine = reader.readLine();
    6
    versionLine = reader.readLine();
    10
    rootLine = reader.readLine();
    Differences
    Expression1Expression2Difference
    versionLinerootLineVARIABLE_NAME_MISMATCH
    10
    rootLine = reader.readLine();
    7
    if (versionLine == null)
    7
    if (versionLine == null)
    11
    if (rootLine == null)
    Differences
    Expression1Expression2Difference
    versionLinerootLineVARIABLE_NAME_MISMATCH
    11
    if (rootLine == null)
    8
    throw new OpenException("Failed to find the release <version> tag");
    8
    throw new OpenException("Failed to find the release <version> tag");
    12
    throw new OpenException("Can't find an <argo> tag in the argo file");
    Differences
    Expression1Expression2Difference
    "Failed to find the release tag""Can't find an tag in the argo file"LITERAL_VALUE_MISMATCH
    12
    throw new OpenException("Can't find an <argo> tag in the argo file");
    Precondition Violations (0)
    Row Violation