Search in sources :

Example 21 with Context

use of org.kie.workbench.common.dmn.api.definition.v1_1.Context in project webtools.servertools by eclipse.

the class TomcatVersionHelper method publishCatalinaContextConfig.

/**
 * Add context configuration found in META-INF/context.xml files
 * present in projects to published server.xml.  Used by
 * Tomcat 4.1, 5.0, and 5.5 which support use of META-INF/context.xml
 * in some form.
 *
 * @param baseDir absolute path to catalina instance directory
 * @param webappsDir absolute path to deployment directory
 * @param monitor a progress monitor or null
 * @return result of operation
 */
public static IStatus publishCatalinaContextConfig(IPath baseDir, IPath webappsDir, IProgressMonitor monitor) {
    if (Trace.isTraceEnabled())
        Trace.trace(Trace.FINER, "Apply context configurations");
    IPath confDir = baseDir.append("conf");
    try {
        monitor = ProgressUtil.getMonitorFor(monitor);
        monitor.beginTask(Messages.publishConfigurationTask, 300);
        monitor.subTask(Messages.publishContextConfigTask);
        Factory factory = new Factory();
        factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
        Server publishedServer = (Server) factory.loadDocument(new FileInputStream(confDir.append("server.xml").toFile()));
        ServerInstance publishedInstance = new ServerInstance(publishedServer, null, null);
        monitor.worked(100);
        boolean modified = false;
        MultiStatus ms = new MultiStatus(TomcatPlugin.PLUGIN_ID, 0, Messages.publishContextConfigTask, null);
        Context[] contexts = publishedInstance.getContexts();
        if (contexts != null) {
            for (int i = 0; i < contexts.length; i++) {
                Context context = contexts[i];
                monitor.subTask(NLS.bind(Messages.checkingContextTask, new String[] { context.getPath() }));
                if (addCatalinaContextConfig(webappsDir, context, ms)) {
                    modified = true;
                }
            }
        }
        monitor.worked(100);
        if (modified) {
            monitor.subTask(Messages.savingContextConfigTask);
            factory.save(confDir.append("server.xml").toOSString());
        }
        // If problem(s) occurred adding context configurations, return error status
        if (ms.getChildren().length > 0) {
            return ms;
        }
        if (Trace.isTraceEnabled())
            Trace.trace(Trace.FINER, "Server.xml updated with context.xml configurations");
        return Status.OK_STATUS;
    } catch (Exception e) {
        Trace.trace(Trace.WARNING, "Could not apply context configurations to published Tomcat configuration from " + 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();
    }
}
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) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) MultiStatus(org.eclipse.core.runtime.MultiStatus) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)

Example 22 with Context

use of org.kie.workbench.common.dmn.api.definition.v1_1.Context in project webtools.servertools by eclipse.

the class TomcatVersionHelper method loadContextFile.

private static Context loadContextFile(File contextFile) {
    FileInputStream fis = null;
    Context context = null;
    if (contextFile != null && contextFile.exists()) {
        try {
            Factory factory = new Factory();
            factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
            fis = new FileInputStream(contextFile);
            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();
                    path = fileName.substring(0, fileName.length() - ".xml".length());
                    if ("ROOT".equals(path))
                        path = "";
                    // Assuming this use for "#" since Tomcat has "reserved" this use of "#" since 5.5.
                    path = path.replace('#', '/');
                    context.setPath("/" + path);
                }
            }
        } catch (Exception e) {
            // may be a spurious xml file in the host dir?
            Trace.trace(Trace.FINER, "Unable to read context " + contextFile.getAbsolutePath());
        } finally {
            try {
                fis.close();
            } catch (IOException e) {
            // ignore
            }
        }
    }
    return context;
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException)

Example 23 with Context

use of org.kie.workbench.common.dmn.api.definition.v1_1.Context in project webtools.servertools by eclipse.

the class TomcatVersionHelper method addCatalinaContextConfig.

/**
 * If the specified Context is linked to a project, try to
 * update it with any configuration from a META-INF/context.xml found
 * relative to the specified web applications directory and context docBase.
 *
 * @param webappsDir Path to server's web applications directory.
 * @param context Context object to receive context.xml contents.
 * @param ms MultiStatus object to receive error status.
 * @return Returns true if context is modified.
 */
private static boolean addCatalinaContextConfig(IPath webappsDir, Context context, MultiStatus ms) {
    boolean modified = false;
    String source = context.getSource();
    if (source != null && source.length() > 0) {
        File docBase = new File(context.getDocBase());
        if (!docBase.isAbsolute())
            docBase = new File(webappsDir.toOSString(), docBase.getPath());
        try {
            Context contextConfig = loadCatalinaContextConfig(docBase);
            if (null != contextConfig) {
                if (context.hasChildNodes())
                    context.removeChildren();
                contextConfig.copyChildrenTo(context);
                Map attrs = contextConfig.getAttributes();
                Iterator iter = attrs.keySet().iterator();
                while (iter.hasNext()) {
                    String name = (String) iter.next();
                    if (!name.equalsIgnoreCase("path") && !name.equalsIgnoreCase("docBase") && !name.equalsIgnoreCase("source")) {
                        String value = (String) attrs.get(name);
                        context.setAttributeValue(name, value);
                    }
                }
                modified = true;
            }
        } catch (Exception e) {
            String contextPath = context.getPath();
            if (contextPath.startsWith("/")) {
                contextPath = contextPath.substring(1);
            }
            Trace.trace(Trace.SEVERE, "Error reading context.xml file for " + contextPath, e);
            IStatus s = new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotLoadContextXml, contextPath), e);
            ms.add(s);
        }
    }
    return modified;
}
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) IStatus(org.eclipse.core.runtime.IStatus) Iterator(java.util.Iterator) JarFile(java.util.jar.JarFile) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException)

Example 24 with Context

use of org.kie.workbench.common.dmn.api.definition.v1_1.Context in project webtools.servertools by eclipse.

the class TomcatVersionHelper method loadSeparateContextFiles.

private static void loadSeparateContextFiles(File contextDir, Factory factory, Map<File, Context> projectContexts) {
    File[] contextFiles = contextDir.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".xml");
        }
    });
    for (int j = 0; j < contextFiles.length; j++) {
        File ctx = contextFiles[j];
        Context context = loadContextFile(ctx);
        if (context != null) {
            // TODO Handle non-project contexts when their removal can be addressed
            String memento = context.getSource();
            if (memento != null) {
                projectContexts.put(ctx, context);
            }
        }
    }
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) FilenameFilter(java.io.FilenameFilter) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 25 with Context

use of org.kie.workbench.common.dmn.api.definition.v1_1.Context in project webtools.servertools by eclipse.

the class TomcatVersionHelper method getCatalinaServerInstance.

/**
 * Gets a ServerInstance for the specified server.xml, Service name,
 * and Host name.  Returns null if server.xml does not exist
 * or an error occurs.
 *
 * @param serverXml path to previously published server.xml
 * @param serviceName name of Service to be used by this instance or null
 * @param hostName name of Host to be used by this instance or null
 * @return ServerInstance for specified server.xml using specified
 * Service and Host names.  null if server.xml does not exist.
 * @throws FileNotFoundException should not occur since existence is tested
 * @throws IOException if there is an error reading server.xml
 * @throws SAXException if there is a syntax error in server.xml
 */
public static ServerInstance getCatalinaServerInstance(IPath serverXml, String serviceName, String hostName) throws FileNotFoundException, IOException, SAXException {
    ServerInstance serverInstance = null;
    Factory factory = new Factory();
    factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
    File serverFile = serverXml.toFile();
    if (serverFile.exists()) {
        Server server = (Server) factory.loadDocument(new FileInputStream(serverFile));
        serverInstance = new ServerInstance(server, serviceName, hostName);
        IPath contextPath = serverInstance.getContextXmlDirectory(serverXml.removeLastSegments(1));
        File contextDir = contextPath.toFile();
        if (contextDir.exists()) {
            Map<File, Context> projectContexts = new HashMap<File, Context>();
            loadSeparateContextFiles(contextPath.toFile(), factory, projectContexts);
            // add any separately saved contexts
            Host host = serverInstance.getHost();
            Collection contexts = projectContexts.values();
            Iterator iter = contexts.iterator();
            while (iter.hasNext()) {
                Context context = (Context) iter.next();
                host.importNode(context.getElementNode(), true);
            }
        // TODO Add handling for non-project contexts when there removal can be addressed
        }
    }
    return serverInstance;
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) Server(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Iterator(java.util.Iterator) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) Collection(java.util.Collection) Host(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Host) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance) JarFile(java.util.jar.JarFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

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)25 BoolExpr (com.microsoft.z3.BoolExpr)23 List (java.util.List)21 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 ArrayList (java.util.ArrayList)15 Map (java.util.Map)14 File (java.io.File)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 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)10