@Override
  protected Object run(Presentation context) {
    final NewModuleFragmentOp op =
        context.part().getModelElement().nearest(NewModuleFragmentOp.class);

    final ElementList<OverrideFilePath> currentFiles = op.getOverrideFiles();

    final String projectName = op.getProjectName().content();

    final OSGiBundleFileSelectionDialog dialog =
        new OSGiBundleFileSelectionDialog(null, currentFiles, projectName);

    final String runtimeName = op.getLiferayRuntimeName().content();

    final IRuntime runtime = ServerUtil.getRuntime(runtimeName);

    final IPath temp = GradleCore.getDefault().getStateLocation();

    dialog.setTitle("Add files from OSGi bundle to override");

    final PortalBundle portalBundle = LiferayServerCore.newPortalBundle(runtime.getLocation());
    String currentOSGiBundle = op.getHostOsgiBundle().content();

    if (!currentOSGiBundle.endsWith("jar")) {
      currentOSGiBundle = currentOSGiBundle + ".jar";
    }

    ServerUtil.getModuleFileFrom70Server(runtime, currentOSGiBundle, temp);

    if (portalBundle != null) {
      try {
        File module =
            portalBundle.getOSGiBundlesDir().append("modules").append(currentOSGiBundle).toFile();

        if (!module.exists()) {
          module = GradleCore.getDefault().getStateLocation().append(currentOSGiBundle).toFile();
        }

        dialog.setInput(module);
      } catch (Exception e) {
      }
    }

    if (dialog.open() == Window.OK) {
      Object[] selected = dialog.getResult();

      for (int i = 0; i < selected.length; i++) {
        OverrideFilePath file = op.getOverrideFiles().insert();
        file.setValue(selected[i].toString());
      }
    }

    return Status.createOkStatus();
  }
  protected void createInfoGroup(Composite parent) {
    new Label(parent, SWT.LEFT).setText(Msgs.liferayPluginTypeLabel);

    final Text pluginTypeLabel = new Text(parent, SWT.READ_ONLY | SWT.BORDER);
    pluginTypeLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

    final IProjectFacet liferayFacet = ProjectUtil.getLiferayFacet(getFacetedProject());

    if (liferayFacet != null) {
      pluginTypeLabel.setText(liferayFacet.getLabel());
    }

    new Label(parent, SWT.LEFT).setText(Msgs.liferayRuntimeLabel);

    this.runtimeCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
    this.runtimeCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

    String currentRuntimeName = null;

    try {
      ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(getProject());

      currentRuntimeName = liferayRuntime.getRuntime().getName();
    } catch (Exception e) {
      ProjectUIPlugin.logError("Could not determine liferay runtime", e); // $NON-NLS-1$
    }

    final List<String> runtimeNames = new ArrayList<String>();
    int selectionIndex = -1;

    for (IRuntime runtime : ServerCore.getRuntimes()) {
      if (ServerUtil.isLiferayRuntime(runtime)) {
        runtimeNames.add(runtime.getName());

        if (runtime.getName().equals(currentRuntimeName)) {
          selectionIndex = runtimeNames.size() - 1;
        }
      }
    }

    if (runtimeNames.size() == 0) {
      runtimeNames.add("No Liferay runtimes available."); // $NON-NLS-1$
    }

    this.runtimeCombo.setItems(runtimeNames.toArray(new String[0]));

    if (selectionIndex > -1) {
      this.runtimeCombo.select(selectionIndex);
    }
  }
  @Override
  public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
    IClasspathContainer classpathContainer = null;

    String root = containerPath.segment(0);

    if (!SDKClasspathContainer.ID.equals(root)) {
      final String msg =
          "Invalid plugin classpath container, expecting container root "; //$NON-NLS-1$
      throw new CoreException(ProjectCore.createErrorStatus(msg + SDKClasspathContainer.ID));
    }

    PortalBundle bundle = ServerUtil.getPortalBundle(project.getProject());

    if (bundle == null) {
      final String msg = "Invalid sdk properties setting.";
      throw new CoreException(ProjectCore.createErrorStatus(msg));
    }

    IPath globalDir = bundle.getAppServerLibGlobalDir();

    IPath portalDir = bundle.getAppServerPortalDir();

    IPath bundleDir = bundle.getAppServerDir();

    IPath[] bundleDependencyLibDir = bundle.getBundleDependencyJars();

    if (portalDir == null) {
      return;
    }

    classpathContainer =
        new SDKClasspathContainer(
            containerPath,
            project,
            portalDir,
            null,
            null,
            globalDir,
            bundleDir,
            bundleDependencyLibDir);

    JavaCore.setClasspathContainer(
        containerPath,
        new IJavaProject[] {project},
        new IClasspathContainer[] {classpathContainer},
        null);
  }
Beispiel #4
0
  public ILiferayProject provide(Object type) {
    final IProject project = (IProject) type;

    ILiferayRuntime liferayRuntime = null;

    try {
      liferayRuntime = ServerUtil.getLiferayRuntime(project);
    } catch (CoreException e) {
    }

    if (liferayRuntime != null) {
      return new LiferayRuntimeProject(project, liferayRuntime);
    }

    return null;
  }
  @Override
  protected IStatus doAddNewPortlet(IDOMDocument document, IDataModel model) {
    IStatus status = Status.OK_STATUS;

    status = super.doAddNewPortlet(document, model);

    if (!status.isOK()) {
      return status;
    }

    final Version runtimeVersion = ServerUtil.getRuntimeVersion(project);

    // Runtime version should be equal or greater than 6.2.
    if (CoreUtil.compareVersions(runtimeVersion, ILiferayConstants.V620) >= 0) {
      final IFile descriptorFile = getDescriptorFile();

      if (descriptorFile != null) {
        DOMModelOperation op =
            new DOMModelEditOperation(descriptorFile) {

              @Override
              protected void createDefaultFile() {
                // Getting document from super( descriptorFile );
              }

              @Override
              protected IStatus doExecute(IDOMDocument document) {
                return updateVaadinLiferayPortletXMLTo62(document);
              }
            };

        return op.execute();
      }
    }

    return status;
  }
  /** @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);
  }
  public IPath publishModuleFull(IProgressMonitor monitor) throws CoreException {
    final IPath deployPath =
        LiferayServerCore.getTempLocation("direct-deploy", StringPool.EMPTY); // $NON-NLS-1$
    File warFile = deployPath.append(getProject().getName() + ".war").toFile(); // $NON-NLS-1$
    warFile.getParentFile().mkdirs();

    final Map<String, String> properties = new HashMap<String, String>();
    properties.put(ISDKConstants.PROPERTY_AUTO_DEPLOY_UNPACK_WAR, "false"); // $NON-NLS-1$

    final ILiferayRuntime runtime = ServerUtil.getLiferayRuntime(getProject());

    final String appServerDeployDirProp =
        ServerUtil.getAppServerPropertyKey(ISDKConstants.PROPERTY_APP_SERVER_DEPLOY_DIR, runtime);

    properties.put(appServerDeployDirProp, deployPath.toOSString());

    // IDE-1073 LPS-37923
    properties.put(ISDKConstants.PROPERTY_PLUGIN_FILE_DEFAULT, warFile.getAbsolutePath());

    properties.put(ISDKConstants.PROPERTY_PLUGIN_FILE, warFile.getAbsolutePath());

    final String fileTimeStamp = System.currentTimeMillis() + "";

    // IDE-1491
    properties.put(ISDKConstants.PROPERTY_LP_VERSION, fileTimeStamp);

    properties.put(ISDKConstants.PROPERTY_LP_VERSION_SUFFIX, ".0");

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

    final IStatus directDeployStatus =
        sdk.war(
            getProject(),
            properties,
            true,
            appServerProperties,
            new String[] {"-Duser.timezone=GMT"},
            monitor);

    if (!directDeployStatus.isOK() || (!warFile.exists())) {
      String pluginVersion = "1";

      final IPath pluginPropertiesPath = new Path("WEB-INF/liferay-plugin-package.properties");
      final IFile propertiesFile =
          CoreUtil.getDocrootFile(getProject(), pluginPropertiesPath.toOSString());

      if (propertiesFile != null) {
        try {
          if (propertiesFile.exists()) {
            final PropertiesConfiguration pluginPackageProperties = new PropertiesConfiguration();
            final InputStream is = propertiesFile.getContents();
            pluginPackageProperties.load(is);
            pluginVersion = pluginPackageProperties.getString("module-incremental-version");
            is.close();
          }
        } catch (Exception e) {
          LiferayCore.logError("error reading module-incremtnal-version. ", e);
        }
      }

      warFile =
          sdk.getLocation()
              .append("dist")
              .append(
                  getProject().getName()
                      + "-"
                      + fileTimeStamp
                      + "."
                      + pluginVersion
                      + ".0"
                      + ".war")
              .toFile();

      if (!warFile.exists()) {
        throw new CoreException(directDeployStatus);
      }
    }

    return new Path(warFile.getAbsolutePath());
  }
 @Override
 public Properties getPortletEntryCategories() {
   return ServerUtil.getEntryCategories(getAppServerPortalDir(), getVersion());
 }
 @Override
 public Properties getPortletCategories() {
   return ServerUtil.getPortletCategories(getAppServerPortalDir());
 }
  @Override
  public void requestClasspathContainerUpdate(
      IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion)
      throws CoreException {

    final String key =
        SDKClasspathContainer.getDecorationManagerKey(
            project.getProject(), containerPath.toString());

    final IClasspathEntry[] entries = containerSuggestion.getClasspathEntries();

    cpDecorations.clearAllDecorations(key);

    for (int i = 0; i < entries.length; i++) {
      final IClasspathEntry entry = entries[i];

      final IPath srcpath = entry.getSourceAttachmentPath();
      final IPath srcrootpath = entry.getSourceAttachmentRootPath();
      final IClasspathAttribute[] attrs = entry.getExtraAttributes();

      if (srcpath != null || attrs.length > 0) {
        final String eid = entry.getPath().toString();
        final ClasspathDecorations dec = new ClasspathDecorations();

        dec.setSourceAttachmentPath(srcpath);
        dec.setSourceAttachmentRootPath(srcrootpath);
        dec.setExtraAttributes(attrs);

        cpDecorations.setDecorations(key, eid, dec);
      }
    }

    cpDecorations.save();

    IPath portalDir = null;
    IPath portalGlobalDir = null;
    String javadocURL = null;
    IPath sourceLocation = null;
    IPath bundleDir = null;
    IPath[] bundleLibDependencyPath = null;

    if (containerSuggestion instanceof SDKClasspathContainer) {
      portalDir = ((SDKClasspathContainer) containerSuggestion).getPortalDir();
      bundleDir = ((SDKClasspathContainer) containerSuggestion).getBundleDir();
      portalGlobalDir = ((SDKClasspathContainer) containerSuggestion).getPortalGlobalDir();
      javadocURL = ((SDKClasspathContainer) containerSuggestion).getJavadocURL();
      sourceLocation = ((SDKClasspathContainer) containerSuggestion).getSourceLocation();
      bundleLibDependencyPath =
          ((SDKClasspathContainer) containerSuggestion).getBundleLibDependencyPath();
    } else {
      PortalBundle bundle = ServerUtil.getPortalBundle(project.getProject());

      if (bundle == null) {
        final String msg = "Invalid sdk properties setting.";
        throw new CoreException(ProjectCore.createErrorStatus(msg));
      }

      portalDir = bundle.getAppServerPortalDir();
      portalGlobalDir = bundle.getAppServerLibGlobalDir();
      bundleLibDependencyPath = bundle.getBundleDependencyJars();
    }

    if (portalDir != null && portalGlobalDir != null) {
      IClasspathContainer newContainer =
          new SDKClasspathContainer(
              containerPath,
              project,
              portalDir,
              javadocURL,
              sourceLocation,
              portalGlobalDir,
              bundleDir,
              bundleLibDependencyPath);

      JavaCore.setClasspathContainer(
          containerPath,
          new IJavaProject[] {project},
          new IClasspathContainer[] {newContainer},
          null);
    }
  }
  @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;
  }