Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.codehaus.mojo.gwt.shell;
  
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
  *
  *   http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
  */
 
 import java.io.File;
 import java.net.URL;
 import java.util.List;
 
Mimic surefire to run GWTTestCases during integration-test phase, until SUREFIRE-508 is fixed

Author(s):
Nicolas De Loof
Version:
$Id: TestMojo.java 9466 2009-04-16 12:03:15Z ndeloof $
See also:
http://code.google.com/intl/fr/webtoolkit/doc/latest/DevGuideTesting.html
Goal:
test
Phase:
integration-test
RequiresDependencyResolution:
test
 
 public class TestMojo
     extends AbstractGwtShellMojo
 {

    
Set this to 'true' to skip running tests, but still compile them. Its use is NOT RECOMMENDED, but quite convenient on occasion.

Parameter:
expression="${skipTests}"
 
     private boolean skipTests;

    
DEPRECATED This old parameter is just like skipTests, but bound to the old property maven.test.skip.exec. Use -DskipTests instead; it's shorter.

Deprecated:
Parameter:
expression="${maven.test.skip.exec}"
 
     private boolean skipExec;

    
Set this to 'true' to bypass unit tests entirely. Its use is NOT RECOMMENDED, especially if you enable it using the "maven.test.skip" property, because maven.test.skip disables both running the tests and compiling the tests. Consider using the skipTests parameter instead.

Parameter:
expression="${maven.test.skip}"
 
     private boolean skip;

    
Set this to true to ignore a failure during testing. Its use is NOT RECOMMENDED, but quite convenient on occasion.

Parameter:
expression="${maven.test.failure.ignore}"
 
     private boolean testFailureIgnore;

    
output directory for code generated by GWT for tests

Parameter:
default-value="target/www-test"
 
     private String out;

    
run tests using web mode rather than developer (a.k.a. hosted) mode

Parameter:
default-value=false expression="${gwt.test.web}"
 
     private boolean webMode;

    
run tests using production mode rather than development (a.k.a. hosted) mode.

See also:
http://code.google.com/intl/fr-FR/webtoolkit/doc/latest/DevGuideCompilingAndDebugging.html.DevGuideProdMode
Parameter:
default-value=false expression="${gwt.test.prod}"
    private boolean productionMode;

    
Configure test mode. Can be set to "manual", "htmlunit", "selenium" or "remoteweb".

Parameter:
expression="${gwt.test.mode}" default-value="manual"
    private String mode;

    
Configure options to run tests with HTMLUnit. The value must descrivbe the browser emulation to be used, FF2, FF3, IE6, IE7, or IE8 (possible multiple values separated by comas).

See also:
http://code.google.com/intl/fr/webtoolkit/doc/latest/DevGuideTestingHtmlUnit.html
Parameter:
expression="${gwt.test.htmlunit}" default-value="FF3"
    private String htmlunit;

    
Configure options to run tests with Selenium. The value must describe the Selenium Remote Control target

See also:
http://code.google.com/intl/fr/webtoolkit/doc/latest/DevGuideTestingRemoteTesting.html.Selenium
Parameter:
expression="${gwt.test.selenium}"
    private String selenium;

    
Configure options to run tests RemoteWebBrowser. The value must describe remote web URL, like "rmi://myhost/ie8"

You must start BrowserManagerServer before running tests with this option (gwt:browser).

See also:
http://code.google.com/intl/fr/webtoolkit/doc/latest/DevGuideTestingRemoteTesting.html.Remote_Web
Parameter:
expression="${gwt.test.remoteweb}"
    private String remoteweb;

    
Time out (in seconds) for test execution in dedicated JVM

Parameter:
default-value="60"
    @SuppressWarnings("unused")
    private int testTimeOut;

    
Comma separated list of ant-style inclusion patterns for GWT integration tests. For example, can be set to **\/*GwtTest.java to match all test class following this naming convention. Surefire plugin may then ne configured to exclude such tests.

It is recommended to use a TestSuite to run GwtTests, as they require some huge setup and are very slow. Running inside a suite allow to execute the setup only once. The default value is defined with this best practice in mind.

Parameter:
default-value="**\/GwtTest*.java,**\/Gwt*Suite.java"
    protected String includes;

    
Comma separated list of ant-style exclusion patterns for GWT integration tests

Parameter:
    protected String excludes;

    
Directory for test reports, defaults to surefire one to match the surefire-report plugin

Parameter:
default-value="${project.build.directory}/surefire-reports"
    private File reportsDirectory;

    
failures counter
    private int failures;
    @Override
    public void doExecute()
    {
        if (  ||  ||  )
        {
            return;
        }
        new TestTemplategetProject(), new TestTemplate.CallBack()
        {
            public void doWithTestFile sourceDirString test )
                throws MojoExecutionException
            {
                forkToRunTesttest );
            }
        } );
        if (  > 0 )
        {
            if (  )
            {
                getLog().error"There are test failures.\n\nPlease refer to " + 
                                    + " for the individual test results." );
            }
            else
            {
                throw new MojoExecutionException"There was test failures." );
            }
        }
    }

    

Parameters:
classpath the test execution classpath
jvm the JVM process command
test the test to run
Throws:
org.apache.maven.plugin.MojoExecutionException some error occured
    private void forkToRunTestString test )
        throws MojoExecutionException
    {
        test = test.substring( 0, test.length() - 5 );
        test = StringUtils.replacetest."." );
        try
        {
            File outFile = new File();
            if (outFile.isAbsolute())
            {
  		outFile.mkdirs();
            }
	    else{
        	new FilegetProject().getBasedir(),  ).mkdirs();
            }
            try
            {
                new JavaCommandMavenTestRunner.class.getName() ).withinScope. ).argtest )
                    .systemProperty"surefire.reports".getAbsolutePath() )
                    .systemProperty"gwt.args"getGwtArgs() ).execute();
            }
            catch ( ForkedProcessExecutionException e )
            {
                ++;
            }
        }
        catch ( Exception e )
        {
            throw new MojoExecutionException"Failed to run GWT tests"e );
        }
    }
    protected String getGwtArgs()
    {
        StringBuilder sb = new StringBuilder();
        sb.append"-out " ).append ).append" " );
        if (  )
        {
            sb.append"-web " );
        }
        if (  )
        {
            sb.append"-prod " );
        }
        if ( .equalsIgnoreCase"manual" ) )
        {
            sb.append"-runStyle Manual:1 " );
        }
        else if ( .equalsIgnoreCase"htmlunit" ) )
        {
            sb.append"-runStyle HtmlUnit:" +  );
        }
        else if ( .equalsIgnoreCase"selenium" ) )
        {
            sb.append"-runStyle Selenium:" +  );
        }
        else if ( .equalsIgnoreCase"remoteweb" ) )
        {
            sb.append"-runStyle RemoteWeb:" +  );
        }
        // TODO Is addArgumentDeploy(cmd) also needed to get readable test stacktraces with an alternative deploy dir?
        return sb.toString();
    }
    @Override
    protected void postProcessClassPathCollection<Fileclasspath )
        throws MojoExecutionException
    {
        classpath.addgetClassPathElementForTestMojo.class ) );
        classpath.addgetClassPathElementForReporterManager.class ) );
        classpath.addgetGwtDevJar() );
    }

    

Parameters:
clazz class to check for classpath resolution
Returns:
The classpath element this class was loaded from
    private File getClassPathElementForClass<?> clazz )
    {
        String classFile = clazz.getName().replace'.''/' ) + ".class";
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        if ( cl == null )
        {
            cl = getClass().getClassLoader();
        }
        URL url = cl.getResourceclassFile );
        getLog().debug"getClassPathElementFor " + clazz.getName() + " file " + url.toString() );
        String path = url.toString();
    
        if ( path.startsWith"jar:" ) )
        {
            path = path.substring( 4, path.indexOf"!" ) );
        }
        else
        {
            path = path.substring( 0, path.length() - classFile.length() );
        }
        if ( path.startsWith"file:" ) )
        {
            path = path.substring( 5 );
            // windauze hack with maven 3 we get those !
            path = path.replace"%20"" " );
        }
        File file = new Filepath );
        getLog().debug"getClassPathElementFor " + clazz.getName() + " file " + file.getPath() );
        return file;
    }

    

Returns:
the project classloader
Throws:
org.apache.maven.artifact.DependencyResolutionRequiredException failed to resolve project dependencies
java.net.MalformedURLException configuration issue ?
    {
        getLog().debug"TestMojo#getProjectClassLoader()" );
        List<?> compile = getProject().getCompileClasspathElements();
        URL[] urls = new URL[compile.size()];
        int i = 0;
        for ( Object object : compile )
        {
            if ( object instanceof Artifact )
            {
                urls[i] = ( (Artifactobject ).getFile().toURI().toURL();
            }
            else
            {
                urls[i] = new File( (Stringobject ).toURI().toURL();
            }
            i++;
        }
        return new URLClassLoaderurls, ClassLoader.getSystemClassLoader() );
    }

    

Parameters:
path file to add to the project compile directories
    protected void addCompileSourceRootFile path )
    {
        getProject().addCompileSourceRootpath.getAbsolutePath() );
    }

    
Add project classpath element to a classpath URL set

Parameters:
originalUrls the initial URL set
Returns:
full classpath URL set
Throws:
org.apache.maven.plugin.MojoExecutionException some error occured
    protected URL[] addProjectClasspathElementsURL[] originalUrls )
        throws MojoExecutionException
    {
        Collection<?> sources = getProject().getCompileSourceRoots();
        Collection<?> resources = getProject().getResources();
        Collection<?> dependencies = getProject().getArtifacts();
        URL[] urls = new URL[originalUrls.length + sources.size() + resources.size() + dependencies.size() + 2];
        int i = originalUrls.length;
        getLog().debug"add compile source roots to GWTCompiler classpath " + sources.size() );
        i = addClasspathElementssourcesurlsi );
        getLog().debug"add resources to GWTCompiler classpath " + resources.size() );
        i = addClasspathElementsresourcesurlsi );
        getLog().debug"add project dependencies to GWTCompiler  classpath " + dependencies.size() );
        i = addClasspathElementsdependenciesurlsi );
        try
        {
            urls[i++] = getGenerateDirectory().toURI().toURL();
            urls[i] = new FilegetProject().getBuild().getOutputDirectory() ).toURI().toURL();
        }
        catch ( MalformedURLException e )
        {
            throw new MojoExecutionException"Failed to convert project.build.outputDirectory to URL"e );
        }
        return urls;
    }

    
Need this to run both pre- and post- PLX-220 fix.

Returns:
a ClassLoader including plugin dependencies and project source foler
Throws:
org.apache.maven.plugin.MojoExecutionException failed to configure ClassLoader
    protected ClassLoader getClassLoader()
        throws MojoExecutionException
    {
        try
        {
            Collection<Fileclasspath = getClasspath. );
            URL[] urls = new URL[classpath.size()];
            int i = 0;
            for ( File file : classpath )
            {
                urls[i++] = file.toURI().toURL();
            }
            ClassLoader parent = getClass().getClassLoader();
            return new URLClassLoaderurlsparent.getParent() );
        }
        catch ( MalformedURLException e )
        {
            throw new MojoExecutionException"Unexpecetd internal error" );
        }
    }

    

Parameters:
testTimeOut the testTimeOut to set
    public void setTestTimeOutint testTimeOut )
    {
        setTimeOuttestTimeOut );
    }
New to GrepCode? Check out our FAQ X