/** * Creates a package descriptor from the specified control file and adds the <tt>Date</tt>, * <tt>Distribution</tt> and <tt>Urgency</tt> fields if missing. The <tt>Installed-Size</tt> field * is also initialized to the actual size of the package. The <tt>Maintainer</tt> field is * overridden by the <tt>DEBEMAIL</tt> and <tt>DEBFULLNAME</tt> environment variables if defined. * * @param file the control file * @param pDataSize the size of the installed package */ private PackageDescriptor createPackageDescriptor(File file, BigInteger pDataSize) throws IOException, ParseException { PackageDescriptor packageDescriptor = new PackageDescriptor(new FileInputStream(file), resolver); if (packageDescriptor.get("Date") == null) { // Mon, 26 Mar 2007 11:44:04 +0200 (RFC 2822) SimpleDateFormat fmt = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH); packageDescriptor.set("Date", fmt.format(new Date())); } if (packageDescriptor.get("Distribution") == null) { packageDescriptor.set("Distribution", "unknown"); } if (packageDescriptor.get("Urgency") == null) { packageDescriptor.set("Urgency", "low"); } packageDescriptor.set("Installed-Size", pDataSize.divide(BigInteger.valueOf(1024)).toString()); // override the Version if the DEBVERSION environment variable is defined final String debVersion = System.getenv("DEBVERSION"); if (debVersion != null) { packageDescriptor.set("Version", debVersion); console.info("Using version'" + debVersion + "' from the environment variables."); } // override the Maintainer field if the DEBFULLNAME and DEBEMAIL environment variables are // defined final String debFullName = System.getenv("DEBFULLNAME"); final String debEmail = System.getenv("DEBEMAIL"); if (debFullName != null && debEmail != null) { final String maintainer = debFullName + " <" + debEmail + ">"; packageDescriptor.set("Maintainer", maintainer); console.info("Using maintainer '" + maintainer + "' from the environment variables."); } return packageDescriptor; }
/** * Build control archive of the deb * * @param pControlFiles * @param pDataSize * @param pChecksums * @param pOutput * @return * @throws FileNotFoundException * @throws IOException * @throws ParseException */ private PackageDescriptor buildControl( final File[] pControlFiles, final BigInteger pDataSize, final StringBuffer pChecksums, final File pOutput) throws IOException, ParseException { PackageDescriptor packageDescriptor = null; final TarOutputStream outputStream = new TarOutputStream(new GZIPOutputStream(new FileOutputStream(pOutput))); outputStream.setLongFileMode(TarOutputStream.LONGFILE_GNU); for (int i = 0; i < pControlFiles.length; i++) { final File file = pControlFiles[i]; if (file.isDirectory()) { continue; } final TarEntry entry = new TarEntry(file); final String name = file.getName(); entry.setName("./" + name); entry.setNames("root", "root"); entry.setMode(PermMapper.toMode("755")); if ("control".equals(name)) { packageDescriptor = new PackageDescriptor(new FileInputStream(file), resolver); if (packageDescriptor.get("Date") == null) { SimpleDateFormat fmt = new SimpleDateFormat( "EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH); // Mon, 26 Mar 2007 11:44:04 +0200 (RFC 2822) // FIXME Is this field allowed in package descriptors ? packageDescriptor.set("Date", fmt.format(new Date())); } if (packageDescriptor.get("Distribution") == null) { packageDescriptor.set("Distribution", "unknown"); } if (packageDescriptor.get("Urgency") == null) { packageDescriptor.set("Urgency", "low"); } final String debFullName = System.getenv("DEBFULLNAME"); final String debEmail = System.getenv("DEBEMAIL"); if (debFullName != null && debEmail != null) { packageDescriptor.set("Maintainer", debFullName + " <" + debEmail + ">"); console.println("Using maintainer from the environment variables."); } continue; } final InputStream inputStream = new FileInputStream(file); outputStream.putNextEntry(entry); Utils.copy(inputStream, outputStream); outputStream.closeEntry(); inputStream.close(); } if (packageDescriptor == null) { throw new FileNotFoundException("No control file in " + Arrays.toString(pControlFiles)); } packageDescriptor.set("Installed-Size", pDataSize.divide(BigInteger.valueOf(1024)).toString()); addEntry("control", packageDescriptor.toString(), outputStream); addEntry("md5sums", pChecksums.toString(), outputStream); outputStream.close(); return packageDescriptor; }