@Override
  public IPath getModuleDeployDirectory(IModule module) {
    final IPath defaultPath = super.getModuleDeployDirectory(module);

    IPath updatedPath = null;

    if (defaultPath != null && defaultPath.lastSegment() != null) {
      final IProject project = module.getProject();
      final String requiredSuffix = ProjectUtil.getRequiredSuffix(project);

      if (requiredSuffix != null && !defaultPath.lastSegment().endsWith(requiredSuffix)) {
        String lastSegment = defaultPath.lastSegment();
        updatedPath = defaultPath.removeLastSegments(1).append(lastSegment + requiredSuffix);
      }
    }

    return updatedPath == null ? defaultPath : updatedPath;
  }
  public IStatus moveContextToAutoDeployDir(
      IModule module,
      IPath deployDir,
      IPath baseDir,
      IPath autoDeployDir,
      boolean noPath,
      boolean serverStopped) {
    IPath confDir = baseDir.append("conf"); // $NON-NLS-1$
    IPath serverXml = confDir.append("server.xml"); // $NON-NLS-1$

    try {
      Factory factory = new Factory();
      factory.setPackageName(
          "org.eclipse.jst.server.tomcat.core.internal.xml.server40"); //$NON-NLS-1$
      Server publishedServer =
          (Server) factory.loadDocument(new FileInputStream(serverXml.toFile()));
      ServerInstance publishedInstance = new ServerInstance(publishedServer, null, null);

      IPath contextPath = null;

      if (autoDeployDir.isAbsolute()) {
        contextPath = autoDeployDir;
      } else {
        contextPath = baseDir.append(autoDeployDir);
      }

      File contextDir = contextPath.toFile();

      if (!contextDir.exists()) {
        contextDir.mkdirs();
      }

      Context context = publishedInstance.createContext(-1);
      context.setReloadable("true"); // $NON-NLS-1$

      final String moduleName = module.getName();
      final String requiredSuffix = ProjectUtil.getRequiredSuffix(module.getProject());

      String contextName = moduleName;

      if (!moduleName.endsWith(requiredSuffix)) {
        contextName = moduleName + requiredSuffix;
      }

      context.setSource("org.eclipse.jst.jee.server:" + contextName); // $NON-NLS-1$

      if (Boolean.valueOf(context.getAttributeValue("antiResourceLocking"))
          .booleanValue()) //$NON-NLS-1$
      {
        context.setAttributeValue("antiResourceLocking", "false"); // $NON-NLS-1$ //$NON-NLS-2$
      }

      File contextFile = new File(contextDir, contextName + ".xml"); // $NON-NLS-1$

      if (!LiferayTomcatUtil.isExtProjectContext(context)) {
        // If requested, remove path attribute
        if (noPath) {
          context.removeAttribute("path"); // $NON-NLS-1$
        }

        // need to fix the doc base to contain entire path to help autoDeployer for Liferay
        context.setDocBase(deployDir.toOSString());
        // context.setAttributeValue("antiJARLocking", "true");

        // check to see if we need to move from conf folder
        // IPath existingContextPath =
        // confDir.append("Catalina/localhost").append(contextFile.getName());
        // if (existingContextPath.toFile().exists()) {
        // existingContextPath.toFile().delete();
        // }

        DocumentBuilder builder = XMLUtil.getDocumentBuilder();
        Document contextDoc = builder.newDocument();
        contextDoc.appendChild(contextDoc.importNode(context.getElementNode(), true));
        XMLUtil.save(contextFile.getAbsolutePath(), contextDoc);
      }
    } catch (Exception e) {
      // Trace.trace(Trace.SEVERE,
      // "Could not modify context configurations to serve directly for Tomcat configuration " +
      // confDir.toOSString() + ": " + e.getMessage());
      return new Status(
          IStatus.ERROR,
          TomcatPlugin.PLUGIN_ID,
          0,
          NLS.bind(Messages.errorPublishConfiguration, new String[] {e.getLocalizedMessage()}),
          e);
    } finally {
      // monitor.done();
    }

    return Status.OK_STATUS;
  }