public void execute()

in installers-maven-plugin/src/main/java/org/apache/directory/server/installers/rpm/RpmInstallerCommand.java [81:218]


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

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

        // Creating the target directory
        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 Rpm installer files" );

        try
        {
            // Create Rpm directories (BUILD, RPMS, SOURCES, SPECS & SRPMS)
            File rpmBuild = new File( getTargetDirectory(), BUILD );

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

            File rpmRpms = new File( getTargetDirectory(), RPMS );

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

            File rpmSources = new File( getTargetDirectory(), SOURCES );

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

            File rpmSpecs = new File( getTargetDirectory(), SPECS );

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

            File rpmSrpms = new File( getTargetDirectory(), SRPMS );

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

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

            // Copying the init script for /etc/init.d/
            MojoHelperUtils.copyAsciiFile( mojo, filterProperties, INSTALLERS_PATH + ETC_INITD_SCRIPT,
                getClass().getResourceAsStream( INSTALLERS_PATH + ETC_INITD_SCRIPT ),
                new File( getAdsSourcesDirectory(), ETC_INITD_SCRIPT ), true );

            // Creating the spec file
            createSpecFile();

            // Generating tar.gz file
            MojoHelperUtils.exec( new String[]
                {
                    TAR,
                    "-zcf",
                    APACHEDS_DASH + getVersion() + ".tar.gz",
                    APACHEDS_DASH + getVersion()
            },
                new File( getTargetDirectory(), File.separator + SOURCES ),
                false );
        }
        catch ( Exception e )
        {
            log.error( e.getMessage() );
            throw new MojoFailureException( "Failed to copy Rpm installer files." );
        }

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

        MojoHelperUtils.exec( new String[]
            {
                mojo.getRpmbuildUtility().getAbsolutePath(),
                "--quiet",
                "-ba",
                "--target",
                target.getOsArch() + "-linux",
                "--define",
                "_topdir " + getTargetDirectory(),
                "--define",
                "_tmppath /tmp",
                SPECS + "/" + APACHEDS_SPEC_FILE
        },
            getTargetDirectory(),
            false );

        // Copying the rpm at the final destination
        try
        {
            String rpmName = APACHEDS_DASH + getVersion() + "-1." + target.getOsArch() + DOT_RPM;
            String finalName = target.getFinalName();

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

            File finalFile = new File( mojo.getOutputDirectory(), finalName );

            FileUtils.copyFile( new File( getTargetDirectory(), RPMS + File.separator + target.getOsArch() + File.separator + rpmName ),
                finalFile );

            log.info( "=> RPM generated at " + finalFile );
        }
        catch ( IOException e )
        {
            throw new MojoFailureException( "Failed to copy generated Rpm installer file." );
        }
    }