KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > test > CoreTestApplication


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.test;
12
13 import java.io.IOException JavaDoc;
14 import org.eclipse.core.runtime.IPlatformRunnable;
15 import org.eclipse.core.runtime.Platform;
16
17 /**
18  * A an application that launches tests once it is started.
19  */

20 public class CoreTestApplication implements IPlatformRunnable {
21     /** true if workspace tests should log their deltas */
22     private static boolean deltas= false;
23     
24     /**
25      * Runs a set of tests as defined by the given command line args.
26      * This is the platform application entry point.
27      * @see IPlatformRunnable
28      */

29     public Object JavaDoc run(Object JavaDoc arguments) throws Exception JavaDoc {
30         String JavaDoc[] args= Platform.getCommandLineArgs();//getCommand//processCommandLine((String[]) arguments);
31
return new Integer JavaDoc(runTests(args));
32     }
33
34     protected int runTests(String JavaDoc[] args) throws IOException JavaDoc {
35         return EclipseTestRunner.run(args);
36     }
37
38     public static boolean deltasEnabled() {
39         return deltas;
40     }
41         
42     protected String JavaDoc[] processCommandLine(String JavaDoc[] args) {
43         int[] configArgs = new int[100];
44         configArgs[0] = -1; // need to initialize the first element to something that could not be an index.
45
int configArgIndex = 0;
46         for (int i = 0; i < args.length; i++) {
47             boolean found = false;
48             // check for args without parameters (i.e., a flag arg)
49
// see if we should be logging deltas
50
if (args[i].equalsIgnoreCase("-deltas")) {
51                 found = true;
52                 deltas = true;
53             }
54             if (found) {
55                 configArgs[configArgIndex++] = i;
56                 continue;
57             }
58     
59             // check for args with parameters
60
if (i == args.length - 1 || args[i + 1].startsWith("-")) {
61                 continue;
62             }
63             String JavaDoc arg = args[++i];
64
65             // done checking for args. Remember where an arg was found
66
if (found) {
67                 configArgs[configArgIndex++] = i - 1;
68                 configArgs[configArgIndex++] = i;
69             }
70         }
71     
72         //remove all the arguments consumed by this argument parsing
73
if (configArgIndex == 0)
74             return args;
75         String JavaDoc[] passThruArgs = new String JavaDoc[args.length - configArgIndex];
76         configArgIndex = 0;
77         int j = 0;
78         for (int i = 0; i < args.length; i++) {
79             if (i == configArgs[configArgIndex])
80                 configArgIndex++;
81             else
82                 passThruArgs[j++] = args[i];
83         }
84         return passThruArgs;
85     }
86 }
87
Popular Tags