/** * Takes the command line arguments and uses them to determine how to * startup JMeter. * * Called reflectively by {@link NewDriver#main(String[])} */ public void start(String[] args) { CLArgsParser parser = new CLArgsParser(args, options); String error = parser.getErrorString(); if (error == null){// Check option combinations boolean gui = parser.getArgumentById(NONGUI_OPT)==null; boolean nonGuiOnly = parser.getArgumentById(REMOTE_OPT)!=null || parser.getArgumentById(REMOTE_OPT_PARAM)!=null || parser.getArgumentById(REMOTE_STOP)!=null; if (gui && nonGuiOnly) { error = "-r and -R and -X are only valid in non-GUI mode"; } } if (null != error) { System.err.println("Error: " + error); System.out.println("Usage"); System.out.println(CLUtil.describeOptions(options).toString()); return; } try { initializeProperties(parser); // Also initialises JMeter logging /* * The following is needed for HTTPClient. * (originally tried doing this in HTTPSampler2, * but it appears that it was done too late when running in GUI mode) * Set the commons logging default to Avalon Logkit, if not already defined */ if (System.getProperty("org.apache.commons.logging.Log") == null) { // $NON-NLS-1$ System.setProperty("org.apache.commons.logging.Log" // $NON-NLS-1$ , "org.apache.commons.logging.impl.LogKitLogger"); // $NON-NLS-1$ } Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { if (!(e instanceof ThreadDeath)) { log.error("Uncaught exception: ", e); System.err.println("Uncaught Exception " + e + ". See log file for details."); } } }); log.info(JMeterUtils.getJMeterCopyright()); log.info("Version " + JMeterUtils.getJMeterVersion()); logProperty("java.version"); //$NON-NLS-1$ logProperty("java.vm.name"); //$NON-NLS-1$ logProperty("os.name"); //$NON-NLS-1$ logProperty("os.arch"); //$NON-NLS-1$ logProperty("os.version"); //$NON-NLS-1$ logProperty("file.encoding"); // $NON-NLS-1$ log.info("Default Locale=" + Locale.getDefault().getDisplayName()); log.info("JMeter Locale=" + JMeterUtils.getLocale().getDisplayName()); log.info("JMeterHome=" + JMeterUtils.getJMeterHome()); logProperty("user.dir"," ="); //$NON-NLS-1$ log.info("PWD ="+new File(".").getCanonicalPath());//$NON-NLS-1$ log.info("IP: "+JMeterUtils.getLocalHostIP() +" Name: "+JMeterUtils.getLocalHostName() +" FullName: "+JMeterUtils.getLocalHostFullName()); setProxy(parser); updateClassLoader(); if (log.isDebugEnabled()) { String jcp=System.getProperty("java.class.path");// $NON-NLS-1$ String bits[] =jcp.split(File.pathSeparator); log.debug("ClassPath"); for(String bit : bits){ log.debug(bit); } log.debug(jcp); } // Set some (hopefully!) useful properties long now=System.currentTimeMillis(); JMeterUtils.setProperty("START.MS",Long.toString(now));// $NON-NLS-1$ Date today=new Date(now); // so it agrees with above // TODO perhaps should share code with __time() function for this... JMeterUtils.setProperty("START.YMD",new SimpleDateFormat("yyyyMMdd").format(today));// $NON-NLS-1$ $NON-NLS-2$ JMeterUtils.setProperty("START.HMS",new SimpleDateFormat("HHmmss").format(today));// $NON-NLS-1$ $NON-NLS-2$ if (parser.getArgumentById(VERSION_OPT) != null) { System.out.println(JMeterUtils.getJMeterCopyright()); System.out.println("Version " + JMeterUtils.getJMeterVersion()); } else if (parser.getArgumentById(HELP_OPT) != null) { System.out.println(JMeterUtils.getResourceFileAsText("org/apache/jmeter/help.txt"));// $NON-NLS-1$ } else if (parser.getArgumentById(SERVER_OPT) != null) { // Start the server try { RemoteJMeterEngineImpl.startServer(JMeterUtils.getPropDefault("server_port", 0)); // $NON-NLS-1$ } catch (Exception ex) { System.err.println("Server failed to start: "+ex); log.error("Giving up, as server failed with:", ex); throw ex; } startOptionalServers(); } else { String testFile=null; CLOption testFileOpt = parser.getArgumentById(TESTFILE_OPT); if (testFileOpt != null){ testFile = testFileOpt.getArgument(); if (USE_LAST_JMX.equals(testFile)) { testFile = LoadRecentProject.getRecentFile(0);// most recent } } if (parser.getArgumentById(NONGUI_OPT) == null) { startGui(testFile); startOptionalServers(); } else { CLOption rem=parser.getArgumentById(REMOTE_OPT_PARAM); if (rem==null) { rem=parser.getArgumentById(REMOTE_OPT); } CLOption jtl = parser.getArgumentById(LOGFILE_OPT); String jtlFile = null; if (jtl != null){ jtlFile=processLAST(jtl.getArgument(), ".jtl"); // $NON-NLS-1$ } startNonGui(testFile, jtlFile, rem); startOptionalServers(); } } } catch (IllegalUserActionException e) { System.out.println(e.getMessage()); System.out.println("Incorrect Usage"); System.out.println(CLUtil.describeOptions(options).toString()); } catch (Throwable e) { log.fatalError("An error occurred: ",e); System.out.println("An error occurred: " + e.getMessage()); System.exit(1); // TODO - could this be return? } }
private static List<String> getClasspathMatches(String[] strPathsOrJars) { final String javaClassPath = System.getProperty("java.class.path"); // $NON-NLS-1$ StringTokenizer stPaths = new StringTokenizer(javaClassPath, System.getProperty("path.separator")); // $NON-NLS-1$ if (log.isDebugEnabled()) { log.debug("Classpath = " + javaClassPath); for (int i = 0; i < strPathsOrJars.length; i++) { log.debug("strPathsOrJars[" + i + "] : " + strPathsOrJars[i]); } } // find all jar files or paths that end with strPathOrJar ArrayList<String> listPaths = new ArrayList<String>(); String strPath = null; while (stPaths.hasMoreTokens()) { strPath = fixPathEntry(stPaths.nextToken()); if (strPathsOrJars == null) { log.debug("Adding: " + strPath); listPaths.add(strPath); } else { boolean found = false; for (int i = 0; i < strPathsOrJars.length; i++) { if (strPath.endsWith(strPathsOrJars[i])) { found = true; log.debug("Adding " + strPath + " found at " + i); listPaths.add(strPath); break;// no need to look further } } if (!found) { log.debug("Did not find: " + strPath); } } } return listPaths; }
Clone fragments detected by clone detection tool
File path: /apache-jmeter-2.11/src/core/org/apache/jmeter/JMeter.java File path: /apache-jmeter-2.11/src/jorphan/org/apache/jorphan/reflect/ClassFinder.java
Method name: void start(String[]) Method name: List getClasspathMatches(String[])
Number of AST nodes: 2 Number of AST nodes: 2
1
/**
1
private static List<String> getClasspathMatches(String[] strPathsOrJars) {
2
     * Takes the command line arguments and uses them to determine how to
2
        final String javaClassPath = System.getProperty("java.class.path"); // $NON-NLS-1$
3
     * startup JMeter.
3
        StringTokenizer stPaths =
4
     * 
4
            new StringTokenizer(javaClassPath,
5
     * Called reflectively by {@link NewDriver#main(String[])}
5
                System.getProperty("path.separator")); // $NON-NLS-1$
6
     */
6
        if (log.isDebugEnabled()) {
7
    public void start(String[] args) {
7
            log.debug("Classpath = " + javaClassPath);
8
8
            for (int i = 0; i < strPathsOrJars.length; i++) {
9
        CLArgsParser parser = new CLArgsParser(args, options);
9
                log.debug("strPathsOrJars[" + i + "] : " + strPathsOrJars[i]);
10
        String error = parser.getErrorString();
10
            }
11
        if (error == null){// Check option combinations
11
        }
12
            boolean gui = parser.getArgumentById(NONGUI_OPT)==null;
12
13
            boolean nonGuiOnly = parser.getArgumentById(REMOTE_OPT)!=null
13
        // find all jar files or paths that end with strPathOrJar
14
                               || parser.getArgumentById(REMOTE_OPT_PARAM)!=null
14
        ArrayList<String> listPaths = new ArrayList<String>();
15
                               || parser.getArgumentById(REMOTE_STOP)!=null;
15
        String strPath = null;
16
            if (gui && nonGuiOnly) {
16
        while (stPaths.hasMoreTokens()) {
17
                error = "-r and -R and -X are only valid in non-GUI mode";
17
            strPath = fixPathEntry(stPaths.nextToken());
18
            }
18
            if (strPathsOrJars == null) {
19
        }
19
                log.debug("Adding: " + strPath);
20
        if (null != error) {
20
                listPaths.add(strPath);
21
            System.err.println("Error: " + error);
21
            } else {
22
            System.out.println("Usage");
22
                boolean found = false;
23
            System.out.println(CLUtil.describeOptions(options).toString());
23
                for (int i = 0; i < strPathsOrJars.length; i++) {
24
            return;
24
                    if (strPath.endsWith(strPathsOrJars[i])) {
25
        }
25
                        found = true;
26
        try {
26
                        log.debug("Adding " + strPath + " found at " + i);
27
            initializeProperties(parser); // Also initialises JMeter logging
27
                        listPaths.add(strPath);
28
28
                        break;// no need to look further
29
            /*
29
                    }
30
             * The following is needed for HTTPClient.
30
                }
31
             * (originally tried doing this in HTTPSampler2,
31
                if (!found) {
32
             * but it appears that it was done too late when running in GUI mode)
32
                    log.debug("Did not find: " + strPath);
33
             * Set the commons logging default to Avalon Logkit, if not already defined
33
                }
34
             */
34
            }
35
            if (System.getProperty("org.apache.commons.logging.Log") == null) { // $NON-NLS-1$
35
        }
36
                System.setProperty("org.apache.commons.logging.Log" // $NON-NLS-1$
36
        return listPaths;
37
                        , "org.apache.commons.logging.impl.LogKitLogger"); // $NON-NLS-1$
37
    }
38
            }
39
40
            Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {                
41
                @Override
42
                public void uncaughtException(Thread t, Throwable e) {
43
                    if (!(e instanceof ThreadDeath)) {
44
                        log.error("Uncaught exception: ", e);
45
                        System.err.println("Uncaught Exception " + e + ". See log file for details.");
46
                    }
47
                }
48
            });
49
50
            log.info(JMeterUtils.getJMeterCopyright());
51
            log.info("Version " + JMeterUtils.getJMeterVersion());
52
            logProperty("java.version"); //$NON-NLS-1$
53
            logProperty("java.vm.name"); //$NON-NLS-1$
54
            logProperty("os.name"); //$NON-NLS-1$
55
            logProperty("os.arch"); //$NON-NLS-1$
56
            logProperty("os.version"); //$NON-NLS-1$
57
            logProperty("file.encoding"); // $NON-NLS-1$
58
            log.info("Default Locale=" + Locale.getDefault().getDisplayName());
59
            log.info("JMeter  Locale=" + JMeterUtils.getLocale().getDisplayName());
60
            log.info("JMeterHome="     + JMeterUtils.getJMeterHome());
61
            logProperty("user.dir","  ="); //$NON-NLS-1$
62
            log.info("PWD       ="+new File(".").getCanonicalPath());//$NON-NLS-1$
63
            log.info("IP: "+JMeterUtils.getLocalHostIP()
64
                    +" Name: "+JMeterUtils.getLocalHostName()
65
                    +" FullName: "+JMeterUtils.getLocalHostFullName());
66
            setProxy(parser);
67
68
            updateClassLoader();
69
            if (log.isDebugEnabled())
70
            {
71
                String jcp=System.getProperty("java.class.path");// $NON-NLS-1$
72
                String bits[] =jcp.split(File.pathSeparator);
73
                log.debug("ClassPath");
74
                for(String bit : bits){
75
                    log.debug(bit);
76
                }
77
                log.debug(jcp);
78
            }
79
80
            // Set some (hopefully!) useful properties
81
            long now=System.currentTimeMillis();
82
            JMeterUtils.setProperty("START.MS",Long.toString(now));// $NON-NLS-1$
83
            Date today=new Date(now); // so it agrees with above
84
            // TODO perhaps should share code with __time() function for this...
85
            JMeterUtils.setProperty("START.YMD",new SimpleDateFormat("yyyyMMdd").format(today));// $NON-NLS-1$ $NON-NLS-2$
86
            JMeterUtils.setProperty("START.HMS",new SimpleDateFormat("HHmmss").format(today));// $NON-NLS-1$ $NON-NLS-2$
87
88
            if (parser.getArgumentById(VERSION_OPT) != null) {
89
                System.out.println(JMeterUtils.getJMeterCopyright());
90
                System.out.println("Version " + JMeterUtils.getJMeterVersion());
91
            } else if (parser.getArgumentById(HELP_OPT) != null) {
92
                System.out.println(JMeterUtils.getResourceFileAsText("org/apache/jmeter/help.txt"));// $NON-NLS-1$
93
            } else if (parser.getArgumentById(SERVER_OPT) != null) {
94
                // Start the server
95
                try {
96
                    RemoteJMeterEngineImpl.startServer(JMeterUtils.getPropDefault("server_port", 0)); // $NON-NLS-1$
97
                } catch (Exception ex) {
98
                    System.err.println("Server failed to start: "+ex);
99
                    log.error("Giving up, as server failed with:", ex);
100
                    throw ex;
101
                }
102
                startOptionalServers();
103
            } else {
104
                String testFile=null;
105
                CLOption testFileOpt = parser.getArgumentById(TESTFILE_OPT);
106
                if (testFileOpt != null){
107
                    testFile = testFileOpt.getArgument();
108
                    if (USE_LAST_JMX.equals(testFile)) {
109
                        testFile = LoadRecentProject.getRecentFile(0);// most recent
110
                    }
111
                }
112
                if (parser.getArgumentById(NONGUI_OPT) == null) {
113
                    startGui(testFile);
114
                    startOptionalServers();
115
                } else {
116
                    CLOption rem=parser.getArgumentById(REMOTE_OPT_PARAM);
117
                    if (rem==null) { rem=parser.getArgumentById(REMOTE_OPT); }
118
                    CLOption jtl = parser.getArgumentById(LOGFILE_OPT);
119
                    String jtlFile = null;
120
                    if (jtl != null){
121
                        jtlFile=processLAST(jtl.getArgument(), ".jtl"); // $NON-NLS-1$
122
                    }
123
                    startNonGui(testFile, jtlFile, rem);
124
                    startOptionalServers();
125
                }
126
            }
127
        } catch (IllegalUserActionException e) {
128
            System.out.println(e.getMessage());
129
            System.out.println("Incorrect Usage");
130
            System.out.println(CLUtil.describeOptions(options).toString());
131
        } catch (Throwable e) {
132
            log.fatalError("An error occurred: ",e);
133
            System.out.println("An error occurred: " + e.getMessage());
134
            System.exit(1); // TODO - could this be return?
135
        }
136
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements2
    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.750
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    38
    for (String bit : bits)
    5
    for (int i = 0; i < strPathsOrJars.length; i++)
    39
    log.debug(bit);
    39
    log.debug(bit);
    6
    log.debug("strPathsOrJars[" + i + "] : " + strPathsOrJars[i]);
    Differences
    Expression1Expression2Difference
    bit"strPathsOrJars[" + i + "] : "+ strPathsOrJars[i]TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression bit cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression "strPathsOrJars[" + i + "] : "+ strPathsOrJars[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6
    log.debug("strPathsOrJars[" + i + "] : " + strPathsOrJars[i]);
    Precondition Violations (2)
    Row Violation
    1Expression bit cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression "strPathsOrJars[" + i + "] : "+ strPathsOrJars[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted