Search in sources :

Example 11 with Context

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context in project kie-wb-common by kiegroup.

the class MoveRowsCommandTest method setup.

@Before
public void setup() {
    this.context = new Context();
    this.uiModel = new DMNGridData();
    doReturn(ruleManager).when(handler).getRuleManager();
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiNameColumn).getIndex();
    doReturn(2).when(uiExpressionEditorColumn).getIndex();
    addContextEntry(II1);
    addContextEntry(II2);
    addUiModelColumn(uiRowNumberColumn);
    addUiModelColumn(uiNameColumn);
    addUiModelColumn(uiExpressionEditorColumn);
    addUiModelRow(0);
    addUiModelRow(1);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.v1_1.Context) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) Before(org.junit.Before)

Example 12 with Context

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context in project liferay-ide by liferay.

the class LiferayTomcatServerBehavior method moveContextToAutoDeployDir.

public IStatus moveContextToAutoDeployDir(IModule module, IPath deployDir, IPath baseDir, IPath autoDeployDir, boolean noPath, boolean serverStopped) {
    // $NON-NLS-1$
    IPath confDir = baseDir.append("conf");
    // $NON-NLS-1$
    IPath serverXml = confDir.append("server.xml");
    try (InputStream newInputStream = Files.newInputStream(serverXml.toFile().toPath())) {
        Factory factory = new Factory();
        // $NON-NLS-1$
        factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
        Server publishedServer = (Server) factory.loadDocument(newInputStream);
        ServerInstance publishedInstance = new ServerInstance(publishedServer, null, null);
        IPath contextPath = null;
        if (autoDeployDir.isAbsolute()) {
            contextPath = autoDeployDir;
        } else {
            contextPath = baseDir.append(autoDeployDir);
        }
        File contextDir = contextPath.toFile();
        if (!contextDir.exists()) {
            contextDir.mkdirs();
        }
        Context context = publishedInstance.createContext(-1);
        // $NON-NLS-1$
        context.setReloadable("true");
        final String moduleName = module.getName();
        final String requiredSuffix = ProjectUtil.getRequiredSuffix(module.getProject());
        String contextName = moduleName;
        if (!moduleName.endsWith(requiredSuffix)) {
            contextName = moduleName + requiredSuffix;
        }
        // $NON-NLS-1$
        context.setSource("org.eclipse.jst.jee.server:" + contextName);
        if (// $NON-NLS-1$
        Boolean.valueOf(context.getAttributeValue("antiResourceLocking")).booleanValue()) {
            // $NON-NLS-1$ //$NON-NLS-2$
            context.setAttributeValue("antiResourceLocking", "false");
        }
        // $NON-NLS-1$
        File contextFile = new File(contextDir, contextName + ".xml");
        if (!LiferayTomcatUtil.isExtProjectContext(context)) {
            // If requested, remove path attribute
            if (noPath) {
                // $NON-NLS-1$
                context.removeAttribute("path");
            }
            // need to fix the doc base to contain entire path to help autoDeployer for Liferay
            context.setDocBase(deployDir.toOSString());
            // context.setAttributeValue("antiJARLocking", "true");
            // check to see if we need to move from conf folder
            // IPath existingContextPath = confDir.append("Catalina/localhost").append(contextFile.getName());
            // if (existingContextPath.toFile().exists()) {
            // existingContextPath.toFile().delete();
            // }
            DocumentBuilder builder = XMLUtil.getDocumentBuilder();
            Document contextDoc = builder.newDocument();
            contextDoc.appendChild(contextDoc.importNode(context.getElementNode(), true));
            XMLUtil.save(contextFile.getAbsolutePath(), contextDoc);
        }
    } catch (Exception e) {
        // confDir.toOSString() + ": " + e.getMessage());
        return new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorPublishConfiguration, new String[] { e.getLocalizedMessage() }), e);
    } finally {
    // monitor.done();
    }
    return Status.OK_STATUS;
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) Server(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server) IServer(org.eclipse.wst.server.core.IServer) DocumentBuilder(javax.xml.parsers.DocumentBuilder) InputStream(java.io.InputStream) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance) Document(org.w3c.dom.Document) File(java.io.File) CoreException(org.eclipse.core.runtime.CoreException)

Example 13 with Context

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context in project liferay-ide by liferay.

the class LiferayTomcatUtil method loadContextFile.

public static Context loadContextFile(File contextFile) {
    Context context = null;
    if (contextFile != null && contextFile.exists()) {
        try (InputStream fis = Files.newInputStream(contextFile.toPath())) {
            Factory factory = new Factory();
            // $NON-NLS-1$
            factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
            context = (Context) factory.loadDocument(fis);
            if (context != null) {
                String path = context.getPath();
                // If path attribute is not set, derive from file name
                if (path == null) {
                    String fileName = contextFile.getName();
                    // $NON-NLS-1$
                    path = fileName.substring(0, fileName.length() - ".xml".length());
                    if (// $NON-NLS-1$
                    "ROOT".equals(path))
                        path = StringPool.EMPTY;
                    context.setPath(StringPool.FORWARD_SLASH + path);
                }
            }
        } catch (Exception e) {
        // may be a spurious xml file in the host dir?
        }
    }
    return context;
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) InputStream(java.io.InputStream) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) NoSuchFileException(java.nio.file.NoSuchFileException) CoreException(org.eclipse.core.runtime.CoreException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 14 with Context

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context in project liferay-ide by liferay.

the class LiferayPublishOperation method publishDir.

private void publishDir(IModule module2, List status, IProgressMonitor monitor) throws CoreException {
    final IPath path = server.getModuleDeployDirectory(module2);
    // Remove if requested or if previously published and are now serving without publishing
    if (kind == IServer.PUBLISH_CLEAN || deltaKind == ServerBehaviourDelegate.REMOVED || server.getTomcatServer().isServeModulesWithoutPublish()) {
        File f = path.toFile();
        if (f.exists()) {
            try {
                IPath baseDir = server.getRuntimeBaseDirectory();
                // $NON-NLS-1$ //$NON-NLS-2$
                IPath serverXml = baseDir.append("conf").append("server.xml");
                ServerInstance oldInstance = TomcatVersionHelper.getCatalinaServerInstance(serverXml, null, null);
                // $NON-NLS-1$
                IPath contextDir = oldInstance.getContextXmlDirectory(baseDir.append("conf"));
                // $NON-NLS-1$
                String contextFileName = path.lastSegment() + ".xml";
                File contextFile = contextDir.append(contextFileName).toFile();
                if (contextFile.exists()) {
                    contextFile.delete();
                }
                File autoDeployDir = baseDir.append(server.getLiferayTomcatServer().getAutoDeployDirectory()).toFile();
                File autoDeployFile = new File(autoDeployDir, contextFileName);
                if (autoDeployFile.exists()) {
                    autoDeployFile.delete();
                }
            } catch (Exception e) {
                // $NON-NLS-1$
                LiferayTomcatPlugin.logError("Could not delete context xml file.", e);
            }
            IStatus[] stat = PublishHelper.deleteDirectory(f, monitor);
            addArrayToList(status, stat);
        }
        if (deltaKind == ServerBehaviourDelegate.REMOVED || server.getTomcatServer().isServeModulesWithoutPublish())
            return;
    }
    IPath baseDir = server.getTomcatServer().getRuntimeBaseDirectory();
    IPath autoDeployDir = new Path(server.getLiferayTomcatServer().getAutoDeployDirectory());
    boolean serverStopped = server.getServer().getServerState() == IServer.STATE_STOPPED;
    if (kind == IServer.PUBLISH_CLEAN || kind == IServer.PUBLISH_FULL) {
        IModuleResource[] mr = server.getResources(module);
        IStatus[] stat = helper.publishFull(mr, path, monitor);
        addArrayToList(status, stat);
        clearWebXmlDescriptors(module2.getProject(), path, monitor);
        server.moveContextToAutoDeployDir(module2, path, baseDir, autoDeployDir, true, serverStopped);
        return;
    }
    IModuleResourceDelta[] delta = server.getPublishedResourceDelta(module);
    // check if we have a anti*Locking directory temp files and copy the resources out there as well
    File[] antiDirs = new File[0];
    try {
        File tempDir = // $NON-NLS-1$
        server.getLiferayTomcatServer().getTomcatRuntime().getRuntime().getLocation().append("temp").toFile();
        antiDirs = tempDir.listFiles(new FilenameFilter() {

            public boolean accept(File dir, String name) {
                return name.endsWith(path.lastSegment());
            }
        });
    } catch (Exception e) {
    }
    int size = delta.length;
    for (int i = 0; i < size; i++) {
        IStatus[] stat = helper.publishDelta(delta[i], path, monitor);
        for (File antiDir : antiDirs) {
            if (antiDir.exists()) {
                try {
                    helper.publishDelta(delta[i], new Path(antiDir.getCanonicalPath()), monitor);
                } catch (Exception e) {
                // best effort
                }
            }
        }
        addArrayToList(status, stat);
    }
    // check to see if we need to re-invoke the liferay plugin deployer
    String[] paths = new String[] { // $NON-NLS-1$ //$NON-NLS-2$
    WEB_XML_PATH, // $NON-NLS-1$ //$NON-NLS-2$
    "WEB-INF/portlet.xml", // $NON-NLS-1$ //$NON-NLS-2$
    "WEB-INF/liferay-portlet.xml", // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
    "WEB-INF/liferay-display.xml", // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
    "WEB-INF/liferay-look-and-feel.xml", // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
    "WEB-INF/liferay-hook.xml", // $NON-NLS-1$//$NON-NLS-2$
    "WEB-INF/liferay-layout-templates.xml", // $NON-NLS-1$//$NON-NLS-2$
    "WEB-INF/liferay-plugin-package.properties", "WEB-INF/liferay-plugin-package.xml", // $NON-NLS-1$ //$NON-NLS-2$
    "WEB-INF/server-config.wsdd" };
    for (IModuleResourceDelta del : delta) {
        if (ComponentUtil.containsMember(del, paths) || isHookProjectDelta(del)) {
            clearWebXmlDescriptors(module2.getProject(), path, monitor);
            server.moveContextToAutoDeployDir(module2, path, baseDir, autoDeployDir, true, serverStopped);
            break;
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) IModuleResourceDelta(org.eclipse.wst.server.core.model.IModuleResourceDelta) CoreException(org.eclipse.core.runtime.CoreException) FilenameFilter(java.io.FilenameFilter) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance) ModuleFile(org.eclipse.wst.server.core.util.ModuleFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 15 with Context

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context in project webtools.servertools by eclipse.

the class Tomcat85Configuration method modifyWebModule.

/**
 * Change a web module.
 * @param index int
 * @param docBase java.lang.String
 * @param path java.lang.String
 * @param reloadable boolean
 */
public void modifyWebModule(int index, String docBase, String path, boolean reloadable) {
    try {
        Context context = serverInstance.getContext(index);
        if (context != null) {
            context.setPath(path);
            context.setDocBase(docBase);
            context.setReloadable(reloadable ? "true" : "false");
            isServerDirty = true;
            WebModule module = new WebModule(path, docBase, null, reloadable);
            firePropertyChangeEvent(MODIFY_WEB_MODULE_PROPERTY, new Integer(index), module);
        }
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Error modifying web module " + index, e);
    }
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)58 Context (com.microsoft.z3.Context)36 CoreException (org.eclipse.core.runtime.CoreException)35 Test (org.junit.Test)24 BoolExpr (com.microsoft.z3.BoolExpr)23 List (java.util.List)20 IOException (java.io.IOException)18 ServerInstance (org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)18 Context (org.kie.workbench.common.dmn.api.definition.v1_1.Context)17 HashMap (java.util.HashMap)16 File (java.io.File)14 Map (java.util.Map)14 ArrayList (java.util.ArrayList)13 Solver (com.microsoft.z3.Solver)12 Status (com.microsoft.z3.Status)12 IPath (org.eclipse.core.runtime.IPath)12 IStatus (org.eclipse.core.runtime.IStatus)12 Status (org.eclipse.core.runtime.Status)11 Factory (org.eclipse.jst.server.tomcat.core.internal.xml.Factory)11 Z3Exception (com.microsoft.z3.Z3Exception)9