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);
}
}
}
}
}
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);
}
}
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);
}
}
}
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);
}
}
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);
}
}
}
Aggregations