alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.test.gui.web.util;

//import org.netbeans.test.oo.gui.jelly.OutputWindow;
//import org.netbeans.test.oo.gui.jelly.Explorer; 

import org.netbeans.jemmy.TimeoutExpiredException;
import org.netbeans.jemmy.Waiter;

import org.netbeans.jellytools.OutputWindowOperator;
import org.netbeans.jellytools.MainWindowOperator; 
import org.netbeans.web.test.util.StatusWaitable;


import java.util.HashSet;
import java.io.File;

/**
 * Compilation Utilites for JSP/Servlet Debug tests.
 * Set of function to check compilation results.
 * @author Vladimir Strigun
 */
public class CompilationUtils {
    private static String classes = "Classes";
    private static String fSep = System.getProperty("file.separator");
    private static String iSep = "|";
    public CompilationUtils() {
    }

    
    public static String checkResultOfJSPCompilation(String node, String name) {
	StringBuffer sb = new StringBuffer(node + ".class");
	//sb.setCharAt(node.indexOf(classes),'c'); //Explorer's "Classes" to FS "classes"
	String file = sb.toString().replace(iSep.charAt(0),fSep.charAt(0));
	String[] variants = {"Finished compilation of JSPs with breakpoints.","Finished " + name + "$jsp.","Finished " + name + ".","Errors compiling " + name + ".", "Breakpoint reached"};
	
	StatusWaitable csw = new StatusWaitable(variants, false);	
	Waiter w = new Waiter(csw);
	try {
            w.waitAction(csw);
        } catch (InterruptedException e) {
            e.printStackTrace();
	    return("Exception while waiting compilation results:" + e);
        } catch (TimeoutExpiredException e1) {
            e1.printStackTrace();
	    //return("Exception while waiting compilation results:" + e1);
        }
        (new OutputWindowOperator()).selectCompilerPage();
        String text = (new OutputWindowOperator()).getText();
	System.out.println("Current status is: " + csw.getStatus());
	System.out.println("Current compiler text is : \"" + text + "\"");
        if(text.indexOf("Error")!=-1) return("ST: " + csw.getStatus()+ " OUT: " + text);
        //mainWindow.switchToDebuggingWorkspace();
	if(csw.getStatus().indexOf("Error")!=-1 | text.indexOf("WARNING:")!=-1) {
	    if(csw.getStatus().indexOf("Finished ")!=-1)
	        return("ST: " + csw.getStatus()+ " OUT: " + text);
            else return null;
	}
	/*if(!(new File(file).exists())) {
	    return("File " + file + " is NOT appears after compilation ");
	} */
	return null;
    }

    public static String checkResultOfServletClean(String node,String name ) {
	StringBuffer sb = new StringBuffer(node + ".class");
	sb.setCharAt(node.indexOf(classes),'c'); //Explorer's "Classes" to FS "classes"
	String file = sb.toString().replace(iSep.charAt(0),fSep.charAt(0));
	String[] variants = {"Finished " + name + ".","Errors compiling " + name + "."};

	StatusWaitable csw = new StatusWaitable(variants);	
	Waiter w = new Waiter(csw);
	try {
            w.waitAction(csw);
        } catch (InterruptedException e) {
            e.printStackTrace();
	    return("Exception while waiting compilation results:" + e);
        } catch (TimeoutExpiredException e1) {
            e1.printStackTrace();
	    return("Exception while waiting compilation results:" + e1);
        }
        (new OutputWindowOperator()).selectCompilerPage();
        String text = (new OutputWindowOperator()).getText();
	System.out.println("Current status is: " + csw.getStatus());
	System.out.println("Current compiler text is : \"" + text + "\"");
	if(csw.getStatus().indexOf("Error")!=-1) {
	    return("ST: " + csw.getStatus()+ " OUT: " + text);
	}
	if(new File(file).exists()) {
	    return("File " + file + " is still present after clean ");
	}
	return null;
    }

/*    public static String checkResultOfCleanAll(String pkg,String name) {
	StringBuffer sb = new StringBuffer(pkg);
	sb.setCharAt(pkg.indexOf(classes),'c'); //Explorer's "Classes" to FS "classes"
	String file = sb.toString().replace(iSep.charAt(0),fSep.charAt(0));
	File dir = new File(file);
	if(!dir.isDirectory()) {
	    return("Wrong parameter for checkResultOfCleanAll: " + pkg);
	}
	String[] variants = {"Finished " + name + ".","Errors compiling " + name + "."};
	StatusWaitable csw = new StatusWaitable(variants);	
	JamWaiter w = new JamWaiter(csw);
	try {
            w.waitAction(csw);
        } catch (InterruptedException e) {
            e.printStackTrace();
	    return("Exception while waiting compilation results:" + e);
        } catch (TimeoutExpiredException e1) {
            e1.printStackTrace();
	    return("Exception while waiting compilation results:" + e1);
        }
	OutputWindow ow = new OutputWindow();
	ow.switchToCompilerTab();
	String text = ow.getText();
	System.out.println("Current status is: " + csw.getStatus());
	System.out.println("Current compiler text is : \"" + text + "\"");
	if(csw.getStatus().indexOf("Error")!=-1) {
	    return("ST: " + csw.getStatus()+ " OUT: " + text);
	}
	if(dir.listFiles(new ClassFileFilter(true)).length != 0) {
	    String list  = "";
	    File[] fl = dir.listFiles(new ClassFileFilter(true));
	    for(int i=0;i
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.