Search in sources :

Example 6 with ILiferayRuntime

use of com.liferay.ide.server.core.ILiferayRuntime in project liferay-ide by liferay.

the class LiferayProjectPropertyPage method createInfoGroup.

protected void createInfoGroup(final 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, 2, 1));
    final IProjectFacet liferayFacet = ProjectUtil.getLiferayFacet(getFacetedProject());
    if (liferayFacet != null) {
        pluginTypeLabel.setText(liferayFacet.getLabel());
    }
    final IProject proj = getProject();
    if ((proj != null) && ProjectUtil.isLiferayFacetedProject(proj)) {
        try {
            if (!ProjectUtil.isMavenProject(proj)) {
                final SDK projectSdk = SDKUtil.getSDK(getProject());
                new Label(parent, SWT.LEFT).setText(Msgs.liferaySdkLabel);
                _sdkLabel = new Text(parent, SWT.READ_ONLY | SWT.BORDER);
                if (projectSdk != null) {
                    _sdkLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
                    _sdkLabel.setText(projectSdk.getName());
                } else {
                    _sdkLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
                    _sdkLabel.setText("");
                    final Hyperlink link = new Hyperlink(parent, SWT.NULL);
                    link.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
                    link.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
                    link.setUnderlined(true);
                    link.setText(Msgs.changeliferaySdk);
                    link.addHyperlinkListener(new HyperlinkAdapter() {

                        public void linkActivated(HyperlinkEvent e) {
                            String dialogId = new String("com.liferay.ide.project.ui.dialog.SelectPluginsSDKDialog");
                            final LiferayPluginSDKOp op = (LiferayPluginSDKOp) (LiferayPluginSDKOp.TYPE.instantiate().initialize());
                            DefinitionLoader sdefLoader = DefinitionLoader.context(getClass()).sdef(dialogId);
                            final Reference<DialogDef> dialogRef = sdefLoader.dialog("ConfigureLiferaySDK");
                            final SapphireDialog dialog = new SapphireDialog(UIUtil.getActiveShell(), op, dialogRef);
                            dialog.setBlockOnOpen(true);
                            final int result = dialog.open();
                            if (result != SapphireDialog.CANCEL) {
                                _sdkLabel.setText(op.getPluginsSDKName().content());
                            }
                        }
                    });
                }
                if (CoreUtil.compareVersions(new Version(projectSdk.getVersion()), ILiferayConstants.V700) < 0) {
                    new Label(parent, SWT.LEFT).setText(Msgs.liferayRuntimeLabel);
                    _runtimeCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
                    _runtimeCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
                    String currentRuntimeName = null;
                    try {
                        ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(getProject());
                        if (liferayRuntime != null) {
                            currentRuntimeName = liferayRuntime.getRuntime().getName();
                        }
                    } catch (Exception e) {
                        ProjectUI.logError("Could not determine liferay runtime", e);
                    }
                    List<String> runtimeNames = new ArrayList<>();
                    int selectionIndex = -1;
                    for (IRuntime runtime : ServerCore.getRuntimes()) {
                        if (ServerUtil.isLiferayRuntime(runtime) && FileUtil.exists(runtime.getLocation()) && (LiferayServerCore.newPortalBundle(runtime.getLocation()) == null)) {
                            runtimeNames.add(runtime.getName());
                            if (runtime.getName().equals(currentRuntimeName)) {
                                selectionIndex = runtimeNames.size() - 1;
                            }
                        }
                    }
                    if (ListUtil.isEmpty(runtimeNames)) {
                        runtimeNames.add("No Liferay runtimes available.");
                    }
                    _runtimeCombo.setItems(runtimeNames.toArray(new String[0]));
                    if (selectionIndex > -1) {
                        _runtimeCombo.select(selectionIndex);
                    }
                }
            }
        } catch (Exception e) {
            ProjectUI.logError("Could not determine whether its a maven project ", e);
        }
    }
}
Also used : HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) Reference(org.eclipse.sapphire.ui.def.DefinitionLoader.Reference) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) LiferayPluginSDKOp(com.liferay.ide.project.core.model.LiferayPluginSDKOp) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) BackingStoreException(org.osgi.service.prefs.BackingStoreException) IRuntime(org.eclipse.wst.server.core.IRuntime) Version(org.osgi.framework.Version) DefinitionLoader(org.eclipse.sapphire.ui.def.DefinitionLoader) ILiferayRuntime(com.liferay.ide.server.core.ILiferayRuntime) GridData(org.eclipse.swt.layout.GridData) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) SDK(com.liferay.ide.sdk.core.SDK) SapphireDialog(org.eclipse.sapphire.ui.forms.swt.SapphireDialog) Hyperlink(org.eclipse.ui.forms.widgets.Hyperlink) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter)

Example 7 with ILiferayRuntime

use of com.liferay.ide.server.core.ILiferayRuntime in project liferay-ide by liferay.

the class DebugPortalLaunchParticipant method provideVMArgs.

public String provideVMArgs(ILaunchConfiguration configuration) {
    String retval = null;
    try {
        String stopServer = configuration.getAttribute(STOP_SERVER, "false");
        if (ILaunchManager.DEBUG_MODE.equals(saveLaunchMode) && "false".equals(stopServer)) {
            final IServer server = org.eclipse.wst.server.core.ServerUtil.getServer(configuration);
            final ILiferayRuntime liferayRuntime = (ILiferayRuntime) server.getRuntime().loadAdapter(ILiferayRuntime.class, null);
            final Version version = new Version(liferayRuntime.getPortalVersion());
            if (CoreUtil.compareVersions(version, ILiferayConstants.V620) >= 0) {
                if (this.fmDebugPort != null) {
                    retval = NLS.bind(FM_PARAMS, PortalCore.getPreference(PortalCore.PREF_FM_DEBUG_PASSWORD), this.fmDebugPort);
                } else {
                    // $NON-NLS-1$
                    PortalCore.logError("The freemarker debug port is invalid.");
                }
            }
        }
    } catch (CoreException e) {
    }
    return retval;
}
Also used : IServer(org.eclipse.wst.server.core.IServer) CoreException(org.eclipse.core.runtime.CoreException) Version(org.osgi.framework.Version) ILiferayRuntime(com.liferay.ide.server.core.ILiferayRuntime)

Example 8 with ILiferayRuntime

use of com.liferay.ide.server.core.ILiferayRuntime in project liferay-ide by liferay.

the class SDKProjectRemoteServerPublisher method publishModuleFull.

@Override
public IPath publishModuleFull(IProgressMonitor monitor) throws CoreException {
    IPath deployPath = LiferayServerCore.getTempLocation("direct-deploy", StringPool.EMPTY);
    File warFile = deployPath.append(getProject().getName() + ".war").toFile();
    warFile.getParentFile().mkdirs();
    Map<String, String> properties = new HashMap<>();
    properties.put(ISDKConstants.PROPERTY_AUTO_DEPLOY_UNPACK_WAR, "false");
    ILiferayRuntime runtime = ServerUtil.getLiferayRuntime(getProject());
    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());
    String fileTimeStamp = System.currentTimeMillis() + "";
    // IDE-1491
    properties.put(ISDKConstants.PROPERTY_LP_VERSION, fileTimeStamp);
    properties.put(ISDKConstants.PROPERTY_LP_VERSION_SUFFIX, ".0");
    IStatus status = _sdk.validate();
    if (!status.isOK()) {
        throw new CoreException(status);
    }
    IStatus directDeployStatus = _sdk.war(getProject(), properties, true, new String[] { "-Duser.timezone=GMT" }, monitor);
    if (!directDeployStatus.isOK() || !warFile.exists()) {
        String pluginVersion = "1";
        IPath pluginPropertiesPath = new Path("WEB-INF/liferay-plugin-package.properties");
        IWebProject webproject = LiferayCore.create(IWebProject.class, getProject());
        if (webproject != null) {
            IResource propsRes = webproject.findDocrootResource(pluginPropertiesPath);
            if (propsRes instanceof IFile && propsRes.exists()) {
                try {
                    PropertiesConfiguration pluginPackageProperties = new PropertiesConfiguration();
                    InputStream is = ((IFile) propsRes).getContents();
                    pluginPackageProperties.load(is);
                    pluginVersion = pluginPackageProperties.getString("module-incremental-version");
                    is.close();
                } catch (Exception e) {
                    LiferayCore.logError("error reading module-incremtnal-version. ", e);
                }
            }
            IPath distPath = _sdk.getLocation().append("dist");
            String fullName = getProject().getName() + "-" + fileTimeStamp + "." + pluginVersion + ".0.war";
            warFile = distPath.append(fullName).toFile();
            if (!warFile.exists()) {
                throw new CoreException(directDeployStatus);
            }
        }
    }
    return new Path(warFile.getAbsolutePath());
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) IWebProject(com.liferay.ide.core.IWebProject) InputStream(java.io.InputStream) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) CoreException(org.eclipse.core.runtime.CoreException) CoreException(org.eclipse.core.runtime.CoreException) ILiferayRuntime(com.liferay.ide.server.core.ILiferayRuntime) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource)

Example 9 with ILiferayRuntime

use of com.liferay.ide.server.core.ILiferayRuntime in project liferay-ide by liferay.

the class LeastVersionRuntimeValidationService method compute.

@Override
protected Status compute() {
    Property property = context(Element.class).property(context(Property.class).definition());
    Value<?> value = (Value<?>) property;
    String runtimeName = value.content().toString();
    IRuntime runtime = ServerUtil.getRuntime(runtimeName);
    if (runtime == null) {
        return Status.createErrorStatus("Liferay runtime must be configured.");
    }
    ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(runtime);
    Version runtimeVersion = new Version(liferayRuntime.getPortalVersion());
    if (CoreUtil.compareVersions(runtimeVersion, ILiferayConstants.V620) < 0) {
        return Status.createErrorStatus("Liferay runtime must be greater than 6.2.0.");
    } else {
        return StatusBridge.create(runtime.validate(new NullProgressMonitor()));
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Version(org.osgi.framework.Version) Element(org.eclipse.sapphire.Element) ILiferayRuntime(com.liferay.ide.server.core.ILiferayRuntime) Value(org.eclipse.sapphire.Value) Property(org.eclipse.sapphire.Property) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 10 with ILiferayRuntime

use of com.liferay.ide.server.core.ILiferayRuntime in project liferay-ide by liferay.

the class LiferayRuntimeStubWizardFragment method getLiferayRuntime.

protected ILiferayRuntime getLiferayRuntime() {
    IRuntimeWorkingCopy runtimeWC = (IRuntimeWorkingCopy) getTaskModel().getObject(TaskModel.TASK_RUNTIME);
    ILiferayRuntime liferayRuntime = (ILiferayRuntime) runtimeWC.loadAdapter(ILiferayRuntime.class, null);
    return liferayRuntime;
}
Also used : ILiferayRuntime(com.liferay.ide.server.core.ILiferayRuntime) IRuntimeWorkingCopy(org.eclipse.wst.server.core.IRuntimeWorkingCopy)

Aggregations

ILiferayRuntime (com.liferay.ide.server.core.ILiferayRuntime)18 CoreException (org.eclipse.core.runtime.CoreException)10 File (java.io.File)9 IPath (org.eclipse.core.runtime.IPath)7 Version (org.osgi.framework.Version)6 IRuntime (org.eclipse.wst.server.core.IRuntime)5 URL (java.net.URL)4 ArrayList (java.util.ArrayList)3 JarFile (java.util.jar.JarFile)3 IStatus (org.eclipse.core.runtime.IStatus)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 IServer (org.eclipse.wst.server.core.IServer)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 Path (org.eclipse.core.runtime.Path)2 IClasspathContainer (org.eclipse.jdt.core.IClasspathContainer)2 ILiferayPortal (com.liferay.ide.core.ILiferayPortal)1 ILiferayProject (com.liferay.ide.core.ILiferayProject)1