@@ -33,32 +33,33 @@ public class GcjFlexTestServlet extends HttpServlet {
3333
3434 private static final long serialVersionUID = 523885428311420041L ;
3535
36- private final ThreadPoolExecutor executor = new ThreadPoolExecutor ( 1 , 1 , 0L ,
37- TimeUnit .MILLISECONDS , new LinkedBlockingQueue <Runnable >());
38- private volatile GcjTestRunner testRunner = null ;
36+ private final ThreadPoolExecutor executor =
37+ new ThreadPoolExecutor ( 1 , 1 , 0L , TimeUnit .MILLISECONDS , new LinkedBlockingQueue <Runnable >());
38+ private volatile GcjTestRunner testRunner ;
3939
4040 @ Override
4141 protected void doPost (HttpServletRequest req , HttpServletResponse resp )
4242 throws ServletException , IOException {
4343 try {
4444 String classNames = req .getParameter ("classes" );
4545 PrintWriter out = resp .getWriter ();
46- out .append (startTest (loadClasses (classNames .split ("[\\ r\\ n]+" )), req , resp ));
46+ List <Class <?>> testClasses = loadClasses (classNames .split ("[\\ r\\ n]+" ));
47+ String output = runTests (testClasses , req , resp );
48+ out .append (output );
4749 out .close ();
4850 } catch (Exception e ) {
4951 throw new RuntimeException (e );
5052 }
5153 }
5254
5355 @ Override
54- public void doGet (HttpServletRequest req , HttpServletResponse resp )
55- throws IOException {
56+ public void doGet (HttpServletRequest req , HttpServletResponse resp ) throws IOException {
5657 PrintWriter out = resp .getWriter ();
5758 out .append (getTestOutput (req , resp ));
5859 out .close ();
5960 }
6061
61- private List <Class <?>> loadClasses (String [] classNames ) throws ClassNotFoundException {
62+ private List <Class <?>> loadClasses (String ... classNames ) throws ClassNotFoundException {
6263 List <Class <?>> classes = new ArrayList <>();
6364 for (String className : classNames ) {
6465 String cn = className .trim ();
@@ -69,34 +70,44 @@ private List<Class<?>> loadClasses(String[] classNames) throws ClassNotFoundExce
6970 return classes ;
7071 }
7172
72- private String startTest ( List < Class <?>> classes , HttpServletRequest req ,
73- HttpServletResponse resp ) {
73+ private String runTests (
74+ List < Class <?>> classes , HttpServletRequest req , HttpServletResponse resp ) {
7475 synchronized (executor ) {
7576 resp .setContentType ("text/html" );
7677 if (executor .getActiveCount () > 0 ) {
7778 return "Cannot start new test: the previous test hasn't completed yet.<p/>"
78- + "The active test progress is at <a href='" + req .getRequestURL ()
79- + "'>" + req .getRequestURL () + "</a>." ;
79+ + "The active test progress is at <a href='"
80+ + req .getRequestURL ()
81+ + "'>"
82+ + req .getRequestURL ()
83+ + "</a>." ;
8084 }
8185
8286 testRunner = new GcjTestRunner (classes );
8387 executor .execute (testRunner );
8488 return "Test started. Check progress at <a href='"
85- + req .getRequestURL () + "'>" + req .getRequestURL () + "</a>" ;
89+ + req .getRequestURL ()
90+ + "'>"
91+ + req .getRequestURL ()
92+ + "</a>" ;
8693 }
8794 }
8895
8996 private String getTestOutput (HttpServletRequest req , HttpServletResponse resp ) {
9097 synchronized (executor ) {
91- if (testRunner == null ) {
92- resp .setContentType ("text/html" );
93- String link = req .getRequestURL ()
94- .substring (0 , req .getRequestURL ().length () - req .getRequestURI ().length ());
95- return "Test hasn't been started yet. Go to <a href='" + link + "'>" + link
96- + "</a> to start a new test" ;
98+ if (testRunner != null ) {
99+ resp .setContentType ("text" );
100+ return testRunner .getOutput ();
97101 }
98- resp .setContentType ("text" );
99- return testRunner .getOutput ();
102+ resp .setContentType ("text/html" );
103+ int urlUriLenDiff = req .getRequestURL ().length () - req .getRequestURI ().length ();
104+ String link = req .getRequestURL ().substring (0 , urlUriLenDiff );
105+ return "Test hasn't been started yet. Go to <a href='"
106+ + link
107+ + "'>"
108+ + link
109+ + "</a> to start a new test" ;
110+
100111 }
101112 }
102113
0 commit comments