use of org.codehaus.plexus.archiver.ArchiverException in project tycho by eclipse.
the class SignRepositoryArtifactsMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
var artifactsXml = new File(repository, "artifacts.xml");
var artifactsXmlXz = new File(repository, "artifacts.xml.xz");
var artifactsJar = new File(repository, "artifacts.jar");
if (!artifactsXml.exists()) {
if (artifactsXmlXz.exists()) {
xzUnarchiver.setSourceFile(artifactsXmlXz);
xzUnarchiver.setDestFile(artifactsXml);
xzUnarchiver.extract();
artifactsXmlXz.delete();
}
if (artifactsJar.exists()) {
zipUnArchiver.setSourceFile(artifactsJar);
zipUnArchiver.setDestDirectory(repository);
zipUnArchiver.extract();
artifactsJar.delete();
}
}
Xpp3Dom dom = null;
try (var stream = new FileInputStream(artifactsXml)) {
dom = Xpp3DomBuilder.build(stream, StandardCharsets.UTF_8.displayName());
} catch (IOException | XmlPullParserException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
ProxySignerWithPublicKeyAccess signer = newSigner(project);
String armoredPublicKey = signer.getPublicKeys();
for (var artifact : dom.getChild("artifacts").getChildren("artifact")) {
Xpp3Dom properties = artifact.getChild("properties");
if (Arrays.stream(properties.getChildren()).anyMatch(property -> IArtifactDescriptor.FORMAT.equals(property.getAttribute("name")) && IArtifactDescriptor.FORMAT_PACKED.equals(property.getAttribute("value")))) {
// skip packed artifacts
continue;
}
var file = new File(repository, "plugins/" + artifact.getAttribute("id") + '_' + artifact.getAttribute("version") + ".jar");
if (!file.canRead()) {
continue;
}
if (skipIfJarsigned && isJarSigned(file)) {
continue;
}
var signatureFile = signer.generateSignatureForArtifact(file);
String signature;
try {
signature = Files.readString(signatureFile.toPath());
var signatureProperty = new Xpp3Dom("property");
signatureProperty.setAttribute("name", "pgp.signatures");
signatureProperty.setAttribute("value", signature);
properties.addChild(signatureProperty);
properties.setAttribute("size", Integer.toString(Integer.parseInt(properties.getAttribute("size")) + 1));
if (addPublicKeysToArtifacts) {
var publicKeyProperty = new Xpp3Dom("property");
publicKeyProperty.setAttribute("name", "pgp.publicKeys");
publicKeyProperty.setAttribute("value", armoredPublicKey);
properties.addChild(publicKeyProperty);
properties.setAttribute("size", Integer.toString(Integer.parseInt(properties.getAttribute("size")) + 1));
}
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
if (addPublicKeyToRepo) {
Xpp3Dom repositoryProperties = dom.getChild("properties");
repositoryProperties.setAttribute("size", Integer.toString(Integer.parseInt(repositoryProperties.getAttribute("size")) + 1));
var signersProperty = new Xpp3Dom("property");
signersProperty.setAttribute("name", "pgp.publicKeys");
signersProperty.setAttribute("value", armoredPublicKey);
repositoryProperties.addChild(signersProperty);
}
try (var writer = new FileWriter(artifactsXml)) {
Xpp3DomWriter.write(writer, dom);
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
xzArchiver.setDestFile(artifactsXmlXz);
xzArchiver.addFile(artifactsXml, artifactsXml.getName());
try {
xzArchiver.createArchive();
} catch (ArchiverException | IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
zipArchiver.setDestFile(artifactsJar);
zipArchiver.addFile(artifactsXml, artifactsXml.getName());
try {
zipArchiver.createArchive();
} catch (ArchiverException | IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project tycho by eclipse.
the class DefaultEquinoxInstallationFactory method unpack.
protected void unpack(File source, File destination) {
UnArchiver unzip;
try {
unzip = plexus.lookup(UnArchiver.class, "zip");
} catch (ComponentLookupException e) {
throw new RuntimeException("Could not lookup required component", e);
}
unzip.setIgnorePermissions(true);
destination.mkdirs();
unzip.setSourceFile(source);
unzip.setDestDirectory(destination);
try {
unzip.extract();
} catch (ArchiverException e) {
throw new RuntimeException("Unable to unpack jar " + source, e);
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project tycho by eclipse.
the class TychoOsgiRuntimeLocator method addRuntimeArtifact.
private void addRuntimeArtifact(EquinoxRuntimeDescription description, MavenSession session, Dependency dependency) throws MavenExecutionException {
Artifact artifact = resolveDependency(session, dependency);
if ("zip".equals(dependency.getType())) {
File artifactFile = new File(session.getLocalRepository().getBasedir(), session.getLocalRepository().pathOf(artifact));
File eclipseDir = new File(artifactFile.getParentFile(), "eclipse");
FileLocker locker = fileLockService.getFileLocker(artifactFile);
locker.lock();
try {
if (!eclipseDir.exists() || artifact.isSnapshot()) {
logger.debug("Extracting Tycho's OSGi runtime");
if (artifact.getFile().lastModified() > eclipseDir.lastModified()) {
logger.debug("Unpacking Tycho's OSGi runtime to " + eclipseDir);
try {
FileUtils.deleteDirectory(eclipseDir);
} catch (IOException e) {
logger.warn("Failed to delete Tycho's OSGi runtime " + eclipseDir + ": " + e.getMessage());
}
eclipseDir.mkdirs();
unArchiver.setSourceFile(artifact.getFile());
unArchiver.setDestDirectory(eclipseDir);
try {
unArchiver.extract();
} catch (ArchiverException e) {
throw new MavenExecutionException("Failed to unpack Tycho's OSGi runtime: " + e.getMessage(), e);
}
eclipseDir.setLastModified(artifact.getFile().lastModified());
}
}
} finally {
locker.release();
}
description.addInstallation(eclipseDir);
} else {
description.addBundle(artifact.getFile());
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project jbehave-core by jbehave.
the class EmbedderMojoBehaviour method shouldNotIgnoreFailureInUnpackingViewResources.
@Test
void shouldNotIgnoreFailureInUnpackingViewResources() throws NoSuchArchiverException, ArchiverException {
// Given
File coreFile = new File("core");
Artifact coreResources = mock(Artifact.class);
when(coreResources.getArtifactId()).thenReturn("jbehave-core");
when(coreResources.getType()).thenReturn("zip");
when(coreResources.getFile()).thenReturn(coreFile);
File siteFile = new File("site");
Artifact siteResources = mock(Artifact.class);
when(siteResources.getArtifactId()).thenReturn("jbehave-site-resources");
when(siteResources.getType()).thenReturn("zip");
when(siteResources.getFile()).thenReturn(siteFile);
Set<Artifact> allArtifacts = new HashSet<>();
allArtifacts.add(coreResources);
allArtifacts.add(siteResources);
String buildDirectory = "target";
Build build = new Build();
build.setDirectory(buildDirectory);
MavenProject project = mock(MavenProject.class);
when(project.getArtifacts()).thenReturn(allArtifacts);
when(project.getBuild()).thenReturn(build);
UnArchiver coreArchiver = mock(UnArchiver.class);
UnArchiver siteArchiver = mock(UnArchiver.class);
ArchiverManager archiveManager = mock(ArchiverManager.class);
when(archiveManager.getUnArchiver(coreFile)).thenReturn(coreArchiver);
when(archiveManager.getUnArchiver(siteFile)).thenReturn(siteArchiver);
UnpackViewResources mojo = new UnpackViewResources() {
@Override
protected Embedder newEmbedder() {
return new Embedder();
}
};
mojo.project = project;
mojo.archiverManager = archiveManager;
// When
doThrow(new ArchiverException("bum")).when(siteArchiver).extract();
// Then fail as expected ...
assertThrows(MojoExecutionException.class, mojo::execute);
}
use of org.codehaus.plexus.archiver.ArchiverException in project alfresco-maven by Acosix.
the class AmpUnArchiver method loadMetaFile.
protected <T> T loadMetaFile(final File context, final String relativePath, final FileReader<T> reader) throws ArchiverException {
this.getLogger().debug("Attempting to resolve meta file " + relativePath + " in context " + context);
T meta = null;
try {
if (context.isFile()) {
try (ZipFile archiveCandidate = new ZipFile(context, this.encoding, true)) {
final ZipArchiveEntry zae = archiveCandidate.getEntry(relativePath);
if (zae != null && !zae.isDirectory()) {
try (InputStream is = archiveCandidate.getInputStream(zae)) {
meta = reader.readFile(is);
this.getLogger().debug("Succesfully read meta file " + relativePath + " from context " + context);
}
}
}
} else {
final File propertiesFile = Paths.get(context.getPath(), relativePath).toFile();
if (propertiesFile.exists() && propertiesFile.isFile()) {
try (InputStream is = new FileInputStream(propertiesFile)) {
meta = reader.readFile(is);
this.getLogger().debug("Succesfully read meta file" + relativePath + " from context " + context);
}
}
}
} catch (final IOException ioex) {
throw new ArchiverException("Error loading file " + relativePath + " from " + context.getAbsolutePath(), ioex);
}
return meta;
}
Aggregations