public void execute()

in nbm-maven-plugin/src/main/java/org/apache/netbeans/nbm/RunNetBeansMojo.java [92:266]


    public void execute()
            throws MojoExecutionException, MojoFailureException
    {
        netbeansUserdir.mkdirs();

        List<File> clusters = new ArrayList<File>();
        if ( !clusterBuildDir.exists() || clusterBuildDir.listFiles() == null )
        {
            throw new MojoExecutionException(
                    "No clusters to include in execution found. "
                    + "Please run the nbm:cluster or nbm:cluster-app goals before this one." );
        }
        File[] fls = clusterBuildDir.listFiles();
        for ( int i = 0; i < fls.length; i++ )
        {
            if ( fls[i].isDirectory() )
            {
                clusters.add( fls[i] );
            }
        }
        StringBuilder buff = new StringBuilder();
        for ( File cluster : clusters )
        {
            buff.append( cluster.getAbsolutePath() );
            buff.append( ":" );
        }
        if ( buff.lastIndexOf( ":" ) > -1 )
        {
            buff.deleteCharAt( buff.lastIndexOf( ":" ) );
        }

        getLog().debug( "cluster path:\n" + buff.toString() );

        //now check what the exec names are to figure the right XXX.clusters name
        File binDir = new File( netbeansInstallation, "bin" );
        File[] execs = binDir.listFiles();
        String appName = null;
        if ( execs != null )
        {
            for ( File f : execs )
            {
                String name = f.getName();
                if ( name.contains( "_w.exe" ) )
                {
                    continue;
                }
                name = name.replaceFirst( "(64)?([.]exe)?$", "" );
                if ( !name.contains( "." ) )
                {
                    if ( appName == null )
                    {
                        appName = name;
                    }
                    else
                    {
                        if ( !appName.equals( name ) )
                        {
                            getLog().debug( "When examining executable names, found clashing results " + f.getName()
                                    + " " + appName );
                        }
                    }
                }
            }
        }
        if ( appName == null )
        {
            appName = "netbeans";
        }

        //http://www.netbeans.org/issues/show_bug.cgi?id=174819
        StringReader sr = new StringReader( appName + "_extraclusters=\"" + buff.toString() + "\"\n"
                + "extraclusters=\""
                + buff.toString() + "\"\n" + "extra_clusters=\"" + buff.toString() + "\"" );

        // write XXX.conf file with cluster information...
        File etc = new File( netbeansUserdir, "etc" );
        etc.mkdirs();
        File confFile = new File( etc, appName + ".conf" );
        FileOutputStream conf = null;
        try
        {
            conf = new FileOutputStream( confFile );
            IOUtil.copy( sr, conf );
        }
        catch ( IOException ex )
        {
            throw new MojoExecutionException( "Error writing " + confFile, ex );
        }
        finally
        {
            IOUtil.close( conf );
        }

        if ( getLog().isDebugEnabled() )
        {
            try ( InputStream io = new FileInputStream( confFile ) )
            {
                getLog().debug( "Configuration file content:\n" + IOUtil.toString( io ) );
            }
            catch ( IOException ex )
            {
                throw new MojoExecutionException( "Error writing " + confFile, ex );
            }
        }

        boolean windows = Os.isFamily( "windows" );
        Commandline cmdLine = new Commandline();
        File exec;
        if ( windows )
        {
            exec = new File( netbeansInstallation, "bin\\nb.exe" );
            if ( !exec.exists() )
            {
                // in 6.7 and onward, there's no nb.exe file.
                exec = new File( netbeansInstallation, "bin\\" + appName + ".exe" );
                String jdkHome = System.getenv( "JAVA_HOME" );
                if ( jdkHome != null )
                {
                    if ( new File( jdkHome, "jre\\lib\\amd64\\jvm.cfg" ).exists()
                         || new File( jdkHome, "bin\\windowsaccessbridge-64.dll" ).exists() )
                    {
                        File exec64 = new File( netbeansInstallation, "bin\\" + appName + "64.exe" );
                        if ( exec64.isFile() )
                        {
                            exec = exec64;
                        }
                    }
                }
                cmdLine.addArguments( new String[]
                {
                    "--console", "suppress"
                } );
            }
        }
        else
        {
            exec = new File( netbeansInstallation, "bin/" + appName );
        }
        cmdLine.setExecutable( exec.getAbsolutePath() );

        try
        {
            String[] args = new String[]
            {
                //TODO --jdkhome
                "--userdir",
                netbeansUserdir.getAbsolutePath(),
                "-J-Dnetbeans.logger.console=true",
                "-J-ea",
            };
            cmdLine.addArguments( args );
            getLog().info( "Additional arguments=" + additionalArguments );
            cmdLine.addArguments( CommandLineUtils.translateCommandline( additionalArguments ) );
            cmdLine.addArguments( CommandLineUtils.translateCommandline( getDebugAdditionalArguments() ) );
            for ( int i = 0; i < cmdLine.getArguments().length; i++ )
            {
                getLog().info( "      " + cmdLine.getArguments()[i] );
            }
            getLog().info( "Executing: " + cmdLine.toString() );
            StreamConsumer out = new StreamConsumer()
            {

                public void consumeLine( String line )
                {
                    getLog().info( line );
                }
            };
            CommandLineUtils.executeCommandLine( cmdLine, out, out );

        }
        catch ( Exception e )
        {
            throw new MojoExecutionException( "Failed executing NetBeans", e );
        }
    }