File tempOutputDir = FileUtils.createTempFile(tempDownloadFile.getName(), ".dir", null);
tempOutputDir.mkdirs();
File extractedFile = new File(tempOutputDir, artifactItem.getExtractFile());
UnArchiver unarchiver;
try
{
try
{
unarchiver = archiverManager.getUnArchiver(tempDownloadFile);
}
catch (NoSuchArchiverException e){
if (tempDownloadFile.getName().endsWith(".gz")){
unarchiver = archiverManager.getUnArchiver("gzip");
unarchiver.setDestFile(extractedFile);
}else
throw e;
}
}
catch (NoSuchArchiverException e)
{
throw new MojoExecutionException( "Archive type, no unarchiver available for it", e);
}
// ensure the path exists to write the file to
File parentDirectory = artifactFile.getParentFile();
if (parentDirectory != null && !parentDirectory.exists())
{
artifactFile.getParentFile().mkdirs();
}
unarchiver.setSourceFile(tempDownloadFile);
if (unarchiver.getDestFile()==null)
unarchiver.setDestDirectory(tempOutputDir);
unarchiver.extract();//will extract nothing, the file selector will do the trick
// if a zip entry was not found, then throw a Mojo
// exception