/** * Execute task. * * @exception BuildException if an error occurs */ public void execute() throws BuildException { // validate the input parameters validate(); // build the rdiff command addCommandArgument("rdiff"); addCommandArgument("-s"); if (mystartTag != null) { addCommandArgument("-r"); addCommandArgument(mystartTag); } else { addCommandArgument("-D"); addCommandArgument(mystartDate); } if (myendTag != null) { addCommandArgument("-r"); addCommandArgument(myendTag); } else { addCommandArgument("-D"); addCommandArgument(myendDate); } // support multiple packages StringTokenizer myTokenizer = new StringTokenizer(mypackage); while (myTokenizer.hasMoreTokens()) { addCommandArgument(myTokenizer.nextToken()); } // force command not to be null setCommand(""); File tmpFile = null; try { tmpFile = FILE_UTILS.createTempFile("cvstagdiff", ".log", null); tmpFile.deleteOnExit(); setOutput(tmpFile); // run the cvs command super.execute(); // parse the rdiff CvsTagEntry[] entries = parseRDiff(tmpFile); // write the tag diff writeTagDiff(entries); } finally { if (tmpFile != null) { tmpFile.delete(); } } }
/** * Execute task * * @exception BuildException if something goes wrong executing the * cvs command */ public void execute() throws BuildException { File savedDir = inputDir; // may be altered in validate try { validate(); final Properties userList = new Properties(); loadUserlist(userList); for (int i = 0, size = cvsUsers.size(); i < size; i++) { final CvsUser user = (CvsUser) cvsUsers.get(i); user.validate(); userList.put(user.getUserID(), user.getDisplayname()); } setCommand("log"); if (getTag() != null) { CvsVersion myCvsVersion = new CvsVersion(); myCvsVersion.setProject(getProject()); myCvsVersion.setTaskName("cvsversion"); myCvsVersion.setCvsRoot(getCvsRoot()); myCvsVersion.setCvsRsh(getCvsRsh()); myCvsVersion.setPassfile(getPassFile()); myCvsVersion.setDest(inputDir); myCvsVersion.execute(); if (myCvsVersion.supportsCvsLogWithSOption()) { addCommandArgument("-S"); } } if (null != startDate) { final SimpleDateFormat outputDate = new SimpleDateFormat("yyyy-MM-dd"); // We want something of the form: -d ">=YYYY-MM-dd" final String dateRange = ">=" + outputDate.format(startDate); // Supply '-d' as a separate argument - Bug# 14397 addCommandArgument("-d"); addCommandArgument(dateRange); } // Check if list of files to check has been specified if (!filesets.isEmpty()) { final Enumeration e = filesets.elements(); while (e.hasMoreElements()) { final FileSet fileSet = (FileSet) e.nextElement(); final DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject()); final String[] files = scanner.getIncludedFiles(); for (int i = 0; i < files.length; i++) { addCommandArgument(files[i]); } } } final ChangeLogParser parser = new ChangeLogParser(); final RedirectingStreamHandler handler = new RedirectingStreamHandler(parser); log(getCommand(), Project.MSG_VERBOSE); setDest(inputDir); setExecuteStreamHandler(handler); try { super.execute(); } finally { final String errors = handler.getErrors(); if (null != errors) { log(errors, Project.MSG_ERR); } } final CVSEntry[] entrySet = parser.getEntrySetAsArray(); final CVSEntry[] filteredEntrySet = filterEntrySet(entrySet); replaceAuthorIdWithName(userList, filteredEntrySet); writeChangeLog(filteredEntrySet); } finally { inputDir = savedDir; } }
Clone fragments detected by clone detection tool
File path: /apache-ant-1.7.0/src/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java File path: /apache-ant-1.7.0/src/org/apache/tools/ant/taskdefs/cvslib/ChangeLogTask.java
Method name: void execute() Method name: void execute()
Number of AST nodes: 2 Number of AST nodes: 2
1
/**
1
/**
2
     * Execute task.
2
     * Execute task
3
     *
3
     *
4
     * @exception BuildException if an error occurs
4
     * @exception BuildException if something goes wrong executing the
5
     */
5
     *            cvs command
6
    public void execute() throws BuildException {
6
     */
7
        // validate the input parameters
7
    public void execute() throws BuildException {
8
        validate();
8
        File savedDir = inputDir; // may be altered in validate
9
9
10
        // build the rdiff command
10
        try {
11
        addCommandArgument("rdiff");
11
12
        addCommandArgument("-s");
12
            validate();
13
        if (mystartTag != null) {
13
            final Properties userList = new Properties();
14
            addCommandArgument("-r");
14
15
            addCommandArgument(mystartTag);
15
            loadUserlist(userList);
16
        } else {
16
17
            addCommandArgument("-D");
17
            for (int i = 0, size = cvsUsers.size(); i < size; i++) {
18
            addCommandArgument(mystartDate);
18
                final CvsUser user = (CvsUser) cvsUsers.get(i);
19
        }
19
                user.validate();
20
        if (myendTag != null) {
20
                userList.put(user.getUserID(), user.getDisplayname());
21
            addCommandArgument("-r");
21
            }
22
            addCommandArgument(myendTag);
22
23
        } else {
23
            setCommand("log");
24
            addCommandArgument("-D");
24
25
            addCommandArgument(myendDate);
25
            if (getTag() != null) {
26
        }
26
                CvsVersion myCvsVersion = new CvsVersion();
27
        // support multiple packages
27
                myCvsVersion.setProject(getProject());
28
        StringTokenizer myTokenizer = new StringTokenizer(mypackage);
28
                myCvsVersion.setTaskName("cvsversion");
29
        while (myTokenizer.hasMoreTokens()) {
29
                myCvsVersion.setCvsRoot(getCvsRoot());
30
            addCommandArgument(myTokenizer.nextToken());
30
                myCvsVersion.setCvsRsh(getCvsRsh());
31
        }
31
                myCvsVersion.setPassfile(getPassFile());
32
        // force command not to be null
32
                myCvsVersion.setDest(inputDir);
33
        setCommand("");
33
                myCvsVersion.execute();
34
        File tmpFile = null;
34
                if (myCvsVersion.supportsCvsLogWithSOption()) {
35
        try {
35
                    addCommandArgument("-S");
36
            tmpFile = FILE_UTILS.createTempFile("cvstagdiff", ".log", null);
36
                }
37
            tmpFile.deleteOnExit();
37
            }
38
            setOutput(tmpFile);
38
            if (null != startDate) {
39
39
                final SimpleDateFormat outputDate =
40
            // run the cvs command
40
                    new SimpleDateFormat("yyyy-MM-dd");
41
            super.execute();
41
42
42
                // We want something of the form: -d ">=YYYY-MM-dd"
43
            // parse the rdiff
43
                final String dateRange = ">=" + outputDate.format(startDate);
44
            CvsTagEntry[] entries = parseRDiff(tmpFile);
44
45
45
                // Supply '-d' as a separate argument - Bug# 14397
46
            // write the tag diff
46
                addCommandArgument("-d");
47
            writeTagDiff(entries);
47
                addCommandArgument(dateRange);
48
48
            }
49
        } finally {
49
50
            if (tmpFile != null) {
50
            // Check if list of files to check has been specified
51
                tmpFile.delete();
51
            if (!filesets.isEmpty()) {
52
            }
52
                final Enumeration e = filesets.elements();
53
        }
53
54
    }
54
                while (e.hasMoreElements()) {
55
                    final FileSet fileSet = (FileSet) e.nextElement();
56
                    final DirectoryScanner scanner =
57
                        fileSet.getDirectoryScanner(getProject());
58
                    final String[] files = scanner.getIncludedFiles();
59
60
                    for (int i = 0; i < files.length; i++) {
61
                        addCommandArgument(files[i]);
62
                    }
63
                }
64
            }
65
66
            final ChangeLogParser parser = new ChangeLogParser();
67
            final RedirectingStreamHandler handler =
68
                new RedirectingStreamHandler(parser);
69
70
            log(getCommand(), Project.MSG_VERBOSE);
71
72
            setDest(inputDir);
73
            setExecuteStreamHandler(handler);
74
            try {
75
                super.execute();
76
            } finally {
77
                final String errors = handler.getErrors();
78
79
                if (null != errors) {
80
                    log(errors, Project.MSG_ERR);
81
                }
82
            }
83
            final CVSEntry[] entrySet = parser.getEntrySetAsArray();
84
            final CVSEntry[] filteredEntrySet = filterEntrySet(entrySet);
85
86
            replaceAuthorIdWithName(userList, filteredEntrySet);
87
88
            writeChangeLog(filteredEntrySet);
89
90
        } finally {
91
            inputDir = savedDir;
92
        }
93
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements3
    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 Score0.500
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    15
    while (myTokenizer.hasMoreTokens())
    15
    while (myTokenizer.hasMoreTokens())
    33
    for (int i = 0; i < files.length; i++)
    Differences
    Expression1Expression2Difference
    myTokenizer.hasMoreTokens()i < files.lengthTYPE_COMPATIBLE_REPLACEMENT
    java.lang.Stringjava.lang.String[]VARIABLE_TYPE_MISMATCH
    java.lang.Stringjava.lang.String[]VARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.lang.String of variable mypackage does not match with type java.lang.String[] of variable files
    • Make classes java.lang.String and java.lang.String[] extend a common superclass
    Type java.lang.String of variable mypackage does not match with type java.lang.String[] of variable files
    • Make classes java.lang.String and java.lang.String[] extend a common superclass
    33
    for (int i = 0; i < files.length; i++)
    16
    addCommandArgument(myTokenizer.nextToken());
    16
    addCommandArgument(myTokenizer.nextToken());
    34
    addCommandArgument(files[i]);
    Differences
    Expression1Expression2Difference
    myTokenizer.nextToken()files[i]TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression files[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
    34
    addCommandArgument(files[i]);
    Precondition Violations (3)
    Row Violation
    1Type java.lang.String of variable mypackage does not match with type java.lang.String[] of variable files
    2Type java.lang.String of variable mypackage does not match with type java.lang.String[] of variable files
    3Expression files[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted