public void execute()

in installers-maven-plugin/src/main/java/org/apache/directory/server/installers/deb/DebInstallerCommand.java [88:218]


    public void execute() throws MojoExecutionException, MojoFailureException
    {
        // Verifying the target
        if ( !verifyTarget() )
        {
            return;
        }

        log.info( "  Creating Deb installer..." );

        // Creating the target directory, which uses the ID of the Target
        File targetDirectory = getTargetDirectory();

        log.info( "Creating target directory : " + targetDirectory.getAbsolutePath() );

        if ( !getTargetDirectory().mkdirs() )
        {
            Exception e = new IOException( I18n.err( I18n.ERR_00004_COULD_NOT_CREATE_DIRECTORY, getTargetDirectory() ) );
            log.error( e.getLocalizedMessage() );
            throw new MojoFailureException( e.getMessage() );
        }

        log.info( "    Copying Deb installer files" );

        try
        {
            // Creating the installation and instance layouts
            createLayouts();

            // Copying the init script in /etc/init.d/
            File debEtcInitdDirectory = new File( getDebDirectory(), ETC_INITD );

            if ( !debEtcInitdDirectory.mkdirs() )
            {
                Exception e = new IOException( I18n.err( I18n.ERR_00004_COULD_NOT_CREATE_DIRECTORY, debEtcInitdDirectory ) );
                log.error( e.getLocalizedMessage() );
                throw new MojoFailureException( e.getMessage() );
            }

            MojoHelperUtils.copyAsciiFile( mojo, filterProperties, INSTALLERS_PATH + ETC_INITD_SCRIPT,
                getClass().getResourceAsStream( INSTALLERS_PATH + ETC_INITD_SCRIPT ),
                new File( debEtcInitdDirectory, APACHEDS_DASH + mojo.getProject().getVersion() + DASH_DEFAULT ), true );
        }
        catch ( Exception e )
        {
            log.error( e.getMessage() );
            throw new MojoFailureException( "Failed to copy Deb installer files." );
        }

        // Create DEBIAN directory
        File debDebianDirectory = new File( getDebDirectory(), DEBIAN_DIR );

        if ( !debDebianDirectory.mkdirs() )
        {
            Exception e = new IOException( I18n.err( I18n.ERR_00004_COULD_NOT_CREATE_DIRECTORY, debDebianDirectory ) );
            log.error( e.getLocalizedMessage() );
            throw new MojoFailureException( e.getMessage() );
        }

        // Copying the 'control', 'postinst' and 'prerm' files
        try
        {
            MojoHelperUtils.copyAsciiFile( mojo, filterProperties, CONTROL_FILE,
                getClass().getResourceAsStream( CONTROL_FILE ),
                new File( debDebianDirectory, CONTROL_FILE ), true );

            MojoHelperUtils.copyAsciiFile( mojo, filterProperties, POSTINST_FILE,
                getClass().getResourceAsStream( POSTINST_FILE ),
                new File( debDebianDirectory, POSTINST_FILE ), true );

            MojoHelperUtils.copyAsciiFile( mojo, filterProperties, PRERM_FILE,
                getClass().getResourceAsStream( PRERM_FILE ),
                new File( debDebianDirectory, PRERM_FILE ), true );
        }
        catch ( IOException e )
        {
            log.error( e.getMessage() );
            throw new MojoFailureException( "Failed to copy DEB 'control' file." );
        }

        // Setting correct permission on the postinst script
        MojoHelperUtils.exec( new String[]
            { CHMOD, RWX_RX_RX, new File( debDebianDirectory, POSTINST_FILE ).toString() }, debDebianDirectory,
            false );
        MojoHelperUtils.exec( new String[]
            { CHMOD, RWX_RX_RX, new File( debDebianDirectory, PRERM_FILE ).toString() }, debDebianDirectory, false );

        // Generating the Deb
        log.info( "    Generating Deb installer" );

        String finalName = target.getFinalName();

        if ( !finalName.endsWith( DOT_DEB_EXTENSION ) )
        {
            finalName = finalName + DOT_DEB_EXTENSION;
        }

        Execute createDebTask = new Execute();

        String[] cmd = new String[]
            {
                mojo.getDpkgUtility().getAbsolutePath(),
                "-b",
                getTargetDirectory().getName() + "/" + getDebDirectory().getName(),
                finalName
        };

        StringBuilder antTask = new StringBuilder();

        for ( String command : cmd )
        {
            antTask.append( command ).append( " " );
        }

        log.info( "Executing the ant task with command : " + antTask.toString() + " into directory "
            + mojo.getOutputDirectory() );
        createDebTask.setCommandline( cmd );
        createDebTask.setWorkingDirectory( mojo.getOutputDirectory() );

        try
        {
            createDebTask.execute();
        }
        catch ( IOException e )
        {
            log.error( e.getMessage() );
            throw new MojoFailureException( "Failed while trying to generate the DEB package: " + e.getMessage() );
        }

        log.info( "Debian DEB package generated at " + new File( mojo.getOutputDirectory(), finalName ) );
    }