use of org.codehaus.plexus.archiver.jar.JarArchiver in project maven-plugins by apache.
the class AbstractWarMojoTest method createArchive.
protected void createArchive(final File directory, final File destinationFile) {
try {
// WarArchiver archiver = new WarArchiver();
Archiver archiver = new JarArchiver();
archiver.setUseJvmChmod(true);
archiver.setDestFile(destinationFile);
archiver.addDirectory(directory);
// archiver.setWebxml( new File(directory, "WEB-INF/web.xml"));
// create archive
archiver.createArchive();
} catch (ArchiverException e) {
e.printStackTrace();
fail("Failed to create overlay archive " + e.getMessage());
} catch (IOException e) {
e.printStackTrace();
fail("Unexpected exception " + e.getMessage());
}
}
use of org.codehaus.plexus.archiver.jar.JarArchiver in project maven-plugins by apache.
the class AssemblyProxyArchiverTest method addDirectory_NoPerms_CallAcceptFilesOnlyOnce.
@Test
public void addDirectory_NoPerms_CallAcceptFilesOnlyOnce() throws IOException, ArchiverException {
final Archiver delegate = new JarArchiver();
final File output = fileManager.createTempFile();
delegate.setDestFile(output);
final CounterSelector counter = new CounterSelector(true);
final List<FileSelector> selectors = new ArrayList<FileSelector>();
selectors.add(counter);
final AssemblyProxyArchiver archiver = new AssemblyProxyArchiver("", delegate, null, selectors, null, new File("."), new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
archiver.setForced(true);
final File dir = fileManager.createTempDir();
FileUtils.cleanDirectory(dir);
fileManager.createFile(dir, "file.txt", "This is a test.");
archiver.addDirectory(dir);
archiver.createArchive();
assertEquals(1, counter.getCount());
}
use of org.codehaus.plexus.archiver.jar.JarArchiver in project tycho by eclipse.
the class PackageFeatureMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
outputDirectory.mkdirs();
Feature feature = Feature.loadFeature(basedir);
File licenseFeature = licenseFeatureHelper.getLicenseFeature(feature, project);
updateLicenseProperties(feature, licenseFeature);
File featureXml = new File(outputDirectory, Feature.FEATURE_XML);
try {
expandVersionQualifiers(feature);
Feature.write(feature, featureXml);
} catch (IOException e) {
throw new MojoExecutionException("Error updating feature.xml", e);
}
BuildProperties buildProperties = buildPropertiesParser.parse(project.getBasedir());
checkBinIncludesExist(buildProperties);
File featureProperties = getFeatureProperties(licenseFeature, buildProperties);
File outputJar = new File(outputDirectory, finalName + ".jar");
outputJar.getParentFile().mkdirs();
MavenArchiver archiver = new MavenArchiver();
JarArchiver jarArchiver = getJarArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(outputJar);
jarArchiver.setDestFile(outputJar);
try {
archiver.getArchiver().addFileSet(getManuallyIncludedFiles(buildProperties));
if (licenseFeature != null) {
archiver.getArchiver().addArchivedFileSet(licenseFeatureHelper.getLicenseFeatureFileSet(licenseFeature));
}
archiver.getArchiver().addFile(featureXml, Feature.FEATURE_XML);
if (featureProperties != null) {
archiver.getArchiver().addFile(featureProperties, FEATURE_PROPERTIES);
}
if (archive == null) {
archive = new MavenArchiveConfiguration();
archive.setAddMavenDescriptor(false);
}
archiver.createArchive(session, project, archive);
} catch (Exception e) {
throw new MojoExecutionException("Error creating feature package", e);
}
project.getArtifact().setFile(outputJar);
if (deployableFeature) {
assembleDeployableFeature();
}
}
use of org.codehaus.plexus.archiver.jar.JarArchiver in project cxf by apache.
the class AbstractCodeGeneratorMojo method runForked.
private void runForked(Set<URI> classPath, Class<?> cls, String[] args) throws MojoExecutionException {
getLog().info("Running wadl2java in fork mode...");
Commandline cmd = new Commandline();
// for JVM args
cmd.getShell().setQuotedArgumentsEnabled(true);
cmd.setWorkingDirectory(project.getBuild().getDirectory());
try {
cmd.setExecutable(getJavaExecutable().getAbsolutePath());
} catch (IOException e) {
getLog().debug(e);
throw new MojoExecutionException(e.getMessage(), e);
}
cmd.createArg().setLine(additionalJvmArgs);
final File file;
try {
// file = new File("/tmp/test.jar");
file = FileUtils.createTempFile("cxf-codegen", ".jar");
JarArchiver jar = new JarArchiver();
jar.setDestFile(file.getAbsoluteFile());
Manifest manifest = new Manifest();
Attribute attr = new Attribute();
attr.setName("Class-Path");
StringBuilder b = new StringBuilder(8000);
for (URI cp : classPath) {
b.append(cp.toURL().toExternalForm()).append(' ');
}
attr.setValue(b.toString());
manifest.getMainSection().addConfiguredAttribute(attr);
attr = new Attribute();
attr.setName("Main-Class");
attr.setValue(cls.getName());
manifest.getMainSection().addConfiguredAttribute(attr);
jar.addConfiguredManifest(manifest);
jar.createArchive();
cmd.createArg().setValue("-jar");
cmd.createArg().setValue(file.getAbsolutePath());
} catch (Exception e1) {
throw new MojoExecutionException("Could not create runtime jar", e1);
}
cmd.addArguments(args);
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
int exitCode;
try {
exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
} catch (CommandLineException e) {
getLog().debug(e);
throw new MojoExecutionException(e.getMessage(), e);
}
String output = StringUtils.isEmpty(out.getOutput()) ? null : '\n' + out.getOutput().trim();
String cmdLine = CommandLineUtils.toString(cmd.getCommandline());
if (exitCode != 0) {
if (StringUtils.isNotEmpty(output)) {
getLog().info(output);
}
StringBuilder msg = new StringBuilder("\nExit code: ");
msg.append(exitCode);
if (StringUtils.isNotEmpty(err.getOutput())) {
msg.append(" - ").append(err.getOutput());
}
msg.append('\n');
msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
throw new MojoExecutionException(msg.toString());
}
if (file != null) {
file.delete();
}
if (StringUtils.isNotEmpty(err.getOutput()) && err.getOutput().contains("WADL2Java Error")) {
StringBuilder msg = new StringBuilder();
msg.append(err.getOutput());
msg.append('\n');
msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
throw new MojoExecutionException(msg.toString());
}
}
Aggregations