Search in sources :

Example 1 with ManifestException

use of org.codehaus.plexus.archiver.jar.ManifestException in project intellij-community by JetBrains.

the class ManifestBuilder method build.

@NotNull
public java.util.jar.Manifest build() throws ManifestBuilderException {
    try {
        Element mavenPackagingPluginConfiguration = getMavenPackagingPluginConfiguration(myMavenProject);
        final Element mavenArchiveConfiguration = mavenPackagingPluginConfiguration != null ? mavenPackagingPluginConfiguration.getChild("archive") : null;
        if (mavenArchiveConfiguration == null)
            return getDefaultManifest(Collections.emptyMap());
        final Element manifestEntries = mavenArchiveConfiguration.getChild("manifestEntries");
        Map<String, String> entries = getManifestEntries(manifestEntries);
        final Element manifestConfiguration = mavenArchiveConfiguration.getChild("manifest");
        final Manifest configuredManifest = getConfiguredManifest(myMavenProject, manifestConfiguration, entries);
        if (!entries.isEmpty()) {
            addManifestEntries(configuredManifest, entries);
        }
        addCustomManifestSections(configuredManifest, mavenArchiveConfiguration);
        Manifest finalManifest = getDefaultManifest(entries);
        // merge configured manifest
        merge(finalManifest, configuredManifest);
        // merge user supplied manifest
        final Manifest userSuppliedManifest = getUserSuppliedManifest(mavenArchiveConfiguration);
        merge(finalManifest, userSuppliedManifest);
        return finalManifest;
    } catch (ManifestException e) {
        throw new ManifestBuilderException(e);
    }
}
Also used : Element(org.jdom.Element) Manifest(org.codehaus.plexus.archiver.jar.Manifest) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ManifestException

use of org.codehaus.plexus.archiver.jar.ManifestException in project maven-plugins by apache.

the class EjbMojo method generateEjbClient.

private File generateEjbClient() throws MojoExecutionException {
    File clientJarFile = EjbHelper.getJarFile(outputDirectory, jarName, getClientClassifier());
    getLog().info("Building EJB client " + clientJarFile.getPath());
    MavenArchiver clientArchiver = new MavenArchiver();
    clientArchiver.setArchiver(clientJarArchiver);
    clientArchiver.setOutputFile(clientJarFile);
    try {
        List<String> defaultExcludes = DEFAULT_CLIENT_EXCLUDES_LIST;
        List<String> defaultIncludes = DEFAULT_INCLUDES_LIST;
        IncludesExcludes ie = new IncludesExcludes(clientIncludes, clientExcludes, defaultIncludes, defaultExcludes);
        clientArchiver.getArchiver().addDirectory(sourceDirectory, ie.resultingIncludes(), ie.resultingExcludes());
        clientArchiver.createArchive(session, project, archive);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("There was a problem creating the EJB client archive: " + e.getMessage(), e);
    } catch (ManifestException e) {
        throw new MojoExecutionException("There was a problem creating the EJB client archive: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException("There was a problem creating the EJB client archive: " + e.getMessage(), e);
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("There was a problem creating the EJB client archive: " + e.getMessage(), e);
    }
    return clientJarFile;
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) File(java.io.File)

Example 3 with ManifestException

use of org.codehaus.plexus.archiver.jar.ManifestException in project maven-plugins by apache.

the class AcrMojo method execute.

/** {@inheritDoc} */
public void execute() throws MojoExecutionException {
    if (getLog().isInfoEnabled()) {
        getLog().info("Building JavaEE Application client: " + jarName);
    }
    File jarFile = getAppClientJarFile(basedir, jarName);
    MavenArchiver archiver = new MavenArchiver();
    archiver.setArchiver(jarArchiver);
    archiver.setOutputFile(jarFile);
    try {
        String[] mainJarExcludes = DEFAULT_EXCLUDES;
        if (excludes != null && !excludes.isEmpty()) {
            excludes.add(APP_CLIENT_XML);
            mainJarExcludes = excludes.toArray(new String[excludes.size()]);
        }
        if (outputDirectory.exists()) {
            archiver.getArchiver().addDirectory(outputDirectory, DEFAULT_INCLUDES, mainJarExcludes);
        } else {
            // CHECKSTYLE_OFF: LineLength
            getLog().info("JAR will only contain the META-INF/application-client.xml as no content was marked for inclusion");
        // CHECKSTYLE_ON: LineLength
        }
        File deploymentDescriptor = new File(outputDirectory, APP_CLIENT_XML);
        if (deploymentDescriptor.exists()) {
            if (filterDeploymentDescriptor) {
                getLog().debug("Filtering deployment descriptor.");
                MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution();
                mavenResourcesExecution.setEscapeString(escapeString);
                List<FilterWrapper> filterWrappers = mavenFileFilter.getDefaultFilterWrappers(project, filters, escapeBackslashesInFilePath, this.session, mavenResourcesExecution);
                // Create a temporary file that we can copy-and-filter
                File unfilteredDeploymentDescriptor = new File(outputDirectory, APP_CLIENT_XML + ".unfiltered");
                FileUtils.copyFile(deploymentDescriptor, unfilteredDeploymentDescriptor);
                mavenFileFilter.copyFile(unfilteredDeploymentDescriptor, deploymentDescriptor, true, filterWrappers, getEncoding(unfilteredDeploymentDescriptor));
                // Remove the temporary file
                FileUtils.forceDelete(unfilteredDeploymentDescriptor);
            }
            archiver.getArchiver().addFile(deploymentDescriptor, APP_CLIENT_XML);
        }
        // create archive
        archiver.createArchive(session, project, archive);
    // CHECKSTYLE_OFF: LineLength
    } catch (ArchiverException e) {
        throw new MojoExecutionException("There was a problem creating the JavaEE Application Client  archive: " + e.getMessage(), e);
    } catch (ManifestException e) {
        throw new MojoExecutionException("There was a problem reading / creating the manifest for the JavaEE Application Client  archive: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException("There was a I/O problem creating the JavaEE Application Client archive: " + e.getMessage(), e);
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("There was a problem resolving dependencies while creating the JavaEE Application Client archive: " + e.getMessage(), e);
    } catch (MavenFilteringException e) {
        throw new MojoExecutionException("There was a problem filtering the deployment descriptor: " + e.getMessage(), e);
    }
    project.getArtifact().setFile(jarFile);
// CHECKSTYLE_ON: LineLength
}
Also used : MavenResourcesExecution(org.apache.maven.shared.filtering.MavenResourcesExecution) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) FilterWrapper(org.apache.maven.shared.utils.io.FileUtils.FilterWrapper) File(java.io.File)

Example 4 with ManifestException

use of org.codehaus.plexus.archiver.jar.ManifestException in project maven-plugins by apache.

the class JavadocJar method generateArchive.

// ----------------------------------------------------------------------
// private methods
// ----------------------------------------------------------------------
/**
     * Method that creates the jar file
     *
     * @param javadocFiles the directory where the generated jar file will be put
     * @param jarFileName the filename of the generated jar file
     * @return a File object that contains the generated jar file
     * @throws ArchiverException {@link ArchiverException}
     * @throws IOException {@link IOException}
     */
private File generateArchive(File javadocFiles, String jarFileName) throws ArchiverException, IOException {
    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 {
        archiver.createArchive(session, project, archive);
    } catch (ManifestException e) {
        throw new ArchiverException("ManifestException: " + e.getMessage(), e);
    } catch (DependencyResolutionRequiredException e) {
        throw new ArchiverException("DependencyResolutionRequiredException: " + e.getMessage(), e);
    }
    return javadocJar;
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) Resource(org.apache.maven.model.Resource) MavenArchiver(org.apache.maven.archiver.MavenArchiver) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) File(java.io.File)

Example 5 with ManifestException

use of org.codehaus.plexus.archiver.jar.ManifestException in project maven-plugins by apache.

the class EarMojo method changeManifestClasspath.

private void changeManifestClasspath(EarModule module, File original, JavaEEVersion javaEEVersion) throws MojoFailureException {
    try {
        File workDirectory;
        // Handle the case that the destination might be a directory (project-038)
        if (original.isFile()) {
            // Create a temporary work directory
            // MEAR-167 use uri as directory to prevent merging of artifacts with the same artifactId
            workDirectory = new File(new File(getTempFolder(), "temp"), module.getUri());
            workDirectory.mkdirs();
            getLog().debug("Created a temporary work directory: " + workDirectory.getAbsolutePath());
            // Unpack the archive to a temporary work directory
            zipUnArchiver.setSourceFile(original);
            zipUnArchiver.setDestDirectory(workDirectory);
            zipUnArchiver.extract();
        } else {
            workDirectory = original;
        }
        // Create a META-INF/MANIFEST.MF file if it doesn't exist (project-038)
        File metaInfDirectory = new File(workDirectory, "META-INF");
        boolean newMetaInfCreated = metaInfDirectory.mkdirs();
        if (newMetaInfCreated) {
            // CHECKSTYLE_OFF: LineLength
            getLog().debug("This project did not have a META-INF directory before, so a new directory was created.");
        // CHECKSTYLE_ON: LineLength
        }
        File newCreatedManifestFile = new File(metaInfDirectory, "MANIFEST.MF");
        boolean newManifestCreated = newCreatedManifestFile.createNewFile();
        if (newManifestCreated) {
            // CHECKSTYLE_OFF: LineLength
            getLog().debug("This project did not have a META-INF/MANIFEST.MF file before, so a new file was created.");
        // CHECKSTYLE_ON: LineLength
        }
        // Read the manifest from disk
        Manifest mf = new Manifest(new FileInputStream(newCreatedManifestFile));
        Attribute classPath = mf.getMainSection().getAttribute("Class-Path");
        List<String> classPathElements = new ArrayList<String>();
        if (classPath != null) {
            classPathElements.addAll(Arrays.asList(classPath.getValue().split(" ")));
        } else {
            classPath = new Attribute("Class-Path", "");
        }
        // Remove JAR modules
        for (JarModule jm : getAllJarModules()) {
            if (module.getLibDir() != null) {
                // MEAR-189:
                // We use the original name, cause in case of fileNameMapping to no-version/full
                // we could not not delete it and it will end up in the resulting EAR and the WAR
                // will not be cleaned up.
                File artifact = new File(new File(workDirectory, module.getLibDir()), jm.getOriginalBundleFileName());
                // the artifact is not found. Therefore respect the current fileNameMapping additionally.
                if (!artifact.exists()) {
                    artifact = new File(new File(workDirectory, module.getLibDir()), jm.getBundleFileName());
                }
                if (artifact.exists()) {
                    getLog().debug(" -> Artifact to delete: " + artifact);
                    if (!artifact.delete()) {
                        getLog().error("Could not delete '" + artifact + "'");
                    }
                }
            }
        }
        // Modify the classpath entries in the manifest
        for (EarModule o : getModules()) {
            if (o instanceof JarModule) {
                JarModule jm = (JarModule) o;
                if (classPathElements.contains(jm.getBundleFileName())) {
                    classPathElements.set(classPathElements.indexOf(jm.getBundleFileName()), jm.getUri());
                } else {
                    if (!skipClassPathModification) {
                        classPathElements.add(jm.getUri());
                    } else {
                        if (javaEEVersion.lt(JavaEEVersion.FIVE) || defaultLibBundleDir == null) {
                            classPathElements.add(jm.getUri());
                        }
                    }
                }
            }
        }
        classPath.setValue(StringUtils.join(classPathElements.iterator(), " "));
        mf.getMainSection().addConfiguredAttribute(classPath);
        // Write the manifest to disk
        PrintWriter pw = new PrintWriter(newCreatedManifestFile);
        mf.write(pw);
        pw.close();
        if (original.isFile()) {
            // Pack up the archive again from the work directory
            if (!original.delete()) {
                getLog().error("Could not delete original artifact file " + original);
            }
            getLog().debug("Zipping module");
            zipArchiver.setDestFile(original);
            zipArchiver.addDirectory(workDirectory);
            zipArchiver.createArchive();
        }
    } catch (ManifestException e) {
        throw new MojoFailureException(e.getMessage());
    } catch (ZipException e) {
        throw new MojoFailureException(e.getMessage());
    } catch (IOException e) {
        throw new MojoFailureException(e.getMessage());
    } catch (ArchiverException e) {
        throw new MojoFailureException(e.getMessage());
    }
}
Also used : Attribute(org.codehaus.plexus.archiver.jar.Manifest.Attribute) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) Manifest(org.codehaus.plexus.archiver.jar.Manifest) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) FileInputStream(java.io.FileInputStream) File(java.io.File) PrintWriter(java.io.PrintWriter)

Aggregations

ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)10 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)8 File (java.io.File)7 IOException (java.io.IOException)7 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)7 MavenArchiver (org.apache.maven.archiver.MavenArchiver)6 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 Manifest (org.codehaus.plexus.archiver.jar.Manifest)4 FileInputStream (java.io.FileInputStream)2 MavenFilteringException (org.apache.maven.shared.filtering.MavenFilteringException)2 Attribute (org.codehaus.plexus.archiver.jar.Manifest.Attribute)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ZipException (java.util.zip.ZipException)1 Resource (org.apache.maven.model.Resource)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1