private void publishArchiveModule(
      String jarURI, Properties p, List status, IProgressMonitor monitor) {
    IPath path = server.getModuleDeployDirectory(module[0]);
    boolean moving = false;
    // Get URI used for previous publish, if known
    String oldURI = (String) p.get(module[1].getId());
    if (oldURI != null) {
      // If old URI found, detect if jar is moving or changing its name
      if (jarURI != null) {
        moving = !oldURI.equals(jarURI);
      }
    }
    // If we don't have a jar URI, make a guess so we have one if we need it
    if (jarURI == null) {
      jarURI = "WEB-INF/lib/" + module[1].getName(); // $NON-NLS-1$
    }
    IPath jarPath = path.append(jarURI);
    // Make our best determination of the path to the old jar
    IPath oldJarPath = jarPath;
    if (oldURI != null) {
      oldJarPath = path.append(oldURI);
    }
    // Establish the destination directory
    path = jarPath.removeLastSegments(1);

    // Remove if requested or if previously published and are now serving without publishing
    if (moving
        || kind == IServer.PUBLISH_CLEAN
        || deltaKind == ServerBehaviourDelegate.REMOVED
        || server.getTomcatServer().isServeModulesWithoutPublish()) {
      File file = oldJarPath.toFile();
      if (file.exists()) {
        file.delete();
      }
      p.remove(module[1].getId());

      if (deltaKind == ServerBehaviourDelegate.REMOVED
          || server.getTomcatServer().isServeModulesWithoutPublish()) return;
    }
    if (!moving && kind != IServer.PUBLISH_CLEAN && kind != IServer.PUBLISH_FULL) {
      // avoid changes if no changes to module since last publish
      IModuleResourceDelta[] delta = server.getPublishedResourceDelta(module);
      if (delta == null || delta.length == 0) return;
    }

    // make directory if it doesn't exist
    if (!path.toFile().exists()) path.toFile().mkdirs();

    IModuleResource[] mr = server.getResources(module);
    IStatus[] stat = helper.publishToPath(mr, jarPath, monitor);
    addArrayToList(status, stat);
    p.put(module[1].getId(), jarURI);
  }
  private void clearWebXmlDescriptors(IProject project, IPath path, IProgressMonitor monitor) {
    // copy over web.xml so the liferay deployer doesn't copy web.xml filters incorrectly
    IModuleResource webXmlRes = getWebXmlFile(project, path);

    if (webXmlRes != null) {
      helper.publishToPath(new IModuleResource[] {webXmlRes}, path.append(WEB_XML_PATH), monitor);
    } else {
      File webXmlFile = path.append(WEB_XML_PATH).toFile();
      File liferayWebXmlFile = path.append(LIFERAY_WEB_XML_PATH).toFile();

      if (webXmlFile.exists()) {
        if (!webXmlFile.delete()) {
          ProjectUtil.createDefaultWebXml(webXmlFile);
        }
      }

      if (liferayWebXmlFile.exists()) {
        if (!liferayWebXmlFile.delete()) {
          ProjectUtil.createDefaultWebXml(liferayWebXmlFile);
        }
      }
    }
  }
  private void publishDir(IModule module2, List status, IProgressMonitor monitor)
      throws CoreException {
    IPath path = server.getModuleDeployDirectory(module2);

    // Remove if requested or if previously published and are now serving without publishing
    if (kind == IServer.PUBLISH_CLEAN
        || deltaKind == ServerBehaviourDelegate.REMOVED
        || server.getTomcatServer().isServeModulesWithoutPublish()) {
      File f = path.toFile();
      if (f.exists()) {
        try {
          IPath baseDir = server.getRuntimeBaseDirectory();
          IPath serverXml =
              baseDir.append("conf").append("server.xml"); // $NON-NLS-1$ //$NON-NLS-2$
          ServerInstance oldInstance =
              TomcatVersionHelper.getCatalinaServerInstance(serverXml, null, null);
          IPath contextDir =
              oldInstance.getContextXmlDirectory(baseDir.append("conf")); // $NON-NLS-1$
          String contextFileName = path.lastSegment() + ".xml"; // $NON-NLS-1$
          File contextFile = contextDir.append(contextFileName).toFile();

          if (contextFile.exists()) {
            contextFile.delete();
          }

          File autoDeployDir =
              baseDir.append(server.getLiferayTomcatServer().getAutoDeployDirectory()).toFile();
          File autoDeployFile = new File(autoDeployDir, contextFileName);

          if (autoDeployFile.exists()) {
            autoDeployFile.delete();
          }
        } catch (Exception e) {
          LiferayTomcatPlugin.logError("Could not delete context xml file.", e); // $NON-NLS-1$
        }

        IStatus[] stat = PublishHelper.deleteDirectory(f, monitor);
        addArrayToList(status, stat);
      }

      if (deltaKind == ServerBehaviourDelegate.REMOVED
          || server.getTomcatServer().isServeModulesWithoutPublish()) return;
    }

    IPath baseDir = server.getTomcatServer().getRuntimeBaseDirectory();
    IPath autoDeployDir = new Path(server.getLiferayTomcatServer().getAutoDeployDirectory());
    boolean serverStopped = server.getServer().getServerState() == IServer.STATE_STOPPED;

    if (kind == IServer.PUBLISH_CLEAN || kind == IServer.PUBLISH_FULL) {
      IModuleResource[] mr = server.getResources(module);
      IStatus[] stat = helper.publishFull(mr, path, monitor);
      addArrayToList(status, stat);

      clearWebXmlDescriptors(module2.getProject(), path, monitor);

      server.moveContextToAutoDeployDir(module2, path, baseDir, autoDeployDir, true, serverStopped);

      return;
    }

    IModuleResourceDelta[] delta = server.getPublishedResourceDelta(module);

    int size = delta.length;
    for (int i = 0; i < size; i++) {
      IStatus[] stat = helper.publishDelta(delta[i], path, monitor);
      addArrayToList(status, stat);
    }

    // check to see if we need to re-invoke the liferay plugin deployer
    String[] paths =
        new String[] {
          WEB_XML_PATH,
          "WEB-INF/portlet.xml",
          "WEB-INF/liferay-portlet.xml", //$NON-NLS-1$ //$NON-NLS-2$
          "WEB-INF/liferay-display.xml",
          "WEB-INF/liferay-look-and-feel.xml",
          "WEB-INF/liferay-hook.xml", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
          "WEB-INF/liferay-layout-templates.xml",
          "WEB-INF/liferay-plugin-package.properties", //$NON-NLS-1$//$NON-NLS-2$
          "WEB-INF/liferay-plugin-package.xml",
          "WEB-INF/server-config.wsdd",
        }; //$NON-NLS-1$ //$NON-NLS-2$

    for (IModuleResourceDelta del : delta) {
      if (CoreUtil.containsMember(del, paths) || isHookProjectDelta(del)) {
        clearWebXmlDescriptors(module2.getProject(), path, monitor);

        server.moveContextToAutoDeployDir(
            module2, path, baseDir, autoDeployDir, true, serverStopped);
        break;
      }
    }
  }