Search in sources :

Example 31 with IRuntimeType

use of org.eclipse.wst.server.core.IRuntimeType in project liferay-ide by liferay.

the class CustomJspPage method _getExistLiferay70Runtime.

private IRuntime _getExistLiferay70Runtime() {
    Set<IRuntime> liferayRuntimes = ServerUtil.getAvailableLiferayRuntimes();
    for (IRuntime liferayRuntime : liferayRuntimes) {
        File customJspFile = liferayRuntime.getLocation().toFile();
        IRuntimeType runtimeType = liferayRuntime.getRuntimeType();
        if (runtimeType.getId().equals("com.liferay.ide.server.portal.runtime") && customJspFile.exists()) {
            return liferayRuntime;
        }
    }
    return null;
}
Also used : IRuntimeType(org.eclipse.wst.server.core.IRuntimeType) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 32 with IRuntimeType

use of org.eclipse.wst.server.core.IRuntimeType in project liferay-ide by liferay.

the class ServerUtil method getRuntime.

public static IRuntimeWorkingCopy getRuntime(String runtimeTypeId, IPath location) {
    IRuntimeType runtimeType = ServerCore.findRuntimeType(runtimeTypeId);
    try {
        // $NON-NLS-1$
        IRuntime runtime = runtimeType.createRuntime("runtime", null);
        IRuntimeWorkingCopy runtimeWC = runtime.createWorkingCopy();
        // $NON-NLS-1$
        runtimeWC.setName("Runtime");
        runtimeWC.setLocation(location);
        return runtimeWC;
    } catch (CoreException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IRuntimeType(org.eclipse.wst.server.core.IRuntimeType) IRuntimeWorkingCopy(org.eclipse.wst.server.core.IRuntimeWorkingCopy) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 33 with IRuntimeType

use of org.eclipse.wst.server.core.IRuntimeType in project liferay-ide by liferay.

the class LiferayRuntimeStubDelegate method getTempRuntime.

protected IRuntimeWorkingCopy getTempRuntime() {
    if (tempRuntime == null && getRuntime().getLocation() != null) {
        IRuntimeType runtimeType = ServerCore.findRuntimeType(getRuntimeStubTypeId());
        try {
            // $NON-NLS-1$
            tempRuntime = runtimeType.createRuntime(getRuntimeStubTypeId() + "-stub", new NullProgressMonitor());
            tempRuntime.setLocation(getRuntime().getLocation());
        } catch (CoreException e) {
            // $NON-NLS-1$
            LiferayServerCore.logError("Error creating runtime", e);
        }
    }
    if (tempRuntime.getLocation() == null || !(tempRuntime.getLocation().equals(getRuntime().getLocation()))) {
        tempRuntime.setLocation(getRuntime().getLocation());
    }
    return tempRuntime;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IRuntimeType(org.eclipse.wst.server.core.IRuntimeType)

Example 34 with IRuntimeType

use of org.eclipse.wst.server.core.IRuntimeType in project liferay-ide by liferay.

the class LiferayServerCore method saveGlobalRuntimeSettings.

private synchronized void saveGlobalRuntimeSettings(IRuntime runtime) {
    final IRuntimeType runtimeType = runtime.getRuntimeType();
    if (runtimeType != null && runtimeType.getId().startsWith("com.liferay")) {
        try {
            LiferayCore.GLOBAL_SETTINGS_PATH.toFile().mkdirs();
            final File runtimesGlobalFile = LiferayCore.GLOBAL_SETTINGS_PATH.append("runtimes.xml").toFile();
            final Set<IMemento> existing = new HashSet<IMemento>();
            if (runtimesGlobalFile.exists()) {
                try {
                    try (InputStream newInputStream = Files.newInputStream(runtimesGlobalFile.toPath())) {
                        IMemento existingMemento = XMLMemento.loadMemento(newInputStream);
                        if (existingMemento != null) {
                            IMemento[] children = existingMemento.getChildren("runtime");
                            if (ListUtil.isNotEmpty(children)) {
                                for (IMemento child : children) {
                                    final IPath loc = Path.fromPortableString(child.getString("location"));
                                    if (loc != null && loc.toFile().exists()) {
                                        boolean duplicate = ServerCore.findRuntime(child.getString("id")) != null;
                                        if (!duplicate) {
                                            existing.add(child);
                                        }
                                    }
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                }
            }
            final Map<String, IMemento> mementos = new HashMap<String, IMemento>();
            final XMLMemento runtimeMementos = XMLMemento.createWriteRoot("runtimes");
            for (IMemento exist : existing) {
                final IMemento copy = runtimeMementos.createChild("runtime");
                copyMemento(exist, copy);
                mementos.put(copy.getString("id"), copy);
            }
            for (IRuntime r : ServerCore.getRuntimes()) {
                if (mementos.get(r.getId()) == null && r.getRuntimeType() != null) {
                    final IMemento rMemento = runtimeMementos.createChild("runtime");
                    if (addRuntimeToMemento(r, rMemento)) {
                        mementos.put(r.getId(), rMemento);
                    }
                }
            }
            final OutputStream fos = Files.newOutputStream(runtimesGlobalFile.toPath());
            runtimeMementos.save(fos);
        } catch (Exception e) {
            LiferayServerCore.logError("Unable to save global runtime settings", e);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) IRuntimeType(org.eclipse.wst.server.core.IRuntimeType) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) IMemento(org.eclipse.wst.server.core.internal.IMemento) BackingStoreException(org.osgi.service.prefs.BackingStoreException) IOException(java.io.IOException) IRuntime(org.eclipse.wst.server.core.IRuntime) XMLMemento(org.eclipse.wst.server.core.internal.XMLMemento) File(java.io.File) HashSet(java.util.HashSet)

Example 35 with IRuntimeType

use of org.eclipse.wst.server.core.IRuntimeType in project liferay-ide by liferay.

the class LiferayRuntimeStubComposite method createControl.

protected void createControl(Composite parent) {
    setLayout(new GridLayout(2, false));
    setLayoutData(new GridData(GridData.FILL_BOTH));
    setBackground(parent.getBackground());
    Label lblName = new Label(this, SWT.NONE);
    lblName.setText(Msgs.name);
    new Label(this, SWT.NONE);
    textName = new Text(this, SWT.BORDER);
    textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    textName.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            runtimeWC.setName(textName.getText());
            validate();
        }
    });
    createSpacer();
    Label lblRuntimeStubType = new Label(this, SWT.NONE);
    lblRuntimeStubType.setText(Msgs.liferayBundleType);
    createSpacer();
    comboRuntimeStubType = new Combo(this, SWT.READ_ONLY);
    comboRuntimeStubType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    createSpacer();
    final Label lblInstall = new Label(this, SWT.WRAP);
    lblInstall.setText(Msgs.liferayBundleDirectory);
    new Label(this, SWT.NONE);
    textInstallDir = new Text(this, SWT.BORDER);
    textInstallDir.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    comboRuntimeStubType.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int index = comboRuntimeStubType.getSelectionIndex();
            ILiferayRuntimeStub selectedStub = LiferayServerCore.getRuntimeStubs()[index];
            LiferayRuntimeStubDelegate delegate = getStubDelegate();
            delegate.setRuntimeStubTypeId(selectedStub.getRuntimeStubTypeId());
            String stubTypeId = selectedStub.getRuntimeStubTypeId();
            IRuntimeType runtimeType = ServerCore.findRuntimeType(stubTypeId);
            for (IRuntime runtime : ServerCore.getRuntimes()) {
                if (runtime.getRuntimeType().equals(runtimeType)) {
                    textInstallDir.setText(runtime.getLocation().toOSString());
                }
            }
            validate();
        }
    });
    textInstallDir.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            textInstallDirChanged(textInstallDir.getText());
        }
    });
    Button btnBrowse = new Button(this, SWT.NONE);
    btnBrowse.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
    btnBrowse.setText(Msgs.browse);
    btnBrowse.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent se) {
            DirectoryDialog dialog = new DirectoryDialog(LiferayRuntimeStubComposite.this.getShell());
            dialog.setMessage(Msgs.selectRuntimeStubDirectory);
            dialog.setFilterPath(textInstallDir.getText());
            String selectedDirectory = dialog.open();
            if (selectedDirectory != null) {
                textInstallDir.setText(selectedDirectory);
            }
        }
    });
    new Label(this, SWT.NONE);
    Dialog.applyDialogFont(this);
    textName.forceFocus();
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) IRuntimeType(org.eclipse.wst.server.core.IRuntimeType) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ILiferayRuntimeStub(com.liferay.ide.server.core.ILiferayRuntimeStub) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) IRuntime(org.eclipse.wst.server.core.IRuntime) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LiferayRuntimeStubDelegate(com.liferay.ide.server.core.LiferayRuntimeStubDelegate) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Aggregations

IRuntimeType (org.eclipse.wst.server.core.IRuntimeType)35 IRuntime (org.eclipse.wst.server.core.IRuntime)17 IRuntimeWorkingCopy (org.eclipse.wst.server.core.IRuntimeWorkingCopy)12 IServerType (org.eclipse.wst.server.core.IServerType)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 IServerWorkingCopy (org.eclipse.wst.server.core.IServerWorkingCopy)9 CoreException (org.eclipse.core.runtime.CoreException)8 IPath (org.eclipse.core.runtime.IPath)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Path (org.eclipse.core.runtime.Path)3 GenericServerRuntime (org.eclipse.jst.server.generic.core.internal.GenericServerRuntime)3 Image (org.eclipse.swt.graphics.Image)3 IServer (org.eclipse.wst.server.core.IServer)3 File (java.io.File)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2