use of org.codehaus.plexus.archiver.tar.TarArchiver in project docker-maven-plugin by fabric8io.
the class DockerAssemblyManager method createBuildTarBall.
// Create final tar-ball to be used for building the archive to send to the Docker daemon
private File createBuildTarBall(BuildDirs buildDirs, List<ArchiverCustomizer> archiverCustomizers, AssemblyConfiguration assemblyConfig, ArchiveCompression compression) throws MojoExecutionException {
File archive = new File(buildDirs.getTemporaryRootDirectory(), "docker-build." + compression.getFileSuffix());
try {
TarArchiver archiver = createBuildArchiver(buildDirs.getOutputDirectory(), archive, assemblyConfig);
for (ArchiverCustomizer customizer : archiverCustomizers) {
if (customizer != null) {
archiver = customizer.customize(archiver);
}
}
archiver.setCompression(compression.getTarCompressionMethod());
archiver.createArchive();
return archive;
} catch (NoSuchArchiverException e) {
throw new MojoExecutionException("No archiver for type 'tar' found", e);
} catch (IOException e) {
throw new MojoExecutionException("Cannot create archive " + archive, e);
}
}
use of org.codehaus.plexus.archiver.tar.TarArchiver in project docker-maven-plugin by fabric8io.
the class DockerAssemblyManager method createBuildArchiver.
private TarArchiver createBuildArchiver(File outputDir, File archive, AssemblyConfiguration assemblyConfig) throws NoSuchArchiverException {
TarArchiver archiver = (TarArchiver) archiverManager.getArchiver("tar");
archiver.setLongfile(TarLongFileMode.posix);
AssemblyMode mode = assemblyConfig != null ? assemblyConfig.getMode() : null;
if (mode != null && mode.isArchive()) {
DefaultArchivedFileSet archiveSet = DefaultArchivedFileSet.archivedFileSet(new File(outputDir, assemblyConfig.getName() + "." + mode.getExtension()));
archiveSet.setPrefix(assemblyConfig.getName() + "/");
archiveSet.setIncludingEmptyDirectories(true);
archiveSet.setUsingDefaultExcludes(false);
archiver.addArchivedFileSet(archiveSet);
} else {
DefaultFileSet fileSet = DefaultFileSet.fileSet(outputDir);
fileSet.setUsingDefaultExcludes(false);
archiver.addFileSet(fileSet);
}
archiver.setDestFile(archive);
return archiver;
}
use of org.codehaus.plexus.archiver.tar.TarArchiver in project fabric8 by fabric8io.
the class BuildMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
File libDir = new File(assembly, "lib");
libDir.mkdirs();
File binDir = new File(assembly, "bin");
binDir.mkdirs();
ArrayList<String> classpath = new ArrayList<String>();
// get sets of dependencies
ArrayList<Artifact> artifacts = null;
try {
artifacts = collectClassPath();
} catch (DependencyGraphBuilderException e) {
throw new MojoExecutionException("Could not get classpath", e);
}
getLog().debug("Classpath for " + scope + ":\n" + artifactsToString(artifacts));
// Lets first copy this project's artifact.
if (project.getArtifact().getFile() != null) {
File target = new File(libDir, project.getArtifact().getFile().getName());
classpath.add(target.getName());
try {
FileUtils.copyFile(project.getArtifact().getFile(), target);
} catch (IOException e) {
throw new MojoExecutionException("Could not copy artifact to lib dir", e);
}
}
// Artifacts in this map point to resolved files.
// project.getArtifactMap() doesn't include type or classifier in map key so we need to roll our own...
Map artifactMap = getArtifactMap();
// Lets then copy the it's dependencies.
for (Artifact x : artifacts) {
// x is not resolved, so lets look it up in the map.
Artifact artifact = (Artifact) artifactMap.get(versionlessKey(x));
// which should be treated as equivalent so we have to roll our own equals...
if (artifact == null || artifact.getFile() == null || !artifactEquals(artifact, x)) {
continue;
}
getLog().debug("Copying " + artifact.toString());
File file = artifact.getFile().getAbsoluteFile();
try {
File target = new File(libDir, file.getName());
// just in case we run into an lib name collision, lets
// find a non-colliding target name
int dupCounter = 1;
while (classpath.contains(target.getName())) {
target = new File(libDir, "dup" + dupCounter + "-" + file.getName());
dupCounter++;
}
classpath.add(target.getName());
FileUtils.copyFile(artifact.getFile(), target);
} catch (IOException e) {
throw new MojoExecutionException("Could not copy artifact to lib dir", e);
}
}
// Finally lets write the classpath.
try {
String classpathTxt = StringUtils.join(classpath.iterator(), "\n") + "\n";
FileUtils.fileWrite(new File(libDir, "classpath"), classpathTxt);
} catch (IOException e) {
throw new MojoExecutionException("Could create the classpath file", e);
}
HashMap<String, String> interpolations = new HashMap<String, String>();
// Be sure that an empty string is replaced when no main class is given
interpolations.put("hawtapp.mvn.main.property", javaMainClass != null ? javaMainClass : "");
File targetRun = new File(binDir, "run.sh");
copyResource("bin/run.sh", targetRun, interpolations, true);
chmodExecutable(targetRun);
File targetRunCmd = new File(binDir, "run.cmd");
copyResource("bin/run.cmd", targetRunCmd, interpolations, false);
if (source != null && source.exists()) {
try {
FileUtils.copyDirectoryStructure(source, assembly);
} catch (IOException e) {
throw new MojoExecutionException("Could copy the hawt-app resources", e);
}
}
Archiver archiver;
String archiveExtension;
if (archive.getName().endsWith(".tar")) {
archiver = tarArchiver;
archiveExtension = "tar";
} else if (archive.getName().endsWith(".tar.gz")) {
((TarArchiver) tarArchiver).setCompression(TarArchiver.TarCompressionMethod.gzip);
archiver = tarArchiver;
archiveExtension = "tar.gz";
} else if (archive.getName().endsWith(".zip")) {
archiver = zipArchiver;
archiveExtension = "zip";
} else {
throw new MojoExecutionException("Invalid archive extension. Should be zip | tar | tar.gz");
}
archiver.setDestFile(archive);
archiver.addFileSet(fileSet(assembly).prefixed(archivePrefix).includeExclude(null, new String[] { "bin/*" }).includeEmptyDirs(true));
archiver.setFileMode(0755);
archiver.addFileSet(fileSet(assembly).prefixed(archivePrefix).includeExclude(new String[] { "bin/*" }, null).includeEmptyDirs(true));
try {
archiver.createArchive();
} catch (IOException e) {
throw new MojoExecutionException("Could not create the " + archive + " file", e);
}
projectHelper.attachArtifact(project, archiveExtension, archiveClassifier, archive);
}
Aggregations