exo-jcr SVN: r3731 - in ws/trunk/exo.ws.rest.ext/src: test/java/org/exoplatform/services/rest/ext/groovy and 1 other directories.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-12-27 08:35:46 -0500 (Mon, 27 Dec 2010)
New Revision: 3731
Added:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ExtendedGroovyClassLoader.java
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/SourceFile.java
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/SourceFolder.java
ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/ExtendedClassLoaderTest.java
Removed:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ClassPath.java
Modified:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ClassPathEntry.java
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyClassLoaderProvider.java
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java
ws/trunk/exo.ws.rest.ext/src/test/resources/GMain1.groovy
ws/trunk/exo.ws.rest.ext/src/test/resources/groovy1.groovy
ws/trunk/exo.ws.rest.ext/src/test/resources/groovy2.groovy
ws/trunk/exo.ws.rest.ext/src/test/resources/groovy3.groovy
Log:
EXOJCR-1105
Deleted: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ClassPath.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ClassPath.java 2010-12-27 13:22:15 UTC (rev 3730)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ClassPath.java 2010-12-27 13:35:46 UTC (rev 3731)
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.rest.ext.groovy;
-
-/**
- * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey Parfonov</a>
- * @version $Id$
- */
-public class ClassPath
-{
- private ClassPathEntry[] entries;
-
- private String[] extensions;
-
- public ClassPath(ClassPathEntry[] entries, String[] extensions)
- {
- this.entries = entries;
- this.extensions = extensions;
- }
-
- public ClassPathEntry[] getEntries()
- {
- return entries;
- }
-
- public String[] getExtensions()
- {
- return extensions;
- }
-}
Modified: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ClassPathEntry.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ClassPathEntry.java 2010-12-27 13:22:15 UTC (rev 3730)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ClassPathEntry.java 2010-12-27 13:35:46 UTC (rev 3731)
@@ -21,44 +21,22 @@
import java.net.URL;
/**
- * Item of Groovy classpath. It may describe source file of folder that contains
- * source files. If <code>ClassPathEntry</code> point to the folder then like
- * Java package structure is expected.
+ * Item of Groovy classpath.
*
* @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey Parfonov</a>
* @version $Id$
*/
-public class ClassPathEntry
+public abstract class ClassPathEntry
{
- /** Type of class-path entry. */
- public enum EntryType {
- SRC_DIR, FILE
- }
+ private final URL path;
- /** Type of entry. */
- private EntryType type;
-
- /** URL. */
- private URL path;
-
- public ClassPathEntry(EntryType type, URL path)
+ public ClassPathEntry(URL path)
{
- this.type = type;
this.path = path;
}
- public EntryType getType()
- {
- return type;
- }
-
public URL getPath()
{
return path;
}
-
- public void setPath(URL path)
- {
- this.path = path;
- }
}
Modified: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java 2010-12-27 13:22:15 UTC (rev 3730)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java 2010-12-27 13:35:46 UTC (rev 3731)
@@ -39,27 +39,19 @@
*/
public class DefaultGroovyResourceLoader implements GroovyResourceLoader
{
- private static final String[] DEFAULT_SCRIPT_EXTENSIONS = new String[]{".groovy"};
+ private static final String DEFAULT_SOURCE_FILE_EXTENSION = ".groovy";
- protected final String[] extensions;
-
- protected final URL[] roots;
-
- protected final URL[] files;
-
// TODO need configurable ?
private int maxEntries = 512;
protected final Map<String, URL> resources;
+ protected final URL[] roots;
+
@SuppressWarnings("serial")
- public DefaultGroovyResourceLoader(URL[] roots, URL[] files, String[] extensions) throws MalformedURLException
+ public DefaultGroovyResourceLoader(URL[] roots) throws MalformedURLException
{
- this.files = files;
this.roots = new URL[roots.length];
- if (extensions == null || extensions.length == 0)
- extensions = DEFAULT_SCRIPT_EXTENSIONS;
- this.extensions = extensions;
for (int i = 0; i < roots.length; i++)
{
String str = roots[i].toString();
@@ -68,7 +60,8 @@
else
this.roots[i] = roots[i];
}
- resources = Collections.synchronizedMap(new LinkedHashMap<String, URL>() {
+ resources = Collections.synchronizedMap(new LinkedHashMap<String, URL>()
+ {
protected boolean removeEldestEntry(Entry<String, URL> eldest)
{
return size() > maxEntries;
@@ -76,16 +69,6 @@
});
}
- public DefaultGroovyResourceLoader(URL[] roots, URL[] files) throws MalformedURLException
- {
- this(roots, files, null);
- }
-
- public DefaultGroovyResourceLoader(URL[] roots) throws MalformedURLException
- {
- this(roots, new URL[0]);
- }
-
public DefaultGroovyResourceLoader(URL root) throws MalformedURLException
{
this(new URL[]{root});
@@ -94,30 +77,26 @@
/**
* {@inheritDoc}
*/
- public final URL loadGroovySource(String classname) throws MalformedURLException
+ public final URL loadGroovySource(String filename) throws MalformedURLException
{
URL resource = null;
- final String baseName = classname.replace('.', '/');
- String[] extensions = getScriptExtensions();
- for (int i = 0; i < extensions.length && resource == null; i++)
+ final String ffilename = filename.replace('.', '/') + getSourceFileExtension();
+ try
{
- final String ext = extensions[i];
- try
+ resource = AccessController.doPrivileged(new PrivilegedExceptionAction<URL>()
{
- resource = AccessController.doPrivileged(new PrivilegedExceptionAction<URL>() {
- public URL run() throws MalformedURLException
- {
- return getResource(baseName + ext);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- Throwable cause = e.getCause();
- // MalformedURLException
- throw (MalformedURLException)cause;
- }
+ public URL run() throws MalformedURLException
+ {
+ return getResource(ffilename);
+ }
+ });
}
+ catch (PrivilegedActionException e)
+ {
+ Throwable cause = e.getCause();
+ // MalformedURLException
+ throw (MalformedURLException)cause;
+ }
return resource;
}
@@ -131,12 +110,6 @@
boolean inCache = resource != null;
if (inCache && !checkResource(resource))
resource = null; // Resource in cache is unreachable.
- for (int i = 0; i < files.length && resource == null; i++)
- {
- URL tmp = files[i];
- if (tmp.toString().endsWith(filename) && checkResource(tmp))
- resource = tmp;
- }
for (int i = 0; i < roots.length && resource == null; i++)
{
URL tmp = new URL(roots[i], filename);
@@ -148,10 +121,14 @@
else if (inCache)
resources.remove(filename);
}
-
return resource;
}
+ protected String getSourceFileExtension()
+ {
+ return DEFAULT_SOURCE_FILE_EXTENSION;
+ }
+
protected boolean checkResource(URL resource)
{
try
@@ -164,9 +141,4 @@
return false;
}
}
-
- protected String[] getScriptExtensions()
- {
- return extensions;
- }
}
Added: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ExtendedGroovyClassLoader.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ExtendedGroovyClassLoader.java (rev 0)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ExtendedGroovyClassLoader.java 2010-12-27 13:35:46 UTC (rev 3731)
@@ -0,0 +1,287 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.rest.ext.groovy;
+
+import groovy.lang.GroovyClassLoader;
+
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.ModuleNode;
+import org.codehaus.groovy.control.CompilationFailedException;
+import org.codehaus.groovy.control.CompilationUnit;
+import org.codehaus.groovy.control.CompilerConfiguration;
+import org.codehaus.groovy.control.Phases;
+import org.codehaus.groovy.control.SourceUnit;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.CodeSource;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author <a href="andrew00x(a)gmail.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+@SuppressWarnings({"rawtypes", "unchecked"})
+public class ExtendedGroovyClassLoader extends GroovyClassLoader
+{
+ public static final String CODE_BASE = "/groovy/script/jaxrs";
+
+ public static class SingleClassCollector extends GroovyClassLoader.ClassCollector
+ {
+ protected final CompilationUnit cunit;
+ protected final SourceUnit sunit;
+ protected Class target;
+
+ protected SingleClassCollector(ExtendedInnerLoader cl, CompilationUnit cunit, SourceUnit sunit)
+ {
+ super(cl, cunit, sunit);
+ this.cunit = cunit;
+ this.sunit = sunit;
+ }
+
+ @Override
+ protected Class createClass(byte[] code, ClassNode classNode)
+ {
+ ExtendedInnerLoader cl = (ExtendedInnerLoader)getDefiningClassLoader();
+ String classname = classNode.getName();
+ int i = classname.lastIndexOf('.');
+ if (i != -1)
+ {
+ String pkgname = classname.substring(0, i);
+ cl.definePackage(pkgname);
+ }
+ Class clazz = cl.defineClass(classNode.getName(), code, cunit.getAST().getCodeSource());
+ getLoadedClasses().add(clazz);
+ if (target == null)
+ {
+ ClassNode targetClassNode = null;
+ SourceUnit targetSunit = null;
+ ModuleNode module = classNode.getModule();
+ if (module != null)
+ {
+ targetClassNode = (ClassNode)module.getClasses().get(0);
+ targetSunit = module.getContext();
+ }
+ if (targetSunit == sunit && targetClassNode == classNode)
+ target = clazz;
+ }
+ return clazz;
+ }
+
+ public Class getTarget()
+ {
+ return target;
+ }
+ }
+
+ public static class MultipleClassCollector extends GroovyClassLoader.ClassCollector
+ {
+ protected final CompilationUnit cunit;
+ protected final Set<SourceUnit> sunitSet;
+ private final List<Class> compiledClasses;
+
+ protected MultipleClassCollector(ExtendedInnerLoader cl, CompilationUnit cunit, Set<SourceUnit> sunitSet)
+ {
+ super(cl, cunit, null);
+ this.cunit = cunit;
+ this.sunitSet = sunitSet;
+ this.compiledClasses = new ArrayList<Class>();
+ }
+
+ @Override
+ protected Class createClass(byte[] code, ClassNode classNode)
+ {
+ ExtendedInnerLoader cl = (ExtendedInnerLoader)getDefiningClassLoader();
+ String classname = classNode.getName();
+ int i = classname.lastIndexOf('.');
+ if (i != -1)
+ {
+ String pkgname = classname.substring(0, i);
+ cl.definePackage(pkgname);
+ }
+ Class clazz = cl.defineClass(classNode.getName(), code, cunit.getAST().getCodeSource());
+ getLoadedClasses().add(clazz);
+ ModuleNode module = classNode.getModule();
+ if (module != null)
+ {
+ SourceUnit currentSunit = module.getContext();
+ if (sunitSet.contains(currentSunit))
+ compiledClasses.add(clazz);
+ }
+ return clazz;
+ }
+
+ public List<Class> getCompiledClasses()
+ {
+ return compiledClasses;
+ }
+ }
+
+ public static class ExtendedInnerLoader extends GroovyClassLoader.InnerLoader
+ {
+ public ExtendedInnerLoader(ExtendedGroovyClassLoader parent)
+ {
+ super(parent);
+ }
+
+ protected Class defineClass(String name, byte[] code, CodeSource cs)
+ {
+ return super.defineClass(name, code, 0, code.length, cs);
+ }
+
+ protected void definePackage(String name) throws IllegalArgumentException
+ {
+ Package pkg = getPackage(name);
+ if (pkg == null)
+ super.definePackage(name, null, null, null, null, null, null, null);
+ }
+ }
+
+ public ExtendedGroovyClassLoader(ClassLoader classLoader)
+ {
+ super(classLoader);
+ }
+
+ public ExtendedGroovyClassLoader(GroovyClassLoader parent)
+ {
+ super(parent);
+ }
+
+ public Class parseClass(InputStream in, String fileName, SourceFile[] files) throws CompilationFailedException
+ {
+ return doParseClass(in, fileName, files, Phases.CLASS_GENERATION, null, false);
+ }
+
+ protected Class doParseClass(InputStream in, String fileName, SourceFile[] files, int phase,
+ CompilerConfiguration config, boolean shouldCacheSource) throws CompilationFailedException
+ {
+ synchronized (sourceCache)
+ {
+ Class target = (Class)sourceCache.get(fileName);
+ if (target == null)
+ {
+ CodeSource cs = new CodeSource(getCodeSource(), (java.security.cert.Certificate[])null);
+ CompilationUnit cunit = createCompilationUnit(config, cs);
+ SourceUnit targetSunit = cunit.addSource(fileName, in);
+ if (files != null)
+ {
+ for (int i = 0; i < files.length; i++)
+ cunit.addSource(files[i].getPath());
+ }
+ SingleClassCollector collector = createSingleCollector(cunit, targetSunit);
+ cunit.setClassgenCallback(collector);
+ cunit.compile(phase);
+
+ for (Iterator iter = collector.getLoadedClasses().iterator(); iter.hasNext();)
+ setClassCacheEntry((Class)iter.next());
+
+ target = collector.getTarget();
+
+ if (shouldCacheSource)
+ sourceCache.put(fileName, target);
+ }
+
+ return target;
+ }
+ }
+
+ public Class[] parseClasses(SourceFile[] files)
+ {
+ return doParseClasses(files, Phases.CLASS_GENERATION, null);
+ }
+
+ protected Class[] doParseClasses(SourceFile[] sources, int phase, CompilerConfiguration config)
+ {
+ synchronized (classCache)
+ {
+ CodeSource cs = new CodeSource(getCodeSource(), (java.security.cert.Certificate[])null);
+ CompilationUnit cunit = createCompilationUnit(config, cs);
+ Set<SourceUnit> setSunit = new HashSet<SourceUnit>();
+ for (int i = 0; i < sources.length; i++)
+ setSunit.add(cunit.addSource(sources[i].getPath()));
+ MultipleClassCollector collector = createMultipleCollector(cunit, setSunit);
+ cunit.setClassgenCallback(collector);
+ cunit.compile(phase);
+
+ for (Iterator iter = collector.getLoadedClasses().iterator(); iter.hasNext();)
+ {
+ Class clazz = (Class)iter.next();
+ setClassCacheEntry(clazz);
+ }
+ List<Class> compiledClasses = collector.getCompiledClasses();
+ return compiledClasses.toArray(new Class[compiledClasses.size()]);
+ }
+ }
+
+ /**
+ * @see groovy.lang.GroovyClassLoader#createCompilationUnit(org.codehaus.groovy.control.CompilerConfiguration,
+ * java.security.CodeSource)
+ */
+ @Override
+ protected CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource cs)
+ {
+ return new CompilationUnit(config, cs, this);
+ }
+
+ protected SingleClassCollector createSingleCollector(CompilationUnit unit, SourceUnit sunit)
+ {
+ ExtendedInnerLoader loader = AccessController.doPrivileged(new PrivilegedAction<ExtendedInnerLoader>() {
+ public ExtendedInnerLoader run()
+ {
+ return new ExtendedInnerLoader(ExtendedGroovyClassLoader.this);
+ }
+ });
+ return new SingleClassCollector(loader, unit, sunit);
+ }
+
+ protected MultipleClassCollector createMultipleCollector(CompilationUnit unit, Set<SourceUnit> setSunit)
+ {
+ ExtendedInnerLoader loader = AccessController.doPrivileged(new PrivilegedAction<ExtendedInnerLoader>() {
+ public ExtendedInnerLoader run()
+ {
+ return new ExtendedInnerLoader(ExtendedGroovyClassLoader.this);
+ }
+ });
+ return new MultipleClassCollector(loader, unit, setSunit);
+ }
+
+ protected URL getCodeSource()
+ {
+ return getCodeSource(CODE_BASE);
+ }
+
+ private URL getCodeSource(String codeBase)
+ {
+ try
+ {
+ return new URL("file", "", codeBase);
+ }
+ catch (MalformedURLException e)
+ {
+ throw new IllegalArgumentException("Unable create code source URL from: " + codeBase + ". " + e.getMessage());
+ }
+ }
+}
\ No newline at end of file
Property changes on: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ExtendedGroovyClassLoader.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyClassLoaderProvider.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyClassLoaderProvider.java 2010-12-27 13:22:15 UTC (rev 3730)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyClassLoaderProvider.java 2010-12-27 13:35:46 UTC (rev 3731)
@@ -20,14 +20,10 @@
import groovy.lang.GroovyClassLoader;
-import org.exoplatform.services.rest.ext.groovy.ClassPathEntry.EntryType;
-
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.List;
/**
* Factory of Groovy class loader. It can provide preset GroovyClassLoader
@@ -41,35 +37,31 @@
public class GroovyClassLoaderProvider
{
/** Preset default GroovyClassLoader. */
- private GroovyClassLoader defaultClassLoader;
+ private ExtendedGroovyClassLoader defaultClassLoader;
- /**
- * Create GroovyClassLoaderProvider that will use specified GroovyClassLoader
- * as default.
- *
- * @param defaultClassLoader GroovyClassLoader
- */
- public GroovyClassLoaderProvider(GroovyClassLoader defaultClassLoader)
- {
- this.defaultClassLoader = defaultClassLoader;
- }
-
+ // TODO
public GroovyClassLoaderProvider()
{
- defaultClassLoader = AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>() {
- public GroovyClassLoader run()
+ this(AccessController.doPrivileged(new PrivilegedAction<ExtendedGroovyClassLoader>()
+ {
+ public ExtendedGroovyClassLoader run()
{
- return new GroovyClassLoader(getClass().getClassLoader());
+ return new ExtendedGroovyClassLoader(getClass().getClassLoader());
}
- });
+ }));
}
+ protected GroovyClassLoaderProvider(ExtendedGroovyClassLoader defaultClassLoader)
+ {
+ this.defaultClassLoader = defaultClassLoader;
+ }
+
/**
* Get default GroovyClassLoader.
*
* @return default GroovyClassLoader
*/
- public GroovyClassLoader getGroovyClassLoader()
+ public ExtendedGroovyClassLoader getGroovyClassLoader()
{
return defaultClassLoader;
}
@@ -78,53 +70,30 @@
* Get customized instance of GroovyClassLoader that able to resolve
* additional Groovy source files.
*
- * @param classPath additional Groovy sources
+ * @param sources additional Groovy sources
* @return GroovyClassLoader
- * @throws MalformedURLException if any of entries in <code>classPath</code>
+ * @throws MalformedURLException if any of entries in <code>sources</code>
* has invalid URL.
*/
- public GroovyClassLoader getGroovyClassLoader(ClassPath classPath) throws MalformedURLException
+ public ExtendedGroovyClassLoader getGroovyClassLoader(SourceFolder[] sources) throws MalformedURLException
{
- List<URL> files = new ArrayList<URL>();
- List<URL> roots = new ArrayList<URL>();
- ClassPathEntry[] classPathEntries = classPath.getEntries();
- if (classPathEntries != null && classPathEntries.length > 0)
- {
- for (int i = 0; i < classPathEntries.length; i++)
+ if (sources == null || sources.length == 0)
+ return getGroovyClassLoader();
+
+ URL[] roots = new URL[sources.length];
+ for (int i = 0; i < sources.length; i++)
+ roots[i] = sources[i].getPath();
+
+ final GroovyClassLoader parent = getGroovyClassLoader();
+ ExtendedGroovyClassLoader classLoader =
+ AccessController.doPrivileged(new PrivilegedAction<ExtendedGroovyClassLoader>()
{
- ClassPathEntry classPathEntry = classPathEntries[i];
- if (EntryType.SRC_DIR == classPathEntry.getType())
+ public ExtendedGroovyClassLoader run()
{
- roots.add(classPathEntry.getPath());
+ return new ExtendedGroovyClassLoader(parent);
}
- else
- {
- files.add(classPathEntry.getPath());
- }
- }
- }
- final GroovyClassLoader parent = getGroovyClassLoader();
- GroovyClassLoader classLoader = AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>() {
- public GroovyClassLoader run()
- {
- return new GroovyClassLoader(parent);
- }
- });
- classLoader.setResourceLoader(new DefaultGroovyResourceLoader(roots.toArray(new URL[roots.size()]), files
- .toArray(new URL[files.size()]), classPath.getExtensions()));
+ });
+ classLoader.setResourceLoader(new DefaultGroovyResourceLoader(roots));
return classLoader;
}
-
- /**
- * Set default Groovy class loader.
- *
- * @param defaultClassLoader default Groovy class loader
- * @throws NullPointerException if <code>defaultClassLoader == null</code>
- */
- public void setGroovyClassLoader(GroovyClassLoader defaultClassLoader)
- {
- if (defaultClassLoader == null)
- throw new NullPointerException("GroovyClassLoader may not be null. ");
- this.defaultClassLoader = defaultClassLoader;
- }
}
Modified: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java 2010-12-27 13:22:15 UTC (rev 3730)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java 2010-12-27 13:35:46 UTC (rev 3731)
@@ -23,6 +23,10 @@
import groovy.lang.GroovyCodeSource;
import org.codehaus.groovy.control.CompilationFailedException;
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
import org.exoplatform.services.rest.ObjectFactory;
import org.exoplatform.services.rest.PerRequestObjectFactory;
import org.exoplatform.services.rest.impl.ResourceBinder;
@@ -33,6 +37,8 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
@@ -40,7 +46,9 @@
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -56,7 +64,23 @@
*/
public class GroovyJaxrsPublisher
{
+ private static final Log log = ExoLogger.getExoLogger(GroovyJaxrsPublisher.class);
+ @SuppressWarnings("rawtypes")
+ private static final Comparator<Constructor> constructorComparator = new Comparator<Constructor>()
+ {
+ public int compare(Constructor o1, Constructor o2)
+ {
+ int c1 = o1.getParameterTypes().length;
+ int c2 = o2.getParameterTypes().length;
+ if (c1 < c2)
+ return 1;
+ if (c1 > c2)
+ return -1;
+ return 0;
+ }
+ };
+
/** Default character set name. */
protected static final String DEFAULT_CHARSET_NAME = "UTF-8";
@@ -111,9 +135,7 @@
@Deprecated
public void setGroovyClassLoader(GroovyClassLoader gcl)
{
- if (gcl == null)
- throw new NullPointerException("GroovyClassLoader may not be null. ");
- classLoaderProvider.setGroovyClassLoader(gcl);
+ log.warn("Method setGroovyClassLoader is deprecated.");
}
/**
@@ -170,34 +192,36 @@
public void publishPerRequest(final InputStream in, final ResourceId resourceId,
MultivaluedMap<String, String> properties)
{
- publishPerRequest(in, resourceId, properties, null);
+ publishPerRequest(in, resourceId, properties, null, null);
}
/**
* Parse given stream and publish result as per-request RESTful service.
*
- * @param in stream which contains groovy source code of RESTful service
+ * @param in stream which contains Groovy source code of RESTful service
* @param resourceId id to be assigned to resource
* @param properties optional resource properties. This parameter may be
* <code>null</code>
- * @param classPath additional path to Groovy sources
+ * @param src additional path to Groovy sources
+ * @param files Groovy source files to be added in build path directly
* @throws NullPointerException if <code>resourceId == null</code>
* @throws ResourcePublicationException see
* {@link ResourceBinder#addResource(Class, MultivaluedMap)}
* @throws CompilationFailedException if compilation fails from source errors
*/
public void publishPerRequest(final InputStream in, final ResourceId resourceId,
- final MultivaluedMap<String, String> properties, final ClassPath classPath)
+ final MultivaluedMap<String, String> properties, final SourceFolder[] src, final SourceFile[] files)
{
- Class<?> rc = AccessController.doPrivileged(new PrivilegedAction<Class<?>>() {
+ Class<?> rc = AccessController.doPrivileged(new PrivilegedAction<Class<?>>()
+ {
public Class<?> run()
{
try
{
- GroovyClassLoader cl =
- (classPath == null) ? classLoaderProvider.getGroovyClassLoader() : classLoaderProvider
- .getGroovyClassLoader(classPath);
- return cl.parseClass(createCodeSource(in, resourceId.getId()));
+ ExtendedGroovyClassLoader cl =
+ (src == null) ? classLoaderProvider.getGroovyClassLoader() : classLoaderProvider
+ .getGroovyClassLoader(src);
+ return cl.parseClass(in, resourceId.getId(), files);
}
catch (MalformedURLException e)
{
@@ -225,7 +249,7 @@
*/
public final void publishPerRequest(String source, ResourceId resourceId, MultivaluedMap<String, String> properties)
{
- publishPerRequest(source, DEFAULT_CHARSET, resourceId, properties, null);
+ publishPerRequest(source, DEFAULT_CHARSET, resourceId, properties, null, null);
}
/**
@@ -236,16 +260,17 @@
* @param resourceId id to be assigned to resource
* @param properties optional resource properties. This parameter may be
* <code>null</code>
- * @param classPath additional path to Groovy sources
+ * @param src additional path to Groovy sources
+ * @param files Groovy source files to be added in build path directly
* @throws NullPointerException if <code>resourceId == null</code>
* @throws ResourcePublicationException see
* {@link ResourceBinder#addResource(Class, MultivaluedMap)}
* @throws CompilationFailedException if compilation fails from source errors
*/
public final void publishPerRequest(String source, ResourceId resourceId, MultivaluedMap<String, String> properties,
- ClassPath classPath)
+ final SourceFolder[] src, final SourceFile[] files)
{
- publishPerRequest(source, DEFAULT_CHARSET, resourceId, properties, classPath);
+ publishPerRequest(source, DEFAULT_CHARSET, resourceId, properties, src, files);
}
/**
@@ -268,7 +293,7 @@
MultivaluedMap<String, String> properties)
{
publishPerRequest(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), resourceId, properties,
- null);
+ null, null);
}
/**
@@ -281,7 +306,8 @@
* @param resourceId id to be assigned to resource
* @param properties optional resource properties. This parameter may be
* <code>null</code>.
- * @param classPath additional path to Groovy sources
+ * @param src additional path to Groovy sources
+ * @param files Groovy source files to be added in build path directly
* @throws UnsupportedCharsetException if <code>charset</code> is unsupported
* @throws NullPointerException if <code>resourceId == null</code>
* @throws ResourcePublicationException see
@@ -289,10 +315,10 @@
* @throws CompilationFailedException if compilation fails from source errors
*/
public final void publishPerRequest(String source, String charset, ResourceId resourceId,
- MultivaluedMap<String, String> properties, ClassPath classPath)
+ MultivaluedMap<String, String> properties, SourceFolder[] src, SourceFile[] files)
{
publishPerRequest(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), resourceId, properties,
- classPath);
+ src, files);
}
/**
@@ -309,7 +335,7 @@
*/
public void publishSingleton(InputStream in, ResourceId resourceId, MultivaluedMap<String, String> properties)
{
- publishSingleton(in, resourceId, properties, null);
+ publishSingleton(in, resourceId, properties, null, null);
}
/**
@@ -319,22 +345,41 @@
* @param resourceId id to be assigned to resource
* @param properties optional resource properties. This parameter may be
* <code>null</code>
- * @param classPath additional path to Groovy sources
+ * @param src additional path to Groovy sources
+ * @param files Groovy source files to be added in build path directly
* @throws NullPointerException if <code>resourceId == null</code>
* @throws ResourcePublicationException see
* {@link ResourceBinder#addResource(Object, MultivaluedMap)}
* @throws CompilationFailedException if compilation fails from source errors
*/
- public void publishSingleton(InputStream in, ResourceId resourceId, MultivaluedMap<String, String> properties,
- ClassPath classPath)
+ public void publishSingleton(final InputStream in, final ResourceId resourceId,
+ MultivaluedMap<String, String> properties, final SourceFolder[] src, final SourceFile[] files/*TODO*/)
{
Object resource;
try
{
- resource =
- instantiator.instantiateScript(createCodeSource(in, resourceId.getId()), (classPath == null)
- ? classLoaderProvider.getGroovyClassLoader() : classLoaderProvider.getGroovyClassLoader(classPath));
+ ExtendedGroovyClassLoader cl =
+ (src == null) ? classLoaderProvider.getGroovyClassLoader() : classLoaderProvider.getGroovyClassLoader(src);
+ @SuppressWarnings("rawtypes")
+ Class clazz = cl.parseClass(in, resourceId.getId(), files);
+ resource = createInstance(clazz);
}
+ catch (IllegalArgumentException e)
+ {
+ throw new ResourcePublicationException(e.getMessage());
+ }
+ catch (InstantiationException e)
+ {
+ throw new ResourcePublicationException(e.getMessage());
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new ResourcePublicationException(e.getMessage());
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new ResourcePublicationException(e.getMessage());
+ }
catch (MalformedURLException e)
{
throw new IllegalArgumentException(e.getMessage());
@@ -358,7 +403,7 @@
*/
public final void publishSingleton(String source, ResourceId resourceId, MultivaluedMap<String, String> properties)
{
- publishSingleton(source, DEFAULT_CHARSET, resourceId, properties, null);
+ publishSingleton(source, DEFAULT_CHARSET, resourceId, properties, null, null);
}
/**
@@ -369,16 +414,17 @@
* @param resourceId name of resource
* @param properties optional resource properties. This parameter may be
* <code>null</code>.
- * @param classPath additional path to Groovy sources
+ * @param src additional path to Groovy sources
+ * @param files Groovy source files to be added in build path directly
* @throws NullPointerException if <code>resourceId == null</code>
* @throws ResourcePublicationException see
* {@link ResourceBinder#addResource(Object, MultivaluedMap)}
* @throws CompilationFailedException if compilation fails from source errors
*/
public final void publishSingleton(String source, ResourceId resourceId, MultivaluedMap<String, String> properties,
- ClassPath classPath)
+ SourceFolder[] src, SourceFile[] files)
{
- publishSingleton(source, DEFAULT_CHARSET, resourceId, properties, classPath);
+ publishSingleton(source, DEFAULT_CHARSET, resourceId, properties, src, files);
}
/**
@@ -401,7 +447,7 @@
MultivaluedMap<String, String> properties)
{
publishSingleton(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), resourceId, properties,
- null);
+ null, null);
}
/**
@@ -414,7 +460,8 @@
* @param resourceId name of resource
* @param properties optional resource properties. This parameter may be
* <code>null</code>.
- * @param classPath additional path to Groovy sources
+ * @param src additional path to Groovy sources
+ * @param files Groovy source files to be added in build path directly
* @throws UnsupportedCharsetException if <code>charset</code> is unsupported
* @throws NullPointerException if <code>resourceId == null</code>
* @throws ResourcePublicationException see
@@ -422,10 +469,10 @@
* @throws CompilationFailedException if compilation fails from source errors
*/
public final void publishSingleton(String source, String charset, ResourceId resourceId,
- MultivaluedMap<String, String> properties, ClassPath classPath)
+ MultivaluedMap<String, String> properties, SourceFolder[] src, SourceFile[] files)
{
publishSingleton(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), resourceId, properties,
- classPath);
+ src, files);
}
/**
@@ -440,14 +487,10 @@
{
String path = resources.get(resourceId);
if (path == null)
- {
return null;
- }
ObjectFactory<AbstractResourceDescriptor> resource = binder.removeResource(path);
if (resource != null)
- {
resources.remove(resourceId);
- }
return resource;
}
@@ -461,25 +504,26 @@
* message in compilation of Groovy fails. If this parameter is
* <code>null</code> then GroovyClassLoader will use automatically
* generated name
- * @param classPath additional path to Groovy sources
+ * @param src additional path to Groovy sources
+ * @param files Groovy source files to be added in build path directly
* @throws MalformedScriptException if source has errors or there is no
* required JAX-RS annotation
*/
- public void validateResource(final InputStream in, final String name, final ClassPath classPath)
- throws MalformedScriptException
+ public void validateResource(final InputStream in, final String name, final SourceFolder[] src,
+ final SourceFile[] files) throws MalformedScriptException
{
- Class<?> rc;
+ //Class<?> rc;
try
{
- rc = AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
+ //rc =
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>()
+ {
public Class<?> run() throws MalformedURLException
{
- GroovyClassLoader cl =
- (classPath == null) ? classLoaderProvider.getGroovyClassLoader() : classLoaderProvider
- .getGroovyClassLoader(classPath);
- if (name == null || name.length() == 0)
- return cl.parseClass(createCodeSource(in, cl.generateScriptName()));
- return cl.parseClass(createCodeSource(in, name));
+ ExtendedGroovyClassLoader cl =
+ (src == null) ? classLoaderProvider.getGroovyClassLoader() : classLoaderProvider
+ .getGroovyClassLoader(src);
+ return cl.parseClass(in, (name != null && name.length() > 0) ? name : cl.generateScriptName(), files);
}
});
}
@@ -521,7 +565,7 @@
*/
public void validateResource(InputStream in, String name) throws MalformedScriptException
{
- validateResource(in, name, null);
+ validateResource(in, name, null, null);
}
/**
@@ -536,14 +580,15 @@
* message in compilation of Groovy fails. If this parameter is
* <code>null</code> then GroovyClassLoader will use automatically
* generated name
- * @param classPath additional path to Groovy sources
+ * @param src additional path to Groovy sources
+ * @param files Groovy source files to be added in build path directly
* @throws MalformedScriptException if source has errors or there is no
* required JAX-RS annotation
*/
- public final void validateResource(String source, String charset, String name, ClassPath classPath)
+ public final void validateResource(String source, String charset, String name, SourceFolder[] src, SourceFile[] files)
throws MalformedScriptException
{
- validateResource(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), name, classPath);
+ validateResource(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), name, src, files);
}
/**
@@ -556,13 +601,15 @@
* message in compilation of Groovy fails. If this parameter is
* <code>null</code> then GroovyClassLoader will use automatically
* generated name
- * @param classPath additional path to Groovy sources
+ * @param src additional path to Groovy sources
+ * @param files Groovy source files to be added in build path directly
* @throws MalformedScriptException if source has errors or there is no
* required JAX-RS annotation
*/
- public final void validateResource(String source, String name, ClassPath classPath) throws MalformedScriptException
+ public final void validateResource(String source, String name, SourceFolder[] src, SourceFile[] files)
+ throws MalformedScriptException
{
- validateResource(source, DEFAULT_CHARSET, name, classPath);
+ validateResource(source, DEFAULT_CHARSET, name, src, files);
}
/**
@@ -580,28 +627,55 @@
*/
public final void validateResource(String source, String name) throws MalformedScriptException
{
- validateResource(source, DEFAULT_CHARSET, name, null);
+ validateResource(source, DEFAULT_CHARSET, name, null, null);
}
+ @SuppressWarnings("rawtypes")
+ private Object createInstance(Class clazz) throws IllegalArgumentException, InstantiationException,
+ IllegalAccessException, InvocationTargetException
+ {
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+ Constructor[] constructors = clazz.getConstructors();
+ //Sort constructors by number of parameters. With more parameters must be first.
+ Arrays.sort(constructors, constructorComparator);
+ l : for (Constructor<?> c : constructors)
+ {
+ Class<?>[] parameterTypes = c.getParameterTypes();
+ if (parameterTypes.length == 0)
+ return c.newInstance();
+ Object[] parameters = new Object[parameterTypes.length];
+ for (int i = 0; i < parameterTypes.length; i++)
+ {
+ Object param = container.getComponentInstanceOfType(parameterTypes[i]);
+ if (param == null)
+ continue l;
+ parameters[i] = param;
+ }
+ return c.newInstance(parameters);
+ }
+ throw new ResourcePublicationException("Unbale create instance of class " + clazz.getName()
+ + ". Required constructor's dependencies can't be resolved. ");
+ }
+
private void publishPerRequest(String source, Charset charset, ResourceId resourceId,
- MultivaluedMap<String, String> properties, ClassPath classPath)
+ MultivaluedMap<String, String> properties, SourceFolder[] src, SourceFile[] files)
{
byte[] bytes = source.getBytes(charset);
- publishPerRequest(new ByteArrayInputStream(bytes), resourceId, properties, classPath);
+ publishPerRequest(new ByteArrayInputStream(bytes), resourceId, properties, src, files);
}
private void publishSingleton(String source, Charset charset, ResourceId resourceId,
- MultivaluedMap<String, String> properties, ClassPath classPath)
+ MultivaluedMap<String, String> properties, SourceFolder[] src, SourceFile[] files)
{
byte[] bytes = source.getBytes(charset);
- publishSingleton(new ByteArrayInputStream(bytes), resourceId, properties, classPath);
+ publishSingleton(new ByteArrayInputStream(bytes), resourceId, properties, src, files);
}
- private void validateResource(String source, Charset charset, String name, ClassPath classPath)
+ private void validateResource(String source, Charset charset, String name, SourceFolder[] src, SourceFile[] files)
throws MalformedScriptException
{
byte[] bytes = source.getBytes(charset);
- validateResource(new ByteArrayInputStream(bytes), name, classPath);
+ validateResource(new ByteArrayInputStream(bytes), name, src, files);
}
/**
@@ -614,13 +688,13 @@
*/
protected GroovyCodeSource createCodeSource(final InputStream in, final String name)
{
- GroovyCodeSource gcs = AccessController.doPrivileged(new PrivilegedAction<GroovyCodeSource>() {
+ GroovyCodeSource gcs = AccessController.doPrivileged(new PrivilegedAction<GroovyCodeSource>()
+ {
public GroovyCodeSource run()
{
- return new GroovyCodeSource(in, name, "/groovy/script/jaxrs");
+ return new GroovyCodeSource(in, name, ExtendedGroovyClassLoader.CODE_BASE);
}
});
-
gcs.setCachable(false);
return gcs;
}
Added: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/SourceFile.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/SourceFile.java (rev 0)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/SourceFile.java 2010-12-27 13:35:46 UTC (rev 3731)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.rest.ext.groovy;
+
+import java.net.URL;
+
+/**
+ * Describe location of Groovy source file.
+ *
+ * @author <a href="andrew00x(a)gmail.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class SourceFile extends ClassPathEntry
+{
+ public SourceFile(URL path)
+ {
+ super(path);
+ }
+}
Property changes on: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/SourceFile.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/SourceFolder.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/SourceFolder.java (rev 0)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/SourceFolder.java 2010-12-27 13:35:46 UTC (rev 3731)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.rest.ext.groovy;
+
+import java.net.URL;
+
+/**
+ * Folder with groovy sources.
+ *
+ * @author <a href="andrew00x(a)gmail.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class SourceFolder extends ClassPathEntry
+{
+ public SourceFolder(URL path)
+ {
+ super(path);
+ }
+}
Property changes on: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/SourceFolder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/ExtendedClassLoaderTest.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/ExtendedClassLoaderTest.java (rev 0)
+++ ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/ExtendedClassLoaderTest.java 2010-12-27 13:35:46 UTC (rev 3731)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.rest.ext.groovy;
+
+import groovy.lang.GroovyObject;
+
+import org.exoplatform.services.rest.ext.BaseTest;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="andrew00x(a)gmail.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+@SuppressWarnings("rawtypes")
+public class ExtendedClassLoaderTest extends BaseTest
+{
+ public void testParseClasses() throws Exception
+ {
+ ExtendedGroovyClassLoader loader = new GroovyClassLoaderProvider().getGroovyClassLoader();
+ SourceFile[] sources = new SourceFile[2];
+ sources[0] = new SourceFile(Thread.currentThread().getContextClassLoader().getResource("GMain1.groovy"));
+ sources[1] =
+ new SourceFile(Thread.currentThread().getContextClassLoader().getResource("repo/dependencies/Dep1.groovy"));
+ Class[] classes = loader.parseClasses(sources);
+ assertEquals(2, classes.length);
+ List<String> names = new ArrayList<String>(2);
+ for (Class c : classes)
+ names.add(c.getName());
+ assertTrue(names.contains("GMain1"));
+ assertTrue(names.contains("dependencies.Dep1"));
+ }
+
+ public void testParseClasses2() throws Exception
+ {
+ ExtendedGroovyClassLoader loader =
+ new GroovyClassLoaderProvider().getGroovyClassLoader(new SourceFolder[]{new SourceFolder(Thread
+ .currentThread().getContextClassLoader().getResource("repo"))});
+ SourceFile[] sources = new SourceFile[1];
+ sources[0] = new SourceFile(Thread.currentThread().getContextClassLoader().getResource("GMain1.groovy"));
+ Class[] classes = loader.parseClasses(sources);
+ assertEquals(1, classes.length);
+ List<String> names = new ArrayList<String>(1);
+ for (Class c : classes)
+ names.add(c.getName());
+ assertTrue(names.contains("GMain1"));
+ }
+
+ public void testParseClassWithDependency() throws Exception
+ {
+ ExtendedGroovyClassLoader loader = new GroovyClassLoaderProvider().getGroovyClassLoader();
+ SourceFile[] sources =
+ new SourceFile[]{new SourceFile(Thread.currentThread().getContextClassLoader()
+ .getResource("repo/dependencies/Dep1.groovy"))};
+ Class clazz =
+ loader.parseClass(Thread.currentThread().getContextClassLoader().getResourceAsStream("GMain1.groovy"),
+ "GMain1", sources);
+ assertEquals("GMain1", clazz.getName());
+ assertEquals("dependencies.Dep1", ((GroovyObject)clazz.newInstance()).invokeMethod("m0", new Object[0]));
+ }
+}
Property changes on: ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/ExtendedClassLoaderTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: ws/trunk/exo.ws.rest.ext/src/test/resources/GMain1.groovy
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/resources/GMain1.groovy 2010-12-27 13:22:15 UTC (rev 3730)
+++ ws/trunk/exo.ws.rest.ext/src/test/resources/GMain1.groovy 2010-12-27 13:35:46 UTC (rev 3731)
@@ -11,4 +11,4 @@
return new Dep1().getName()
}
-}
\ No newline at end of file
+}
Modified: ws/trunk/exo.ws.rest.ext/src/test/resources/groovy1.groovy
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/resources/groovy1.groovy 2010-12-27 13:22:15 UTC (rev 3730)
+++ ws/trunk/exo.ws.rest.ext/src/test/resources/groovy1.groovy 2010-12-27 13:35:46 UTC (rev 3731)
@@ -4,10 +4,10 @@
import javax.ws.rs.core.Context;
@Path("a")
-class CroovyResource1
+class GroovyResource1
{
- CroovyResource1(@Context HttpServletRequest req1)
+ GroovyResource1(@Context HttpServletRequest req1)
{
this.req1 = req1;
}
@@ -24,4 +24,4 @@
return req.getMethod() + "\n" +req.getRequestURI().toString()
}
-}
\ No newline at end of file
+}
Modified: ws/trunk/exo.ws.rest.ext/src/test/resources/groovy2.groovy
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/resources/groovy2.groovy 2010-12-27 13:22:15 UTC (rev 3730)
+++ ws/trunk/exo.ws.rest.ext/src/test/resources/groovy2.groovy 2010-12-27 13:35:46 UTC (rev 3731)
@@ -4,11 +4,11 @@
import javax.ws.rs.Path;
@Path("a")
-class CroovyResource2
+class GroovyResource2
{
private Component1 component
- CroovyResource2(Component1 component)
+ GroovyResource2(Component1 component)
{
this.component = component
}
Modified: ws/trunk/exo.ws.rest.ext/src/test/resources/groovy3.groovy
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/resources/groovy3.groovy 2010-12-27 13:22:15 UTC (rev 3730)
+++ ws/trunk/exo.ws.rest.ext/src/test/resources/groovy3.groovy 2010-12-27 13:35:46 UTC (rev 3731)
@@ -2,10 +2,10 @@
import javax.ws.rs.Path;
@Path("a")
-class CroovyResource3
+class GroovyResource3
{
- CroovyResource3()
+ GroovyResource3()
{
}
13 years, 4 months
exo-jcr SVN: r3730 - jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-27 08:22:15 -0500 (Mon, 27 Dec 2010)
New Revision: 3730
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java
Log:
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java 2010-12-27 11:03:47 UTC (rev 3729)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java 2010-12-27 13:22:15 UTC (rev 3730)
@@ -133,6 +133,11 @@
public static final int DB_DIALECT_DB2V8 = DBConstants.DB_DIALECT_DB2V8.hashCode();
/**
+ * PGSQL dialect.
+ */
+ public static final int DB_DIALECT_PGSQL = DBConstants.DB_DIALECT_PGSQL.hashCode();
+
+ /**
* {@inheritDoc}
*/
@Override
@@ -179,6 +184,7 @@
notifyListeners();
Connection jdbcConn = null;
+ Statement lockStatemnt = null;
try
{
WorkspaceEntry workspaceEntry = null;
@@ -262,26 +268,29 @@
// Lock tables
ResultSet rs = null;
- Statement st = null;
try
{
DatabaseMetaData metaData = jdbcConn.getMetaData();
rs = metaData.getTables(null, null, "%", new String[]{"TABLE"});
- st = jdbcConn.createStatement();
+ lockStatemnt = jdbcConn.createStatement();
int dialect = DialectDetecter.detect(metaData).hashCode();
- while (rs.next())
+ if (dialect == DB_DIALECT_HSQLDB)
{
- String tableName = rs.getString("TABLE_NAME");
- if (dialect == DB_DIALECT_HSQLDB)
+ while (rs.next())
{
- st.execute("SET TABLE " + tableName + " READONLY TRUE");
+ lockStatemnt.execute("SET TABLE " + rs.getString("TABLE_NAME") + " READONLY TRUE");
}
- else
+ }
+ else if (dialect == DB_DIALECT_MYSQL || dialect == DB_DIALECT_MYSQL_UTF8)
+ {
+ String lock = "";
+ while (rs.next())
{
- st.execute("LOCK TABLES " + tableName + " WRITE");
+ lock += rs.getString("TABLE_NAME") + " READ,";
}
+ lockStatemnt.execute("LOCK TABLES " + lock.substring(0, lock.length() - 1));
}
}
finally
@@ -290,19 +299,15 @@
{
rs.close();
}
-
- if (st != null)
- {
- st.close();
- }
}
+ // dump JCR data
for (String script[] : scripts)
{
dumpTable(jdbcConn, script[0], script[1]);
}
- // dump LOCK data
+ // dump JCR LOCK data
LockManagerEntry lockEntry = workspaceEntry.getLockManager();
if (lockEntry != null)
{
@@ -355,41 +360,42 @@
{
if (jdbcConn != null)
{
- // unlock tables
try
{
- ResultSet rs = null;
- Statement st = null;
- try
+ // unlock tables
+ if (lockStatemnt != null)
{
- DatabaseMetaData metaData = jdbcConn.getMetaData();
- st = jdbcConn.createStatement();
- int dialect = DialectDetecter.detect(metaData).hashCode();
+ ResultSet rs = null;
+ try
+ {
+ DatabaseMetaData metaData = jdbcConn.getMetaData();
+ int dialect = DialectDetecter.detect(metaData).hashCode();
- if (dialect == DB_DIALECT_HSQLDB)
- {
- rs = metaData.getTables(null, null, "%", new String[]{"TABLE"});
- while (rs.next())
+ if (dialect == DB_DIALECT_HSQLDB)
{
- String tableName = rs.getString("TABLE_NAME");
- st.execute("SET TABLE " + tableName + " READONLY FALSE");
+ rs = metaData.getTables(null, null, "%", new String[]{"TABLE"});
+ while (rs.next())
+ {
+ String tableName = rs.getString("TABLE_NAME");
+ lockStatemnt.execute("SET TABLE " + tableName + " READONLY FALSE");
+ }
}
+ else
+ {
+ lockStatemnt.execute("UNLOCK TABLES");
+ }
}
- else
+ finally
{
- st.execute("UNLOCK TABLES");
- }
- }
- finally
- {
- if (rs != null)
- {
- rs.close();
- }
+ if (rs != null)
+ {
+ rs.close();
+ }
- if (st != null)
- {
- st.close();
+ if (lockStatemnt != null)
+ {
+ lockStatemnt.close();
+ }
}
}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java 2010-12-27 11:03:47 UTC (rev 3729)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java 2010-12-27 13:22:15 UTC (rev 3730)
@@ -169,8 +169,6 @@
protected void fullRdbmsRestore() throws RepositoryException
{
Connection jdbcConn = null;
- Statement st = null;
-
try
{
String dsName = workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
@@ -208,15 +206,6 @@
RDBMSBackupInfoReader backupInfo = new RDBMSBackupInfoReader(restorePath);
- // Lock db
- if (dialect != FullBackupJob.DB_DIALECT_HSQLDB)
- {
- RestoreTableHelper helper = new RestoreTableHelper(RestoreTableHelper.ITEM_TABLE, isMultiDb, backupInfo);
-
- st = jdbcConn.createStatement();
- st.execute("LOCK TABLES " + helper.getTableName() + " WRITE");
- }
-
restoreJCRTables(jdbcConn, dialect, isMultiDb, backupInfo);
restoreLockTables(jdbcConn, isMultiDb, backupInfo);
@@ -252,27 +241,6 @@
}
finally
{
- if (st != null)
- {
- try
- {
- st.execute("UNLOCK TABLES");
- }
- catch (SQLException e)
- {
- throw new RepositoryException(e);
- }
-
- try
- {
- st.close();
- }
- catch (SQLException e)
- {
- throw new RepositoryException(e);
- }
- }
-
if (jdbcConn != null)
{
try
@@ -796,7 +764,14 @@
ba.read(readBuffer);
String value = new String(readBuffer);
- insertNode.setBoolean(targetIndex + 1, value.equals("t"));
+ if (dialect == FullBackupJob.DB_DIALECT_PGSQL)
+ {
+ insertNode.setBoolean(targetIndex + 1, value.equals("t"));
+ }
+ else
+ {
+ insertNode.setBoolean(targetIndex + 1, value.equals("1"));
+ }
}
else if (columnType.get(i) == Types.BOOLEAN)
{
13 years, 4 months
exo-jcr SVN: r3729 - in jcr/branches/1.12.x: exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/initializer and 1 other directories.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-12-27 06:03:47 -0500 (Mon, 27 Dec 2010)
New Revision: 3729
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/initializer/RemoteWorkspaceInitializer.java
jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java
Log:
JCR-1558 : Get FileCleaner form FileCleanerHolder in SysViewWorkspaceInitializer.
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java 2010-12-27 10:48:16 UTC (rev 3728)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java 2010-12-27 11:03:47 UTC (rev 3729)
@@ -40,6 +40,7 @@
import org.exoplatform.services.jcr.impl.storage.JCRInvalidItemStateException;
import org.exoplatform.services.jcr.impl.storage.JCRItemExistsException;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
import org.exoplatform.services.jcr.impl.util.io.SpoolFile;
import org.exoplatform.services.jcr.observation.ExtendedEvent;
@@ -74,8 +75,6 @@
{
private final String restoreDir;
- private FileCleaner fileCleaner;
-
/**
* Temporary directory;
*/
@@ -84,13 +83,12 @@
public BackupWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl namespaceRegistry,
LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
- AccessManager accessManager) throws RepositoryConfigurationException, PathNotFoundException, RepositoryException
+ AccessManager accessManager, FileCleanerHolder cleanerHolder) throws RepositoryConfigurationException,
+ PathNotFoundException, RepositoryException
{
super(config, repConfig, dataManager, namespaceRegistry, locationFactory, nodeTypeManager, valueFactory,
- accessManager);
+ accessManager, cleanerHolder);
- this.fileCleaner = valueFactory.getFileCleaner();
-
restoreDir = restorePath;
String fullBackupPath = getFullBackupPath();
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java 2010-12-27 10:48:16 UTC (rev 3728)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java 2010-12-27 11:03:47 UTC (rev 3729)
@@ -43,6 +43,7 @@
import org.exoplatform.services.jcr.impl.dataflow.persistent.CacheableWorkspaceDataManager;
import org.exoplatform.services.jcr.impl.util.JCRDateFormat;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
import org.exoplatform.services.jcr.impl.util.io.SpoolFile;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
import org.exoplatform.services.log.ExoLogger;
@@ -99,7 +100,7 @@
/**
* Cleaner should be started! .
*/
- private final FileCleaner fileCleaner;
+ protected final FileCleaner fileCleaner;
protected String restorePath;
@@ -389,7 +390,8 @@
public SysViewWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl namespaceRegistry,
LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
- AccessManager accessManager) throws RepositoryConfigurationException, PathNotFoundException, RepositoryException
+ AccessManager accessManager, FileCleanerHolder cleanerHolder) throws RepositoryConfigurationException,
+ PathNotFoundException, RepositoryException
{
this.workspaceName = config.getName();
@@ -399,7 +401,7 @@
this.namespaceRegistry = namespaceRegistry;
this.locationFactory = locationFactory;
- this.fileCleaner = valueFactory.getFileCleaner();
+ this.fileCleaner = cleanerHolder.getFileCleaner();
this.maxBufferSize =
config.getContainer().getParameterInteger(WorkspaceDataContainer.MAXBUFFERSIZE_PROP,
WorkspaceDataContainer.DEF_MAXBUFFERSIZE);
@@ -441,7 +443,7 @@
public SysViewWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl namespaceRegistry,
LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
- AccessManager accessManager, String restorePath) throws RepositoryException
+ AccessManager accessManager, String restorePath, FileCleanerHolder cleanerHolder) throws RepositoryException
{
this.workspaceName = config.getName();
@@ -451,7 +453,7 @@
this.namespaceRegistry = namespaceRegistry;
this.locationFactory = locationFactory;
- this.fileCleaner = valueFactory.getFileCleaner();
+ this.fileCleaner = cleanerHolder.getFileCleaner();
this.maxBufferSize =
config.getContainer().getParameterInteger(WorkspaceDataContainer.MAXBUFFERSIZE_PROP,
WorkspaceDataContainer.DEF_MAXBUFFERSIZE);
Modified: jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/initializer/RemoteWorkspaceInitializer.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/initializer/RemoteWorkspaceInitializer.java 2010-12-27 10:48:16 UTC (rev 3728)
+++ jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/initializer/RemoteWorkspaceInitializer.java 2010-12-27 11:03:47 UTC (rev 3729)
@@ -30,6 +30,7 @@
import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeManagerImpl;
import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
import org.exoplatform.services.jcr.impl.dataflow.persistent.CacheableWorkspaceDataManager;
+import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
import java.io.File;
@@ -51,10 +52,11 @@
public RemoteWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl namespaceRegistry,
LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
- AccessManager accessManager) throws RepositoryConfigurationException, PathNotFoundException, RepositoryException
+ AccessManager accessManager, FileCleanerHolder cleanerHolder) throws RepositoryConfigurationException,
+ PathNotFoundException, RepositoryException
{
super(config, repConfig, dataManager, namespaceRegistry, locationFactory, nodeTypeManager, valueFactory,
- accessManager, null);
+ accessManager, cleanerHolder);
if (!isWorkspaceInitialized())
{
Modified: jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java 2010-12-27 10:48:16 UTC (rev 3728)
+++ jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java 2010-12-27 11:03:47 UTC (rev 3729)
@@ -32,6 +32,7 @@
import javax.jcr.Node;
import javax.jcr.RepositoryException;
+import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.lock.Lock;
@@ -155,6 +156,8 @@
ws1TestRoot.getNode("node_5").remove();
ws1TestRoot.addNode("node #3").setProperty("exo:data", "property #3");
ws1TestRoot.addNode("node #5").setProperty("exo:extraData", "property #5");
+
+ ws1TestRoot.addNode("binary_data").setProperty("data", new FileInputStream(createBLOBTempFile(500)));
ws1TestRoot.save(); // log here via listener
@@ -862,6 +865,13 @@
Thread.sleep(50);
}
+ //will be saved in incremental backup
+ Session wsSession = getReposityToBackup().login(credentials, "ws");
+ wsSession.getRootNode().getNode("backupTest").addNode("binary_data")
+ .setProperty("data",
+ new FileInputStream(createBLOBTempFile(500)));
+ wsSession.save();
+
// stop fullBackup
backup.stopBackup(bch);
@@ -893,6 +903,12 @@
Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
assertEquals("Restored content should be same", "property-5", ws1backTestRoot.getNode("node_5")
.getProperty("exo:data").getString());
+
+ if (wsName.equals("ws"))
+ {
+ assertNotNull(ws1backTestRoot.getNode("binary_data"));
+ assertNotNull(ws1backTestRoot.getNode("binary_data").getProperty("data"));
+ }
}
catch (Exception e)
{
13 years, 4 months
exo-jcr SVN: r3728 - jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-12-27 05:48:16 -0500 (Mon, 27 Dec 2010)
New Revision: 3728
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java
Log:
JCR-1502 : Fix problem with HTTPBackupAgentTest.
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-12-27 10:19:58 UTC (rev 3727)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-12-27 10:48:16 UTC (rev 3728)
@@ -18,7 +18,11 @@
*/
package org.exoplatform.services.jcr.ext.backup;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.PropertiesParam;
+import org.exoplatform.services.jcr.ext.backup.impl.BackupManagerImpl;
+
/**
* Created by The eXo Platform SAS.
* Author : Peter Nedonosko peter.nedonosko(a)exoplatform.com.ua
@@ -33,6 +37,20 @@
protected ExtendedBackupManager getBackupManager()
{
- return (ExtendedBackupManager) container.getComponentInstanceOfType(BackupManager.class);
+ InitParams initParams = new InitParams();
+ PropertiesParam pps = new PropertiesParam();
+ pps.setProperty(BackupManagerImpl.FULL_BACKUP_TYPE,
+ "org.exoplatform.services.jcr.ext.backup.impl.fs.FullBackupJob");
+ pps.setProperty(BackupManagerImpl.INCREMENTAL_BACKUP_TYPE,
+ "org.exoplatform.services.jcr.ext.backup.impl.fs.IncrementalBackupJob");
+ pps.setProperty(BackupManagerImpl.BACKUP_DIR, "target/backup_testBackupManager");
+ pps.setProperty(BackupManagerImpl.DEFAULT_INCREMENTAL_JOB_PERIOD, "3600");
+
+ initParams.put(BackupManagerImpl.BACKUP_PROPERTIES, pps);
+
+ BackupManagerImpl backupManagerImpl = new BackupManagerImpl(initParams, repositoryService);
+ backupManagerImpl.start();
+
+ return backupManagerImpl;
}
}
13 years, 4 months
exo-jcr SVN: r3727 - jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-12-27 05:19:58 -0500 (Mon, 27 Dec 2010)
New Revision: 3727
Modified:
jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java
Log:
JCR-1502 : Fix problem with HTTPBackupAgentTest.
Modified: jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-12-24 15:27:32 UTC (rev 3726)
+++ jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-12-27 10:19:58 UTC (rev 3727)
@@ -18,7 +18,11 @@
*/
package org.exoplatform.services.jcr.ext.backup;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.PropertiesParam;
+import org.exoplatform.services.jcr.ext.backup.impl.BackupManagerImpl;
+
/**
* Created by The eXo Platform SAS.
* Author : Peter Nedonosko peter.nedonosko(a)exoplatform.com.ua
@@ -33,6 +37,20 @@
protected ExtendedBackupManager getBackupManager()
{
- return (ExtendedBackupManager) container.getComponentInstanceOfType(BackupManager.class);
+ InitParams initParams = new InitParams();
+ PropertiesParam pps = new PropertiesParam();
+ pps.setProperty(BackupManagerImpl.FULL_BACKUP_TYPE,
+ "org.exoplatform.services.jcr.ext.backup.impl.fs.FullBackupJob");
+ pps.setProperty(BackupManagerImpl.INCREMENTAL_BACKUP_TYPE,
+ "org.exoplatform.services.jcr.ext.backup.impl.fs.IncrementalBackupJob");
+ pps.setProperty(BackupManagerImpl.BACKUP_DIR, "target/backup_testBackupManager");
+ pps.setProperty(BackupManagerImpl.DEFAULT_INCREMENTAL_JOB_PERIOD, "3600");
+
+ initParams.put(BackupManagerImpl.BACKUP_PROPERTIES, pps);
+
+ BackupManagerImpl backupManagerImpl = new BackupManagerImpl(initParams, repositoryService);
+ backupManagerImpl.start();
+
+ return backupManagerImpl;
}
}
13 years, 4 months
exo-jcr SVN: r3726 - in jcr/trunk: exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms and 2 other directories.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-12-24 10:27:32 -0500 (Fri, 24 Dec 2010)
New Revision: 3726
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsBackupWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/TesterRdbmsWorkspaceInitializer.java
Log:
EXOJCR-1125 : Get FileCleaner form FileCleanerHolder in SysViewWorkspaceInitializer.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java 2010-12-24 10:19:57 UTC (rev 3725)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java 2010-12-24 15:27:32 UTC (rev 3726)
@@ -41,6 +41,7 @@
import org.exoplatform.services.jcr.impl.storage.JCRInvalidItemStateException;
import org.exoplatform.services.jcr.impl.storage.JCRItemExistsException;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
import org.exoplatform.services.jcr.impl.util.io.SpoolFile;
import org.exoplatform.services.jcr.observation.ExtendedEvent;
@@ -77,10 +78,11 @@
public BackupWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl namespaceRegistry,
LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
- AccessManager accessManager) throws RepositoryConfigurationException, PathNotFoundException, RepositoryException
+ AccessManager accessManager, FileCleanerHolder cleanerHolder) throws RepositoryConfigurationException,
+ PathNotFoundException, RepositoryException
{
super(config, repConfig, dataManager, namespaceRegistry, locationFactory, nodeTypeManager, valueFactory,
- accessManager);
+ accessManager, cleanerHolder);
restoreDir = restorePath;
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java 2010-12-24 10:19:57 UTC (rev 3725)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java 2010-12-24 15:27:32 UTC (rev 3726)
@@ -45,6 +45,7 @@
import org.exoplatform.services.jcr.impl.dataflow.persistent.CacheableWorkspaceDataManager;
import org.exoplatform.services.jcr.impl.util.JCRDateFormat;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
import org.exoplatform.services.jcr.impl.util.io.SpoolFile;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
import org.exoplatform.services.log.ExoLogger;
@@ -405,10 +406,11 @@
public SysViewWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl namespaceRegistry,
LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
- AccessManager accessManager) throws RepositoryConfigurationException, PathNotFoundException, RepositoryException
+ AccessManager accessManager, FileCleanerHolder cleanerHolder) throws RepositoryConfigurationException,
+ PathNotFoundException, RepositoryException
{
this(config, repConfig, dataManager, namespaceRegistry, locationFactory, nodeTypeManager, valueFactory,
- accessManager, config.getInitializer().getParameterValue(RESTORE_PATH_PARAMETER, null));
+ accessManager, config.getInitializer().getParameterValue(RESTORE_PATH_PARAMETER, null), cleanerHolder);
}
/**
@@ -438,7 +440,8 @@
public SysViewWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl namespaceRegistry,
LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
- AccessManager accessManager, String restorePath) throws RepositoryException
+ AccessManager accessManager, String restorePath, FileCleanerHolder cleanerHolder)
+ throws RepositoryException
{
this.workspaceEntry = config;
this.workspaceName = config.getName();
@@ -450,7 +453,7 @@
this.namespaceRegistry = namespaceRegistry;
this.locationFactory = locationFactory;
- this.fileCleaner = valueFactory.getFileCleaner();
+ this.fileCleaner = cleanerHolder.getFileCleaner();
this.maxBufferSize =
config.getContainer().getParameterInteger(WorkspaceDataContainer.MAXBUFFERSIZE_PROP,
WorkspaceDataContainer.DEF_MAXBUFFERSIZE);
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsBackupWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsBackupWorkspaceInitializer.java 2010-12-24 10:19:57 UTC (rev 3725)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsBackupWorkspaceInitializer.java 2010-12-24 15:27:32 UTC (rev 3726)
@@ -28,6 +28,7 @@
import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeManagerImpl;
import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
import org.exoplatform.services.jcr.impl.dataflow.persistent.CacheableWorkspaceDataManager;
+import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
import org.exoplatform.services.jcr.impl.util.jdbc.cleaner.DBCleanerException;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -58,11 +59,12 @@
public RdbmsBackupWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl namespaceRegistry,
LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
- AccessManager accessManager, RepositoryService repositoryService) throws RepositoryConfigurationException,
+ AccessManager accessManager, RepositoryService repositoryService, FileCleanerHolder cleanerHolder)
+ throws RepositoryConfigurationException,
PathNotFoundException, RepositoryException
{
super(config, repConfig, dataManager, namespaceRegistry, locationFactory, nodeTypeManager, valueFactory,
- accessManager, repositoryService);
+ accessManager, repositoryService, cleanerHolder);
}
/**
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java 2010-12-24 10:19:57 UTC (rev 3725)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java 2010-12-24 15:27:32 UTC (rev 3726)
@@ -48,6 +48,7 @@
import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
import org.exoplatform.services.jcr.impl.storage.value.fs.FileValueStorage;
+import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
import org.exoplatform.services.jcr.impl.util.jdbc.cleaner.DBCleanerException;
import org.exoplatform.services.jcr.impl.util.jdbc.cleaner.DBCleanerService;
import org.exoplatform.services.log.ExoLogger;
@@ -106,11 +107,12 @@
public RdbmsWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl namespaceRegistry,
LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
- AccessManager accessManager, RepositoryService repositoryService) throws RepositoryConfigurationException,
+ AccessManager accessManager, RepositoryService repositoryService, FileCleanerHolder cleanerHolder)
+ throws RepositoryConfigurationException,
PathNotFoundException, RepositoryException
{
super(config, repConfig, dataManager, namespaceRegistry, locationFactory, nodeTypeManager, valueFactory,
- accessManager);
+ accessManager, cleanerHolder);
this.repositoryService = repositoryService;
}
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java 2010-12-24 10:19:57 UTC (rev 3725)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java 2010-12-24 15:27:32 UTC (rev 3726)
@@ -32,6 +32,7 @@
import javax.jcr.Node;
import javax.jcr.RepositoryException;
+import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.lock.Lock;
@@ -156,6 +157,8 @@
ws1TestRoot.addNode("node #3").setProperty("exo:data", "property #3");
ws1TestRoot.addNode("node #5").setProperty("exo:extraData", "property #5");
+ ws1TestRoot.addNode("binary_data").setProperty("data", new FileInputStream(createBLOBTempFile(500)));
+
ws1TestRoot.save(); // log here via listener
// stop all
@@ -862,8 +865,14 @@
Thread.sleep(50);
}
+ //will be saved in incremental backup
+ //will be saved in incremental backup
+ Session wsSession = getReposityToBackup().login(credentials, "ws");
+ wsSession.getRootNode().getNode("backupTest").addNode("binary_data").setProperty("data",
+ new FileInputStream(createBLOBTempFile(500)));
+ wsSession.save();
+
// stop fullBackup
-
backup.stopBackup(bch);
// restore
@@ -893,6 +902,12 @@
Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
assertEquals("Restored content should be same", "property-5", ws1backTestRoot.getNode("node_5")
.getProperty("exo:data").getString());
+
+ if (wsName.equals("ws"))
+ {
+ assertNotNull(ws1backTestRoot.getNode("binary_data"));
+ assertNotNull(ws1backTestRoot.getNode("binary_data").getProperty("data"));
+ }
}
catch (Exception e)
{
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java 2010-12-24 10:19:57 UTC (rev 3725)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java 2010-12-24 15:27:32 UTC (rev 3726)
@@ -27,6 +27,7 @@
import org.exoplatform.services.jcr.impl.core.TesterRdbmsWorkspaceInitializer;
import org.exoplatform.services.jcr.impl.core.query.SystemSearchManager;
import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
+import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.jcr.util.TesterConfigurationHelper;
@@ -90,7 +91,7 @@
TesterRdbmsWorkspaceInitializer initializer =
new TesterRdbmsWorkspaceInitializer(newEntry, repositoryService.getRepository("db1").getConfiguration(),
- cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService);
+ cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService, new FileCleanerHolder());
initializer.restoreValueFiles();
assertTrue(new File(newValueStoragePath).list().length > 0);
@@ -144,7 +145,8 @@
TesterRdbmsWorkspaceInitializer initializer =
new TesterRdbmsWorkspaceInitializer(newEntry, repositoryService.getRepository("db1").getConfiguration(),
- cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService);
+ cacheableDataManager, null, null, null,
+ (ValueFactoryImpl) valueFactory, null, repositoryService, new FileCleanerHolder());
initializer.restoreValueFiles();
assertFalse(new File(newValueStoragePath).exists());
@@ -214,7 +216,8 @@
TesterRdbmsWorkspaceInitializer initializer =
new TesterRdbmsWorkspaceInitializer(newEntry, repositoryService.getRepository("db1").getConfiguration(),
- cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService);
+ cacheableDataManager, null, null, null,
+ (ValueFactoryImpl) valueFactory, null, repositoryService, new FileCleanerHolder());
// restore multi -> multi
initializer.restoreTables(conn, 0, true, workspaceEntry.getLockManager(), url.getFile());
@@ -259,7 +262,7 @@
initializer =
new TesterRdbmsWorkspaceInitializer(newEntry, repositoryService.getRepository("db1").getConfiguration(),
- cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService);
+ cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService, new FileCleanerHolder());
// restore multi -> single
initializer.restoreTables(conn, 0, false, workspaceEntry.getLockManager(), url.getFile());
@@ -331,7 +334,7 @@
TesterRdbmsWorkspaceInitializer initializer =
new TesterRdbmsWorkspaceInitializer(newEntry, repositoryService.getRepository("db3").getConfiguration(),
- cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService);
+ cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService, new FileCleanerHolder());
// restore single -> multi
initializer.restoreTables(conn, 0, true, workspaceEntry.getLockManager(), url.getFile());
@@ -376,7 +379,7 @@
initializer =
new TesterRdbmsWorkspaceInitializer(newEntry, repositoryService.getRepository("db3").getConfiguration(),
- cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService);
+ cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService, new FileCleanerHolder());
// restore single -> single
initializer.restoreTables(conn, 0, false, workspaceEntry.getLockManager(), url.getFile());
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/TesterRdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/TesterRdbmsWorkspaceInitializer.java 2010-12-24 10:19:57 UTC (rev 3725)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/TesterRdbmsWorkspaceInitializer.java 2010-12-24 15:27:32 UTC (rev 3726)
@@ -29,6 +29,7 @@
import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeManagerImpl;
import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
import org.exoplatform.services.jcr.impl.dataflow.persistent.CacheableWorkspaceDataManager;
+import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
import java.io.IOException;
import java.sql.Connection;
@@ -53,11 +54,12 @@
public TesterRdbmsWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl namespaceRegistry,
LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
- AccessManager accessManager, RepositoryService repositoryService) throws RepositoryConfigurationException,
+ AccessManager accessManager, RepositoryService repositoryService, FileCleanerHolder cleanerHolder)
+ throws RepositoryConfigurationException,
PathNotFoundException, RepositoryException
{
super(config, repConfig, dataManager, namespaceRegistry, locationFactory, nodeTypeManager, valueFactory,
- accessManager, repositoryService);
+ accessManager, repositoryService, cleanerHolder);
}
public void restoreValueFiles() throws RepositoryConfigurationException, IOException
13 years, 4 months
exo-jcr SVN: r3724 - jcr/trunk/exo.jcr.component.core.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-24 04:33:37 -0500 (Fri, 24 Dec 2010)
New Revision: 3724
Modified:
jcr/trunk/exo.jcr.component.core/pom.xml
Log:
EXOJCR-852: exclude TestRollbackBigFiles.java
Modified: jcr/trunk/exo.jcr.component.core/pom.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/pom.xml 2010-12-24 07:24:21 UTC (rev 3723)
+++ jcr/trunk/exo.jcr.component.core/pom.xml 2010-12-24 09:33:37 UTC (rev 3724)
@@ -415,6 +415,7 @@
<excludes>
<exclude>org/exoplatform/services/jcr/**/api/TestAll.java</exclude>
<exclude>org/exoplatform/services/jcr/**/TestErrorMultithreading.java</exclude>
+ <exclude>org/exoplatform/services/jcr/**/TestRollbackBigFiles.java</exclude>
<exclude>org/exoplatform/services/jcr/**/api/**/TestVersionRestore.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestWorkspaceManagement.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestWorkspaceRestore.java</exclude>
@@ -706,6 +707,7 @@
<excludes>
<!-- From default tests -->
<exclude>org/exoplatform/services/jcr/**/TestQueryUsecases.java</exclude>
+ <exclude>org/exoplatform/services/jcr/**/TestRollbackBigFiles.java</exclude>
<exclude>org/exoplatform/services/jcr/**/TestImport.java</exclude>
<exclude>org/exoplatform/services/jcr/**/TestRollbackBigFiles.java</exclude>
<exclude>org/exoplatform/services/jcr/**/TestErrorMultithreading.java</exclude>
13 years, 4 months
exo-jcr SVN: r3723 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2010-12-24 02:24:21 -0500 (Fri, 24 Dec 2010)
New Revision: 3723
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/SessionChangesLog.java
Log:
EXOJCR-1120: changes log traversing optimized
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/SessionChangesLog.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/SessionChangesLog.java 2010-12-23 21:26:50 UTC (rev 3722)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/SessionChangesLog.java 2010-12-24 07:24:21 UTC (rev 3723)
@@ -204,16 +204,24 @@
private void traverseChangesByIdentifier(String identifier, List<ItemState> changesList)
{
- for (int i = 0, length = items.size(); i < length; i++)
+ ItemState item = getItemState(identifier);
+ if (item != null)
{
- ItemState item = items.get(i);
- if (item.getData().getIdentifier().equals(identifier))
+ changesList.add(item);
+ Map<String, ItemState> children = lastChildPropertyStates.get(identifier);
+ if (children != null)
{
- changesList.add(item);
+ // Add all the properties
+ changesList.addAll(children.values());
}
- else if (item.getData().getParentIdentifier().equals(identifier))
+ children = lastChildNodeStates.get(identifier);
+ if (children != null)
{
- traverseChangesByIdentifier(item.getData().getIdentifier(), changesList);
+ // Recursively call the method traverseChangesByIdentifier(String identifier, List<ItemState> changesList) for each sub node
+ for (ItemState child : children.values())
+ {
+ traverseChangesByIdentifier(child.getData().getIdentifier(), changesList);
+ }
}
}
}
@@ -226,17 +234,27 @@
*/
public void eraseEventFire(String identifier)
{
- for (int i = 0, length = items.size(); i < length; i++)
+ ItemState item = getItemState(identifier);
+ if (item != null)
{
- ItemState item = items.get(i);
- if (item.getData().getIdentifier().equals(identifier))
+ item.eraseEventFire();
+ Map<String, ItemState> children = lastChildPropertyStates.get(identifier);
+ if (children != null)
{
- // erase flag
- item.eraseEventFire();
+ // Call the method ItemState.eraseEventFire() on each properties
+ for (ItemState child : children.values())
+ {
+ child.eraseEventFire();
+ }
}
- else if (item.getData().getParentIdentifier().equals(identifier))
+ children = lastChildNodeStates.get(identifier);
+ if (children != null)
{
- eraseEventFire(item.getData().getIdentifier());
+ // Recursively call the method eraseEventFire(String identifier) for each sub node
+ for (ItemState child : children.values())
+ {
+ eraseEventFire(child.getData().getIdentifier());
+ }
}
}
}
13 years, 4 months
exo-jcr SVN: r3722 - kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2010-12-23 16:26:50 -0500 (Thu, 23 Dec 2010)
New Revision: 3722
Modified:
kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java
Log:
EXOJCR-1073: Unit Test fixed
Modified: kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java 2010-12-23 15:19:02 UTC (rev 3721)
+++ kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java 2010-12-23 21:26:50 UTC (rev 3722)
@@ -18,13 +18,6 @@
*/
package org.exoplatform.services.rpc.impl;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Vector;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicReference;
-
import org.exoplatform.container.PortalContainer;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.container.xml.InitParams;
@@ -38,6 +31,13 @@
import org.exoplatform.test.BasicTestCase;
import org.jgroups.Address;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicReference;
+
/**
* This is the unit test class for the service {@link RPCServiceImpl}
*
@@ -1189,7 +1189,7 @@
private boolean isCoordinator;
private int count;
- private CountDownLatch lock;
+ private CountDownLatch lock = new CountDownLatch(2);
/**
* @see org.exoplatform.services.rpc.TopologyChangeListener#onChange(org.exoplatform.services.rpc.TopologyChangeEvent)
@@ -1200,15 +1200,11 @@
this.isCoordinator = event.isCoordinator();
count++;
- if (lock != null)
- {
- lock.countDown();
- }
+ lock.countDown();
}
public void waitTopologyChange() throws InterruptedException
{
- lock = new CountDownLatch(1);
lock.await();
}
}
13 years, 4 months