Search in sources :

Example 91 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project alfresco-maven by Acosix.

the class AmpUnArchiver method validate.

/**
 * {@inheritDoc}
 */
@Override
protected void validate(final String path, final File outputDirectory) throws ArchiverException {
    // for some reason there is an empty validation impl in base class(es)
    final File sourceFile = this.getSourceFile();
    if (sourceFile == null) {
        throw new ArchiverException("The source file isn't defined.");
    }
    if (sourceFile.isDirectory()) {
        throw new ArchiverException("The source must not be a directory.");
    }
    if (!sourceFile.exists()) {
        throw new ArchiverException("The source file " + sourceFile + " doesn't exist.");
    }
    File destDirectory = this.getDestDirectory();
    File destFile = this.getDestFile();
    if (destDirectory == null && destFile == null) {
        throw new ArchiverException("The destination isn't defined.");
    }
    if (destDirectory != null && destFile != null) {
        throw new ArchiverException("You must choose between a destination directory and a destination file.");
    }
    if (destDirectory != null && !destDirectory.isDirectory()) {
        this.setDestFile(destDirectory);
        this.setDestDirectory(null);
        destFile = destDirectory;
        destDirectory = null;
    }
    if (destFile != null && destFile.isDirectory()) {
        this.setDestDirectory(destFile);
        this.setDestFile(null);
        destDirectory = destFile;
        destFile = null;
    }
    this.validateAlfrescoModuleMetadata();
}
Also used : ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File)

Example 92 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project alfresco-maven by Acosix.

the class ModuleDependencyImpl method buildVersionRanges.

private static List<VersionRange> buildVersionRanges(final String versionStr) {
    final List<VersionRange> versionRanges = new ArrayList<>(1);
    final StringTokenizer rangesTokenizer = new StringTokenizer(versionStr, ",");
    while (rangesTokenizer.hasMoreTokens()) {
        String range = rangesTokenizer.nextToken().trim();
        if (range.equals("*")) {
            range = "*-*";
        }
        if (range.startsWith("-")) {
            range = "*" + range;
        }
        if (range.endsWith("-")) {
            range = range + "*";
        }
        final StringTokenizer rangeTokenizer = new StringTokenizer(range, "-", false);
        ComparableVersion versionLower = null;
        ComparableVersion versionUpper = null;
        while (rangeTokenizer.hasMoreTokens()) {
            String version = rangeTokenizer.nextToken();
            version = version.trim();
            if (versionLower == null) {
                if (version.equals("*")) {
                    versionLower = ModuleDetails.VERSION_ZERO;
                } else {
                    versionLower = new ComparableVersion(version);
                }
            } else if (versionUpper == null) {
                if (version.equals("*")) {
                    versionUpper = ModuleDetails.VERSION_BIG;
                } else {
                    versionUpper = new ComparableVersion(version);
                }
            }
        }
        // Check
        if (versionUpper == null && versionLower == null) {
            throw new ArchiverException("Valid dependency version ranges are: \n" + "   LOW  - HIGH \n" + "   *    - HIGH \n" + "   LOW  - *    \n" + "   *       ");
        } else if (versionUpper == null && versionLower != null) {
            versionUpper = versionLower;
        } else if (versionLower == null && versionUpper != null) {
            versionLower = versionUpper;
        }
        versionRanges.add(new VersionRange(versionLower, versionUpper));
    }
    return versionRanges;
}
Also used : StringTokenizer(java.util.StringTokenizer) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ArrayList(java.util.ArrayList) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion)

Example 93 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project tis by qlangtech.

the class AbstractHpiMojo method unpack.

/**
 * Unpacks the archive file.
 *
 * @param file     File to be unpacked.
 * @param location Location where to put the unpacked files.
 */
private void unpack(File file, File location) throws MojoExecutionException, NoSuchArchiverException {
    String archiveExt = FileUtils.getExtension(file.getAbsolutePath()).toLowerCase();
    try {
        UnArchiver unArchiver = archiverManager.getUnArchiver(archiveExt);
        unArchiver.setSourceFile(file);
        unArchiver.setDestDirectory(location);
        unArchiver.extract();
    } catch (IOException e) {
        throw new MojoExecutionException("Error unpacking file: " + file + "to: " + location, e);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Error unpacking file: " + file + "to: " + location, e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) UnArchiver(org.codehaus.plexus.archiver.UnArchiver)

Example 94 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project conga by wcm-io-devops.

the class PackageMojo method buildZipFile.

/**
 * Build JAR file with definitions.
 * @param contentDirectory Content directory for JAR file
 * @return JAR file
 */
private File buildZipFile(File contentDirectory, String classifier) throws MojoExecutionException {
    File zipFile = new File(getProject().getBuild().getDirectory(), buildZipFileName(classifier));
    String basePath = toZipDirectoryPath(contentDirectory);
    addZipDirectory(basePath, contentDirectory);
    zipArchiver.setDestFile(zipFile);
    try {
        zipArchiver.createArchive();
    } catch (ArchiverException | IOException ex) {
        throw new MojoExecutionException("Unable to build file " + zipFile.getPath() + ": " + ex.getMessage(), ex);
    }
    return zipFile;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) IOException(java.io.IOException) File(java.io.File)

Example 95 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project myfaces-build-tools by apache.

the class JSDocJarMojo method generateArchive.

// ----------------------------------------------------------------------
// private methods
// ----------------------------------------------------------------------
/**
 * Method that creates the jar file
 *
 * @param jsdocFiles 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 if any
 * @throws IOException if any
 */
private File generateArchive(File jsdocFiles, String jarFileName) throws ArchiverException, IOException {
    File jsdocJar = new File(jarOutputDirectory, jarFileName);
    if (jsdocJar.exists()) {
        jsdocJar.delete();
    }
    MavenArchiver archiver = new MavenArchiver();
    archiver.setArchiver(jarArchiver);
    archiver.setOutputFile(jsdocJar);
    File contentDirectory = jsdocFiles;
    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);
    }
    return jsdocJar;
}
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)

Aggregations

ArchiverException (org.codehaus.plexus.archiver.ArchiverException)99 File (java.io.File)69 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)54 IOException (java.io.IOException)48 NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)28 UnArchiver (org.codehaus.plexus.archiver.UnArchiver)18 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)15 MavenArchiver (org.apache.maven.archiver.MavenArchiver)14 Artifact (org.apache.maven.artifact.Artifact)14 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)14 Archiver (org.codehaus.plexus.archiver.Archiver)8 Resource (org.apache.maven.model.Resource)7 IncludeExcludeFileSelector (org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector)7 MojoFailureException (org.apache.maven.plugin.MojoFailureException)6 DefaultFileSet (org.codehaus.plexus.archiver.util.DefaultFileSet)6 ArrayList (java.util.ArrayList)5 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)5 MavenProject (org.apache.maven.project.MavenProject)5 FileInputStream (java.io.FileInputStream)4 FileWriter (java.io.FileWriter)4