Package org.apache.maven.plugin

Examples of org.apache.maven.plugin.MojoFailureException


            new File( pkgRootUsrLocalApachedsDirectory, "conf/server.xml" ).delete();
        }
        catch ( IOException e )
        {
            log.error( e.getMessage() );
            throw new MojoFailureException( "Failed to copy image (" + target.getLayout().getBaseDirectory()
                + ") to the PKG directory (" + pkgRootDirectory + ")" );
        }

        // Create Resources folder and sub-folder
        // Copying the resources files and Info.plist file needed for the
        // generation of the PKG
        File pkgResourcesEnglishDirectory = new File( pkgDirectory, "Resources/en.lproj" );
        pkgResourcesEnglishDirectory.mkdirs();
        File pkgScriptsDirectory = new File( pkgDirectory, "scripts" );
        pkgScriptsDirectory.mkdirs();

        try
        {
            MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream( "pkg-background.tiff" ), new File(
                pkgResourcesEnglishDirectory, "background.tiff" ) );

            MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream( "License.rtf" ), new File(
                pkgResourcesEnglishDirectory, "License.rtf" ) );

            MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream( "Info.plist" ), new File( pkgDirectory,
                "Info.plist" ) );

            MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream( "postflight" ), new File(
                pkgScriptsDirectory, "postflight" ) );
        }
        catch ( IOException e )
        {
            log.error( e.getMessage() );
            throw new MojoFailureException( "Failed to copy PKG resources files." );
        }

        // Generating the PKG
        log.info( "Generating Mac OS X PKG Installer" );
        Execute createPkgTask = new Execute();
        String[] cmd = new String[]
            { packageMakerUtility.getAbsolutePath(), "--root", "root/", "--resources", "Resources/", "--info",
                "Info.plist", "--title", "Apache Directory Server " + target.getApplication().getVersion(),
                "--version", target.getApplication().getVersion(), "--scripts", "scripts", "--out",
                "Apache Directory Server Installer.pkg" };
        createPkgTask.setCommandline( cmd );
        createPkgTask.setSpawn( true );
        createPkgTask.setWorkingDirectory( pkgDirectory );
        try
        {
            createPkgTask.execute();
        }
        catch ( IOException e )
        {
            log.error( e.getMessage() );
            throw new MojoFailureException( "Failed while trying to generate the PKG: " + e.getMessage() );
        }

        log.info( "Mac OS X PKG Installer generated at "
            + new File( pkgDirectory, "Apache Directory Server Installer.pkg" ) );

        log.info( "Creating Mac OS X DMG..." );

        // Creating the disc image directory
        File dmgDirectory = new File( imagesDirectory, target.getId() + "-dmg" );
        dmgDirectory.mkdirs();

        log.info( "Copying DMG files" );

        // Create dmg directory and its sub-directory
        File dmgDmgBackgroundDirectory = new File( dmgDirectory, "dmg/.background" );
        dmgDmgBackgroundDirectory.mkdirs();

        // Copying the files
        try
        {
            MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream( "dmg-background.png" ), new File(
                dmgDirectory, "dmg/.background/background.png" ) );

            MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream( "DS_Store" ), new File( dmgDirectory,
                "dmg/.DS_Store" ) );

            MojoHelperUtils.copyFiles( new File( pkgDirectory, "Apache Directory Server Installer.pkg" ), new File(
                dmgDirectory, "dmg/Apache Directory Server Installer.pkg" ) );

        }
        catch ( IOException e )
        {
            log.error( e.getMessage() );
            throw new MojoFailureException( "Failed to copy DMG resources files." );
        }

        // Setting execution permission to the postflight script
        // (unfortunately, the execution permission has been lost after the
        // copy of the PKG to the dmg folder)
        MojoHelperUtils.exec( new String[]
            {
                "chmod",
                "755",
                new File( dmgDirectory, "dmg/Apache Directory Server Installer.pkg/Contents/Resources/postflight" )
                    .toString() }, dmgDirectory, false );

        // Generating the DMG
        log.info( "Generating Mac OS X DMG Installer" );
        String finalName = target.getFinalName();
        if ( !finalName.endsWith( ".dmg" ) )
        {
            finalName = finalName + ".dmg";
        }
        try
        {
            Execute createDmgTask = new Execute();
            createDmgTask.setCommandline( new String[]
                { hdiutilUtility.getAbsolutePath(), "makehybrid", "-hfs", "-hfs-volume-name",
                    "Apache Directory Server Installer", "-hfs-openfolder", "dmg/", "dmg/", "-o", "TMP.dmg" } );
            createDmgTask.setSpawn( true );
            createDmgTask.setWorkingDirectory( dmgDirectory );
            createDmgTask.execute();

            createDmgTask.setCommandline( new String[]
                { hdiutilUtility.getAbsolutePath(), "convert", "-format", "UDZO", "TMP.dmg", "-o", "../" + finalName } );
            createDmgTask.execute();

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

        log.info( "Mac OS X DMG generated at " + new File( imagesDirectory, finalName ) );
    }
View Full Code Here


                new File( debApacheDsHomeDirectory, "conf/apacheds.conf" ), false );
        }
        catch ( IOException e )
        {
            log.error( e.getMessage() );
            throw new MojoFailureException( "Failed to copy image (" + target.getLayout().getBaseDirectory()
                + ") to the DEB directory (" + debApacheDsHomeDirectory + ")" );
        }

        // Copying the instances in the '/var/lib/apacheds-$VERSION/default' directory
        File debDefaultInstanceDirectory = new File( debDirectory, "var/lib/apacheds-"
            + target.getApplication().getVersion() + "/default" );
        debDefaultInstanceDirectory.mkdirs();
        File debDefaultInstanceConfDirectory = new File( debDefaultInstanceDirectory, "conf" );
        debDefaultInstanceConfDirectory.mkdirs();
        new File( debDefaultInstanceDirectory, "ldif" ).mkdirs();
        new File( debDefaultInstanceDirectory, "log" ).mkdirs();
        new File( debDefaultInstanceDirectory, "partitions" ).mkdirs();
        new File( debDefaultInstanceDirectory, "run" ).mkdirs();
        File debEtcInitdDirectory = new File( debDirectory, "etc/init.d" );
        debEtcInitdDirectory.mkdirs();
        new File( debDirectory, "/var/run/apacheds-" + target.getApplication().getVersion() ).mkdirs();
        try
        {
            // Copying the apacheds.conf file in the default instance conf directory
            MojoHelperUtils.copyAsciiFile( mymojo, filterProperties, getClass().getResourceAsStream(
                "apacheds-default.conf" ), new File( debDefaultInstanceConfDirectory, "apacheds.conf" ), false );

            // Copying the log4j.properties file in the default instance conf directory
            MojoHelperUtils.copyAsciiFile( mymojo, filterProperties, new File( debApacheDsHomeDirectory,
                "conf/log4j.properties" ), new File( debDefaultInstanceConfDirectory, "log4j.properties" ), false );

            // Copying the server.xml file in the default instance conf directory
            MojoHelperUtils.copyAsciiFile( mymojo, filterProperties, new File( debApacheDsHomeDirectory,
                "conf/server.xml" ), new File( debDefaultInstanceConfDirectory, "server.xml" ), false );

            // Copying the init script in /etc/init.d/
            MojoHelperUtils
                .copyAsciiFile( mymojo, filterProperties, getClass().getResourceAsStream( "apacheds-init" ), new File(
                    debEtcInitdDirectory, "apacheds-" + target.getApplication().getVersion() + "-default" ), true );

            // Removing the redundant server.xml file (see DIRSERVER-1112)
            new File( debApacheDsHomeDirectory, "conf/server.xml" ).delete();
        }
        catch ( IOException e )
        {
            log.error( e.getMessage() );
            throw new MojoFailureException( "Failed to copy resources files to the DEB directory ("
                + debDefaultInstanceDirectory + ")" );
        }

        // Create DEBIAN directory
        File debDebianDirectory = new File( debDirectory, "DEBIAN" );
        debDebianDirectory.mkdirs();

        // Copying the 'control' file
        try
        {
            MojoHelperUtils.copyAsciiFile( mymojo, filterProperties, getClass().getResourceAsStream( "control" ),
                new File( debDebianDirectory, "control" ), true );

            MojoHelperUtils.copyAsciiFile( mymojo, filterProperties, getClass().getResourceAsStream( "postinst" ),
                new File( debDebianDirectory, "postinst" ), true );

            MojoHelperUtils.copyAsciiFile( mymojo, filterProperties, getClass().getResourceAsStream( "prerm" ),
                new File( debDebianDirectory, "prerm" ), 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", "755", new File( debDebianDirectory, "postinst" ).toString() }, debDebianDirectory, false );
        MojoHelperUtils.exec( new String[]
            { "chmod", "755", new File( debDebianDirectory, "prerm" ).toString() }, debDebianDirectory, false );

        // Generating the DEB
        log.info( "Generating Debian DEB Package" );
        String finalName = target.getFinalName();
        if ( !finalName.endsWith( ".deb" ) )
        {
            finalName = finalName + ".deb";
        }
        Execute createDebTask = new Execute();
        String[] cmd = new String[]
            { dpkgUtility.getAbsolutePath(), "-b", target.getId() + "-deb", finalName };
        createDebTask.setCommandline( cmd );
        createDebTask.setSpawn( true );
        createDebTask.setWorkingDirectory( imagesDirectory );

        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( imagesDirectory, finalName ) );
    }
View Full Code Here

            return;
        }

        if ( application.getName() == null )
        {
            throw new MojoFailureException( "Installed application name cannot be null." );
        }

        if ( application.getCompany() == null )
        {
            if ( project.getOrganization() != null )
View Full Code Here

            }
        }

        if ( bootstrapper == null )
        {
            throw new MojoFailureException( "Bootstrapper dependency artifact required: " + BOOTSTRAPPER_GROUP_ID + ":"
                + BOOTSTRAPPER_ARTIFACT_ID );
        }
        if ( logger == null )
        {
            throw new MojoFailureException( "Logger dependency artifact required: " + LOGGER_GROUP_ID + ":"
                + LOGGER_ARTIFACT_ID );
        }
        if ( daemon == null )
        {
            throw new MojoFailureException( "Daemon dependency artifact required: " + DAEMON_GROUP_ID + ":"
                + DAEMON_ARTIFACT_ID );
        }
    }
View Full Code Here

        {
            FileUtils.copyDirectoryStructure( exportTarget, docsTarget );
        }
        catch ( IOException e )
        {
            throw new MojoFailureException( "Failed to copy exported sources from svn here "
                + exportTarget.getAbsolutePath() + " to " + docsTarget.getAbsolutePath() );
        }

        String[] cmd = null;
        if ( Os.isFamily( "windows" ) )
View Full Code Here

            MojoHelperUtils.copyFiles( targetDirectory, archiveDirectory );
        }
        catch ( IOException e )
        {
            log.error( e.getMessage() );
            throw new MojoFailureException( "Failed to copy Archive Installer resources files." );
        }

        // Generating the Bin
        log.info( "Generating Archive Installer" );
View Full Code Here

            {
                FileUtils.copyFile( target.getApplication().getReadme(), readmeTarget );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to copy read me file " + target.getApplication().getReadme()
                    + " into position " + readmeTarget );
            }
        }

        // copy over the license file if present otherwise use the bundled copy
        File licenseTarget = layout.getLicenseFile( target.getApplication().getLicense().getName() );
        if ( target.getApplication().getLicense().exists() )
        {
            try
            {
                FileUtils.copyFile( target.getApplication().getLicense(), licenseTarget );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to copy license file " + target.getApplication().getLicense()
                    + " into position " + licenseTarget );
            }
        }
        else
        {
            try
            {
                MojoHelperUtils.copyAsciiFile( mymojo, filterProperties, getClass().getResourceAsStream( "LICENSE" ),
                    licenseTarget, false );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to bundled ASL license file "
                    + getClass().getResource( "LICENSE" ) + " into position " + licenseTarget );
            }
        }

        // copy over the icon if present otherwise use the bundled copy
        File iconTarget = layout.getLogoIconFile( target.getApplication().getIcon().getName() );
        if ( target.getApplication().getIcon().exists() )
        {
            try
            {
                FileUtils.copyFile( target.getApplication().getIcon(), iconTarget );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to copy icon file " + target.getApplication().getIcon()
                    + " into position " + iconTarget );
            }
        }
        else
        {
            try
            {
                MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream( "logo.ico" ), iconTarget );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to copy icon file " + getClass().getResource( "logo.ico" )
                    + " into position " + iconTarget );
            }
        }

        // copy over the REQUIRED bootstrapper.jar file
        try
        {
            FileUtils.copyFile( mymojo.getBootstrapper().getFile(), layout.getBootstrapper() );
        }
        catch ( IOException e )
        {
            throw new MojoFailureException( "Failed to copy bootstrapper.jar " + mymojo.getBootstrapper().getFile()
                + " into position " + layout.getBootstrapper() );
        }

        // copy over the REQUIRED logger artifact
        /*
                try
                {
                    FileUtils.copyFile( mymojo.getLogger().getFile(), layout.getLogger() );
                }
                catch ( IOException e )
                {
                    throw new MojoFailureException( "Failed to copy logger.jar " + mymojo.getLogger().getFile()
                        + " into position " + layout.getLogger() );
                }
        */

        // copy over the REQUIRED daemon.jar file
        try
        {
            FileUtils.copyFile( mymojo.getDaemon().getFile(), new File( layout.getLibDirectory(), "wrapper.jar" ) );
        }
        catch ( IOException e )
        {
            throw new MojoFailureException( "Failed to copy daemon.jar " + mymojo.getDaemon().getFile()
                + " into position " + layout.getDaemon() );
        }

        // copy over the optional bootstrapper configuration file
        if ( target.getBootstrapperConfigurationFile() != null )
        {
            try
            {
                FileUtils.copyFile( target.getBootstrapperConfigurationFile(), layout
                    .getBootstrapperConfigurationFile() );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to copy project bootstrapper configuration file "
                    + target.getBootstrapperConfigurationFile() + " into position "
                    + layout.getBootstrapperConfigurationFile() );
            }
        }

        // copy over the optional logging configuration file
        if ( target.getLoggerConfigurationFile().exists() )
        {
            try
            {
                FileUtils.copyFile( target.getLoggerConfigurationFile(), layout.getLoggerConfigurationFile() );
            }
            catch ( IOException e )
            {
                log.error( "Failed to copy logger configuration file " + target.getLoggerConfigurationFile()
                    + " into position " + layout.getLoggerConfigurationFile(), e );
            }
        }

        // copy over the optional server configuration file
        if ( target.getServerConfigurationFile().exists() )
        {
            try
            {
                FileUtils.copyFile( target.getServerConfigurationFile(), layout.getConfigurationFile() );
            }
            catch ( IOException e )
            {
                log.error( "Failed to copy server configuration file " + target.getServerConfigurationFile()
                    + " into position " + layout.getConfigurationFile(), e );
            }
        }

        // -------------------------------------------------------------------
        // Copy Wrapper Files
        // -------------------------------------------------------------------

        // LINUX I386
        if ( target.getOsName().equals( "linux" ) && target.getOsArch().equals( "i386" )
            && target.getDaemonFramework().equals( "tanuki" ) )
        {
            try
            {
                MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream( "wrapper/bin/wrapper-linux-x86-32" ),
                    new File( layout.getBinDirectory(), target.getApplication().getName() ) );
                MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream(
                    "wrapper/lib/libwrapper-linux-x86-32.so" ), new File( layout.getLibDirectory(), "libwrapper.so" ) );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to copy Tanuki binary files to lib and bin directories" );
            }
        }

        // LINUX X86_64 (AMD64)
        if ( target.getOsName().equals( "linux" )
            && ( target.getOsArch().equals( "x86_64" ) || target.getOsArch().equals( "amd64" ) )
            && target.getDaemonFramework().equals( "tanuki" ) )
        {
            try
            {
                MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream( "wrapper/bin/wrapper-linux-x86-64" ),
                    new File( layout.getBinDirectory(), target.getApplication().getName() ) );
                MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream(
                    "wrapper/lib/libwrapper-linux-x86-64.so" ), new File( layout.getLibDirectory(), "libwrapper.so" ) );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to copy Tanuki binary files to lib and bin directories" );
            }
        }

        // MAC OS X
        if ( target.getOsName().equalsIgnoreCase( "mac os x" ) && target.getDaemonFramework().equals( "tanuki" ) )
        {
            try
            {
                MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream(
                    "wrapper/bin/wrapper-macosx-universal-32" ), new File( layout.getBinDirectory(), target
                    .getApplication().getName() ) );
                MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream(
                    "wrapper/lib/libwrapper-macosx-universal-32.jnilib" ), new File( layout.getLibDirectory(),
                    "libwrapper.jnilib" ) );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to copy Tanuki binary files to lib and bin directories" );
            }
        }

        // SOLARIS X86
        if ( target.getOsName().equalsIgnoreCase( "solaris" ) && target.getOsArch().equals( "x86" )
            && target.getDaemonFramework().equals( "tanuki" ) )
        {
            try
            {
                MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream(
                    "wrapper/bin/wrapper-solaris-x86-32" ), new File( layout.getBinDirectory(), target
                    .getApplication().getName() ) );
                MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream(
                    "wrapper/lib/libwrapper-solaris-x86-32.so" ), new File( layout.getLibDirectory(),
                    "libwrapper.so" ) );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to copy Tanuki binary files to lib and bin directories" );
            }
        }

        // SOLARIS SPARC
        if ( target.getOsName().equalsIgnoreCase( "solaris" ) && target.getOsArch().equals( "sparc" )
            && target.getDaemonFramework().equals( "tanuki" ) )
        {
            try
            {
                MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream(
                    "wrapper/bin/wrapper-solaris-sparc-32" ), new File( layout.getBinDirectory(), target
                    .getApplication().getName() ) );
                MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream(
                    "wrapper/lib/libwrapper-solaris-sparc-32.so" ), new File( layout.getLibDirectory(),
                    "libwrapper.so" ) );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to copy Tanuki binary files to lib and bin directories" );
            }
        }

        // now copy over the jsvc executable renaming it to the mymojo.getApplicationName()
        if ( target.getOsName().equals( "sunos" ) && target.getOsArch().equals( "sparc" ) )
        {
            File executable = new File( layout.getBinDirectory(), target.getApplication().getName() );
            try
            {
                MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream( "jsvc_solaris_sparc" ), executable );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to copy jsvc executable file "
                    + getClass().getResource( "jsvc_solaris_sparc" ) + " into position " + executable.getAbsolutePath() );
            }
        }

        if ( target.getOsName().equals( "sunos" ) && target.getOsArch().equals( "i386" ) )
        {
            File executable = new File( layout.getBinDirectory(), target.getApplication().getName() );
            try
            {
                MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream( "jsvc_solaris_i386" ), executable );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to copy jsvc executable file "
                    + getClass().getResource( "jsvc_solaris_i386" ) + " into position " + executable.getAbsolutePath() );
            }
        }

        // now copy over the jsvc executable renaming it to the mymojo.getApplicationName()
        //        if ( target.getOsName().equals( "macosx" ) && target.getOsArch().equals( "ppc" ) )
        //        {
        //            File executable = new File( layout.getBinDirectory(), target.getApplication().getName() );
        //            try
        //            {
        //                MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream( "jsvc_macosx_ppc" ), executable );
        //            }
        //            catch ( IOException e )
        //            {
        //                throw new MojoFailureException( "Failed to copy jsvc executable file "
        //                    + getClass().getResource( "jsvc_macosx_ppc" ) + " into position " + executable.getAbsolutePath() );
        //            }
        //        }

        target.setLibArtifacts( MojoHelperUtils.copyDependencies( mymojo, layout ) );

        // -- copy sources if set --

        if ( target.getSourcesDirectory() != null )
        {
            File sourcesDirectory = new File( layout.getBaseDirectory(), target.getSourcesTargetPath() );
            try
            {
                FileUtils.copyDirectoryStructure( target.getSourcesDirectory(), sourcesDirectory );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to copy sources exported from " + target.getSourcesDirectory()
                    + " to " + sourcesDirectory );
            }
        }

        // -- copy doco if set --

        if ( target.getDocsDirectory() != null )
        {
            File docsDirectory = new File( layout.getBaseDirectory(), target.getDocsTargetPath() );
            try
            {
                FileUtils.copyDirectoryStructure( target.getDocsDirectory(), docsDirectory );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to copy generated docs from " + target.getDocsDirectory()
                    + " to " + docsDirectory );
            }
        }

        // -- if present copy the NOTICE.txt file --
View Full Code Here

                {
                    Artifact artifact = dependencyMap.get( packagedFiles[ii].getSource() );
                   
                    if ( artifact == null )
                    {
                        throw new MojoFailureException( "The packaged file setup as a dependency on artifact "
                            + packagedFiles[ii].getSource() + " has not been found in the project.  " +
                                    "Check your <dependencies> in the project pom." );
                    }
                    source = artifact.getFile().getAbsoluteFile();
                }
                else
                {
                    source = new File( packagedFiles[ii].getSource() );
                }
               
                if ( ! source.isAbsolute() )
                {
                    File sourceDirectoryRelative = new File( mymojo.getSourceDirectory(), packagedFiles[ii].getSource() );
                    File baseRelative = new File( mymojo.getProject().getBasedir(), packagedFiles[ii].getSource() );
                    if ( sourceDirectoryRelative.exists() )
                    {
                        source = sourceDirectoryRelative;
                    }
                    else if ( baseRelative.exists() )
                    {
                        source = baseRelative;
                    }
                    else if ( ! source.exists() )
                    {
                        throw new MojoFailureException( "Failed to copy packagedFile. Cannot locate source: " + source );
                    }
                   
                    source = source.getAbsoluteFile();
                }
               
                if ( packagedFiles[ii].isExpandable() )
                {
                    File dest = new File( target.getLayout().getBaseDirectory(), packagedFiles[ii].getDestinationPath() );
                    if ( ! dest.exists() )
                    {
                        dest.mkdirs();
                    }
                   
                    String fileExtension = source.getName().substring( source.getName().lastIndexOf( '.' ) );
                    if ( fileExtension.equalsIgnoreCase( ".jar" ) || fileExtension.equalsIgnoreCase( ".zip" )
                        || fileExtension.equalsIgnoreCase( ".war" ) || fileExtension.equalsIgnoreCase( ".sar" ) )
                    {
                        log.info( "\t\t\t ... expanding " + source  + "\n\t\t\t => to " + dest );
                        Expand expand = new Expand();
                        expand.setSrc( source );
                        expand.setOverwrite( true );
                        expand.setDest( dest );
                        try
                        {
                            expand.execute();
                            continue;
                        }
                        catch ( Exception e )
                        {
                            throw new MojoFailureException( "Failed to expaned packagedFile " + source + ": " + e.getMessage() );
                        }
                    }
                   
                    throw new MojoFailureException( "Failed to expand packagedFile: " + source
                        + ". It does not have a jar, war or zip extension" );
                }
               
                File dest = new File( target.getLayout().getBaseDirectory(), packagedFiles[ii].getDestinationPath() );
               
                if ( packagedFiles[ii].isDirectory() )
                {
                    try
                    {
                        FileUtils.copyDirectoryStructure( source, dest );
                    }
                    catch ( IOException e )
                    {
                        throw new MojoFailureException( "Failed to copy packagedFile [directory=true] from source "
                            + source + " to destination " + dest );
                    }
                    continue;
                }
                else if ( packagedFiles[ii].isFiltered() )
                {
                    try
                    {
                        MojoHelperUtils.copyAsciiFile( mymojo, getFilterProperties(), source, dest, true );
                    }
                    catch ( IOException e )
                    {
                        throw new MojoFailureException( "Failed to copy packagedFile from source " + source +
                            " to destination " + dest );
                    }
                    continue;
                }
               
                try
                {
                    FileUtils.copyFile( source, dest );
                }
                catch ( IOException e )
                {
                    throw new MojoFailureException( "Failed to copy packagedFile from source " + source +
                        " to destination " + dest );
                }
            }
            catch ( Exception e )
            {
View Full Code Here

        // Step 1 & 4: do some error checking first for compiler and OS
        // -------------------------------------------------------------------

        if ( !target.getOsFamily().equals( "windows" ) )
        {
            throw new MojoFailureException( "Inno installers can only be targeted for windows platforms!" );
        }

        if ( !Os.isFamily( "windows" ) )
        {
            log.warn( "Inno target " + target.getId() + " cannot be built on a non-windows machine!" );
            log.warn( "The build will not fail because of this acceptable situation." );
            return;
        }

        // @todo this should really be a parameter taken from the user's settings
        // because the compiler may be installed in different places and is specific
        if ( !target.getInnoCompiler().exists() )
        {
            throw new MojoFailureException( "Cannot find Inno compiler: " + target.getInnoCompiler() );
        }
        else
        {
            this.innoCompiler = target.getInnoCompiler();
        }

        // -------------------------------------------------------------------
        // Step 2 & 3: copy inno file and filter
        // -------------------------------------------------------------------

        // check first to see if the default install.iss file is present in src/main/installers
        File projectInnoFile = new File( mymojo.getSourceDirectory(), "install.iss" );
        if ( target.getInnoConfigurationFile() != null && target.getInnoConfigurationFile().exists() )
        {
            try
            {
                MojoHelperUtils.copyAsciiFile( mymojo, filterProperties, target.getInnoConfigurationFile(),
                    innoConfigurationFile, true );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to filter and copy project provided "
                    + target.getInnoConfigurationFile() + " to " + innoConfigurationFile );
            }
        }
        else if ( projectInnoFile.exists() )
        {
            try
            {
                MojoHelperUtils.copyAsciiFile( mymojo, filterProperties, projectInnoFile, innoConfigurationFile, true );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to filter and copy project provided " + projectInnoFile
                    + " to " + innoConfigurationFile );
            }
        }
        else
        {
            InputStream in = getClass().getResourceAsStream( "install.iss" );
            URL resource = getClass().getResource( "install.iss" );
            try
            {
                MojoHelperUtils.copyAsciiFile( mymojo, filterProperties, in, innoConfigurationFile, true );
            }
            catch ( IOException e )
            {
                throw new MojoFailureException( "Failed to filter and copy bundled " + resource + " to "
                    + innoConfigurationFile );
            }
        }

        // -------------------------------------------------------------------
        // 3: copy procrun files
        // -------------------------------------------------------------------

        // now copy over the Prunsrv and Prunmgr executables renaming them to the mymojo.getApplicationName() + w for mgr
        if ( target.getOsFamily().equals( "windows" ) && target.getOsArch().equals( "x86" ) )
        {
            // ---------------------------------------------------------------
            // Handle the server process: prunsrv.exe
            // ---------------------------------------------------------------

            File executableTarget = new File( target.getLayout().getBinDirectory(),
                target.getApplication().getName() + ".exe" );
            File override = new File( mymojo.getSourceDirectory(), target.getPrunsrvExecutablePath() );
            if ( override.exists() )
            {
                mymojo.getLog().info( "Using procrun prunsrv.exe supplied by project: " + override.getAbsolutePath() );
                try
                {
                    FileUtils.copyFile( override, executableTarget );
                }
                catch ( IOException e )
                {
                    throw new MojoFailureException( "Failed to copy project supplied prunsrv executable override "
                        + override.getAbsolutePath() + " into position " + executableTarget.getAbsolutePath() );
                }
            }
            else
            {
                try
                {
                    MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream( "../wrapper/bin/wrapper-windows-x86-32.exe" ), executableTarget );
                }
                catch ( IOException e )
                {
                    throw new MojoFailureException( "Failed to copy prunsrv executable file "
                        + getClass().getResource( "../wrapper/bin/wrapper-windows-x86-32.exe" ) + " into position " + executableTarget.getAbsolutePath() );
                }
            }
           

            // ---------------------------------------------------------------
            // Handle the manager process: prunmgr.exe
            // ---------------------------------------------------------------

/*
            executableTarget = new File( target.getLayout().getBinDirectory(),
                target.getApplication().getName() + "w.exe" );
            override = new File( mymojo.getSourceDirectory(), target.getWrapperExecutablePath() );
            if ( override.exists() )
            {
                mymojo.getLog().info( "Using procrun prunmgr.exe supplied by project: " + override.getAbsolutePath() );
                try
                {
                    FileUtils.copyFile( override, executableTarget );
                }
                catch ( IOException e )
                {
                    throw new MojoFailureException( "Failed to copy project supplied prunmgr executable override "
                        + override.getAbsolutePath() + " into position " + executableTarget.getAbsolutePath() );
                }
            }
            else
            {
                try
                {
                    MojoHelperUtils.copyBinaryFile( getClass().getResourceAsStream( "../prunmgr.exe" ), executableTarget );
                }
                catch ( IOException e )
                {
                    throw new MojoFailureException( "Failed to copy prunmgr executable file "
                        + getClass().getResource( "../prunmgr.exe" ) + " into position " + executableTarget.getAbsolutePath() );
                }
            }
*/
        }

        processPackagedFiles( target, target.getPackagedFiles() );

        Execute task = new Execute();
        System.out.println( "innoCompiler = " + innoCompiler );
        System.out.println( "innoConfigurationFile = " + innoConfigurationFile );
        String[] cmd = new String[]
            { innoCompiler.getAbsolutePath(), innoConfigurationFile.getAbsolutePath() };
        task.setCommandline( cmd );
        task.setSpawn( true );
        task.setWorkingDirectory( target.getLayout().getBaseDirectory() );
        try
        {
            task.execute();
        }
        catch ( IOException e )
        {
            throw new MojoFailureException( "Failed while trying to execute " + innoCompiler.getAbsolutePath() + ": "
                + e.getMessage() );
        }

        if ( task.getExitValue() != 0 )
        {
            throw new MojoFailureException( innoCompiler.getAbsolutePath()
                + " execution resulted in a non-zero exit value: " + task.getExitValue() );
        }
    }
View Full Code Here

                    libArtifacts.add( artifact );
                    mymojo.getLog().info( "        o " + key );
                }
                catch ( IOException e )
                {
                    throw new MojoFailureException( "Failed to copy dependency artifact " + artifact
                        + " into position " + layout.getLibDirectory() );
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.maven.plugin.MojoFailureException

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.