Search in sources :

Example 16 with IServer

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

the class PortalPublishTask method getTasks.

@SuppressWarnings("rawtypes")
public PublishOperation[] getTasks(IServer server, int kind, List modules, List kindList) {
    List<BundlePublishOperation> tasks = new ArrayList<BundlePublishOperation>();
    PortalServerBehavior serverBehavior = (PortalServerBehavior) server.loadAdapter(PortalServerBehavior.class, null);
    if (ListUtil.isNotEmpty(modules)) {
        final int size = modules.size();
        for (int i = 0; i < size; i++) {
            IModule[] module = (IModule[]) modules.get(i);
            Integer deltaKind = (Integer) kindList.get(i);
            boolean needClean = false;
            IModuleResourceDelta[] deltas = ((Server) server).getPublishedResourceDelta(module);
            for (IModuleResourceDelta delta : deltas) {
                final IModuleResource resource = delta.getModuleResource();
                final IFile resourceFile = (IFile) resource.getAdapter(IFile.class);
                if (resourceFile != null && resourceFile.getName().equals("bnd.bnd")) {
                    needClean = true;
                    break;
                }
            }
            switch(kind) {
                case IServer.PUBLISH_FULL:
                case IServer.PUBLISH_INCREMENTAL:
                case IServer.PUBLISH_AUTO:
                    final IProject project = module[0].getProject();
                    switch(deltaKind) {
                        case ServerBehaviourDelegate.ADDED:
                            addOperation(BundlePublishFullAddCleanBuild.class, tasks, server, module);
                            break;
                        case ServerBehaviourDelegate.CHANGED:
                            if (needClean) {
                                addOperation(BundlePublishFullAddCleanBuild.class, tasks, server, module);
                            } else {
                                addOperation(BundlePublishFullAdd.class, tasks, server, module);
                            }
                            break;
                        case ServerBehaviourDelegate.REMOVED:
                            addOperation(BundlePublishFullRemove.class, tasks, server, module);
                            break;
                        case ServerBehaviourDelegate.NO_CHANGE:
                            final IBundleProject bundleProject = LiferayCore.create(IBundleProject.class, project);
                            if (bundleProject != null) {
                                try {
                                    if (isUserRedeploy(serverBehavior, module[0]) || !isDeployed(server, serverBehavior, bundleProject.getSymbolicName())) {
                                        addOperation(BundlePublishFullAddCleanBuild.class, tasks, server, module);
                                    }
                                } catch (CoreException e) {
                                    LiferayServerCore.logError("Unable to get bsn for project " + project.getName(), e);
                                }
                            }
                            break;
                        default:
                            break;
                    }
                    break;
                default:
                    break;
            }
        }
    }
    return tasks.toArray(new PublishOperation[0]);
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IModule(org.eclipse.wst.server.core.IModule) IFile(org.eclipse.core.resources.IFile) IServer(org.eclipse.wst.server.core.IServer) Server(org.eclipse.wst.server.core.internal.Server) IBundleProject(com.liferay.ide.core.IBundleProject) ArrayList(java.util.ArrayList) IModuleResourceDelta(org.eclipse.wst.server.core.model.IModuleResourceDelta) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException)

Example 17 with IServer

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

the class ServerUtil method deleteRuntimeAndServer.

public static void deleteRuntimeAndServer(String runtimeType, File portalBundle) throws Exception {
    IRuntime[] runtimes = ServerCore.getRuntimes();
    IRuntime targetRuntime = null;
    for (IRuntime runtime : runtimes) {
        if (runtime.getRuntimeType().getId().equals(runtimeType)) {
            File runtimeFile = runtime.getLocation().toFile();
            if (runtimeFile.getCanonicalFile().equals(portalBundle)) {
                targetRuntime = runtime;
            }
        }
    }
    if (targetRuntime != null) {
        IServer[] servers = ServerCore.getServers();
        for (IServer server : servers) {
            IRuntime runtime = server.getRuntime();
            if (runtime != null && runtime.equals(targetRuntime)) {
                server.delete();
            }
        }
        targetRuntime.delete();
    }
}
Also used : IServer(org.eclipse.wst.server.core.IServer) JarFile(java.util.jar.JarFile) File(java.io.File) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 18 with IServer

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

the class PortalSourcePathComputerDelegate method computeSourceContainers.

@Override
public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
    final List<ISourceContainer> sourceContainers = new ArrayList<ISourceContainer>();
    final IServer server = ServerUtil.getServer(configuration);
    IWorkspaceProject workspaceProject = LiferayCore.create(IWorkspaceProject.class, server);
    if (workspaceProject != null) {
        addSourceContainers(configuration, monitor, sourceContainers, workspaceProject.getProject());
    }
    Stream.of(server.getModules()).map(module -> LiferayCore.create(module.getProject())).filter(liferayProject -> liferayProject != null).forEach(liferayProject -> addSourceContainers(configuration, monitor, sourceContainers, liferayProject.getProject()));
    return sourceContainers.toArray(new ISourceContainer[0]);
}
Also used : JavaSourcePathComputer(org.eclipse.jdt.launching.sourcelookup.containers.JavaSourcePathComputer) DebugPlugin(org.eclipse.debug.core.DebugPlugin) IServer(org.eclipse.wst.server.core.IServer) LiferayServerCore(com.liferay.ide.server.core.LiferayServerCore) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ArrayList(java.util.ArrayList) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) LiferayCore(com.liferay.ide.core.LiferayCore) ServerUtil(org.eclipse.wst.server.core.ServerUtil) List(java.util.List) Stream(java.util.stream.Stream) IProject(org.eclipse.core.resources.IProject) ISourceContainer(org.eclipse.debug.core.sourcelookup.ISourceContainer) IWorkspaceProject(com.liferay.ide.core.IWorkspaceProject) IJavaLaunchConfigurationConstants(org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants) IServer(org.eclipse.wst.server.core.IServer) ArrayList(java.util.ArrayList) ISourceContainer(org.eclipse.debug.core.sourcelookup.ISourceContainer) IWorkspaceProject(com.liferay.ide.core.IWorkspaceProject)

Example 19 with IServer

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

the class RemoteServerWizardFragment method performFinish.

@Override
public void performFinish(IProgressMonitor monitor) throws CoreException {
    try {
        this.wizard.run(false, false, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                if (lastServerStatus == null || (!lastServerStatus.isOK())) {
                    lastServerStatus = getRemoteServerWC().validate(monitor);
                    if (!lastServerStatus.isOK()) {
                        throw new InterruptedException(lastServerStatus.getMessage());
                    }
                }
            }
        });
    } catch (Exception e) {
    }
    ServerCore.addServerLifecycleListener(new IServerLifecycleListener() {

        String id = getServerWorkingCopy().getId();

        public void serverAdded(final IServer server) {
            if (server.getId().equals(id)) {
                UIUtil.async(new Runnable() {

                    public void run() {
                        // $NON-NLS-1$
                        IViewPart serversView = UIUtil.showView("org.eclipse.wst.server.ui.ServersView");
                        CommonViewer viewer = (CommonViewer) serversView.getAdapter(CommonViewer.class);
                        viewer.setSelection(new StructuredSelection(server));
                    }
                });
                ServerCore.removeServerLifecycleListener(this);
                server.addServerListener(new IServerListener() {

                    public void serverChanged(ServerEvent event) {
                        if (event.getServer().getServerState() == IServer.STATE_STARTED) {
                            server.publish(IServer.PUBLISH_INCREMENTAL, null, null, null);
                            server.removeServerListener(this);
                        }
                    }
                });
            }
        }

        public void serverChanged(IServer server) {
        }

        public void serverRemoved(IServer server) {
        }
    });
}
Also used : IServer(org.eclipse.wst.server.core.IServer) IViewPart(org.eclipse.ui.IViewPart) CommonViewer(org.eclipse.ui.navigator.CommonViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IServerLifecycleListener(org.eclipse.wst.server.core.IServerLifecycleListener) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ServerEvent(org.eclipse.wst.server.core.ServerEvent) IServerListener(org.eclipse.wst.server.core.IServerListener)

Example 20 with IServer

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

the class OpenLiferayHomeFolderHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        List selectedObj = ((IStructuredSelection) selection).toList();
        if ((selectedObj.size() == 1) && (selectedObj.get(0) instanceof IServer)) {
            final IServer server = (IServer) selectedObj.get(0);
            final IPath path = ServerUtil.getLiferayRuntime(server.getRuntime()).getAppServerDir();
            try {
                ServerUIUtil.openFileInSystemExplorer(path);
            } catch (IOException e) {
                LiferayServerUI.logError("Error opening portal home folder.", e);
            }
        }
    }
    return null;
}
Also used : IServer(org.eclipse.wst.server.core.IServer) IPath(org.eclipse.core.runtime.IPath) ISelection(org.eclipse.jface.viewers.ISelection) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException)

Aggregations

IServer (org.eclipse.wst.server.core.IServer)183 CoreException (org.eclipse.core.runtime.CoreException)39 IModule (org.eclipse.wst.server.core.IModule)32 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)30 Test (org.junit.Test)30 IProject (org.eclipse.core.resources.IProject)25 IStatus (org.eclipse.core.runtime.IStatus)25 IServerWorkingCopy (org.eclipse.wst.server.core.IServerWorkingCopy)23 ArrayList (java.util.ArrayList)20 File (java.io.File)17 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 Status (org.eclipse.core.runtime.Status)12 Iterator (java.util.Iterator)11 IPath (org.eclipse.core.runtime.IPath)11 IServerType (org.eclipse.wst.server.core.IServerType)11 CDKServer (org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)11 IOException (java.io.IOException)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 Server (org.eclipse.wst.server.core.internal.Server)10 IFolder (org.eclipse.core.resources.IFolder)8