Пример #1
0
  public void testNoCompression() throws Exception {
    project.executeTarget("no-compression");

    File deb = new File("target/test-classes/test.deb");
    assertTrue("package not build", deb.exists());

    boolean found = false;

    ArArchiveInputStream in = new ArArchiveInputStream(new FileInputStream(deb));
    ArArchiveEntry entry;
    while ((entry = in.getNextArEntry()) != null) {
      if (entry.getName().equals("data.tar")) {
        found = true;

        TarInputStream tar = new TarInputStream(new NonClosingInputStream(in));
        while ((tar.getNextEntry()) != null) ;
        tar.close();
      } else {
        // skip to the next entry
        long skip = entry.getLength();
        while (skip > 0) {
          long skipped = in.skip(skip);
          if (skipped == -1) {
            throw new IOException("Failed to skip");
          }
          skip -= skipped;
        }
      }
    }
    in.close();

    assertTrue("tar file not found", found);
  }
Пример #2
0
  public static List<File> unDeb(final File inputDeb, final File outputDir)
      throws IOException, ArchiveException {
    final List<File> unpackedFiles = new ArrayList<File>();
    if (OMWPP.DEBUG) {
      Log.i("OMWPPdeb", String.format("Unzipping deb file %s.", inputDeb.getAbsoluteFile()));
    }

    final InputStream is = new FileInputStream(inputDeb);
    final ArArchiveInputStream debInputStream =
        (ArArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("ar", is);
    ArArchiveEntry entry = null;
    while ((entry = (ArArchiveEntry) debInputStream.getNextEntry()) != null) {
      if (OMWPP.DEBUG) Log.i("OMWPPdeb", "Read entry: " + entry.getName());
      if (entry.getName().toLowerCase().endsWith(".png")
          || entry.getName().toLowerCase().endsWith(".jpg")) {
        if (OMWPP.DEBUG) Log.i("OMWPPdeb", "Is background, extracting.");
        final File outputFile = new File(outputDir, entry.getName());
        final OutputStream outputFileStream = new FileOutputStream(outputFile);
        IOUtils.copy(debInputStream, outputFileStream);
        outputFileStream.close();
        unpackedFiles.add(outputFile);

      } else if (entry.getName().toLowerCase().endsWith(".gz")) {
        // RECURSIVE CALL
        final File outputFile = new File(outputDir, entry.getName());
        final OutputStream outputFileStream = new FileOutputStream(outputFile);
        IOUtils.copy(debInputStream, outputFileStream);
        outputFileStream.close();
        gunzip(outputFile, SDROOT);
        outputFile.delete();
      } else if (entry.getName().toLowerCase().endsWith(".tar")) {
        // RECURSIVE CALL
        final File outputFile = new File(outputDir, entry.getName());
        final OutputStream outputFileStream = new FileOutputStream(outputFile);
        IOUtils.copy(debInputStream, outputFileStream);
        outputFileStream.close();
        gunzip(outputFile, SDROOT);
      } else {
        if (OMWPP.DEBUG) Log.i("OMWPPdeb", "Is not background, skipping.");
      }
    }
    debInputStream.close();
    return unpackedFiles;
  }
Пример #3
0
  public void testTarFileSet() throws Exception {
    project.executeTarget("tarfileset");

    File deb = new File("target/test-classes/test.deb");
    assertTrue("package not build", deb.exists());

    ArArchiveInputStream in = new ArArchiveInputStream(new FileInputStream(deb));
    ArArchiveEntry entry;
    while ((entry = in.getNextArEntry()) != null) {
      if (entry.getName().equals("data.tar.gz")) {
        TarInputStream tar = new TarInputStream(new GZIPInputStream(new NonClosingInputStream(in)));
        TarEntry tarentry;
        while ((tarentry = tar.getNextEntry()) != null) {
          assertTrue("prefix", tarentry.getName().startsWith("./foo/"));
          if (tarentry.isDirectory()) {
            assertEquals("directory mode (" + tarentry.getName() + ")", 040700, tarentry.getMode());
          } else {
            assertEquals("file mode (" + tarentry.getName() + ")", 0100600, tarentry.getMode());
          }
          assertEquals("user", "ebourg", tarentry.getUserName());
          assertEquals("group", "ebourg", tarentry.getGroupName());
        }
        tar.close();
      } else {
        // skip to the next entry
        long skip = entry.getLength();
        while (skip > 0) {
          long skipped = in.skip(skip);
          if (skipped == -1) {
            throw new IOException("Failed to skip");
          }
          skip -= skipped;
        }
      }
    }
    in.close();
  }
Пример #4
0
 public void execute() {
   if (repoDir == null) {
     log("repoDir attribute is empty !", LogLevel.ERR.getLevel());
     throw new RuntimeException("Bad attributes for apt-repo task");
   }
   log("repo dir: " + repoDir);
   File repoFolder = new File(repoDir);
   if (!repoFolder.exists()) {
     repoFolder.mkdirs();
   }
   File[] files =
       repoFolder.listFiles(
           new FileFilter() {
             public boolean accept(File pathname) {
               if (pathname.getName().endsWith(FILE_DEB_EXT)) {
                 return true;
               }
               return false;
             }
           });
   Packages packages = new Packages();
   for (int i = 0; i < files.length; i++) {
     File file = files[i];
     PackageEntry packageEntry = new PackageEntry();
     packageEntry.setSize(file.length());
     packageEntry.setSha1(Utils.getDigest("SHA-1", file));
     packageEntry.setSha256(Utils.getDigest("SHA-256", file));
     packageEntry.setMd5sum(Utils.getDigest("MD5", file));
     String fileName = file.getName();
     packageEntry.setFilename(fileName);
     log("found deb: " + fileName);
     try {
       ArchiveInputStream control_tgz;
       ArArchiveEntry entry;
       TarArchiveEntry control_entry;
       ArchiveInputStream debStream =
           new ArchiveStreamFactory().createArchiveInputStream("ar", new FileInputStream(file));
       while ((entry = (ArArchiveEntry) debStream.getNextEntry()) != null) {
         if (entry.getName().equals("control.tar.gz")) {
           ControlHandler controlHandler = new ControlHandler();
           GZIPInputStream gzipInputStream = new GZIPInputStream(debStream);
           control_tgz =
               new ArchiveStreamFactory().createArchiveInputStream("tar", gzipInputStream);
           while ((control_entry = (TarArchiveEntry) control_tgz.getNextEntry()) != null) {
             log("control entry: " + control_entry.getName(), LogLevel.DEBUG.getLevel());
             if (control_entry.getName().trim().equals(CONTROL_FILE_NAME)) {
               ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
               IOUtils.copy(control_tgz, outputStream);
               String content_string = outputStream.toString("UTF-8");
               outputStream.close();
               controlHandler.setControlContent(content_string);
               log("control cont: " + outputStream.toString("utf-8"), LogLevel.DEBUG.getLevel());
               break;
             }
           }
           control_tgz.close();
           if (controlHandler.hasControlContent()) {
             controlHandler.handle(packageEntry);
           } else {
             throw new RuntimeException("no control content found for: " + file.getName());
           }
           break;
         }
       }
       debStream.close();
       packages.addPackageEntry(packageEntry);
     } catch (Exception e) {
       String msg = FAILED_TO_CREATE_APT_REPO + " " + file.getName();
       log(msg, e, LogLevel.ERR.getLevel());
       throw new RuntimeException(msg, e);
     }
   }
   try {
     File packagesFile = new File(repoDir, PACKAGES_GZ);
     packagesWriter =
         new BufferedWriter(
             new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(packagesFile))));
     packagesWriter.write(packages.toString());
     DefaultHashes hashes = Utils.getDefaultDigests(packagesFile);
     ReleaseInfo pinfo = new ReleaseInfo(PACKAGES_GZ, packagesFile.length(), hashes);
     Release release = new Release();
     release.addInfo(pinfo);
     final File releaseFile = new File(repoDir, RELEASE);
     FileUtils.fileWrite(releaseFile, release.toString());
   } catch (IOException e) {
     throw new RuntimeException("writing files failed", e);
   } finally {
     if (packagesWriter != null) {
       try {
         packagesWriter.close();
       } catch (IOException e) {
         throw new RuntimeException("writing files failed", e);
       }
     }
   }
 }