Package org.apache.maven.surefire.booter

Examples of org.apache.maven.surefire.booter.SurefireBooterForkException


        try {
            testsClassLoader = createClassLoader(classPathUrls, null, false);
            // TODO: assertions = true shouldn't be required if we had proper separation (see TestNG)
            surefireClassLoader = createClassLoader(surefireClassPathUrls, testsClassLoader, false);
        } catch (MalformedURLException e) {
            throw new SurefireBooterForkException("Unable to create classloader to find test suites", e);
        }

        int globalResult = 0;

        boolean showHeading = true;
View Full Code Here


        Object suite;
        try {
            suite = Surefire.instantiateObject(className, params, surefireClassLoader);
        } catch (TestSetFailedException e) {
            throw new SurefireBooterForkException(e.getMessage(), e.getCause());
        } catch (ClassNotFoundException e) {
            throw new SurefireBooterForkException("Unable to find class for test suite '" + className + "'", e);
        } catch (NoSuchMethodException e) {
            throw new SurefireBooterForkException("Unable to find appropriate constructor for test suite '" + className
                + "': "
                + e.getMessage(), e);
        }

        Map testSets;
        try {
            Method m = suite.getClass().getMethod("locateTestSets", new Class[] {ClassLoader.class});

            testSets = (Map)m.invoke(suite, new Object[] {testsClassLoader});
        } catch (IllegalAccessException e) {
            throw new SurefireBooterForkException("Error obtaining test sets", e);
        } catch (NoSuchMethodException e) {
            throw new SurefireBooterForkException("Error obtaining test sets", e);
        } catch (InvocationTargetException e) {
            throw new SurefireBooterForkException(e.getTargetException().getMessage(), e.getTargetException());
        }
        return testSets;
    }
View Full Code Here

            surefireProperties = writePropertiesFile("surefire", properties);
            if (forkConfiguration.getSystemProperties() != null) {
                systemProperties = writePropertiesFile("surefire", forkConfiguration.getSystemProperties());
            }
        } catch (IOException e) {
            throw new SurefireBooterForkException("Error creating properties files for forking", e);
        }

        /*
        System.out.println("cp:   " + classPathUrls);
        System.out.println("scp:  " + surefireClassPathUrls);
        System.out.println("sbcp: " + surefireBootClassPathUrls);
        */
       
        List bootClasspath = new ArrayList(surefireBootClassPathUrls.size() + classPathUrls.size());

        bootClasspath.addAll(surefireBootClassPathUrls);

        if (useSystemClassLoader()) {
            bootClasspath.addAll(classPathUrls);
        }

        Commandline cli =
            forkConfiguration.createCommandLine(bootClasspath, useManifestOnlyJar());

        cli.createArg().setFile(surefireProperties);

        if (systemProperties != null) {
            cli.createArg().setFile(systemProperties);
        }

        ForkingStreamConsumer out = getForkingStreamConsumer(showHeading, showFooter, redirectTestOutputToFile);

        StreamConsumer err;

        if (redirectTestOutputToFile) {
            err = out;
        } else {
            err = getForkingStreamConsumer(showHeading, showFooter, redirectTestOutputToFile);
        }

        if (forkConfiguration.isDebug()) {
            System.out.println("Forking command line: " + cli);
        }

        int returnCode;

        try {
            returnCode =
                org.apache.maven.surefire.booter.shade.org.codehaus.plexus.util.cli.CommandLineUtils
                    .executeCommandLine(cli, out, err, forkedProcessTimeoutInSeconds);
        } catch (org.apache.maven.surefire.booter.shade.org.codehaus.plexus.util.cli.CommandLineException e) {
            throw new SurefireBooterForkException("Error while executing forked tests.", e);
        }

        if (redirectTestOutputToFile) {
            // ensure the FileOutputConsumerProxy flushes/closes the output file
            try {
                out.getOutputConsumer().testSetCompleted();
            } catch (Exception e) {
                // the FileOutputConsumerProxy might throw an IllegalStateException but that's not of interest now
            }
        }

        if (surefireProperties != null && surefireProperties.exists()) {
            FileInputStream inStream = null;
            try {
                inStream = new FileInputStream(surefireProperties);

                properties.load(inStream);
            } catch (FileNotFoundException e) {
                throw new SurefireBooterForkException("Unable to reload properties file from forked process", e);
            } catch (IOException e) {
                throw new SurefireBooterForkException("Unable to reload properties file from forked process", e);
            } finally {
                IOUtil.close(inStream);
            }
        }

View Full Code Here

        if (useJar) {
            File jarFile;
            try {
                jarFile = createJar(classPath);
            } catch (IOException e) {
                throw new SurefireBooterForkException("Error creating archive file", e);
            }

            cli.createArg().setValue("-jar");

            cli.createArg().setValue(jarFile.getAbsolutePath());
View Full Code Here

                    {
                        globalResult = globalResult.aggregate( cur );
                    }
                    else
                    {
                        throw new SurefireBooterForkException( "No results for " + result.toString() );
                    }
                }
                catch ( InterruptedException e )
                {
                    throw new SurefireBooterForkException( "Interrupted", e );
                }
                catch ( ExecutionException e )
                {
                    throw new SurefireBooterForkException( "ExecutionException", e );
                }
            }
            return globalResult;

        }
View Full Code Here

                    {
                        globalResult = globalResult.aggregate( cur );
                    }
                    else
                    {
                        throw new SurefireBooterForkException( "No results for " + result.toString() );
                    }
                }
                catch ( InterruptedException e )
                {
                    throw new SurefireBooterForkException( "Interrupted", e );
                }
                catch ( ExecutionException e )
                {
                    throw new SurefireBooterForkException( "ExecutionException", e );
                }
            }
            return globalResult;

        }
View Full Code Here

            // Should stop immediately, as we got all the results if we are here
            executorService.awaitTermination( 60 * 60, TimeUnit.SECONDS );
        }
        catch ( InterruptedException e )
        {
            throw new SurefireBooterForkException( "Interrupted", e );
        }
    }
View Full Code Here

                                                               forkConfiguration.isDebug() );
            }
        }
        catch ( IOException e )
        {
            throw new SurefireBooterForkException( "Error creating properties files for forking", e );
        }

        // this could probably be simplified further
        final Classpath bootClasspathConfiguration = startupConfiguration.isProviderMainClass()
            ? startupConfiguration.getClasspathConfiguration().getProviderClasspath()
            : forkConfiguration.getBootClasspath();

        Classpath bootClasspath = join(
            join( bootClasspathConfiguration, startupConfiguration.getClasspathConfiguration().getTestClasspath() ),
            startupConfiguration.getClasspathConfiguration().getProviderClasspath() );

        if ( log.isDebugEnabled() )
        {
            log.debug( bootClasspath.getLogMessage( "boot" ) );
            log.debug( bootClasspath.getCompactLogMessage( "boot(compact)" ) );
        }
        OutputStreamFlushableCommandline cli =
            forkConfiguration.createCommandLine( bootClasspath.getClassPath(), startupConfiguration, forkNumber );

        final InputStreamCloser inputStreamCloser;
        final Thread inputStreamCloserHook;
        if ( testProvidingInputStream != null )
        {
            testProvidingInputStream.setFlushReceiverProvider( cli );
            inputStreamCloser = new InputStreamCloser( testProvidingInputStream );
            inputStreamCloserHook = new Thread( inputStreamCloser );
            ShutdownHookUtils.addShutDownHook( inputStreamCloserHook );
        }
        else
        {
            inputStreamCloser = null;
            inputStreamCloserHook = null;
        }

        cli.createArg().setFile( surefireProperties );

        if ( systPropsFile != null )
        {
            cli.createArg().setFile( systPropsFile );
        }

        ThreadedStreamConsumer threadedStreamConsumer = new ThreadedStreamConsumer( forkClient );

        if ( forkConfiguration.isDebug() )
        {
            System.out.println( "Forking command line: " + cli );
        }

        RunResult runResult = null;

        try
        {
            final int timeout = forkedProcessTimeoutInSeconds > 0 ? forkedProcessTimeoutInSeconds : 0;
            final int result =
                CommandLineUtils.executeCommandLine( cli, testProvidingInputStream, threadedStreamConsumer,
                                                     threadedStreamConsumer, timeout, inputStreamCloser );
            if ( result != RunResult.SUCCESS )
            {
                throw new SurefireBooterForkException( "Error occurred in starting fork, check output in log" );
            }

        }
        catch ( CommandLineTimeOutException e )
        {
            runResult = RunResult.timeout( defaultReporterFactory.getGlobalRunStatistics().getRunResult() );
        }
        catch ( CommandLineException e )
        {
            runResult = RunResult.failure( defaultReporterFactory.getGlobalRunStatistics().getRunResult(), e );
            throw new SurefireBooterForkException( "Error while executing forked tests.", e.getCause() );
        }
        finally
        {
            threadedStreamConsumer.close();
            if ( inputStreamCloser != null )
View Full Code Here

            SurefireProvider surefireProvider = providerFactory.createProvider( false );
            return surefireProvider.getSuites();
        }
        catch ( SurefireExecutionException e )
        {
            throw new SurefireBooterForkException( "Unable to create classloader to find test suites", e );
        }
    }
View Full Code Here

            {
                jarFile = createJar( classPath, providerThatHasMainMethod );
            }
            catch ( IOException e )
            {
                throw new SurefireBooterForkException( "Error creating archive file", e );
            }

            cli.createArg().setValue( "-jar" );

            cli.createArg().setValue( jarFile.getAbsolutePath() );
View Full Code Here

TOP

Related Classes of org.apache.maven.surefire.booter.SurefireBooterForkException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.