Package org.apache.maven.surefire.booter

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


        // ----------------------------------------------------------------------
        // Forking
        // ----------------------------------------------------------------------

        ForkConfiguration fork = new ForkConfiguration();

        // DUNS
        if ( project.getPackaging().equals( "nar" ) || ( getNarArtifacts().size() > 0 ) )
        {
            forkMode = "pertest";
        }

        fork.setForkMode( forkMode );

        processSystemProperties( !fork.isForking() );

        if ( getLog().isDebugEnabled() )
        {
            showMap( systemProperties, "system property" );
        }

        if ( fork.isForking() )
        {
            useSystemClassLoader = useSystemClassLoader == null ? Boolean.TRUE : useSystemClassLoader;
            fork.setUseSystemClassLoader( useSystemClassLoader.booleanValue() );
            fork.setUseManifestOnlyJar( useManifestOnlyJar );

            fork.setSystemProperties( systemProperties );

            if ( "true".equals( debugForkedProcess ) )
            {
                debugForkedProcess =
                    "-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005";
            }

            fork.setDebugLine( debugForkedProcess );

            if ( jvm == null || "".equals( jvm ) )
            {
                // use the same JVM as the one used to run Maven (the "java.home" one)
                jvm = System.getProperty( "java.home" ) + File.separator + "bin" + File.separator + "java";
                getLog().debug( "Using JVM: " + jvm );
            }

            fork.setJvmExecutable( jvm );

            if ( workingDirectory != null )
            {
                fork.setWorkingDirectory( workingDirectory );
            }
            else
            {
                fork.setWorkingDirectory( basedir );
            }

            // BEGINDUNS
            if ( argLine == null )
            {
                argLine = "";
            }

            StringBuffer javaLibraryPath = new StringBuffer();
            if ( testJNIModule() )
            {
                // Add libraries to java.library.path for testing
                File jniLibraryPathEntry =
                    getLayout().getLibDirectory( getTargetDirectory(), getMavenProject().getArtifactId(),
                                                 getMavenProject().getVersion(), getAOL().toString(), Library.JNI );
                if ( jniLibraryPathEntry.exists() )
                {
                    getLog().debug( "Adding library directory to java.library.path: " + jniLibraryPathEntry );
                    if ( javaLibraryPath.length() > 0 )
                    {
                        javaLibraryPath.append( File.pathSeparator );
                    }
                    javaLibraryPath.append( jniLibraryPathEntry );
                }

                File sharedLibraryPathEntry =
                    getLayout().getLibDirectory( getTargetDirectory(), getMavenProject().getArtifactId(),
                                                 getMavenProject().getVersion(), getAOL().toString(), Library.SHARED );
                if ( sharedLibraryPathEntry.exists() )
                {
                    getLog().debug( "Adding library directory to java.library.path: " + sharedLibraryPathEntry );
                    if ( javaLibraryPath.length() > 0 )
                    {
                        javaLibraryPath.append( File.pathSeparator );
                    }
                    javaLibraryPath.append( sharedLibraryPathEntry );
                }

                // add jar file to classpath, as one may want to read a
                // properties file for artifactId and version
                String narFile = "target/" + project.getArtifactId() + "-" + project.getVersion() + ".jar";
                getLog().debug( "Adding to surefire test classpath: " + narFile );
                surefireBooter.addClassPathUrl( narFile );
            }

            List dependencies = getNarArtifacts(); // TODO: get seems heavy, not sure if we can push this up to before the fork to use it multiple times.
            for ( Iterator i = dependencies.iterator(); i.hasNext(); )
            {
                NarArtifact dependency = (NarArtifact) i.next();
                // FIXME this should be overridable
                // NarInfo info = dependency.getNarInfo();
                // String binding = info.getBinding(getAOL(), Library.STATIC);
                // NOTE: fixed to shared, jni
                String[] bindings = { Library.SHARED, Library.JNI };
                for ( int j = 0; j < bindings.length; j++ )
                {
                    String binding = bindings[j];
                    if ( !binding.equals( Library.STATIC ) )
                    {
                        File depLibPathEntry =
                            getLayout().getLibDirectory( getUnpackDirectory(), dependency.getArtifactId(),
                                                         dependency.getVersion(), getAOL().toString(), binding );
                        if ( depLibPathEntry.exists() )
                        {
                            getLog().debug( "Adding dependency directory to java.library.path: " + depLibPathEntry );
                            if ( javaLibraryPath.length() > 0 )
                            {
                                javaLibraryPath.append( File.pathSeparator );
                            }
                            javaLibraryPath.append( depLibPathEntry );
                        }
                    }
                }
            }

            // add final javalibrary path
            if ( javaLibraryPath.length() > 0 )
            {
                // NOTE java.library.path only works for the jni lib itself, and
                // not for its dependent shareables.
                // NOTE: java.library.path does not work with arguments with
                // spaces as
                // SureFireBooter splits the line in parts and then quotes
                // it wrongly
                NarUtil.addLibraryPathToEnv( javaLibraryPath.toString(), environmentVariables, getOS() );
            }

            // necessary to find WinSxS
            if ( getOS().equals( OS.WINDOWS ) )
            {
                environmentVariables.put( "SystemRoot", NarUtil.getEnv( "SystemRoot", "SystemRoot", "C:\\Windows" ) );
            }
            // ENDDUNS

            fork.setArgLine( argLine );

            fork.setEnvironmentVariables( environmentVariables );

            if ( getLog().isDebugEnabled() )
            {
                showMap( environmentVariables, "environment variable" );

                fork.setDebug( true );
            }

            if ( argLine != null )
            {
                List args = Arrays.asList( argLine.split( " " ) );
                if ( args.contains( "-da" ) || args.contains( "-disableassertions" ) )
                {
                    enableAssertions = false;
                }
            }
        }

        surefireBooter.setFailIfNoTests( failIfNoTests == null ? false : failIfNoTests.booleanValue() );

        surefireBooter.setForkedProcessTimeoutInSeconds( forkedProcessTimeoutInSeconds );

        surefireBooter.setRedirectTestOutputToFile( redirectTestOutputToFile );

        surefireBooter.setForkConfiguration( fork );

        surefireBooter.setChildDelegation( childDelegation );

        surefireBooter.setEnableAssertions( enableAssertions );

        surefireBooter.setReportsDirectory( reportsDirectory );

        addReporters( surefireBooter, fork.isForking() );

        return surefireBooter;
    }
View Full Code Here


        // ----------------------------------------------------------------------
        // Forking
        // ----------------------------------------------------------------------

        ForkConfiguration fork = new ForkConfiguration();

        // DUNS
        if ( project.getPackaging().equals( "nar" ) || ( getNarManager().getNarDependencies( "test" ).size() > 0 ) )
        {
            forkMode = "pertest";
        }

        fork.setForkMode( forkMode );

        processSystemProperties( !fork.isForking() );

        if ( getLog().isDebugEnabled() )
        {
            showMap( systemProperties, "system property" );
        }

        if ( fork.isForking() )
        {
            useSystemClassLoader = useSystemClassLoader == null ? Boolean.TRUE : useSystemClassLoader;
            fork.setUseSystemClassLoader( useSystemClassLoader.booleanValue() );
            fork.setUseManifestOnlyJar( useManifestOnlyJar );

            fork.setSystemProperties( systemProperties );

            if ( "true".equals( debugForkedProcess ) )
            {
                debugForkedProcess =
                    "-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005";
            }

            fork.setDebugLine( debugForkedProcess );

            if ( jvm == null || "".equals( jvm ) )
            {
                // use the same JVM as the one used to run Maven (the "java.home" one)
                jvm = System.getProperty( "java.home" ) + File.separator + "bin" + File.separator + "java";
                getLog().debug( "Using JVM: " + jvm );
            }

            fork.setJvmExecutable( jvm );

            if ( workingDirectory != null )
            {
                fork.setWorkingDirectory( workingDirectory );
            }
            else
            {
                fork.setWorkingDirectory( basedir );
            }

            // BEGINDUNS
            if ( argLine == null )
            {
                argLine = "";
            }

            StringBuffer javaLibraryPath = new StringBuffer();
            if ( testJNIModule() )
            {
                // Add libraries to java.library.path for testing
                File jniLibraryPathEntry =
                    getLayout().getLibDirectory( getTargetDirectory(), getMavenProject().getArtifactId(),
                                                 getMavenProject().getVersion(), getAOL().toString(), Library.JNI );
                if ( jniLibraryPathEntry.exists() )
                {
                    getLog().debug( "Adding library directory to java.library.path: " + jniLibraryPathEntry );
                    if ( javaLibraryPath.length() > 0 )
                    {
                        javaLibraryPath.append( File.pathSeparator );
                    }
                    javaLibraryPath.append( jniLibraryPathEntry );
                }

                File sharedLibraryPathEntry =
                    getLayout().getLibDirectory( getTargetDirectory(), getMavenProject().getArtifactId(),
                                                 getMavenProject().getVersion(), getAOL().toString(), Library.SHARED );
                if ( sharedLibraryPathEntry.exists() )
                {
                    getLog().debug( "Adding library directory to java.library.path: " + sharedLibraryPathEntry );
                    if ( javaLibraryPath.length() > 0 )
                    {
                        javaLibraryPath.append( File.pathSeparator );
                    }
                    javaLibraryPath.append( sharedLibraryPathEntry );
                }

                // add jar file to classpath, as one may want to read a
                // properties file for artifactId and version
                String narFile = "target/" + project.getArtifactId() + "-" + project.getVersion() + ".jar";
                getLog().debug( "Adding to surefire test classpath: " + narFile );
                surefireBooter.addClassPathUrl( narFile );
            }

            List dependencies = getNarManager().getNarDependencies( "test" );
            for ( Iterator i = dependencies.iterator(); i.hasNext(); )
            {
                NarArtifact dependency = (NarArtifact) i.next();
                // FIXME this should be overridable
                // NarInfo info = dependency.getNarInfo();
                // String binding = info.getBinding(getAOL(), Library.STATIC);
                // NOTE: fixed to shared, jni
                String[] bindings = { Library.SHARED, Library.JNI };
                for ( int j = 0; j < bindings.length; j++ )
                {
                    String binding = bindings[j];
                    if ( !binding.equals( Library.STATIC ) )
                    {
                        File depLibPathEntry =
                            getLayout().getLibDirectory( getUnpackDirectory(), dependency.getArtifactId(),
                                                         dependency.getVersion(), getAOL().toString(), binding );
                        if ( depLibPathEntry.exists() )
                        {
                            getLog().debug( "Adding dependency directory to java.library.path: " + depLibPathEntry );
                            if ( javaLibraryPath.length() > 0 )
                            {
                                javaLibraryPath.append( File.pathSeparator );
                            }
                            javaLibraryPath.append( depLibPathEntry );
                        }
                    }
                }
            }

            // add final javalibrary path
            if ( javaLibraryPath.length() > 0 )
            {
                // NOTE java.library.path only works for the jni lib itself, and
                // not for its dependent shareables.
                // NOTE: java.library.path does not work with arguments with
                // spaces as
                // SureFireBooter splits the line in parts and then quotes
                // it wrongly
                NarUtil.addLibraryPathToEnv( javaLibraryPath.toString(), environmentVariables, getOS() );
            }

            // necessary to find WinSxS
            if ( getOS().equals( OS.WINDOWS ) )
            {
                environmentVariables.put( "SystemRoot", NarUtil.getEnv( "SystemRoot", "SystemRoot", "C:\\Windows" ) );
            }
            // ENDDUNS

            fork.setArgLine( argLine );

            fork.setEnvironmentVariables( environmentVariables );

            if ( getLog().isDebugEnabled() )
            {
                showMap( environmentVariables, "environment variable" );

                fork.setDebug( true );
            }

            if ( argLine != null )
            {
                List args = Arrays.asList( argLine.split( " " ) );
                if ( args.contains( "-da" ) || args.contains( "-disableassertions" ) )
                {
                    enableAssertions = false;
                }
            }
        }

        surefireBooter.setFailIfNoTests( failIfNoTests == null ? false : failIfNoTests.booleanValue() );

        surefireBooter.setForkedProcessTimeoutInSeconds( forkedProcessTimeoutInSeconds );

        surefireBooter.setRedirectTestOutputToFile( redirectTestOutputToFile );

        surefireBooter.setForkConfiguration( fork );

        surefireBooter.setChildDelegation( childDelegation );

        surefireBooter.setEnableAssertions( enableAssertions );

        surefireBooter.setReportsDirectory( reportsDirectory );

        addReporters( surefireBooter, fork.isForking() );

        return surefireBooter;
    }
View Full Code Here

       
        // ----------------------------------------------------------------------
        // Forking
        // ----------------------------------------------------------------------

        ForkConfiguration fork = new ForkConfiguration();

        fork.setForkMode( forkMode );

        processSystemProperties( !fork.isForking() );

        if ( getLog().isDebugEnabled() )
        {
            showMap( systemProperties, "system property" );
        }

        if ( fork.isForking() )
        {
            useSystemClassLoader = useSystemClassLoader == null ? Boolean.TRUE : useSystemClassLoader;
            fork.setUseSystemClassLoader( useSystemClassLoader.booleanValue() );
            fork.setUseManifestOnlyJar( useManifestOnlyJar );

            fork.setSystemProperties( systemProperties );
           
            if ( "true".equals( debugForkedProcess ) )
            {
                debugForkedProcess = "-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005";
            }
           
            fork.setDebugLine( debugForkedProcess );

            if ( jvm == null || "".equals( jvm ) )
            {
                // use the same JVM as the one used to run Maven (the "java.home" one)
                jvm = System.getProperty( "java.home" ) + File.separator + "bin" + File.separator + "java";
                getLog().debug( "Using JVM: " + jvm );
            }

            fork.setJvmExecutable( jvm );

            if ( workingDirectory != null )
            {
                fork.setWorkingDirectory( workingDirectory );
            }
            else
            {
                fork.setWorkingDirectory( basedir );
            }

            fork.setArgLine( argLine );

            fork.setEnvironmentVariables( environmentVariables );

            if ( getLog().isDebugEnabled() )
            {
                showMap( environmentVariables, "environment variable" );

                fork.setDebug( true );
            }

            if ( argLine != null )
            {
                List args = Arrays.asList( argLine.split( " " ) );
                if ( args.contains( "-da" ) || args.contains( "-disableassertions" ) )
                {
                    enableAssertions = false;
                }
            }
        }

        surefireBooter.setFailIfNoTests( failIfNoTests == null ? false : failIfNoTests.booleanValue() );
       
        surefireBooter.setForkedProcessTimeoutInSeconds( forkedProcessTimeoutInSeconds );

        surefireBooter.setRedirectTestOutputToFile( redirectTestOutputToFile );

        surefireBooter.setForkConfiguration( fork );

        surefireBooter.setChildDelegation( childDelegation );

        surefireBooter.setEnableAssertions( enableAssertions );

        surefireBooter.setReportsDirectory( reportsDirectory );

        addReporters( surefireBooter, fork.isForking() );

        return surefireBooter;
    }
View Full Code Here

TOP

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

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.