Enumeration e = fileCopyMap.keys(); while (e.hasMoreElements()) { String fromFile = (String) e.nextElement(); String[] toFiles = (String[]) fileCopyMap.get(fromFile); for (int i = 0; i < toFiles.length; i++) { String toFile = toFiles[i]; if (fromFile.equals(toFile)) { log("Skipping self-copy of " + fromFile, verbosity); continue; } try { log("Copying " + fromFile + " to " + toFile, verbosity); FilterSetCollection executionFilters = new FilterSetCollection(); if (filtering) { executionFilters .addFilterSet(getProject().getGlobalFilterSet()); } for (Enumeration filterEnum = filterSets.elements(); filterEnum.hasMoreElements();) { executionFilters .addFilterSet((FilterSet) filterEnum.nextElement()); } fileUtils.copyFile(fromFile, toFile, executionFilters, filterChains, forceOverwrite, preserveLastModified, inputEncoding, outputEncoding, getProject()); } catch (IOException ioe) { String msg = "Failed to copy " + fromFile + " to " + toFile + " due to " + getDueTo(ioe); File targetFile = new File(toFile); if (targetFile.exists() && !targetFile.delete()) { msg += " and I couldn't delete the corrupt " + toFile; } if (failonerror) { throw new BuildException(msg, ioe, getLocation()); } log(msg, Project.MSG_ERR); } } }
if (map.size() > 0) { log("Copying " + map.size() + " resource" + (map.size() == 1 ? "" : "s") + " to " + destDir.getAbsolutePath()); Iterator iter = map.keySet().iterator(); while (iter.hasNext()) { Resource fromResource = (Resource) iter.next(); String[] toFiles = (String[]) map.get(fromResource); for (int i = 0; i < toFiles.length; i++) { String toFile = toFiles[i]; try { log("Copying " + fromResource + " to " + toFile, verbosity); FilterSetCollection executionFilters = new FilterSetCollection(); if (filtering) { executionFilters .addFilterSet(getProject().getGlobalFilterSet()); } for (Enumeration filterEnum = filterSets.elements(); filterEnum.hasMoreElements();) { executionFilters .addFilterSet((FilterSet) filterEnum.nextElement()); } ResourceUtils.copyResource(fromResource, new FileResource(destDir, toFile), executionFilters, filterChains, forceOverwrite, preserveLastModified, inputEncoding, outputEncoding, getProject()); } catch (IOException ioe) { String msg = "Failed to copy " + fromResource + " to " + toFile + " due to " + getDueTo(ioe); File targetFile = new File(toFile); if (targetFile.exists() && !targetFile.delete()) { msg += " and I couldn't delete the corrupt " + toFile; } if (failonerror) { throw new BuildException(msg, ioe, getLocation()); } log(msg, Project.MSG_ERR); } } } }
Clone fragments detected by clone detection tool
File path: /apache-ant-1.7.0/src/org/apache/tools/ant/taskdefs/Copy.java File path: /apache-ant-1.7.0/src/org/apache/tools/ant/taskdefs/Copy.java
Method name: void doFileOperations() Method name: void doResourceOperations(Map)
Number of AST nodes: 17 Number of AST nodes: 16
1
Enumeration e = fileCopyMap.keys
1
if (map.size() > 0) {
2
            log("Copying " + map.size()
3
                + " resource" + (map.size() == 1 ? "" : "s")
4
                + " to " + destDir.getAbsolutePath());
2
();
5
            Iterator iter = map.keySet().iterator();
3
            while (e.hasMoreElements()) {
6
            while (iter.hasNext()) {
4
                String fromFile = (String) e.nextElement();
7
                Resource fromResource = (Resource) iter.next();
5
                String[] toFiles = (String[]) fileCopyMap.get(fromFile);
8
                String[] toFiles = (String[]) map.get(fromResource);
6
                for (int i = 0; i < toFiles.length; i++) {
9
                for (int i = 0; i < toFiles.length; i++) {
7
                    String toFile = toFiles[i];
10
                    String toFile = toFiles[i];
8
                    if (fromFile.equals(toFile)) {
11
                    try {
9
                        log("Skipping self-copy of " + fromFile, verbosity);
12
                        log("
10
                        continue;
11
                    }
12
                    try {
13
                        log("Copying " + fromFile + " to " + toFile,
13
Copying " + fromResource + " to " + toFile,
14
 verbosity);
14
                            verbosity);
15
                        FilterSetCollection executionFilters =
15
                        FilterSetCollection executionFilters =
16
                            new FilterSetCollection();
16
                            new FilterSetCollection();
17
                        if (filtering) {
17
                        if (filtering) {
18
                            executionFilters
18
                            executionFilters
19
                                .addFilterSet(getProject().getGlobalFilterSet());
19
                                .addFilterSet(getProject().getGlobalFilterSet());
20
                        }
20
                        }
21
                        for (Enumeration filterEnum = filterSets.elements();
21
                        for (Enumeration filterEnum = filterSets.elements();
22
                            filterEnum.hasMoreElements();) {
22
                            filterEnum.hasMoreElements();) {
23
                            executionFilters
23
                            executionFilters
24
                                .addFilterSet((FilterSet) filterEnum.nextElement());
24
                                .addFilterSet((FilterSet) filterEnum.nextElement());
25
                        }
25
                        }
26
                        fileUtils.copyFile(fromFile, toFile,
26
                        ResourceUtils.copyResource(fromResource,
27
                                                   new FileResource(destDir,
28
                                                                    toFile),
27
 executionFilters,
29
                                                   executionFilters,
28
                                           filterChains,
30
                                                   filterChains,
29
 forceOverwrite,
31
                                                   forceOverwrite,
30
                                           preserveLastModified,
32
                                                   preserveLastModified,
31
 inputEncoding,
33
                                                   inputEncoding,
32
                                           outputEncoding,
34
                                                   outputEncoding,
33
 getProject());
35
                                                   getProject());
34
                    } catch (IOException ioe) {
36
                    } catch (IOException ioe) {
35
                        String msg = "Failed to copy " + fromFile
37
                        String msg = "Failed to copy " + fromResource
36
 + " to " + toFile
38
                            + " to " + toFile
37
                            + " due to " + getDueTo(ioe);
39
                            + " due to " + getDueTo(ioe);
38
                        File targetFile = new File(toFile);
40
                        File targetFile = new File(toFile);
39
                        if (targetFile.exists() && !targetFile.delete()) {
41
                        if (targetFile.exists() && !targetFile.delete()) {
40
                            msg += " and I couldn't delete the corrupt " + toFile;
42
                            msg += " and I couldn't delete the corrupt " + toFile;
41
                        }
43
                        }
42
                        if (failonerror) {
44
                        if (failonerror) {
43
                            throw new BuildException(msg, ioe, getLocation());
45
                            throw new BuildException(msg, ioe, getLocation());
44
                        }
46
                        }
45
                        log(msg, Project.MSG_ERR);
47
                        log(msg, Project.MSG_ERR);
46
                    }
48
                    }
47
                }
49
                }
48
            }
50
            }
51
        }
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)2.0
Clones locationClones are declared in the same class
Number of node comparisons41
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements10
    Number of unmapped statements in the first code fragment5
    Number of unmapped statements in the second code fragment2
    Time elapsed for statement mapping (ms)11.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
                                                                                                  
    5
    Resource fromResource = (Resource)iter.next();
    Preondition Violations
    Unmatched statement Resource fromResource=(Resource)iter.next(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5
    Resource fromResource = (Resource)iter.next();
    5
    String fromFile = (String)e.nextElement();
    5
    String fromFile = (String)e.nextElement();
    Preondition Violations
    Unmatched statement String fromFile=(String)e.nextElement(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                          
    6
    String[] toFiles = (String[])fileCopyMap.get(fromFile);
    6
    String[] toFiles = (String[])fileCopyMap.get(fromFile);
    6
    String[] toFiles = (String[])map.get(fromResource);
    Differences
    Expression1Expression2Difference
    fromFilefromResourceVARIABLE_NAME_MISMATCH
    java.lang.Stringorg.apache.tools.ant.types.ResourceVARIABLE_TYPE_MISMATCH
    fileCopyMapmapVARIABLE_NAME_MISMATCH
    java.util.Hashtablejava.util.MapVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.lang.String of variable fromFile does not match with type org.apache.tools.ant.types.Resource of variable fromResource
    • Make classes java.lang.String and org.apache.tools.ant.types.Resource extend a common superclass
    Type java.util.Hashtable of variable fileCopyMap does not match with type java.util.Map of variable map
    • Make classes java.util.Hashtable and java.util.Map extend a common superclass
    6
    String[] toFiles = (String[])map.get(fromResource);
    7
    for (int i = 0; i < toFiles.length; i++)
    7
    for (int i = 0; i < toFiles.length; i++)
    8
    String toFile = toFiles[i];
    8
    String toFile = toFiles[i];
    9
    if (fromFile.equals(toFile))
    9
    if (fromFile.equals(toFile))
    Preondition Violations
    Unmatched statement if(fromFile.equals(toFile)) cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                
    10
    log("Skipping self-copy of " + fromFile, verbosity);
                                                                                                                  
    11
    continue;
    11
    continue;
    Preondition Violations
    Unmatched continue;
                              
    12
    try
    12
    try
    9
    try
    Differences
    Expression1Expression2Difference
    fromFilefromResourceVARIABLE_NAME_MISMATCH
    java.lang.Stringorg.apache.tools.ant.types.ResourceVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.lang.String of variable fromFile does not match with type org.apache.tools.ant.types.Resource of variable fromResource
    • Make classes java.lang.String and org.apache.tools.ant.types.Resource extend a common superclass
    9
    try
    13
    log("Copying " + fromFile + " to " + toFile, verbosity);
    13
    log("Copying " + fromFile + " to " + toFile, verbosity);
    10
    log("Copying " + fromResource + " to " + toFile, verbosity);
    Differences
    Expression1Expression2Difference
    fromFilefromResourceVARIABLE_NAME_MISMATCH
    java.lang.Stringorg.apache.tools.ant.types.ResourceVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.lang.String of variable fromFile does not match with type org.apache.tools.ant.types.Resource of variable fromResource
    • Make classes java.lang.String and org.apache.tools.ant.types.Resource extend a common superclass
    10
    log("Copying " + fromResource + " to " + toFile, verbosity);
    14
    FilterSetCollection executionFilters = new FilterSetCollection();
    11
    FilterSetCollection executionFilters = new FilterSetCollection();
    15
    if (filtering)
    12
    if (filtering)
    16
    executionFilters.addFilterSet(getProject().getGlobalFilterSet());
    13
    executionFilters.addFilterSet(getProject().getGlobalFilterSet());
    17
    for (Enumeration filterEnum = filterSets.elements(); filterEnum.hasMoreElements(); )
    14
    for (Enumeration filterEnum = filterSets.elements(); filterEnum.hasMoreElements(); )
    18
    executionFilters.addFilterSet((FilterSet)filterEnum.nextElement());
    15
    executionFilters.addFilterSet((FilterSet)filterEnum.nextElement());
                                                                                                                                                                                                                                                                                                                                                                                        
    16
    ResourceUtils.copyResource(fromResource, new FileResource(destDir, toFile), executionFilters, filterChains, forceOverwrite, preserveLastModified, inputEncoding, outputEncoding, getProject());
    Preondition Violations
    Unmatched statement ResourceUtils.copyResource(fromResource,new FileResource(destDir,toFile),executionFilters,filterChains,forceOverwrite,preserveLastModified,inputEncoding,outputEncoding,getProject()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement ResourceUtils.copyResource(fromResource,new FileResource(destDir,toFile),executionFilters,filterChains,forceOverwrite,preserveLastModified,inputEncoding,outputEncoding,getProject()); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    16
    ResourceUtils.copyResource(fromResource, new FileResource(destDir, toFile), executionFilters, filterChains, forceOverwrite, preserveLastModified, inputEncoding, outputEncoding, getProject());
    19
    fileUtils.copyFile(fromFile, toFile, executionFilters, filterChains, forceOverwrite, preserveLastModified, inputEncoding, outputEncoding, getProject());
    19
    fileUtils.copyFile(fromFile, toFile, executionFilters, filterChains, forceOverwrite, preserveLastModified, inputEncoding, outputEncoding, getProject());
    Preondition Violations
    Unmatched statement fileUtils.copyFile(fromFile,toFile,executionFilters,filterChains,forceOverwrite,preserveLastModified,inputEncoding,outputEncoding,getProject()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement fileUtils.copyFile(fromFile,toFile,executionFilters,filterChains,forceOverwrite,preserveLastModified,inputEncoding,outputEncoding,getProject()); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
                                                                                                                                                                                                                                                                                                            
    Precondition Violations (13)
    Row Violation
    1Unmatched statement Resource fromResource=(Resource)iter.next(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement String fromFile=(String)e.nextElement(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Type java.lang.String of variable fromFile does not match with type org.apache.tools.ant.types.Resource of variable fromResource
    4Type java.util.Hashtable of variable fileCopyMap does not match with type java.util.Map of variable map
    5Unmatched statement if(fromFile.equals(toFile)) cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched continue;
    7Type java.lang.String of variable fromFile does not match with type org.apache.tools.ant.types.Resource of variable fromResource
    8Type java.lang.String of variable fromFile does not match with type org.apache.tools.ant.types.Resource of variable fromResource
    9Unmatched statement ResourceUtils.copyResource(fromResource,new FileResource(destDir,toFile),executionFilters,filterChains,forceOverwrite,preserveLastModified,inputEncoding,outputEncoding,getProject()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10Unmatched statement ResourceUtils.copyResource(fromResource,new FileResource(destDir,toFile),executionFilters,filterChains,forceOverwrite,preserveLastModified,inputEncoding,outputEncoding,getProject()); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    11Unmatched statement fileUtils.copyFile(fromFile,toFile,executionFilters,filterChains,forceOverwrite,preserveLastModified,inputEncoding,outputEncoding,getProject()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12Unmatched statement fileUtils.copyFile(fromFile,toFile,executionFilters,filterChains,forceOverwrite,preserveLastModified,inputEncoding,outputEncoding,getProject()); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    13Clone fragment #1 returns variables toFile, executionFilters , while Clone fragment #2 returns variables toFile, executionFilters