Пример #1
0
  private static void processResourceDeltasZip(
      IModuleResourceDelta[] deltas,
      ZipOutputStream zip,
      Map<ZipEntry, String> deleteEntries,
      String deletePrefix,
      String deltaPrefix,
      boolean adjustGMTOffset)
      throws IOException, CoreException {

    for (IModuleResourceDelta delta : deltas) {
      int deltaKind = delta.getKind();

      IResource deltaResource = (IResource) delta.getModuleResource().getAdapter(IResource.class);

      IProject deltaProject = deltaResource.getProject();

      IFolder docroot = CoreUtil.getDocroot(deltaProject);

      IPath deltaPath =
          new Path(deltaPrefix + deltaResource.getFullPath().makeRelativeTo(docroot.getFullPath()));

      if (deltaKind == IModuleResourceDelta.ADDED || deltaKind == IModuleResourceDelta.CHANGED) {
        addToZip(deltaPath, deltaResource, zip, adjustGMTOffset);
      } else if (deltaKind == IModuleResourceDelta.REMOVED) {
        addRemoveProps(deltaPath, deltaResource, zip, deleteEntries, deletePrefix);
      } else if (deltaKind == IModuleResourceDelta.NO_CHANGE) {
        IModuleResourceDelta[] children = delta.getAffectedChildren();
        processResourceDeltasZip(
            children, zip, deleteEntries, deletePrefix, deltaPrefix, adjustGMTOffset);
      }
    }
  }
Пример #2
0
  public static File createPartialEAR(
      String archiveName,
      IModuleResourceDelta[] deltas,
      String deletePrefix,
      String deltaPrefix,
      boolean adjustGMTOffset) {
    IPath path = LiferayServerCorePlugin.getTempLocation("partial-ear", archiveName);

    FileOutputStream outputStream = null;
    ZipOutputStream zip = null;
    File file = path.toFile();

    file.getParentFile().mkdirs();

    try {
      outputStream = new FileOutputStream(file);
      zip = new ZipOutputStream(outputStream);

      Map<ZipEntry, String> deleteEntries = new HashMap<ZipEntry, String>();

      processResourceDeltasZip(
          deltas, zip, deleteEntries, deletePrefix, deltaPrefix, adjustGMTOffset);

      for (ZipEntry entry : deleteEntries.keySet()) {
        zip.putNextEntry(entry);
        zip.write(deleteEntries.get(entry).getBytes());
      }

      // if ((removedResources != null) && (removedResources.size() > 0)) {
      // writeRemovedResources(removedResources, zip);
      // }
    } catch (Exception ex) {
      ex.printStackTrace();
    } finally {
      if (zip != null) {
        try {
          zip.close();
        } catch (IOException localIOException1) {

        }
      }
    }

    return file;
  }