Package org.apache.maven.archiver

Examples of org.apache.maven.archiver.MavenArchiver


      getLog().info("Adding licenses");
      zipArchiver.addDirectory(licensesDirectory, "licenses/");
    }

    // JAR file
    MavenArchiver archiver = new MavenArchiver();
    archiver.setArchiver(jarArchiver);
    archiver.setOutputFile(jarFile);
    jarArchiver.addDirectory(outputDirectory, new String[] { "**/*.class" }, null);
    MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
    try {
      archiver.createArchive(session, project, archive);
    } catch (Exception e) {
      throw new MojoExecutionException("Could not build the jar file", e);
    }

    if (jarFile.exists()) {
View Full Code Here


     * Generates the configuration archive.
     */
    private File createArchive() throws MojoExecutionException {
        File archiveFile = getArchiveFile(outputDirectory, finalName, null);

        MavenArchiver archiver = new MavenArchiver();
        archiver.setArchiver(jarArchiver);
        archiver.setOutputFile(archiveFile);

        try {
            // Incldue the generated artifact contents
            archiver.getArchiver().addDirectory(getArtifactInRepositoryDir());

            // Include the optional classes.resources
            if (classesDirectory.isDirectory()) {
                archiver.getArchiver().addDirectory(classesDirectory);
            }

            //
            // HACK: Include legal files here for sanity
            //

            //
            // NOTE: Would be nice to share this with the copy-legal-files mojo
            //
            String[] includes = {
                "LICENSE.txt",
                "LICENSE",
                "NOTICE.txt",
                "NOTICE",
                "DISCLAIMER.txt",
                "DISCLAIMER"
            };

            archiver.getArchiver().addDirectory(baseDirectory, "META-INF/", includes, new String[0]);

            if (classpath != null) {
                archive.addManifestEntry("Class-Path", getClassPath());
            }

            archiver.createArchive(project, archive);

            return archiveFile;
        }
        catch (Exception e) {
            throw new MojoExecutionException("Failed to create archive", e);
View Full Code Here

        {
            getLog().info("Analyzing war: " + this.srcFile.getAbsolutePath());
        }
       
        WebXml webXml = null;
        MavenArchiver archiver = new MavenArchiver();
        archiver.setArchiver(warArchiver);
        archiver.setOutputFile(destFile);
       
        File tmpWebXml = null;
        File tempLocation = null;
       
        try
        {
            if (srcFile != null)
            {
                webXml = getOriginalWebXml();
                if (webXml == null)
                {
                    if (this.version == null)
                    {
                        throw new MojoExecutionException("Your source file "
                           + "does not contain a web.xml. Please provide a "
                           + "war with a web.xml or specify the [version] "
                           + "attribute.");
                    }
                    WebXmlVersion webXmlVersion = null;
                    if (this.version.equals("2.2"))
                    {
                        webXmlVersion = WebXmlVersion.V2_2;
                    }
                    else if (this.version.equals("2.3"))
                    {
                        webXmlVersion = WebXmlVersion.V2_3;
                    }
                    else
                    {
                        webXmlVersion = WebXmlVersion.V2_4;
                    }
                    webXml = WebXmlIo.newWebXml(webXmlVersion);
                }
            }
            else
            {
               
                if (this.version == null)
                {
                    throw new MojoExecutionException("You need to specify "
                           + "either the [srcFile] or the [version] attribute");
                }
                else
                {
                    WebXmlVersion webXmlVersion = null;
                    if (this.version.equals("2.2"))
                    {
                        webXmlVersion = WebXmlVersion.V2_2;
                    }
                    else if (this.version.equals("2.3"))
                    {
                        webXmlVersion = WebXmlVersion.V2_3;
                    }
                    else
                    {
                        webXmlVersion = WebXmlVersion.V2_4;
                    }
                    webXml = WebXmlIo.newWebXml(webXmlVersion);
                }
            }
            tmpWebXml = cactifyWebXml(webXml);
           
            //Add the required libs for Cactus.
            addJarWithClass("org.aspectj.lang.JoinPoint",
            "AspectJ Runtime");
            addJarWithClass("org.apache.cactus."
                   + "ServletTestCase", "Cactus Framework");
            addJarWithClass("org.apache.commons.logging.Log",
                "Commons-Logging");
            addJarWithClass("org.apache.commons."
                   + "httpclient.HttpClient", "Commons-HttpClient");
            addJarWithClass("junit.framework."
                   + "TestCase", "JUnit");
           
            tempLocation = createTempFile("cactus", "explode.tmp.dir",
                    getProject().getBasedir(), true);
            tempLocation.mkdirs();
            tempLocation.deleteOnExit();

            if (testClasses != null)
            {
              //Add the classes.
              warArchiver.addClasses(new File(testClasses.getDirectory()),
                              testClasses.getIncludesArray(),
                              testClasses.getExcludesArray());
            }

            //Now add all of the additional lib files.
            for (Iterator iter = libDependencies.iterator(); iter.hasNext();)
            {
                org.apache.cactus.maven2.mojos.Dependency dependency =
                    (org.apache.cactus.maven2.mojos.Dependency) iter.next();
                warArchiver.addLib(new File(dependency.getDependencyPath(
                    project, getLog())));
            }
           
            try
            {
                if(this.srcFile != null)
                {
                    AssemblyFileUtils.unpack(this.srcFile, tempLocation,
                        archiverManager);
                }
            }
            catch (ArchiveExpansionException e)
            {
                throw new MojoExecutionException("Error extracting the"
                       + " archive.", e);
            }
            catch (NoSuchArchiverException e)
            {
                throw new MojoExecutionException("Problem reading the "
                       + "source archive.", e);
            }
            warArchiver.addDirectory(tempLocation);
            warArchiver.setWebxml(tmpWebXml);
            archiver.createArchive(getProject(), getArchive());
        }
        catch (ArchiverException e)
        {
            throw new MojoExecutionException("Problem reading the "
                   + "source archive.", e);
View Full Code Here

        if (getSrcFile() == null)
        {
            throw new MojoExecutionException("You need to specify [srcFile] "
                + "attribute for cactification!");
        }
        MavenArchiver archiver = new MavenArchiver();
        archiver.setArchiver(earArchiver);
       
        //Add everything that's in the source EAR to the destination EAR
        File tempLocation = null;
       
        tempLocation = FileUtils.createTempFile("cactus", "explode.tmp.dir",
                getProject().getBasedir());
        tempLocation.mkdirs();
        tempLocation.deleteOnExit();
       
        try
        {
            if (this.srcFile != null)
            {
                AssemblyFileUtils.unpack(this.srcFile, tempLocation,
                    archiverManager);
            }
        }
        catch (ArchiveExpansionException e)
        {
            throw new MojoExecutionException("Error extracting the"
                   + " archive.", e);
        }
        catch (NoSuchArchiverException e)
        {
            throw new MojoExecutionException("Problem reading the "
                   + "source archive.", e);
        }
       
        try
        {
      earArchiver.addDirectory(tempLocation);
    }
        catch (ArchiverException e1)
        {
      // Cannot add the temp location for some reason.
          throw new MojoExecutionException("Problem adding the source " +
              "files to the dest. archive ", e1);
    }
       
        // cactify the application.xml
        ApplicationXml appXml = null;
        try
        {
            appXml = getOriginalApplicationXml();
        }
        catch (JDOMException e)
        {
            throw new MojoExecutionException("Unable to get the "
               + "original application.xml", e);
        }
       
        File tmpAppXml = cactifyApplicationXml(appXml);
       
        try
        {
            earArchiver.addDirectory(tempLocation);
            earArchiver.setAppxml(tmpAppXml);
           
            archiver.setOutputFile(getDestFile());
           
            // create the cactus war
            File cactusWarFile = createCactusWarFile();
            addFileToEar(cactusWarFile, cactusWar.getFileName());
           
            archiver.createArchive(getProject(), getArchive());
        }
        catch (ArchiverException aex)
        {
            throw new MojoExecutionException("Error while performing the "
                    + "cactified archive.", aex);
View Full Code Here

    }

    private void packageWarFile(File war, File warFile) throws IOException {
        getLog().info("Build war file " + warFile.getAbsolutePath() + " from " + war.getAbsolutePath());
        // We build a Jar from the webappDirectory.
        MavenArchiver archiver = new MavenArchiver();
        archiver.setArchiver(warArchiver);
        archiver.setOutputFile(warFile);
        try {
            warArchiver.addDirectory(webappDirectory);

            // Manage additional files if any
            if (! additionalFiles.isEmpty()) {
                getLog().info("Adding additional files to War file : " + additionalFiles);
                for (String file : additionalFiles) {
                    File fileToAdd = new File(project.getBasedir(), file);
                    if (!fileToAdd.exists()) {
                        throw new IOException(fileToAdd.getCanonicalPath() + " not found, can't add to war file");
                    }
                    warArchiver.addFile(fileToAdd, fileToAdd.getName());
                }
            }


            warArchiver.setIgnoreWebxml(false);
            MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
            archiver.createArchive(session, project, archive);
        } catch (Exception e) {
            getLog().error("Error during the construction of the War file with the archiving process", e);
            throw new IOException("Cannot build the War file", e);
        }
View Full Code Here

  private String moduleClassesJsFile;

  public void execute()
      throws MojoExecutionException {
    File jarFile = new File(targetDir, finalName + "." + Types.JAVASCRIPT_EXTENSION);
    MavenArchiver mavenArchiver = new MavenArchiver();
    mavenArchiver.setArchiver(archiver);
    mavenArchiver.setOutputFile(jarFile);
    try {
      if (archive.getManifestFile() == null) {
        if (useDefaultManifestFile && defaultManifestFile.exists()) {
          getLog().info( "Adding existing MANIFEST to archive. Found under: " + defaultManifestFile.getPath() );
          archive.setManifestFile( defaultManifestFile );
        } else if (manifest != null) {
          archive.setManifestFile(manifest);
        } else {
          archive.setManifestFile(createDefaultManifest(project));
        }
      }
      if (outputDirectory.exists()) {
        mavenArchiver.getArchiver().addDirectory(outputDirectory);
        if (!getModuleJsFile().exists() && new File(outputDirectory, moduleClassesJsFile).exists()) {
          createDefaultModuleJsFile();
        }
      }

      String groupId = project.getGroupId();
      String artifactId = project.getArtifactId();
      mavenArchiver.getArchiver().addFile(project.getFile(), "META-INF/maven/" + groupId + "/" + artifactId
              + "/pom.xml");

      mavenArchiver.createArchive(project, archive);
    } catch (Exception e) { // NOSONAR
      throw new MojoExecutionException("Failed to create the javascript archive", e);
    }
    project.getArtifact().setFile(jarFile);
View Full Code Here

        buildExplodedAar();

        // generate aar file
        getLog().info("Generating aar " + aarFile.getAbsolutePath());
        MavenArchiver archiver = new MavenArchiver();
        archiver.setArchiver(jarArchiver);
        archiver.setOutputFile(aarFile);
        jarArchiver.addDirectory(aarDirectory);

        // create archive
        archiver.createArchive(project, archive);

        if (classifier != null) {
            projectHelper.attachArtifact(project, "aar", classifier, aarFile);
        } else {
            Artifact artifact = project.getArtifact();
View Full Code Here

        buildExplodedMar( );

        // generate mar file
        getLog().info( "Generating mar " + marFile.getAbsolutePath() );
        MavenArchiver archiver = new MavenArchiver();
        archiver.setArchiver( jarArchiver );
        archiver.setOutputFile( marFile );
        jarArchiver.addDirectory( marDirectory );

        // create archive
        archiver.createArchive( project, archive );

        if ( classifier != null )
        {
            projectHelper.attachArtifact( project, "mar", classifier, marFile );
        }
View Full Code Here

  private File generateArchive( File javadocFiles, String jarFileName ) throws ArchiverException, IOException {
    final File javadocJar = new File( jarOutputDirectory, jarFileName );
    if(javadocJar.exists()) {
      javadocJar.delete();
    }
    MavenArchiver archiver = new MavenArchiver();
    archiver.setArchiver( jarArchiver );
    archiver.setOutputFile( javadocJar );
    File contentDirectory = javadocFiles;
    if(!contentDirectory.exists()) {
      getLog().warn( "JAR will be empty - no content was marked for inclusion!" );
    } else {
      archiver.getArchiver().addDirectory( contentDirectory, DEFAULT_INCLUDES, DEFAULT_EXCLUDES );
    }
    List<Resource> resources = project.getBuild().getResources();
    for ( Resource r : resources ) {
      if ( r.getDirectory().endsWith( "maven-shared-archive-resources" ) ) {
        archiver.getArchiver().addDirectory( new File( r.getDirectory() ) );
      }
    }
    if ( useDefaultManifestFile && defaultManifestFile.exists() && archive.getManifestFile() == null ) {
      getLog().info("Adding existing MANIFEST to archive. Found under: " + defaultManifestFile.getPath());
      archive.setManifestFile(defaultManifestFile);
    }
    try {
      // we don't want Maven stuff
      archive.setAddMavenDescriptor( false );
      archiver.createArchive( project, archive );
    } catch ( ManifestException e ) {
      throw new ArchiverException( "ManifestException: " + e.getMessage(), e );
    } catch ( DependencyResolutionRequiredException e ) {
      throw new ArchiverException( "DependencyResolutionRequiredException: " + e.getMessage(), e );
    }
View Full Code Here

     * Generates the configuration archive.
     */
    private File createArchive() throws MojoExecutionException {
        File archiveFile = getArchiveFile(outputDirectory, finalName, null);

        MavenArchiver archiver = new MavenArchiver();
        archiver.setArchiver(jarArchiver);
        archiver.setOutputFile(archiveFile);

        try {
            // Incldue the generated artifact contents
            File artifactDirectory = getArtifactInRepositoryDir();
            if (artifactDirectory.exists()) {
                archiver.getArchiver().addDirectory(artifactDirectory);
            }

            // Include the optional classes.resources
            if (classesDirectory.isDirectory()) {
                archiver.getArchiver().addDirectory(classesDirectory);
            }

            if (resourcesDir.isDirectory()) {
                archiver.getArchiver().addDirectory(resourcesDir);
            }

            //
            // HACK: Include legal files here for sanity
            //

            //
            // NOTE: Would be nice to share this with the copy-legal-files mojo
            //
            String[] includes = {
                "LICENSE.txt",
                "LICENSE",
                "NOTICE.txt",
                "NOTICE",
                "DISCLAIMER.txt",
                "DISCLAIMER"
            };

            archiver.getArchiver().addDirectory(baseDirectory, "META-INF/", includes, new String[0]);

            if (classpath != null) {
                archive.addManifestEntry("Class-Path", getClassPath());
            }

            archiver.createArchive(project, archive);

            return archiveFile;
        }
        catch (Exception e) {
            throw new MojoExecutionException("Failed to create archive", e);
View Full Code Here

TOP

Related Classes of org.apache.maven.archiver.MavenArchiver

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.