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 | } | | | |