private void configureRuntimeCombo() throws CoreException {
    if (Widgets.isDisposed(runtimeComboViewer)) {
      return;
    }

    String lastUsedRuntime = lastSelectedRuntime;
    List<String> runtimesList = new ArrayList<String>();
    String selectedRuntime = null;

    serverRuntimes = getServerRuntimes(null);
    runtimeComboViewer.setInput(ArrayContentProvider.getInstance());
    runtimesList.addAll(serverRuntimes.keySet());
    runtimesList.add(Messages.newProjectWizardRuntimePageNoRuntimeSelectedLabel);
    runtimeComboViewer.setInput(runtimesList);
    runtimeComboViewer.setSelection(
        new StructuredSelection(Messages.newProjectWizardRuntimePageNoRuntimeSelectedLabel));

    for (Map.Entry<String, IRuntime> entry : serverRuntimes.entrySet()) {
      IRuntime runtime = entry.getValue();
      if (lastUsedRuntime != null && lastUsedRuntime.equals(runtime.getId())) {
        selectedRuntime = lastUsedRuntime;
      }
    }

    if (selectedRuntime != null) {
      runtimeComboViewer.setSelection(new StructuredSelection(selectedRuntime));
    }
  }
예제 #2
0
  public static Object getRuntimeAdapter(
      org.eclipse.wst.common.project.facet.core.runtime.IRuntime facetRuntime,
      Class<?> adapterClass) {

    String runtimeId = facetRuntime.getProperty("id");

    for (org.eclipse.wst.server.core.IRuntime runtime : ServerCore.getRuntimes()) {
      if (runtime.getId().equals(runtimeId)) {

        if (IRuntime.class.equals(adapterClass)) {
          return runtime;
        }

        IRuntimeWorkingCopy runtimeWC = null;

        if (!runtime.isWorkingCopy()) {
          runtimeWC = runtime.createWorkingCopy();
        } else {
          runtimeWC = (IRuntimeWorkingCopy) runtime;
        }

        return (ILiferayRuntime) runtimeWC.loadAdapter(adapterClass, null);
      }
    }

    return null;
  }
예제 #3
0
 /**
  * @deprecated
  * @param folder
  * @param runtime
  * @param ignoreError
  * @return
  */
 public static String getFolder(String folder, IRuntime runtime, boolean ignoreError) {
   String tmp =
       new ConfigNameResolver()
           .performSubstitutions(folder, runtime == null ? null : runtime.getName(), ignoreError);
   IPath p = new Path(tmp);
   if (!p.isAbsolute() && runtime != null) {
     p = runtime.getLocation().append(p);
   }
   return p.toString();
 }
  @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);
    }
  }
예제 #6
0
  public static ILiferayRuntime getLiferayRuntime(IRuntime runtime) {
    if (runtime != null) {
      return (ILiferayRuntime) runtime.createWorkingCopy().loadAdapter(ILiferayRuntime.class, null);
    }

    return null;
  }
예제 #7
0
  public static IRuntimeWorkingCopy getRuntime(String runtimeTypeId, IPath location) {
    IRuntimeType runtimeType = ServerCore.findRuntimeType(runtimeTypeId);

    try {
      IRuntime runtime = runtimeType.createRuntime("runtime", null);

      IRuntimeWorkingCopy runtimeWC = runtime.createWorkingCopy();
      runtimeWC.setName("Runtime");
      runtimeWC.setLocation(location);

      return runtimeWC;
    } catch (CoreException e) {
      e.printStackTrace();
    }

    return null;
  }
  public static String getDeployDirectory(IServer server) {
    IDeployableServer deployableServer = ServerConverter.getDeployableServer(server);
    if (server != null && deployableServer != null) {
      return deployableServer.getDeployFolder();
    }
    String ret =
        server.getAttribute(IDeployableServer.DEPLOY_DIRECTORY, (String) null); // $NON-NLS-1$
    if (ret != null) return ret.trim();

    // Other runtimes like tomcat / default behavior (?)
    IRuntime rt = server.getRuntime();
    if (rt != null) {
      return rt.getLocation().toString();
    }

    return null; // No idea
  }
예제 #9
0
  public static IServerWorkingCopy createServerForRuntime(IRuntime runtime) {
    for (IServerType serverType : ServerCore.getServerTypes()) {
      if (serverType.getRuntimeType().equals(runtime.getRuntimeType())) {
        try {
          return serverType.createServer("server", null, runtime, null);
        } catch (CoreException e) {
        }
      }
    }

    return null;
  }
예제 #10
0
  public static IServer[] getServersForRuntime(IRuntime runtime) {
    List<IServer> serverList = new ArrayList<IServer>();

    if (runtime != null) {
      IServer[] servers = ServerCore.getServers();

      if (!CoreUtil.isNullOrEmpty(servers)) {
        for (IServer server : servers) {
          if (runtime.equals(server.getRuntime())) {
            serverList.add(server);
          }
        }
      }
    }

    return serverList.toArray(new IServer[0]);
  }
예제 #11
0
  @Override
  public String[] getClasspathAdditions(TestServerConfiguration config) {
    List<String> entries = new ArrayList<String>(2);
    String entry =
        ClasspathUtil.getClasspathEntry("org.eclipse.edt.ide.deployment.core"); // $NON-NLS-1$
    if (entry != null) {
      entries.add(entry);
    }

    entry =
        ClasspathUtil.getClasspathEntry("org.eclipse.edt.ide.deployment.services"); // $NON-NLS-1$
    if (entry != null) {
      entries.add(entry);
    }

    entry = ClasspathUtil.getClasspathEntry("org.eclipse.edt.runtime.java"); // $NON-NLS-1$
    if (entry != null) {
      entries.add(entry);
    }

    entry = ClasspathUtil.getClasspathEntry("com.ibm.icu"); // $NON-NLS-1$
    if (entry != null) {
      entries.add(entry);
    }

    DDUtil.addJDBCJars(
        config.getProject(), new HashSet<IProject>(), new HashSet<IResource>(), entries);

    // Add a Tomcat runtime if one's available, so that JNDI can use connection pooling.
    IRuntime bestTomcat = null;
    for (IRuntime rt : ServerUtil.getRuntimes(null, null)) {
      if (rt.getRuntimeType().getName().toLowerCase().contains("tomcat")) { // $NON-NLS-1$
        if (bestTomcat == null) {
          bestTomcat = rt;
        } else if (bestTomcat
                .getRuntimeType()
                .getVersion()
                .compareTo(rt.getRuntimeType().getVersion())
            < 0) {
          bestTomcat = rt;
        }
      }
    }

    if (bestTomcat != null) {
      RuntimeClasspathProviderWrapper rcpw =
          JavaServerPlugin.findRuntimeClasspathProvider(bestTomcat.getRuntimeType());
      if (rcpw != null) {
        entries.add(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?><runtimeClasspathEntry containerPath=\"" //$NON-NLS-1$
                + RuntimeClasspathContainer.SERVER_CONTAINER
                + "/"
                + rcpw.getId()
                + "/"
                + bestTomcat.getId() // $NON-NLS-1$ //$NON-NLS-2$
                + "\" path=\"3\" type=\"4\"/>"); //$NON-NLS-1$
      }
    }

    return entries.toArray(new String[entries.size()]);
  }