Search in sources :

Example 81 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project tycho by eclipse.

the class ProductExportMojo method copyExecutable.

private void copyExecutable(TargetEnvironment environment, File target) throws MojoExecutionException {
    getLog().debug("Creating launcher");
    ArtifactDescriptor artifact = getDependencyArtifacts().getArtifact(ArtifactType.TYPE_ECLIPSE_FEATURE, "org.eclipse.equinox.executable", null);
    if (artifact == null) {
        throw new MojoExecutionException("Native launcher is not found for " + environment.toString());
    }
    File location = artifact.getLocation(true);
    String os = environment.getOs();
    String ws = environment.getWs();
    String arch = environment.getArch();
    try {
        String launcherRelPath = "bin/" + ws + "/" + os + "/" + arch + "/";
        String excludes = "**/eclipsec*";
        if (location.isDirectory()) {
            copyDirectory(new File(location, launcherRelPath), target, excludes);
        } else {
            unzipDirectory(location, launcherRelPath, target, excludes);
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to copy launcher executable", e);
    }
    File launcher = getLauncher(environment, target);
    // make launcher executable
    try {
        getLog().debug("running chmod");
        ArchiveEntryUtils.chmod(launcher, 0755);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Unable to make launcher being executable", e);
    }
    File osxEclipseApp = null;
    // Rename launcher
    if (productConfiguration.getLauncher() != null && productConfiguration.getLauncher().getName() != null) {
        String launcherName = productConfiguration.getLauncher().getName();
        String newName = launcherName;
        // win32 has extensions
        if (PlatformPropertiesUtils.OS_WIN32.equals(os)) {
            String extension = FileUtils.getExtension(launcher.getAbsolutePath());
            newName = launcherName + "." + extension;
        } else if (PlatformPropertiesUtils.OS_MACOSX.equals(os)) {
            // the launcher is renamed to "eclipse", because
            // this is the value of the CFBundleExecutable
            // property within the Info.plist file.
            // see http://jira.codehaus.org/browse/MNGECLIPSE-1087
            newName = "eclipse";
        }
        getLog().debug("Renaming launcher to " + newName);
        File newLauncher = new File(launcher.getParentFile(), newName);
        if (!launcher.renameTo(newLauncher)) {
            throw new MojoExecutionException("Could not rename native launcher to " + newName);
        }
        launcher = newLauncher;
        // see http://jira.codehaus.org/browse/MNGECLIPSE-1087
        if (PlatformPropertiesUtils.OS_MACOSX.equals(os)) {
            newName = launcherName + ".app";
            getLog().debug("Renaming Eclipse.app to " + newName);
            File eclipseApp = new File(target, "Eclipse.app");
            osxEclipseApp = new File(eclipseApp.getParentFile(), newName);
            eclipseApp.renameTo(osxEclipseApp);
        // ToDo: the "Info.plist" file must be patched, so that the
        // property "CFBundleName" has the value of the
        // launcherName variable
        }
    }
    // icons
    if (productConfiguration.getLauncher() != null) {
        if (PlatformPropertiesUtils.OS_WIN32.equals(os)) {
            getLog().debug("win32 icons");
            List<String> icons = productConfiguration.getW32Icons();
            if (icons != null) {
                getLog().debug(icons.toString());
                try {
                    String[] args = new String[icons.size() + 1];
                    args[0] = launcher.getAbsolutePath();
                    int pos = 1;
                    for (String string : icons) {
                        args[pos] = string;
                        pos++;
                    }
                    IconExe.main(args);
                } catch (Exception e) {
                    throw new MojoExecutionException("Unable to replace icons", e);
                }
            } else {
                getLog().debug("icons is null");
            }
        } else if (PlatformPropertiesUtils.OS_LINUX.equals(os)) {
            String icon = productConfiguration.getLinuxIcon();
            if (icon != null) {
                try {
                    File sourceXPM = new File(project.getBasedir(), removeFirstSegment(icon));
                    File targetXPM = new File(launcher.getParentFile(), "icon.xpm");
                    Files.copy(sourceXPM.toPath(), targetXPM.toPath());
                } catch (IOException e) {
                    throw new MojoExecutionException("Unable to create ico.xpm", e);
                }
            }
        } else if (PlatformPropertiesUtils.OS_FREEBSD.equals(os)) {
            String icon = productConfiguration.getFreeBSDIcon();
            if (icon != null) {
                try {
                    File sourceXPM = new File(project.getBasedir(), removeFirstSegment(icon));
                    File targetXPM = new File(launcher.getParentFile(), "icon.xpm");
                    FileUtils.copyFile(sourceXPM, targetXPM);
                } catch (IOException e) {
                    throw new MojoExecutionException("Unable to create ico.xpm", e);
                }
            }
        } else if (PlatformPropertiesUtils.OS_MACOSX.equals(os)) {
            String icon = productConfiguration.getMacIcon();
            if (icon != null) {
                try {
                    if (osxEclipseApp == null) {
                        osxEclipseApp = new File(target, "Eclipse.app");
                    }
                    File source = new File(project.getBasedir(), removeFirstSegment(icon));
                    File targetFolder = new File(osxEclipseApp, "/Resources/" + source.getName());
                    FileUtils.copyFile(source, targetFolder);
                    // Modify eclipse.ini
                    File iniFile = new File(osxEclipseApp + "/Contents/MacOS/eclipse.ini");
                    if (iniFile.exists() && iniFile.canWrite()) {
                        StringBuilder buf = new StringBuilder(Files.readString(iniFile.toPath(), StandardCharsets.UTF_8));
                        int pos = buf.indexOf("Eclipse.icns");
                        buf.replace(pos, pos + 12, source.getName());
                        Files.writeString(iniFile.toPath(), buf.toString());
                    }
                } catch (Exception e) {
                    throw new MojoExecutionException("Unable to create macosx icon", e);
                }
            }
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 82 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project tycho by eclipse.

the class PackageIUMojo method createArtifact.

private File createArtifact() throws MojoExecutionException {
    try {
        File payload = getPayloadDir();
        File newArtifact = new File(outputDirectory, project.getArtifactId() + "-" + project.getVersion() + ".zip");
        if (newArtifact.exists()) {
            newArtifact.delete();
        }
        if (hasPayload()) {
            DefaultFileSet fs = new DefaultFileSet();
            fs.setDirectory(payload);
            zipArchiver.addFileSet(fs);
            zipArchiver.setDestFile(newArtifact);
            zipArchiver.setCompress(true);
            zipArchiver.createArchive();
        } else {
            // Force create the file
            newArtifact.createNewFile();
        }
        return newArtifact;
    } catch (IOException | ArchiverException e) {
        throw new MojoExecutionException("Error assembling ZIP", e);
    }
}
Also used : DefaultFileSet(org.codehaus.plexus.archiver.util.DefaultFileSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) IOException(java.io.IOException) File(java.io.File)

Example 83 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project tycho by eclipse.

the class PackageUpdateSiteMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (target == null || !target.isDirectory()) {
        throw new MojoExecutionException("Update site folder does not exist at: " + target != null ? target.getAbsolutePath() : "null");
    }
    synchronized (LOCK) {
        try {
            ZipArchiver siteZipper = new ZipArchiver();
            File siteDestination = new File(target.getParentFile(), "site.zip");
            siteZipper.addFile(new File(target, "site.xml"), "site.xml");
            siteZipper.setDestFile(siteDestination);
            siteZipper.createArchive();
            project.getArtifact().setFile(siteDestination);
            if (archiveSite) {
                ZipArchiver asssemblyZipper = new ZipArchiver();
                File asssemblyDestFile = new File(target.getParentFile(), "site_assembly.zip");
                asssemblyZipper.addDirectory(target);
                asssemblyZipper.setDestFile(asssemblyDestFile);
                asssemblyZipper.createArchive();
                projectHelper.attachArtifact(project, "zip", "assembly", asssemblyDestFile);
            }
        } catch (IOException | ArchiverException e) {
            throw new MojoExecutionException("Error packing update site", e);
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ZipArchiver(org.codehaus.plexus.archiver.zip.ZipArchiver) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) IOException(java.io.IOException) File(java.io.File)

Example 84 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project tycho by eclipse.

the class UpdateSiteAssembler method packDir.

private void packDir(File sourceDir, File targetZip) {
    ZipArchiver archiver;
    try {
        archiver = (ZipArchiver) session.lookup(ZipArchiver.ROLE, "zip");
    } catch (ComponentLookupException e) {
        throw new RuntimeException("Unable to resolve ZipArchiver", e);
    }
    archiver.setDestFile(targetZip);
    try {
        archiver.addDirectory(sourceDir);
        archiver.createArchive();
    } catch (IOException | ArchiverException e) {
        throw new RuntimeException("Error packing zip", e);
    }
}
Also used : ZipArchiver(org.codehaus.plexus.archiver.zip.ZipArchiver) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) IOException(java.io.IOException)

Example 85 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project tycho by eclipse.

the class AbstractSourceJarMojo method archiveProjectContent.

protected void archiveProjectContent(MavenProject p, Archiver archiver) throws MojoExecutionException {
    if (includePom) {
        try {
            archiver.addFile(p.getFile(), p.getFile().getName());
        } catch (ArchiverException e) {
            throw new MojoExecutionException("Error adding POM file to target jar file.", e);
        }
    }
    for (Resource resource : getSources(p)) {
        File sourceDirectory = new File(resource.getDirectory());
        if (sourceDirectory.exists()) {
            String path = resource.getTargetPath();
            if (path == null) {
                addDirectory(archiver, sourceDirectory, getCombinedIncludes(null), getCombinedExcludes(null));
            } else {
                if (!path.trim().endsWith("/")) {
                    path += "/";
                }
                addDirectory(archiver, sourceDirectory, path, getCombinedIncludes(null), getCombinedExcludes(null));
            }
        }
    }
    // MAPI: this should be taken from the resources plugin
    for (Resource resource : getResources(p)) {
        File sourceDirectory = new File(resource.getDirectory());
        if (!sourceDirectory.exists()) {
            continue;
        }
        List<String> resourceIncludes = resource.getIncludes();
        String[] combinedIncludes = getCombinedIncludes(resourceIncludes);
        List<String> resourceExcludes = resource.getExcludes();
        String[] combinedExcludes = getCombinedExcludes(resourceExcludes);
        String targetPath = resource.getTargetPath();
        if (targetPath != null) {
            if (!targetPath.trim().endsWith("/")) {
                targetPath += "/";
            }
            addDirectory(archiver, sourceDirectory, targetPath, combinedIncludes, combinedExcludes);
        } else {
            addDirectory(archiver, sourceDirectory, combinedIncludes, combinedExcludes);
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) Resource(org.apache.maven.model.Resource) 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