コード例 #1
0
  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);
  }
コード例 #2
0
  /** @see PublishOperation#execute(IProgressMonitor, IAdaptable) */
  public void execute(IProgressMonitor monitor, IAdaptable info) throws CoreException {
    List status = new ArrayList();

    // If parent web module
    if (module.length == 1) {
      if (!ServerUtil.isExtProject(module[0].getProject())) {
        publishDir(module[0], status, monitor);
      }
    }
    // Else a child module
    else {
      Properties p = server.loadModulePublishLocations();

      // Try to determine the URI for the child module
      IWebModule webModule = (IWebModule) module[0].loadAdapter(IWebModule.class, monitor);
      String childURI = null;
      if (webModule != null) {
        childURI = webModule.getURI(module[1]);
      }
      // Try to determine if child is binary
      IJ2EEModule childModule = (IJ2EEModule) module[1].loadAdapter(IJ2EEModule.class, monitor);
      boolean isBinary = false;
      if (childModule != null) {
        isBinary = childModule.isBinary();
      }

      if (isBinary) {
        publishArchiveModule(childURI, p, status, monitor);
      } else {
        publishJar(childURI, p, status, monitor);
      }
      server.saveModulePublishLocations(p);
    }
    throwException(status);
    server.setModulePublishState2(module, IServer.PUBLISH_STATE_NONE);
  }
コード例 #3
0
 /**
  * Construct the operation object to publish the specified module to the specified server.
  *
  * @param server server to which the module will be published
  * @param kind kind of publish
  * @param module module to publish
  * @param deltaKind kind of change
  */
 public LiferayPublishOperation(
     LiferayTomcatServerBehavior server, int kind, IModule[] module, int deltaKind) {
   super(Msgs.publishServer, Msgs.publishWebModule);
   this.server = server;
   this.module = module;
   this.kind = kind;
   this.deltaKind = deltaKind;
   IPath base = server.getRuntimeBaseDirectory();
   if (base != null) {
     helper = new PublishHelper(base.append("temp").toFile()); // $NON-NLS-1$
   } else {
     // We are doomed without a base directory.  However, allow the catastrophe
     // to occur elsewhere and hope for a useful error message.
     helper = new PublishHelper(null);
   }
 }
コード例 #4
0
  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;
      }
    }
  }