Search in sources :

Example 1 with ClassMatcher

use of org.voltdb.compiler.ClassMatcher in project voltdb by VoltDB.

the class UpdateApplicationBase method modifyCatalogClasses.

/**
     * @return NUll if no classes changed, otherwise return the update jar file.
     * @throws ClassNotFoundException
     * @throws IOException
     */
private static InMemoryJarfile modifyCatalogClasses(Catalog catalog, InMemoryJarfile jarfile, String deletePatterns, InMemoryJarfile newJarfile, boolean isXDCR) throws ClassNotFoundException, IOException {
    // modify the old jar in place based on the @UpdateClasses inputs, and then
    // recompile it if necessary
    boolean deletedClasses = false;
    if (deletePatterns != null) {
        String[] patterns = deletePatterns.split(",");
        ClassMatcher matcher = new ClassMatcher();
        // Need to concatenate all the classnames together for ClassMatcher
        String currentClasses = "";
        for (String classname : jarfile.getLoader().getClassNames()) {
            currentClasses = currentClasses.concat(classname + "\n");
        }
        matcher.m_classList = currentClasses;
        for (String pattern : patterns) {
            ClassNameMatchStatus status = matcher.addPattern(pattern.trim());
            if (status == ClassNameMatchStatus.MATCH_FOUND) {
                deletedClasses = true;
            }
        }
        for (String classname : matcher.getMatchedClassList()) {
            jarfile.removeClassFromJar(classname);
        }
    }
    boolean foundClasses = false;
    if (newJarfile != null) {
        for (Entry<String, byte[]> e : newJarfile.entrySet()) {
            String filename = e.getKey();
            if (!filename.endsWith(".class")) {
                continue;
            }
            foundClasses = true;
            jarfile.put(e.getKey(), e.getValue());
        }
    }
    if (!deletedClasses && !foundClasses) {
        return null;
    }
    compilerLog.info("Updating java classes available to stored procedures");
    VoltCompiler compiler = new VoltCompiler(isXDCR);
    compiler.compileInMemoryJarfile(jarfile);
    return jarfile;
}
Also used : ClassMatcher(org.voltdb.compiler.ClassMatcher) VoltCompiler(org.voltdb.compiler.VoltCompiler) ClassNameMatchStatus(org.voltdb.compiler.ClassMatcher.ClassNameMatchStatus)

Aggregations

ClassMatcher (org.voltdb.compiler.ClassMatcher)1 ClassNameMatchStatus (org.voltdb.compiler.ClassMatcher.ClassNameMatchStatus)1 VoltCompiler (org.voltdb.compiler.VoltCompiler)1