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;
  }
예제 #2
0
  @Override
  protected IStatus run(IProgressMonitor monitor) {
    IStatus retval = Status.OK_STATUS;

    if (monitor != null) {
      monitor.beginTask(Msgs.runningCleanAppServerTask, IProgressMonitor.UNKNOWN);
    }

    try {
      IRuntime runtime = ServerUtil.getRuntime(project);
      IServer[] servers = ServerUtil.getServersForRuntime(runtime);

      for (IServer server : servers) {
        String mode = server.getServerState() == IServer.STATE_STARTED ? server.getMode() : null;

        if (mode != null) {
          LiferayTomcatUtil.syncStopServer(server);
        }
      }

      ILiferayTomcatRuntime portalTomcatRuntime =
          LiferayTomcatUtil.getLiferayTomcatRuntime(runtime);
      IPath bundleZipLocation = portalTomcatRuntime.getBundleZipLocation();

      Map<String, String> appServerProperties = ServerUtil.configureAppServerProperties(project);

      String appServerDir =
          ServerUtil.getAppServerPropertyKey(
              ISDKConstants.PROPERTY_APP_SERVER_DIR, portalTomcatRuntime);

      IStatus status =
          getSDK()
              .cleanAppServer(
                  project, bundleZipLocation, appServerDir, appServerProperties, monitor);

      assertStatus(status);

      for (IServer server : servers) {
        // need to mark all other server modules at needing republishing since ext will wipe out
        // webapps folder
        IModule[] modules = server.getModules();

        for (IModule mod : modules) {
          IModule[] m = new IModule[] {mod};

          ((LiferayTomcatServerBehavior)
                  server.loadAdapter(LiferayTomcatServerBehavior.class, monitor))
              .setModulePublishState2(m, IServer.PUBLISH_STATE_FULL);
        }
      }

    } catch (Exception ex) {
      retval = LiferayTomcatPlugin.createErrorStatus(ex);
    }

    if (monitor != null) {
      monitor.done();
    }

    return retval;
  }