Search in sources :

Example 11 with Context

use of org.eclipse.jst.server.tomcat.core.internal.xml.server32.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.server32.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.server32.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.server32.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)

Example 15 with Context

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

the class Tomcat85PublishModuleVisitor method endVisitWebComponent.

/**
 * {@inheritDoc}
 */
@Override
public void endVisitWebComponent(IVirtualComponent component) throws CoreException {
    // track context changes, don't rewrite if not needed
    boolean dirty = false;
    IModule module = ServerUtil.getModule(component.getProject());
    // we need this for the user-specified context path
    Context context = findContext(module);
    if (context == null) {
        String name = module != null ? module.getName() : component.getName();
        Trace.trace(Trace.SEVERE, "Could not find context for module " + name);
        throw new CoreException(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorPublishContextNotFound, name), null));
    }
    dirty = includeProjectContextXml(component, context);
    dirty = updateDocBaseAndPath(component, context);
    // Add WEB-INF/classes elements as PreResources
    for (Iterator iterator = virtualClassClasspathElements.iterator(); iterator.hasNext(); ) {
        Object virtualClassClasspathElement = iterator.next();
        PreResources preResources = (PreResources) context.getResources().createElement("PreResources");
        preResources.setClassName("org.apache.catalina.webresources.DirResourceSet");
        preResources.setBase(virtualClassClasspathElement.toString());
        preResources.setWebAppMount("/WEB-INF/classes");
        preResources.setInternalPath("/");
        preResources.setClassLoaderOnly("false");
    }
    virtualClassClasspathElements.clear();
    // Add Jars as JarResources if a jar, or as PostResources if a utility project
    for (Iterator iterator = virtualJarClasspathElements.iterator(); iterator.hasNext(); ) {
        Object virtualJarClassClasspathElement = iterator.next();
        String jarPath = virtualJarClassClasspathElement.toString();
        if (jarPath.endsWith(".jar")) {
            JarResources jarResources = (JarResources) context.getResources().createElement("JarResources");
            jarResources.setClassName("org.apache.catalina.webresources.JarResourceSet");
            jarResources.setBase(jarPath);
            jarResources.setWebAppMount("/WEB-INF/classes");
            jarResources.setInternalPath("/");
            jarResources.setClassLoaderOnly("true");
        } else {
            PostResources postResources = (PostResources) context.getResources().createElement("PostResources");
            postResources.setClassName("org.apache.catalina.webresources.DirResourceSet");
            postResources.setBase(jarPath);
            postResources.setWebAppMount("/WEB-INF/classes");
            postResources.setInternalPath("/");
            postResources.setClassLoaderOnly("false");
            // Map META-INF tld files to WEB-INF
            File metaInfDir = new File(jarPath + "/META-INF");
            if (metaInfDir.isDirectory() && metaInfDir.exists()) {
                // Map META-INF directory directly to /META-INF
                postResources = (PostResources) context.getResources().createElement("PostResources");
                postResources.setClassName("org.apache.catalina.webresources.DirResourceSet");
                postResources.setBase(metaInfDir.getPath());
                postResources.setWebAppMount("/META-INF");
                postResources.setInternalPath("/");
                postResources.setClassLoaderOnly("false");
                File[] tldFiles = metaInfDir.listFiles(new FileFilter() {

                    public boolean accept(File file) {
                        if (file.isFile() && file.getName().endsWith(".tld")) {
                            return true;
                        }
                        return false;
                    }
                });
                for (int i = 0; i < tldFiles.length; i++) {
                    postResources = (PostResources) context.getResources().createElement("PostResources");
                    postResources.setClassName("org.apache.catalina.webresources.FileResourceSet");
                    postResources.setBase(tldFiles[0].getPath());
                    postResources.setWebAppMount("/WEB-INF/" + tldFiles[0].getName());
                    postResources.setInternalPath("/");
                    postResources.setClassLoaderOnly("false");
                }
            }
        }
    }
    virtualJarClasspathElements.clear();
    Set<String> rtPathsProcessed = new HashSet<String>();
    Set<String> locationsIncluded = new HashSet<String>();
    String docBase = context.getDocBase();
    locationsIncluded.add(docBase);
    Map<String, String> retryLocations = new HashMap<String, String>();
    IVirtualResource[] virtualResources = component.getRootFolder().getResources("");
    // Loop over the module's resources
    for (int i = 0; i < virtualResources.length; i++) {
        String rtPath = virtualResources[i].getRuntimePath().toString();
        // If this runtime path has not yet been processed
        if (!rtPathsProcessed.contains(rtPath)) {
            // If not a Java related resource
            if (!"/WEB-INF/classes".equals(rtPath)) {
                // Get all resources for this runtime path
                IResource[] underlyingResources = virtualResources[i].getUnderlyingResources();
                // to a mapping in the .components file
                if ("/".equals(rtPath)) {
                    for (int j = 0; j < underlyingResources.length; j++) {
                        IPath resLoc = underlyingResources[j].getLocation();
                        String location = resLoc.toOSString();
                        if (!location.equals(docBase)) {
                            PreResources preResources = (PreResources) context.getResources().createElement("PreResources");
                            preResources.setClassName("org.apache.catalina.webresources.DirResourceSet");
                            preResources.setBase(location);
                            preResources.setWebAppMount("/");
                            preResources.setInternalPath("/");
                            preResources.setClassLoaderOnly("false");
                            // Add to the set of locations included
                            locationsIncluded.add(location);
                        }
                    }
                } else // Else this runtime path is something other than "/"
                {
                    int idx = rtPath.lastIndexOf('/');
                    // If a "normal" runtime path
                    if (idx >= 0) {
                        // Get the name of the last segment in the runtime path
                        String lastSegment = rtPath.substring(idx + 1);
                        // Check the underlying resources to determine which correspond to mappings
                        for (int j = 0; j < underlyingResources.length; j++) {
                            IPath resLoc = underlyingResources[j].getLocation();
                            String location = resLoc.toOSString();
                            // from the .contents file.
                            if (!lastSegment.equals(resLoc.lastSegment())) {
                                PreResources preResources = (PreResources) context.getResources().createElement("PreResources");
                                preResources.setClassName("org.apache.catalina.webresources.DirResourceSet");
                                preResources.setBase(location);
                                preResources.setWebAppMount(rtPath);
                                preResources.setInternalPath("/");
                                preResources.setClassLoaderOnly("false");
                                // Add to the set of locations included
                                locationsIncluded.add(location);
                            } else // Else last segment of runtime path did match the last segment
                            // of the location.  We likely have a subfolder of a mapping
                            // that matches a portion of the runtime path.
                            {
                                // Since we can't be sure, save so it can be check again later
                                retryLocations.put(location, rtPath);
                            }
                        }
                    }
                }
            }
            // Add the runtime path to those already processed
            rtPathsProcessed.add(rtPath);
        }
    }
    // If there are locations to retry, add any not yet included in extra paths setting
    if (!retryLocations.isEmpty()) {
        // Remove retry locations already included in the extra paths
        for (Iterator iterator = retryLocations.keySet().iterator(); iterator.hasNext(); ) {
            String location = (String) iterator.next();
            for (Iterator iterator2 = locationsIncluded.iterator(); iterator2.hasNext(); ) {
                String includedLocation = (String) iterator2.next();
                if (location.equals(includedLocation) || location.startsWith(includedLocation + File.separator)) {
                    iterator.remove();
                    break;
                }
            }
        }
        // If any entries are left, include them in the extra paths
        if (!retryLocations.isEmpty()) {
            for (Iterator iterator = retryLocations.entrySet().iterator(); iterator.hasNext(); ) {
                Map.Entry entry = (Map.Entry) iterator.next();
                String location = (String) entry.getKey();
                String rtPath = (String) entry.getValue();
                PreResources preResources = (PreResources) context.getResources().createElement("PreResources");
                preResources.setClassName("org.apache.catalina.webresources.DirResourceSet");
                preResources.setBase(location);
                preResources.setWebAppMount(rtPath);
                preResources.setInternalPath("/");
                preResources.setClassLoaderOnly("false");
            }
        }
    }
    if (!virtualDependentResources.isEmpty()) {
        for (Map.Entry<String, List<String>> entry : virtualDependentResources.entrySet()) {
            String rtPath = entry.getKey();
            List<String> locations = entry.getValue();
            for (String location : locations) {
                PostResources postResources = (PostResources) context.getResources().createElement("PostResources");
                postResources.setClassName("org.apache.catalina.webresources.DirResourceSet");
                postResources.setBase(location);
                postResources.setWebAppMount(rtPath.length() > 0 ? rtPath : "/");
                postResources.setInternalPath("/");
                postResources.setClassLoaderOnly("false");
            }
        }
    }
    virtualDependentResources.clear();
    if (dirty) {
    // TODO If writing to separate context XML files, save "dirty" status for later use
    }
}
Also used : IModule(org.eclipse.wst.server.core.IModule) HashMap(java.util.HashMap) Iterator(java.util.Iterator) List(java.util.List) FileFilter(java.io.FileFilter) JarResources(org.eclipse.jst.server.tomcat.core.internal.xml.server40.JarResources) HashSet(java.util.HashSet) Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) IVirtualResource(org.eclipse.wst.common.componentcore.resources.IVirtualResource) PreResources(org.eclipse.jst.server.tomcat.core.internal.xml.server40.PreResources) CoreException(org.eclipse.core.runtime.CoreException) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) PostResources(org.eclipse.jst.server.tomcat.core.internal.xml.server40.PostResources) IResource(org.eclipse.core.resources.IResource)

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)34 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)17 Context (org.kie.workbench.common.dmn.api.definition.v1_1.Context)17 HashMap (java.util.HashMap)16 Map (java.util.Map)14 File (java.io.File)13 ArrayList (java.util.ArrayList)13 Solver (com.microsoft.z3.Solver)12 Status (com.microsoft.z3.Status)12 IPath (org.eclipse.core.runtime.IPath)11 IStatus (org.eclipse.core.runtime.IStatus)11 Status (org.eclipse.core.runtime.Status)11 Factory (org.eclipse.jst.server.tomcat.core.internal.xml.Factory)11 Z3Exception (com.microsoft.z3.Z3Exception)9