Ejemplo n.º 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);
      }
    }
  }
  @Override
  public void processResourceDeltas(
      final IModuleResourceDelta[] deltas,
      ZipOutputStream zip,
      Map<ZipEntry, String> deleteEntries,
      final String deletePrefix,
      final String deltaPrefix,
      final boolean adjustGMTOffset)
      throws IOException, CoreException {
    for (final IModuleResourceDelta delta : deltas) {
      final int deltaKind = delta.getKind();
      final IResource deltaResource =
          (IResource) delta.getModuleResource().getAdapter(IResource.class);
      final IProject deltaProject = deltaResource.getProject();
      final ILiferayProject lrproject = LiferayCore.create(deltaProject);
      final IFolder webappRoot = lrproject.getDefaultDocrootFolder();
      final IPath deltaFullPath = deltaResource.getFullPath();

      boolean deltaZip = false;
      IPath deltaPath = null;

      if (webappRoot != null && webappRoot.exists()) {
        final IPath containerFullPath = webappRoot.getFullPath();

        if (containerFullPath.isPrefixOf(deltaFullPath)) {
          deltaZip = true;
          deltaPath = new Path(deltaPrefix + deltaFullPath.makeRelativeTo(containerFullPath));
        }
      }

      if (deltaZip == false && new Path("WEB-INF").isPrefixOf(delta.getModuleRelativePath())) {
        final List<IFolder> folders = CoreUtil.getSourceFolders(JavaCore.create(deltaProject));

        for (IFolder folder : folders) {
          final IPath folderPath = folder.getFullPath();

          if (folderPath.isPrefixOf(deltaFullPath)) {
            deltaZip = true;
            break;
          }
        }
      }

      if (deltaZip == false
          && (deltaKind == IModuleResourceDelta.ADDED
              || deltaKind == IModuleResourceDelta.CHANGED
              || deltaKind == IModuleResourceDelta.REMOVED)) {
        final IPath targetPath = JavaCore.create(deltaProject).getOutputLocation();

        deltaZip = true;
        deltaPath = new Path("WEB-INF/classes").append(deltaFullPath.makeRelativeTo(targetPath));
      }

      if (deltaZip) {
        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) {
          final IModuleResourceDelta[] children = delta.getAffectedChildren();
          processResourceDeltas(
              children, zip, deleteEntries, deletePrefix, deltaPrefix, adjustGMTOffset);
        }
      }
    }
  }