/** * Create the debian archive with from the provided control files and data producers. * * @param pControlFiles * @param pData * @param pOutput * @param compression the compression method used for the data file (gzip, bzip2 or anything else * for no compression) * @return PackageDescriptor * @throws PackagingException */ public PackageDescriptor createDeb( final File[] pControlFiles, final DataProducer[] pData, final File pOutput, String compression) throws PackagingException, InvalidDescriptorException { File tempData = null; File tempControl = null; try { tempData = File.createTempFile("deb", "data"); tempControl = File.createTempFile("deb", "control"); console.println("Building data"); final StringBuffer md5s = new StringBuffer(); final BigInteger size = buildData(pData, tempData, md5s, compression); console.println("Building control"); final PackageDescriptor packageDescriptor = buildControl(pControlFiles, size, md5s, tempControl); if (!packageDescriptor.isValid()) { throw new InvalidDescriptorException(packageDescriptor); } pOutput.getParentFile().mkdirs(); final InformationOutputStream md5output = new InformationOutputStream( new FileOutputStream(pOutput), MessageDigest.getInstance("MD5")); // Add chain of filters in order to calculate sha1 and sha256 for 1.8 format final InformationOutputStream sha1output = new InformationOutputStream(md5output, MessageDigest.getInstance("SHA1")); final InformationOutputStream sha256output = new InformationOutputStream(sha1output, MessageDigest.getInstance("SHA-256")); final ArArchiveOutputStream ar = new ArArchiveOutputStream(sha256output); addTo(ar, "debian-binary", "2.0\n"); addTo(ar, "control.tar.gz", tempControl); addTo(ar, "data.tar" + getExtension(compression), tempData); ar.close(); // intermediate values packageDescriptor.set("MD5", md5output.getHexDigest()); packageDescriptor.set("SHA1", sha1output.getHexDigest()); packageDescriptor.set("SHA256", sha256output.getHexDigest()); packageDescriptor.set("Size", "" + md5output.getSize()); packageDescriptor.set("File", pOutput.getName()); return packageDescriptor; } catch (InvalidDescriptorException e) { throw e; } catch (Exception e) { throw new PackagingException("Could not create deb package", e); } finally { if (tempData != null) { if (!tempData.delete()) { throw new PackagingException("Could not delete " + tempData); } } if (tempControl != null) { if (!tempControl.delete()) { throw new PackagingException("Could not delete " + tempControl); } } } }
/** * Create the debian archive with from the provided control files and data producers. * * @param pControlFiles * @param pData * @param pOutput * @param compression the compression method used for the data file * @return PackageDescriptor * @throws PackagingException */ public PackageDescriptor createDeb( final File[] pControlFiles, final DataProducer[] pData, final File pOutput, Compression compression) throws PackagingException { File tempData = null; File tempControl = null; try { tempData = File.createTempFile("deb", "data"); tempControl = File.createTempFile("deb", "control"); console.info("Building data"); final StringBuilder md5s = new StringBuilder(); final BigInteger size = buildData(pData, tempData, md5s, compression); console.info("Building control"); final PackageDescriptor packageDescriptor = buildControl(pControlFiles, size, md5s, tempControl); if (!packageDescriptor.isValid()) { throw new PackagingException( "Control file descriptor keys are invalid " + packageDescriptor.invalidKeys() + ". The following keys are mandatory " + Arrays.toString(PackageDescriptor.MANDATORY_KEYS) + ". Please check your pom.xml/build.xml and your control file."); } pOutput.getParentFile().mkdirs(); // pass through stream chain to calculate all the different digests final InformationOutputStream md5output = new InformationOutputStream( new FileOutputStream(pOutput), MessageDigest.getInstance("MD5")); final InformationOutputStream sha1output = new InformationOutputStream(md5output, MessageDigest.getInstance("SHA1")); final InformationOutputStream sha256output = new InformationOutputStream(sha1output, MessageDigest.getInstance("SHA-256")); final ArArchiveOutputStream ar = new ArArchiveOutputStream(sha256output); addTo(ar, "debian-binary", "2.0\n"); addTo(ar, "control.tar.gz", tempControl); addTo(ar, "data.tar" + compression.getExtension(), tempData); ar.close(); // intermediate values packageDescriptor.set("MD5", md5output.getHexDigest()); packageDescriptor.set("SHA1", sha1output.getHexDigest()); packageDescriptor.set("SHA256", sha256output.getHexDigest()); packageDescriptor.set("Size", "" + md5output.getSize()); packageDescriptor.set("File", pOutput.getName()); return packageDescriptor; } catch (Exception e) { throw new PackagingException("Could not create deb package", e); } finally { if (tempData != null) { if (!tempData.delete()) { console.warn("Could not delete the temporary file " + tempData); } } if (tempControl != null) { if (!tempControl.delete()) { console.warn("Could not delete the temporary file " + tempControl); } } } }