Search in sources :

Example 6 with IWebModule

use of org.eclipse.jst.server.core.IWebModule in project webtools.servertools by eclipse.

the class ContextPublisherDelegate method execute.

public IStatus execute(int kind, IProgressMonitor monitor, IAdaptable info) throws CoreException {
    // this publisher only runs when there is a UI
    if (info == null)
        return Status.OK_STATUS;
    final Shell shell = (Shell) info.getAdapter(Shell.class);
    if (shell == null)
        return Status.OK_STATUS;
    IServer server = (IServer) getTaskModel().getObject(TaskModel.TASK_SERVER);
    TomcatServer tomcatServer = (TomcatServer) server.loadAdapter(TomcatServer.class, monitor);
    final TomcatConfiguration configuration = tomcatServer.getTomcatConfiguration();
    final boolean[] save = new boolean[1];
    List modules = (List) getTaskModel().getObject(TaskModel.TASK_MODULES);
    int size = modules.size();
    for (int i = 0; i < size; i++) {
        IModule[] module = (IModule[]) modules.get(i);
        final IModule m = module[module.length - 1];
        IWebModule webModule = (IWebModule) m.loadAdapter(IWebModule.class, monitor);
        final WebModule webModule2 = configuration.getWebModule(m);
        if (webModule != null && webModule2 != null) {
            String contextRoot = webModule.getContextRoot();
            if (contextRoot != null && !contextRoot.startsWith("/") && contextRoot.length() > 0)
                contextRoot = "/" + contextRoot;
            if (!contextRoot.equals(webModule2.getPath()) && shouldPrompt(m, contextRoot)) {
                final String context = contextRoot;
                shell.getDisplay().syncExec(new Runnable() {

                    public void run() {
                        if (MessageDialog.openQuestion(shell, Messages.wizardTitle, NLS.bind(Messages.contextCleanup, m.getName()))) {
                            int index = configuration.getWebModules().indexOf(webModule2);
                            configuration.modifyWebModule(index, webModule2.getDocumentBase(), context, webModule2.isReloadable());
                            save[0] = true;
                        }
                    }
                });
                markProject(m, contextRoot);
            }
        }
    }
    if (save[0])
        tomcatServer.saveConfiguration(monitor);
    return Status.OK_STATUS;
}
Also used : IServer(org.eclipse.wst.server.core.IServer) IModule(org.eclipse.wst.server.core.IModule) TomcatConfiguration(org.eclipse.jst.server.tomcat.core.internal.TomcatConfiguration) IWebModule(org.eclipse.jst.server.core.IWebModule) WebModule(org.eclipse.jst.server.tomcat.core.internal.WebModule) IWebModule(org.eclipse.jst.server.core.IWebModule) Shell(org.eclipse.swt.widgets.Shell) List(java.util.List) TomcatServer(org.eclipse.jst.server.tomcat.core.internal.TomcatServer)

Example 7 with IWebModule

use of org.eclipse.jst.server.core.IWebModule in project webtools.servertools by eclipse.

the class WebModuleDialog method createDialogArea.

/**
 * Creates and returns the contents of the upper part
 * of this dialog (above the button bar).
 * <p>
 * The <code>Dialog</code> implementation of this framework method
 * creates and returns a new <code>Composite</code> with
 * standard margins and spacing. Subclasses should override.
 * </p>
 *
 * @param parent the parent composite to contain the dialog area
 * @return the dialog area control
 */
protected Control createDialogArea(Composite parent) {
    // create a composite with standard margins and spacing
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setFont(parent.getFont());
    IWorkbenchHelpSystem whs = PlatformUI.getWorkbench().getHelpSystem();
    whs.setHelp(composite, ContextIds.CONFIGURATION_EDITOR_WEBMODULE_DIALOG);
    // add project field if we are adding a project
    if (!isEdit && isProject) {
        Label l = new Label(composite, SWT.NONE);
        l.setText(Messages.configurationEditorWebModuleDialogProjects);
        GridData data = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
        l.setLayoutData(data);
        projTable = new Table(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
        data = new GridData();
        data.widthHint = 150;
        data.heightHint = 75;
        projTable.setLayoutData(data);
        whs.setHelp(projTable, ContextIds.CONFIGURATION_EDITOR_WEBMODULE_DIALOG_PROJECT);
        // fill table with web module projects
        ILabelProvider labelProvider = ServerUICore.getLabelProvider();
        IModule[] modules = ServerUtil.getModules(server2.getServerType().getRuntimeType().getModuleTypes());
        if (modules != null) {
            int size = modules.length;
            for (int i = 0; i < size; i++) {
                IModule module3 = modules[i];
                if ("jst.web".equals(module3.getModuleType().getId())) {
                    IStatus status = server2.canModifyModules(new IModule[] { module3 }, null, null);
                    if (status != null && status.isOK()) {
                        TableItem item = new TableItem(projTable, SWT.NONE);
                        item.setText(0, labelProvider.getText(module3));
                        item.setImage(0, labelProvider.getImage(module3));
                        item.setData(module3);
                    }
                }
            }
        }
        labelProvider.dispose();
        new Label(composite, SWT.NONE).setText(" ");
    }
    new Label(composite, SWT.NONE).setText(Messages.configurationEditorWebModuleDialogDocumentBase);
    docBase = new Text(composite, SWT.BORDER);
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    docBase.setLayoutData(data);
    docBase.setText(module.getDocumentBase());
    whs.setHelp(docBase, ContextIds.CONFIGURATION_EDITOR_WEBMODULE_DIALOG_DOCBASE);
    // disable document base for project modules
    if (isProject || (module.getMemento() != null && module.getMemento().length() > 0))
        docBase.setEditable(false);
    else {
        docBase.addModifyListener(new ModifyListener() {

            public void modifyText(ModifyEvent e) {
                module = new WebModule(module.getPath(), docBase.getText(), module.getMemento(), module.isReloadable());
                validate();
            }
        });
    }
    if (isEdit || isProject)
        new Label(composite, SWT.NONE).setText(" ");
    else {
        Button browse = new Button(composite, SWT.NONE);
        browse.setText(Messages.browse);
        browse.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent se) {
                try {
                    DirectoryDialog dialog = new DirectoryDialog(getShell());
                    dialog.setMessage(Messages.configurationEditorWebModuleDialogSelectDirectory);
                    String selectedDirectory = dialog.open();
                    if (selectedDirectory != null)
                        docBase.setText(selectedDirectory);
                } catch (Exception e) {
                    Trace.trace(Trace.SEVERE, "Error browsing", e);
                }
            }
        });
    }
    // path (context-root)
    new Label(composite, SWT.NONE).setText(Messages.configurationEditorWebModuleDialogPath);
    final Text path = new Text(composite, SWT.BORDER);
    data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    data.widthHint = 150;
    path.setLayoutData(data);
    path.setText(module.getPath());
    /*if (module.getMemento() != null && module.getMemento().length() > 0)
			path.setEditable(false);
		else*/
    path.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            module = new WebModule(path.getText(), module.getDocumentBase(), module.getMemento(), module.isReloadable());
        }
    });
    whs.setHelp(path, ContextIds.CONFIGURATION_EDITOR_WEBMODULE_DIALOG_PATH);
    new Label(composite, SWT.NONE).setText("");
    if (!isProject) {
        // auto reload
        new Label(composite, SWT.NONE).setText("");
        final Button reloadable = new Button(composite, SWT.CHECK);
        reloadable.setText(Messages.configurationEditorWebModuleDialogReloadEnabled);
        data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
        reloadable.setLayoutData(data);
        reloadable.setSelection(module.isReloadable());
        reloadable.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                module = new WebModule(module.getPath(), module.getDocumentBase(), module.getMemento(), reloadable.getSelection());
            }
        });
        whs.setHelp(reloadable, ContextIds.CONFIGURATION_EDITOR_WEBMODULE_DIALOG_RELOAD);
    }
    if (!isEdit && isProject) {
        projTable.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent event) {
                try {
                    IModule module3 = (IModule) projTable.getSelection()[0].getData();
                    IWebModule module2 = (IWebModule) module3.loadAdapter(IWebModule.class, null);
                    String contextRoot = module2.getContextRoot();
                    if (contextRoot != null && !contextRoot.startsWith("/") && contextRoot.length() > 0)
                        contextRoot = "/" + contextRoot;
                    module = new WebModule(contextRoot, module3.getName(), module3.getId(), module.isReloadable());
                    docBase.setText(module3.getName());
                    path.setText(contextRoot);
                    module4 = module3;
                } catch (Exception e) {
                // ignore
                }
                validate();
            }
        });
        new Label(composite, SWT.NONE).setText("");
    }
    Dialog.applyDialogFont(composite);
    return composite;
}
Also used : IModule(org.eclipse.wst.server.core.IModule) IStatus(org.eclipse.core.runtime.IStatus) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) TableItem(org.eclipse.swt.widgets.TableItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) WebModule(org.eclipse.jst.server.tomcat.core.internal.WebModule) IWebModule(org.eclipse.jst.server.core.IWebModule) IWebModule(org.eclipse.jst.server.core.IWebModule) GridLayout(org.eclipse.swt.layout.GridLayout) IWorkbenchHelpSystem(org.eclipse.ui.help.IWorkbenchHelpSystem) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 8 with IWebModule

use of org.eclipse.jst.server.core.IWebModule in project webtools.servertools by eclipse.

the class TomcatConfiguration method getWebModuleURL.

/**
 * Returns the partial URL applicable to this module.
 *
 * @param webModule a web module
 * @return the partial URL
 */
protected String getWebModuleURL(IModule webModule) {
    WebModule module = getWebModule(webModule);
    if (module != null)
        return module.getPath();
    IWebModule webModule2 = (IWebModule) webModule.loadAdapter(IWebModule.class, null);
    return "/" + webModule2.getContextRoot();
}
Also used : IWebModule(org.eclipse.jst.server.core.IWebModule) IWebModule(org.eclipse.jst.server.core.IWebModule)

Example 9 with IWebModule

use of org.eclipse.jst.server.core.IWebModule in project webtools.servertools by eclipse.

the class TomcatServerBehaviour method publishModule.

/*
	 * Publishes the given module to the server.
	 */
protected void publishModule(int kind, int deltaKind, IModule[] moduleTree, IProgressMonitor monitor) throws CoreException {
    if (getServer().getServerState() != IServer.STATE_STOPPED) {
        if (deltaKind == ServerBehaviourDelegate.ADDED || deltaKind == ServerBehaviourDelegate.REMOVED)
            setServerRestartState(true);
    }
    if (getTomcatServer().isTestEnvironment())
        return;
    Properties p = loadModulePublishLocations();
    PublishHelper helper = new PublishHelper(getRuntimeBaseDirectory().append("temp").toFile());
    // If parent web module
    if (moduleTree.length == 1) {
        publishDir(deltaKind, p, moduleTree, helper, monitor);
    } else // Else a child module
    {
        // Try to determine the URI for the child module
        IWebModule webModule = (IWebModule) moduleTree[0].loadAdapter(IWebModule.class, monitor);
        String childURI = null;
        if (webModule != null) {
            childURI = webModule.getURI(moduleTree[1]);
        }
        // Try to determine if child is binary
        IJ2EEModule childModule = (IJ2EEModule) moduleTree[1].loadAdapter(IJ2EEModule.class, monitor);
        boolean isBinary = false;
        if (childModule != null) {
            isBinary = childModule.isBinary();
        }
        if (isBinary) {
            publishArchiveModule(childURI, kind, deltaKind, p, moduleTree, helper, monitor);
        } else {
            publishJar(childURI, kind, deltaKind, p, moduleTree, helper, monitor);
        }
    }
    setModulePublishState(moduleTree, IServer.PUBLISH_STATE_NONE);
    saveModulePublishLocations(p);
}
Also used : IJ2EEModule(org.eclipse.jst.server.core.IJ2EEModule) PublishHelper(org.eclipse.wst.server.core.util.PublishHelper) IModulePublishHelper(org.eclipse.wst.server.core.internal.IModulePublishHelper) IWebModule(org.eclipse.jst.server.core.IWebModule) Properties(java.util.Properties)

Example 10 with IWebModule

use of org.eclipse.jst.server.core.IWebModule in project webtools.servertools by eclipse.

the class TomcatServerBehaviour method publishDir.

/**
 * Publish a web module.
 *
 * @param deltaKind
 * @param p
 * @param module
 * @param monitor
 * @throws CoreException
 */
private void publishDir(int deltaKind, Properties p, IModule[] module, PublishHelper helper, IProgressMonitor monitor) throws CoreException {
    List<IStatus> status = new ArrayList<IStatus>();
    // Remove if requested or if previously published and are now serving without publishing
    if (deltaKind == REMOVED || getTomcatServer().isServeModulesWithoutPublish()) {
        String publishPath = (String) p.get(module[0].getId());
        if (publishPath != null) {
            try {
                File f = new File(publishPath);
                if (f.exists()) {
                    IStatus[] stat = PublishHelper.deleteDirectory(f, monitor);
                    PublishOperation2.addArrayToList(status, stat);
                }
            } catch (Exception e) {
                throw new CoreException(new Status(IStatus.WARNING, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorPublishCouldNotRemoveModule, module[0].getName()), e));
            }
            p.remove(module[0].getId());
        }
    } else {
        IPath path = getModuleDeployDirectory(module[0]);
        IModuleResource[] mr = getResources(module);
        IPath[] jarPaths = null;
        IWebModule webModule = (IWebModule) module[0].loadAdapter(IWebModule.class, monitor);
        IModule[] childModules = getServer().getChildModules(module, monitor);
        if (childModules != null && childModules.length > 0) {
            jarPaths = new IPath[childModules.length];
            for (int i = 0; i < childModules.length; i++) {
                if (webModule != null) {
                    jarPaths[i] = new Path(webModule.getURI(childModules[i]));
                } else {
                    IJ2EEModule childModule = (IJ2EEModule) childModules[i].loadAdapter(IJ2EEModule.class, monitor);
                    if (childModule != null && childModule.isBinary()) {
                        jarPaths[i] = new Path("WEB-INF/lib").append(childModules[i].getName());
                    } else {
                        jarPaths[i] = new Path("WEB-INF/lib").append(childModules[i].getName() + ".jar");
                    }
                }
            }
        }
        IStatus[] stat = helper.publishSmart(mr, path, jarPaths, monitor);
        PublishOperation2.addArrayToList(status, stat);
        p.put(module[0].getId(), path.toOSString());
    }
    PublishOperation2.throwException(status);
}
Also used : IJ2EEModule(org.eclipse.jst.server.core.IJ2EEModule) ArrayList(java.util.ArrayList) IWebModule(org.eclipse.jst.server.core.IWebModule) IOException(java.io.IOException) File(java.io.File)

Aggregations

IWebModule (org.eclipse.jst.server.core.IWebModule)16 IJ2EEModule (org.eclipse.jst.server.core.IJ2EEModule)6 IModule (org.eclipse.wst.server.core.IModule)6 ArrayList (java.util.ArrayList)5 List (java.util.List)4 CoreException (org.eclipse.core.runtime.CoreException)4 Properties (java.util.Properties)3 IStatus (org.eclipse.core.runtime.IStatus)3 IOException (java.io.IOException)2 URL (java.net.URL)2 Status (org.eclipse.core.runtime.Status)2 WebModule (org.eclipse.jst.server.tomcat.core.internal.WebModule)2 IStaticWeb (org.eclipse.wst.server.core.util.IStaticWeb)2 File (java.io.File)1 IPath (org.eclipse.core.runtime.IPath)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 IEnterpriseApplication (org.eclipse.jst.server.core.IEnterpriseApplication)1 IMemento (org.eclipse.jst.server.preview.adapter.internal.IMemento)1 XMLMemento (org.eclipse.jst.server.preview.adapter.internal.XMLMemento)1