exo-jcr SVN: r3741 - jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-12-28 04:30:56 -0500 (Tue, 28 Dec 2010)
New Revision: 3741
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyClassLoaderProvider.java
Log:
EXOJCR-1105
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyClassLoaderProvider.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyClassLoaderProvider.java 2010-12-28 09:30:26 UTC (rev 3740)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyClassLoaderProvider.java 2010-12-28 09:30:56 UTC (rev 3741)
@@ -140,7 +140,7 @@
super(AccessController.doPrivileged(new PrivilegedAction<JcrGroovyClassLoader>() {
public JcrGroovyClassLoader run()
{
- return new JcrGroovyClassLoader(getClass().getClassLoader());
+ return new JcrGroovyClassLoader(JcrGroovyClassLoaderProvider.class.getClassLoader());
}
}));
}
13 years, 4 months
exo-jcr SVN: r3740 - ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-12-28 04:30:26 -0500 (Tue, 28 Dec 2010)
New Revision: 3740
Modified:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ExtendedGroovyClassLoader.java
Log:
EXOJCR-1105
Modified: 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 2010-12-28 09:11:49 UTC (rev 3739)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ExtendedGroovyClassLoader.java 2010-12-28 09:30:26 UTC (rev 3740)
@@ -196,12 +196,18 @@
cunit.setClassgenCallback(collector);
cunit.compile(phase);
- for (Iterator iter = collector.getLoadedClasses().iterator(); iter.hasNext();) {
+ for (Iterator iter = collector.getLoadedClasses().iterator(); iter.hasNext();)
+ {
Class clazz = (Class)iter.next();
String classname = clazz.getName();
int i = classname.lastIndexOf('.');
if (i != -1)
- definePackage(classname.substring(0, i), null, null, null, null, null, null, null);
+ {
+ String pkgname = classname.substring(0, i);
+ Package pkg = getPackage(pkgname);
+ if (pkg == null)
+ definePackage(pkgname, null, null, null, null, null, null, null);
+ }
setClassCacheEntry(clazz);
}
@@ -239,7 +245,12 @@
String classname = clazz.getName();
int i = classname.lastIndexOf('.');
if (i != -1)
- definePackage(classname.substring(0, i), null, null, null, null, null, null, null);
+ {
+ String pkgname = classname.substring(0, i);
+ Package pkg = getPackage(pkgname);
+ if (pkg == null)
+ definePackage(pkgname, null, null, null, null, null, null, null);
+ }
setClassCacheEntry(clazz);
}
List<Class> compiledClasses = collector.getCompiledClasses();
13 years, 4 months
exo-jcr SVN: r3739 - jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/server.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-12-28 04:11:49 -0500 (Tue, 28 Dec 2010)
New Revision: 3739
Modified:
jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.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/server/HTTPBackupAgentTest.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.java 2010-12-28 09:01:56 UTC (rev 3738)
+++ jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.java 2010-12-28 09:11:49 UTC (rev 3739)
@@ -36,6 +36,7 @@
import org.exoplatform.services.jcr.ext.backup.ExtendedBackupManager;
import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChain;
import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChainLog;
+import org.exoplatform.services.jcr.ext.backup.impl.JobRepositoryRestore;
import org.exoplatform.services.jcr.ext.backup.impl.JobWorkspaceRestore;
import org.exoplatform.services.jcr.ext.backup.server.bean.BackupConfigBean;
import org.exoplatform.services.jcr.ext.backup.server.bean.response.BackupServiceInfoBean;
@@ -898,7 +899,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitWorkspaceRestore("db6", "ws3");
// Get restore info to workspace /db6/ws3
{
@@ -1049,7 +1050,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitWorkspaceRestore("db6", "ws3");
// Get restore info to workspace /db6/ws3
{
@@ -1168,7 +1169,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitWorkspaceRestore("db6", "ws3");
// Get restore info to workspace /db6/ws3
{
@@ -1260,7 +1261,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitWorkspaceRestore("db6", "ws2");
// Get restore info to workspace /db6/ws2
{
@@ -1354,7 +1355,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitWorkspaceRestore("db6", "ws2");
// Get restore info to workspace /db6/ws2
{
@@ -1481,7 +1482,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitWorkspaceRestore("db6", "ws3");
// Get restore info to workspace /db6/ws3
{
@@ -1583,7 +1584,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitWorkspaceRestore("db6", "ws2");
// Get restore info to workspace /db6/ws2
{
@@ -1686,7 +1687,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitWorkspaceRestore("db6", "ws2");
// Get restore info to workspace /db6/ws2
{
@@ -1815,7 +1816,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitWorkspaceRestore("db6", "ws3");
// Get restore info to workspace /db6/ws3
{
@@ -1950,7 +1951,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitRepositoryRestore("db6backup");
// Get restore info
{
@@ -2120,7 +2121,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitRepositoryRestore("db6backup");
// Get restore info
{
@@ -2257,7 +2258,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitRepositoryRestore("db6backup");
// Get restore info
{
@@ -2349,7 +2350,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitRepositoryRestore("db6");
// Get restore info
{
@@ -2441,7 +2442,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitRepositoryRestore("db6");
// Get restore info
{
@@ -2589,7 +2590,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitRepositoryRestore("db6backup");
// Get restore info
{
@@ -2736,7 +2737,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitRepositoryRestore("db6backup");
// Get restore info
{
@@ -2837,7 +2838,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitRepositoryRestore("db6");
// Get restore info
{
@@ -2939,7 +2940,7 @@
assertEquals(200, cres.getStatus());
}
- Thread.sleep(2000);
+ waitRepositoryRestore("db6");
// Get restore info
{
@@ -3089,4 +3090,74 @@
{
return (ExtendedBackupManager) container.getComponentInstanceOfType(BackupManager.class);
}
+
+ protected void waitWorkspaceRestore(String repoName, String wsName) throws Exception
+ {
+ boolean wait = true;
+
+ while (wait)
+ {
+
+ // Get restore info to workspace /<repoName>/<wsName>
+ MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+ ContainerRequestUserRole creq =
+ new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
+ + HTTPBackupAgent.Constants.OperationType.CURRENT_RESTORE_INFO_ON_WS + "/" + repoName + "/"
+ + wsName), new URI(""), null, new InputHeadersMap(headers));
+
+ ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
+ ContainerResponse cres = new ContainerResponse(responseWriter);
+ handler.handleRequest(creq, cres);
+
+ assertEquals(200, cres.getStatus());
+
+ DetailedInfo info = (DetailedInfo) getObject(DetailedInfo.class, responseWriter.getBody());
+
+ if (info.getState().intValue() == JobWorkspaceRestore.RESTORE_SUCCESSFUL
+ || info.getState().intValue() == JobWorkspaceRestore.RESTORE_FAIL)
+ {
+ wait = false;
+ }
+ else
+ {
+ Thread.sleep(500);
+ }
+ }
+ }
+
+
+ protected void waitRepositoryRestore(String repoName) throws Exception
+ {
+ boolean wait = true;
+
+ while (wait)
+ {
+ // Get restore info
+ MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+ ContainerRequestUserRole creq =
+ new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
+ + HTTPBackupAgent.Constants.OperationType.CURRENT_RESTORE_INFO_ON_REPOSITORY + "/"
+ + repoName), new URI(""), null, new InputHeadersMap(headers));
+
+ ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
+ ContainerResponse cres = new ContainerResponse(responseWriter);
+ handler.handleRequest(creq, cres);
+
+ assertEquals(200, cres.getStatus());
+
+ DetailedInfo info = (DetailedInfo) getObject(DetailedInfo.class, responseWriter.getBody());
+
+ if (info.getState().intValue() == JobRepositoryRestore.REPOSITORY_RESTORE_SUCCESSFUL
+ || info.getState().intValue() == JobRepositoryRestore.REPOSITORY_RESTORE_FAIL)
+ {
+ wait = false;
+ }
+ else
+ {
+ Thread.sleep(500);
+ }
+ }
+ }
+
+
}
13 years, 4 months
exo-jcr SVN: r3738 - ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-12-28 04:01:56 -0500 (Tue, 28 Dec 2010)
New Revision: 3738
Modified:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyClassLoaderProvider.java
Log:
EXOJCR-1105
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-28 08:07:06 UTC (rev 3737)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyClassLoaderProvider.java 2010-12-28 09:01:56 UTC (rev 3738)
@@ -39,14 +39,13 @@
/** Preset default GroovyClassLoader. */
private ExtendedGroovyClassLoader defaultClassLoader;
- // TODO
public GroovyClassLoaderProvider()
{
this(AccessController.doPrivileged(new PrivilegedAction<ExtendedGroovyClassLoader>()
{
public ExtendedGroovyClassLoader run()
{
- return new ExtendedGroovyClassLoader(getClass().getClassLoader());
+ return new ExtendedGroovyClassLoader(GroovyClassLoaderProvider.class.getClassLoader());
}
}));
}
13 years, 4 months
exo-jcr SVN: r3737 - ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-12-28 03:07:06 -0500 (Tue, 28 Dec 2010)
New Revision: 3737
Modified:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ExtendedGroovyClassLoader.java
Log:
EXOJCR-1105
Modified: 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 2010-12-28 07:20:40 UTC (rev 3736)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ExtendedGroovyClassLoader.java 2010-12-28 08:07:06 UTC (rev 3737)
@@ -42,7 +42,8 @@
/**
* @author <a href="andrew00x(a)gmail.com">Andrey Parfonov</a>
- * @version $Id$
+ * @version $Id: ExtendedGroovyClassLoader.java 3731 2010-12-27 13:35:46Z
+ * aparfonov $
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public class ExtendedGroovyClassLoader extends GroovyClassLoader
@@ -66,13 +67,13 @@
protected Class createClass(byte[] code, ClassNode classNode)
{
ExtendedInnerLoader cl = (ExtendedInnerLoader)getDefiningClassLoader();
- String classname = classNode.getName();
+ /*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)
@@ -115,13 +116,13 @@
protected Class createClass(byte[] code, ClassNode classNode)
{
ExtendedInnerLoader cl = (ExtendedInnerLoader)getDefiningClassLoader();
- String classname = classNode.getName();
+ /*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();
@@ -195,8 +196,14 @@
cunit.setClassgenCallback(collector);
cunit.compile(phase);
- for (Iterator iter = collector.getLoadedClasses().iterator(); iter.hasNext();)
- setClassCacheEntry((Class)iter.next());
+ for (Iterator iter = collector.getLoadedClasses().iterator(); iter.hasNext();) {
+ Class clazz = (Class)iter.next();
+ String classname = clazz.getName();
+ int i = classname.lastIndexOf('.');
+ if (i != -1)
+ definePackage(classname.substring(0, i), null, null, null, null, null, null, null);
+ setClassCacheEntry(clazz);
+ }
target = collector.getTarget();
@@ -229,6 +236,10 @@
for (Iterator iter = collector.getLoadedClasses().iterator(); iter.hasNext();)
{
Class clazz = (Class)iter.next();
+ String classname = clazz.getName();
+ int i = classname.lastIndexOf('.');
+ if (i != -1)
+ definePackage(classname.substring(0, i), null, null, null, null, null, null, null);
setClassCacheEntry(clazz);
}
List<Class> compiledClasses = collector.getCompiledClasses();
13 years, 4 months
exo-jcr SVN: r3736 - jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-28 02:20:40 -0500 (Tue, 28 Dec 2010)
New Revision: 3736
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java
Log:
EXOJCR-1078: make TestLoadBackup independent
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java 2010-12-28 07:18:36 UTC (rev 3735)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java 2010-12-28 07:20:40 UTC (rev 3736)
@@ -196,7 +196,7 @@
System.out.println(" ============ BACKUP FINISHED ============");
// restore
- WorkspaceEntry ws1back = makeWorkspaceEntry("ws1back", "jdbcjcr3");
+ WorkspaceEntry ws1back = makeWorkspaceEntry("ws1back", "jdbcrestore");
File backLog = new File(bch.getLogFilePath());
if (backLog.exists())
13 years, 4 months
exo-jcr SVN: r3735 - in jcr/trunk/exo.jcr.component.ext/src/test: resources/conf/standalone and 1 other directory.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-28 02:18:36 -0500 (Tue, 28 Dec 2010)
New Revision: 3735
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java
jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml
Log:
EXOJCR-1078: make TestLoadBackup independent
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java 2010-12-27 14:08:38 UTC (rev 3734)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java 2010-12-28 07:18:36 UTC (rev 3735)
@@ -18,9 +18,15 @@
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.PropertiesParam;
+import org.exoplatform.services.jcr.config.ContainerEntry;
+import org.exoplatform.services.jcr.config.QueryHandlerEntry;
+import org.exoplatform.services.jcr.config.QueryHandlerParams;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.SimpleParameterEntry;
+import org.exoplatform.services.jcr.config.ValueStorageEntry;
+import org.exoplatform.services.jcr.config.ValueStorageFilterEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.core.ManageableRepository;
-import org.exoplatform.services.jcr.ext.backup.AbstractBackupTestCase;
+import org.exoplatform.services.jcr.ext.BaseStandaloneTest;
import org.exoplatform.services.jcr.ext.backup.BackupChain;
import org.exoplatform.services.jcr.ext.backup.BackupChainLog;
import org.exoplatform.services.jcr.ext.backup.BackupConfig;
@@ -28,9 +34,12 @@
import org.exoplatform.services.jcr.ext.backup.BackupManager;
import org.exoplatform.services.jcr.ext.backup.ExtendedBackupManager;
import org.exoplatform.services.jcr.ext.backup.impl.BackupManagerImpl;
+import org.exoplatform.services.jcr.ext.backup.impl.JobWorkspaceRestore;
import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.core.NodeImpl;
import org.exoplatform.services.jcr.impl.core.PropertyImpl;
+import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
import java.io.File;
import java.io.FileInputStream;
@@ -40,6 +49,8 @@
import java.util.Iterator;
import java.util.List;
+import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
@@ -57,7 +68,7 @@
* @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
* @version $Id: TestLoadBackup.java 111 2008-11-11 11:11:11Z serg $
*/
-public class TestLoadBackup extends AbstractBackupTestCase
+public class TestLoadBackup extends BaseStandaloneTest
{
protected final String REPOSITORY_NAME = "db7";
@@ -69,8 +80,6 @@
protected final int BACKUP_TYPE = BackupManager.FULL_BACKUP_ONLY;
- protected ManageableRepository repository;
-
/**
* Writer.
*/
@@ -101,6 +110,7 @@
}
catch (Exception e)
{
+ e.printStackTrace();
}
}
}
@@ -112,7 +122,7 @@
*/
public void testBackupRestore() throws Exception
{
- BackupManagerImpl backupManagerImpl = null;
+ BackupManagerImpl backupManagerImpl = (BackupManagerImpl)getBackupManager();
List<TreeWriterThread> threads = new ArrayList<TreeWriterThread>();
List<Session> sessions = new ArrayList<Session>();
@@ -120,7 +130,7 @@
//writers
for (int i = 0; i < WRITER_COUNT; i++)
{
- Session writerSession = repository.login(credentials, WORKSPACE_NAME);
+ Session writerSession = repositoryService.getRepository(REPOSITORY_NAME).login(credentials, WORKSPACE_NAME);
TreeWriterThread writer = new TreeWriterThread(writerSession, "subnode" + i);
writer.start();
threads.add(writer);
@@ -136,7 +146,6 @@
backDir.mkdirs();
BackupChain bch = null;
- backupManagerImpl = (BackupManagerImpl)getBackupManager();
backupManagerImpl.start();
BackupConfig config = new BackupConfig();
@@ -163,10 +172,10 @@
Thread.sleep(5 * 1000);
}
- for (Thread thread : threads)
- {
- thread.interrupt();
- }
+ // for (Thread thread : threads)
+ // {
+ // thread.interrupt();
+ // }
if (BACKUP_TYPE == BackupManager.FULL_AND_INCREMENTAL)
{
@@ -199,7 +208,23 @@
assertNotNull(bchLog.getStartedTime());
assertNotNull(bchLog.getFinishedTime());
- backup.restore(bchLog, repositoryNameToBackup, ws1back, false);
+ backupManagerImpl.restore(bchLog, REPOSITORY_NAME, ws1back, false);
+
+ JobWorkspaceRestore restore = backupManagerImpl.getLastRestore(REPOSITORY_NAME, ws1back.getName());
+ if (restore != null)
+ {
+ while (restore.getStateRestore() == JobWorkspaceRestore.RESTORE_FAIL
+ || restore.getStateRestore() == JobWorkspaceRestore.RESTORE_SUCCESSFUL)
+ {
+ Thread.sleep(1000);
+ }
+
+ if (restore.getStateRestore() == JobWorkspaceRestore.RESTORE_FAIL)
+ {
+ restore.getRestoreException().printStackTrace();
+ fail(restore.getRestoreException().getMessage());
+ }
+ }
}
else
{
@@ -208,7 +233,7 @@
System.out.println(" ============ CHECKING INTEGRITY ============");
- checkIntegrity((NodeImpl)repositoryService.getRepository(repositoryNameToBackup).login(credentials, "ws1back")
+ checkIntegrity((NodeImpl)repositoryService.getRepository(REPOSITORY_NAME).login(credentials, "ws1back")
.getRootNode());
}
@@ -241,7 +266,6 @@
/**
* {@inheritDoc}
*/
- @Override
protected ExtendedBackupManager getBackupManager()
{
InitParams initParams = new InitParams();
@@ -308,7 +332,7 @@
public void _testTableLock() throws Exception
{
- Session writerSession = repository.login(credentials, WORKSPACE_NAME);
+ Session writerSession = repositoryService.getRepository(REPOSITORY_NAME).login(credentials, WORKSPACE_NAME);
// TreeWriterThread writer = new TreeWriterThread(writerSession, "subnode");
// writer.start();
@@ -334,6 +358,79 @@
addChilds(writerSession, writerSession.getRootNode(), 0);
}
+ protected WorkspaceEntry makeWorkspaceEntry(String name, String sourceName) throws LoginException,
+ NoSuchWorkspaceException, RepositoryException, RepositoryConfigurationException
+ {
+ SessionImpl session =
+ (SessionImpl)repositoryService.getRepository(REPOSITORY_NAME).login(credentials, WORKSPACE_NAME);
+
+ WorkspaceEntry ws1e = (WorkspaceEntry)session.getContainer().getComponentInstanceOfType(WorkspaceEntry.class);
+
+ WorkspaceEntry ws1back = new WorkspaceEntry();
+ ws1back.setName(name);
+ // RepositoryContainer rcontainer = (RepositoryContainer)
+ // container.getComponentInstanceOfType(RepositoryContainer.class);
+ ws1back.setUniqueName(((RepositoryImpl)session.getRepository()).getName() + "_" + ws1back.getName()); // EXOMAN
+
+ ws1back.setAccessManager(ws1e.getAccessManager());
+ ws1back.setCache(ws1e.getCache());
+ // ws1back.setContainer(ws1e.getContainer());
+ ws1back.setLockManager(ws1e.getLockManager());
+ ws1back.setInitializer(ws1e.getInitializer());
+
+ // Indexer
+ ArrayList qParams = new ArrayList();
+ // qParams.add(new SimpleParameterEntry("indexDir", "target" + File.separator+ "temp" +
+ // File.separator +"index" + name));
+ qParams.add(new SimpleParameterEntry(QueryHandlerParams.PARAM_INDEX_DIR, "target/temp/index/" + name
+ + System.currentTimeMillis()));
+ QueryHandlerEntry qEntry =
+ new QueryHandlerEntry("org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex", qParams);
+
+ ws1back.setQueryHandler(qEntry); // EXOMAN
+
+ ArrayList params = new ArrayList();
+ for (Iterator i = ws1e.getContainer().getParameters().iterator(); i.hasNext();)
+ {
+ SimpleParameterEntry p = (SimpleParameterEntry)i.next();
+ SimpleParameterEntry newp = new SimpleParameterEntry(p.getName(), p.getValue());
+
+ if (newp.getName().equals("source-name") && sourceName != null)
+ newp.setValue(sourceName);
+ else if (newp.getName().equals("swap-directory"))
+ newp.setValue("target/temp/swap/" + name + System.currentTimeMillis());
+
+ params.add(newp);
+ }
+
+ ContainerEntry ce =
+ new ContainerEntry("org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer", params);
+
+ ArrayList<ValueStorageEntry> list = new ArrayList<ValueStorageEntry>();
+
+ // value storage
+ ArrayList<ValueStorageFilterEntry> vsparams = new ArrayList<ValueStorageFilterEntry>();
+ ValueStorageFilterEntry filterEntry = new ValueStorageFilterEntry();
+ filterEntry.setPropertyType("Binary");
+ vsparams.add(filterEntry);
+
+ ValueStorageEntry valueStorageEntry =
+ new ValueStorageEntry("org.exoplatform.services.jcr.impl.storage.value.fs.TreeFileValueStorage", vsparams);
+ ArrayList<SimpleParameterEntry> spe = new ArrayList<SimpleParameterEntry>();
+ spe.add(new SimpleParameterEntry("path", "target/temp/values/" + name + "_" + System.currentTimeMillis()));
+ valueStorageEntry.setId("draft");
+ valueStorageEntry.setParameters(spe);
+ valueStorageEntry.setFilters(vsparams);
+
+ // containerEntry.setValueStorages();
+ list.add(valueStorageEntry);
+ ce.setValueStorages(list);
+
+ ws1back.setContainer(ce);
+
+ return ws1back;
+ }
+
/**
* {@inheritDoc}
*/
@@ -341,8 +438,6 @@
public void setUp() throws Exception
{
super.setUp();
-
- repository = repositoryService.getRepository(REPOSITORY_NAME);
}
/**
Modified: jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml 2010-12-27 14:08:38 UTC (rev 3734)
+++ jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml 2010-12-28 07:18:36 UTC (rev 3735)
@@ -30,7 +30,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="true" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -63,7 +63,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr1" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="true" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -86,7 +86,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr2" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="true" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -105,34 +105,34 @@
</properties>
</query-handler>
</workspace>
- <workspace name="ws3" auto-init-root-nodetype="nt:unstructured">
- <container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
- <properties>
- <property name="source-name" value="jdbcjcr3" />
- <property name="dialect" value="hsqldb" />
- <property name="multi-db" value="true" />
- <property name="update-storage" value="true" />
- <property name="max-buffer-size" value="200k" />
- <property name="swap-directory" value="target/temp/swap/ws3" />
- </properties>
- </container>
- <cache enabled="true">
- <properties>
- <property name="max-size" value="5k" />
- <property name="live-time" value="1h" />
- </properties>
- </cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
- <properties>
- <property name="index-dir" value="target/temp/index/ws3" />
- </properties>
- </query-handler>
- </workspace>
+ <workspace name="ws3" auto-init-root-nodetype="nt:unstructured">
+ <container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
+ <properties>
+ <property name="source-name" value="jdbcjcr3" />
+ <property name="dialect" value="auto" />
+ <property name="multi-db" value="true" />
+ <property name="update-storage" value="true" />
+ <property name="max-buffer-size" value="200k" />
+ <property name="swap-directory" value="target/temp/swap/ws3" />
+ </properties>
+ </container>
+ <cache enabled="true">
+ <properties>
+ <property name="max-size" value="5k" />
+ <property name="live-time" value="1h" />
+ </properties>
+ </cache>
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
+ <properties>
+ <property name="index-dir" value="target/temp/index/ws3" />
+ </properties>
+ </query-handler>
+ </workspace>
<workspace name="ws4" auto-init-root-nodetype="nt:unstructured">
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr4" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="true" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -155,7 +155,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr5" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="true" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -186,7 +186,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr19" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="true" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -217,7 +217,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr77" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="false" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -248,7 +248,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr20" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="true" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -272,7 +272,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr22" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="true" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -303,7 +303,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr21" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="true" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -327,7 +327,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr23" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="true" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -358,7 +358,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr24" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="false" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -381,7 +381,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr25" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="false" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -404,7 +404,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr26" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="false" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -435,7 +435,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr_to_repository_restore_singel_db" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="false" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -468,7 +468,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr_to_repository_restore_singel_db" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="false" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -509,7 +509,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr_backup_only_use_1" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="true" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
@@ -542,7 +542,7 @@
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
<property name="source-name" value="jdbcjcr_backup_only_use_2" />
- <property name="dialect" value="hsqldb" />
+ <property name="dialect" value="auto" />
<property name="multi-db" value="true" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
13 years, 4 months
exo-jcr SVN: r3734 - ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-12-27 09:08:38 -0500 (Mon, 27 Dec 2010)
New Revision: 3734
Modified:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java
Log:
EXOJCR-1105
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:58:13 UTC (rev 3733)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java 2010-12-27 14:08:38 UTC (rev 3734)
@@ -627,7 +627,7 @@
}
@SuppressWarnings("rawtypes")
- private Object createInstance(Class clazz) throws IllegalArgumentException, InstantiationException,
+ protected Object createInstance(Class clazz) throws IllegalArgumentException, InstantiationException,
IllegalAccessException, InvocationTargetException
{
ExoContainer container = ExoContainerContext.getCurrentContainer();
13 years, 4 months
exo-jcr SVN: r3733 - ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-12-27 08:58:13 -0500 (Mon, 27 Dec 2010)
New Revision: 3733
Modified:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java
Log:
EXOJCR-1105: cleanup
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:37:04 UTC (rev 3732)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java 2010-12-27 13:58:13 UTC (rev 3733)
@@ -67,8 +67,7 @@
private static final Log log = ExoLogger.getExoLogger(GroovyJaxrsPublisher.class);
@SuppressWarnings("rawtypes")
- private static final Comparator<Constructor> constructorComparator = new Comparator<Constructor>()
- {
+ private static final Comparator<Constructor> constructorComparator = new Comparator<Constructor>() {
public int compare(Constructor o1, Constructor o2)
{
int c1 = o1.getParameterTypes().length;
@@ -189,8 +188,7 @@
* {@link ResourceBinder#addResource(Class, MultivaluedMap)}
* @throws CompilationFailedException if compilation fails from source errors
*/
- public void publishPerRequest(final InputStream in, final ResourceId resourceId,
- MultivaluedMap<String, String> properties)
+ public void publishPerRequest(InputStream in, ResourceId resourceId, MultivaluedMap<String, String> properties)
{
publishPerRequest(in, resourceId, properties, null, null);
}
@@ -212,8 +210,7 @@
public void publishPerRequest(final InputStream in, final ResourceId resourceId,
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
@@ -268,7 +265,7 @@
* @throws CompilationFailedException if compilation fails from source errors
*/
public final void publishPerRequest(String source, ResourceId resourceId, MultivaluedMap<String, String> properties,
- final SourceFolder[] src, final SourceFile[] files)
+ SourceFolder[] src, SourceFile[] files)
{
publishPerRequest(source, DEFAULT_CHARSET, resourceId, properties, src, files);
}
@@ -353,7 +350,7 @@
* @throws CompilationFailedException if compilation fails from source errors
*/
public void publishSingleton(final InputStream in, final ResourceId resourceId,
- MultivaluedMap<String, String> properties, final SourceFolder[] src, final SourceFile[] files/*TODO*/)
+ MultivaluedMap<String, String> properties, final SourceFolder[] src, final SourceFile[] files)
{
Object resource;
try
@@ -516,8 +513,7 @@
try
{
//rc =
- AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>()
- {
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
public Class<?> run() throws MalformedURLException
{
ExtendedGroovyClassLoader cl =
@@ -688,8 +684,7 @@
*/
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, ExtendedGroovyClassLoader.CODE_BASE);
13 years, 4 months
exo-jcr SVN: r3732 - in jcr/trunk/exo.jcr.component.ext/src: test/java/org/exoplatform/services/jcr/ext/script/groovy and 1 other directory.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-12-27 08:37:04 -0500 (Mon, 27 Dec 2010)
New Revision: 3732
Removed:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrClassPathEntry.java
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/BaseGroovyScriptManager.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScriptAddRepoPlugin.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyClassLoaderProvider.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyCompiler.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyResourceLoader.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyCompilerTest.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java
Log:
EXOJCR-1105
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/BaseGroovyScriptManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/BaseGroovyScriptManager.java 2010-12-27 13:35:46 UTC (rev 3731)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/BaseGroovyScriptManager.java 2010-12-27 13:37:04 UTC (rev 3732)
@@ -33,7 +33,8 @@
/**
* @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey Parfonov</a>
- * @version $Id$
+ * @version $Id: BaseGroovyScriptManager.java 3720 2010-12-23 15:06:33Z
+ * aparfonov $
* @deprecated
*/
// Contains all method what we do not need any more in GroovyScript2RestLoader
@@ -68,12 +69,12 @@
}
public abstract Response load(String repository, String workspace, String path, boolean state, List<String> sources,
- List<String> files, List<String> extensions, MultivaluedMap<String, String> properties);
+ List<String> files, MultivaluedMap<String, String> properties);
public Response load(String repository, String workspace, String path, boolean state,
MultivaluedMap<String, String> properties)
{
- return load(repository, workspace, path, state, null, null, null, properties);
+ return load(repository, workspace, path, state, null, null, properties);
}
public boolean loadScript(ScriptKey key, String name, InputStream stream) throws IOException
@@ -130,9 +131,8 @@
public Response validateScript(String name, final InputStream script)
{
- return validateScript(name, script, null, null, null);
+ return validateScript(name, script, null, null);
}
- public abstract Response validateScript(String name, InputStream script, List<String> sources, List<String> files,
- List<String> extensions);
+ public abstract Response validateScript(String name, InputStream script, List<String> sources, List<String> files);
}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java 2010-12-27 13:35:46 UTC (rev 3731)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java 2010-12-27 13:37:04 UTC (rev 3732)
@@ -20,7 +20,6 @@
import org.apache.commons.fileupload.FileItem;
import org.codehaus.groovy.control.CompilationFailedException;
-import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.container.component.ComponentPlugin;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.container.xml.InitParams;
@@ -35,13 +34,12 @@
import org.exoplatform.services.jcr.ext.resource.UnifiedNodeReference;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import org.exoplatform.services.rest.ext.groovy.ClassPath;
-import org.exoplatform.services.rest.ext.groovy.ClassPathEntry;
-import org.exoplatform.services.rest.ext.groovy.ClassPathEntry.EntryType;
import org.exoplatform.services.rest.ext.groovy.GroovyClassLoaderProvider;
import org.exoplatform.services.rest.ext.groovy.GroovyJaxrsPublisher;
import org.exoplatform.services.rest.ext.groovy.MalformedScriptException;
import org.exoplatform.services.rest.ext.groovy.ResourceId;
+import org.exoplatform.services.rest.ext.groovy.SourceFile;
+import org.exoplatform.services.rest.ext.groovy.SourceFolder;
import org.exoplatform.services.rest.impl.ResourceBinder;
import org.exoplatform.services.rest.impl.ResourcePublicationException;
import org.exoplatform.services.script.groovy.GroovyScriptInstantiator;
@@ -55,6 +53,8 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Calendar;
@@ -523,12 +523,20 @@
LOG.debug(">>> Save init parametrs in registry service.");
}
- Document doc = SecurityHelper.doPrivilegedParserConfigurationAction(new PrivilegedExceptionAction<Document>() {
- public Document run() throws Exception
- {
- return DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
- }
- });
+ Document doc;
+ try
+ {
+ doc = AccessController.doPrivileged(new PrivilegedExceptionAction<Document>() {
+ public Document run() throws ParserConfigurationException
+ {
+ return DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (ParserConfigurationException)e.getCause();
+ }
Element root = doc.createElement(SERVICE_NAME);
doc.appendChild(root);
@@ -750,26 +758,51 @@
* <code>null</code> then GroovyClassLoader will use automatically
* generated name
* @param script Groovy source stream
- * @param sources locations (URL) of source folders that should be add in
- * class path when compile Groovy script
- * @param files locations (URL) of source files that should be add in class
- * path when compile Groovy script
- * @param extensions extensions of files from source folders that should be
- * added in class path. By default only files with .groovy
- * extension are processed. Extensions must be set in form
- * '.{extensions}'
+ * @param sources locations (string representation of URL) of source folders
+ * that should be add in class path when compile Groovy script.
+ * <b>NOTE</b> To be able load Groovy source files from specified
+ * folders the following rules must be observed:
+ * <ul>
+ * <li>Groovy source files must be located in folder with respect
+ * to package structure</li>
+ * <li>Name of Groovy source files must be the same as name of
+ * class located in file</li>
+ * <li>Groovy source file must have extension '.groovy'</li>
+ * </ul>
+ * <br/>
+ * Example: If source stream that we want validate contains the
+ * following code:
+ *
+ * <pre>
+ * package c.b.a
+ *
+ * import a.b.c.A
+ *
+ * class B extends A {
+ * // Do something.
+ * }
+ * </pre>
+ *
+ * Assume we store dependencies in JCR then URL of folder with
+ * Groovy sources may be like this:
+ * <code>jcr://repository/workspace#/groovy-library</code>. Then
+ * absolute path to JCR node that contains Groovy source must be as
+ * following: <code>/groovy-library/a/b/c/A.groovy</code>
+ * @param files locations (string representation of URL) of source files that
+ * should be add in class path when compile Groovy script. Each
+ * location must point directly to file that contains Groovy
+ * source. Source file can have any name and extension
* @return Response with corresponded status. 200 if source code is valid
*/
@POST
@Consumes({"script/groovy"})
@Path("validate{name:.*}")
public Response validateScript(@PathParam("name") String name, final InputStream script,
- @QueryParam("sources") List<String> sources, @QueryParam("file") List<String> files,
- @QueryParam("extension") List<String> extensions)
+ @QueryParam("sources") List<String> sources, @QueryParam("file") List<String> files)
{
try
{
- validateScript(name, script, createClassPath(sources, files, extensions));
+ validateScript(name, script, createSourceFolders(sources), createSourceFiles(files));
return Response.ok().build();
}
catch (MalformedScriptException e)
@@ -794,15 +827,32 @@
* <code>null</code> then GroovyClassLoader will use automatically
* generated name
* @param script Groovy source stream
- * @param classPath class path
+ * @param src set of folders that contains Groovy source files that should be
+ * add in class-path when validate <code>script</code>, see
+ * {@link SourceFolder#getPath()}. <b>NOTE</b> To be able load
+ * Groovy source files from specified folders the following rules
+ * must be observed:
+ * <ul>
+ * <li>Groovy source files must be located in folder with respect
+ * to package structure</li>
+ * <li>Name of Groovy source files must be the same as name of
+ * class located in file</li>
+ * <li>Groovy source file must have extension '.groovy'</li>
+ * </ul>
+ * @param files set of groovy source files that should be add in class-path
+ * when validate <code>script</code>. Each item must point directly
+ * to file that contains Groovy source, see
+ * {@link SourceFile#getPath()} . Source file can have any name and
+ * extension
* @throws MalformedScriptException if <code>script</code> contains not valid
* source code
*/
- public void validateScript(String name, InputStream script, ClassPath classPath) throws MalformedScriptException
+ public void validateScript(String name, InputStream script, SourceFolder[] src, SourceFile[] files)
+ throws MalformedScriptException
{
if (name != null && name.length() > 0 && name.startsWith("/"))
name = name.substring(1);
- groovyPublisher.validateResource(script, name, classPath);
+ groovyPublisher.validateResource(script, name, src, files);
}
/**
@@ -931,14 +981,40 @@
* @param state <code>true</code> if resource should be loaded and
* <code>false</code> otherwise. If this attribute is not present
* in HTTP request then it will be considered as <code>true</code>
- * @param sources locations (URL) of source folders that should be add in
- * class path when compile Groovy script
- * @param files locations (URL) of source files that should be add in class
- * path when compile Groovy script
- * @param extensions extensions of files from source folders that should be
- * added in class path. By default only files with .groovy
- * extension are processed. Extensions must be set in form
- * '.{extensions}'
+ * @param sources locations (string representation of URL) of source folders
+ * that should be add in class path when compile Groovy script.
+ * <b>NOTE</b> To be able load Groovy source files from specified
+ * folders the following rules must be observed:
+ * <ul>
+ * <li>Groovy source files must be located in folder with respect
+ * to package structure</li>
+ * <li>Name of Groovy source files must be the same as name of
+ * class located in file</li>
+ * <li>Groovy source file must have extension '.groovy'</li>
+ * </ul>
+ * <br/>
+ * Example: If source stream that we want validate contains the
+ * following code:
+ *
+ * <pre>
+ * package c.b.a
+ *
+ * import a.b.c.A
+ *
+ * class B extends A {
+ * // Do something.
+ * }
+ * </pre>
+ *
+ * Assume we store dependencies in JCR then URL of folder with
+ * Groovy sources may be like this:
+ * <code>jcr://repository/workspace#/groovy-library</code>. Then
+ * absolute path to JCR node that contains Groovy source must be as
+ * following: <code>/groovy-library/a/b/c/A.groovy</code>
+ * @param files locations (string representation of URL) of source files that
+ * should be add in class path when compile Groovy script. Each
+ * location must point directly to file that contains Groovy
+ * source. Source file can have any name and extension
* @param properties optional properties to be applied to loaded resource.
* Ignored if <code>state</code> parameter is false
*/
@@ -948,11 +1024,12 @@
public Response load(@PathParam("repository") String repository, @PathParam("workspace") String workspace,
@PathParam("path") String path, @DefaultValue("true") @QueryParam("state") boolean state,
@QueryParam("sources") List<String> sources, @QueryParam("file") List<String> files,
- @QueryParam("extension") List<String> extensions, MultivaluedMap<String, String> properties)
+ MultivaluedMap<String, String> properties)
{
try
{
- return load(repository, workspace, path, state, properties, createClassPath(sources, files, extensions));
+ return load(repository, workspace, path, state, properties, createSourceFolders(sources),
+ createSourceFiles(files));
}
catch (MalformedURLException e)
{
@@ -976,10 +1053,25 @@
* in HTTP request then it will be considered as <code>true</code>
* @param properties optional properties to be applied to loaded resource.
* Ignored if <code>state</code> parameter is false
- * @param classPath class path
+ * @param src set of folders that contains Groovy source files that should be
+ * add in class-path when compile file located at <code>path</code>
+ * . <b>NOTE</b> To be able load Groovy source files from specified
+ * folders the following rules must be observed:
+ * <ul>
+ * <li>Groovy source files must be located in folder with respect
+ * to package structure</li>
+ * <li>Name of Groovy source files must be the same as name of
+ * class located in file</li>
+ * <li>Groovy source file must have extension '.groovy'</li>
+ * </ul>
+ * @param files set of groovy source files that should be add in class-path
+ * when compile file located at <code>path</code>. Each item must
+ * point directly to file that contains Groovy source, see
+ * {@link SourceFile#getPath()} . Source file can have any name and
+ * extension
*/
public Response load(String repository, String workspace, String path, boolean state,
- MultivaluedMap<String, String> properties, ClassPath classPath)
+ MultivaluedMap<String, String> properties, SourceFolder[] src, SourceFile[] files)
{
Session ses = null;
try
@@ -992,7 +1084,7 @@
if (state)
{
groovyPublisher.unpublishResource(key);
- groovyPublisher.publishPerRequest(script.getProperty("jcr:data").getStream(), key, properties, classPath);
+ groovyPublisher.publishPerRequest(script.getProperty("jcr:data").getStream(), key, properties, src, files);
}
else
{
@@ -1314,46 +1406,44 @@
}
}
- ///////////////////////////////////////////////////////////////////////////////////////
-
- private ClassPath createClassPath(List<String> sources, List<String> files, List<String> extensions)
- throws MalformedURLException
+ private SourceFolder[] createSourceFolders(List<String> sources) throws MalformedURLException
{
- if ((sources == null || sources.size() == 0) && (files == null || files.size() == 0)
- && (extensions == null || extensions.size() == 0))
- return null;
-
- List<ClassPathEntry> classPathEntries = new ArrayList<ClassPathEntry>();
-
+ SourceFolder[] src = null;
if (sources != null && sources.size() > 0)
{
- for (String src : sources)
+ src = new SourceFolder[sources.size()];
+ for (int i = 0; i < sources.size(); i++)
{
- if (src.startsWith("jcr://"))
- classPathEntries.add(new JcrClassPathEntry(EntryType.SRC_DIR, new URL(null, src, UnifiedNodeReference
- .getURLStreamHandler())));
+ String str = sources.get(i);
+ URL url = null;
+ if (str.startsWith("jcr://"))
+ url = new URL(null, str, UnifiedNodeReference.getURLStreamHandler());
else
- classPathEntries.add(new JcrClassPathEntry(EntryType.SRC_DIR, new URL(src)));
+ url = new URL(str);
+ src[i] = new SourceFolder(url);
}
}
+ return src;
+ }
+ private SourceFile[] createSourceFiles(List<String> files) throws MalformedURLException
+ {
+ SourceFile[] srcFiles = null;
if (files != null && files.size() > 0)
{
- for (String file : files)
+ srcFiles = new SourceFile[files.size()];
+ for (int i = 0; i < files.size(); i++)
{
- if (file.startsWith("jcr://"))
- classPathEntries.add(new JcrClassPathEntry(EntryType.FILE, new URL(null, file, UnifiedNodeReference
- .getURLStreamHandler())));
+ String str = files.get(i);
+ URL url = null;
+ if (str.startsWith("jcr://"))
+ url = new URL(null, str, UnifiedNodeReference.getURLStreamHandler());
else
- classPathEntries.add(new JcrClassPathEntry(EntryType.FILE, new URL(file)));
+ url = new URL(str);
+ srcFiles[i] = new SourceFile(url);
}
}
-
- ClassPath classPath =
- new ClassPath(classPathEntries.toArray(new ClassPathEntry[classPathEntries.size()]),
- (extensions != null && extensions.size() > 0) ? extensions.toArray(new String[extensions.size()]) : null);
-
- return classPath;
+ return srcFiles;
}
/**
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScriptAddRepoPlugin.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScriptAddRepoPlugin.java 2010-12-27 13:35:46 UTC (rev 3731)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScriptAddRepoPlugin.java 2010-12-27 13:37:04 UTC (rev 3732)
@@ -19,7 +19,6 @@
package org.exoplatform.services.jcr.ext.script.groovy;
-import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.container.component.BaseComponentPlugin;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.PropertiesParam;
@@ -29,6 +28,8 @@
import java.net.MalformedURLException;
import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Collection;
import java.util.Collections;
@@ -69,18 +70,19 @@
final String path = p.getProperty("path");
try
{
- SecurityHelper.doPrivilegedMalformedURLExceptionAction(new PrivilegedExceptionAction<Void>()
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Void>()
{
- public Void run() throws Exception
+ public Void run() throws MalformedURLException
{
repos.add(new UnifiedNodeReference(repository, workspace, path).getURL());
return null;
}
});
}
- catch (MalformedURLException e)
+ catch (PrivilegedActionException e)
{
- LOG.error("Failed add groovy script repository. " + e.getMessage());
+ // MalformedURLException
+ LOG.error("Failed add groovy script repository. " + e.getCause().getMessage());
}
}
return repos;
Deleted: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrClassPathEntry.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrClassPathEntry.java 2010-12-27 13:35:46 UTC (rev 3731)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrClassPathEntry.java 2010-12-27 13:37:04 UTC (rev 3732)
@@ -1,42 +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.jcr.ext.script.groovy;
-
-import org.exoplatform.services.jcr.ext.resource.UnifiedNodeReference;
-import org.exoplatform.services.rest.ext.groovy.ClassPathEntry;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-
-/**
- * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey Parfonov</a>
- * @version $Id$
- */
-public class JcrClassPathEntry extends ClassPathEntry
-{
- public JcrClassPathEntry(EntryType type, URL path)
- {
- super(type, path);
- }
-
- public JcrClassPathEntry(EntryType type, UnifiedNodeReference path) throws MalformedURLException
- {
- this(type, path.getURL());
- }
-}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyClassLoaderProvider.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyClassLoaderProvider.java 2010-12-27 13:35:46 UTC (rev 3731)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyClassLoaderProvider.java 2010-12-27 13:37:04 UTC (rev 3732)
@@ -20,17 +20,22 @@
import groovy.lang.GroovyClassLoader;
-import org.exoplatform.services.rest.ext.groovy.ClassPath;
-import org.exoplatform.services.rest.ext.groovy.ClassPathEntry;
-import org.exoplatform.services.rest.ext.groovy.ClassPathEntry.EntryType;
+import org.codehaus.groovy.control.CompilationUnit;
+import org.codehaus.groovy.control.CompilerConfiguration;
+import org.codehaus.groovy.control.ErrorCollector;
+import org.codehaus.groovy.control.SourceUnit;
+import org.codehaus.groovy.control.io.ReaderSource;
+import org.codehaus.groovy.control.io.URLReaderSource;
+import org.exoplatform.services.rest.ext.groovy.ExtendedGroovyClassLoader;
import org.exoplatform.services.rest.ext.groovy.GroovyClassLoaderProvider;
+import org.exoplatform.services.rest.ext.groovy.SourceFolder;
+import java.io.File;
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.List;
/**
* @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey Parfonov</a>
@@ -39,39 +44,128 @@
*/
public class JcrGroovyClassLoaderProvider extends GroovyClassLoaderProvider
{
+
+ public static class JcrGroovyClassLoader extends ExtendedGroovyClassLoader
+ {
+ public JcrGroovyClassLoader(ClassLoader classLoader)
+ {
+ super(classLoader);
+ }
+
+ public JcrGroovyClassLoader(GroovyClassLoader parent)
+ {
+ super(parent);
+ }
+
+ /**
+ * @see org.exoplatform.services.rest.ext.groovy.ExtendedGroovyClassLoader#createCompilationUnit(org.codehaus.groovy.control.CompilerConfiguration,
+ * java.security.CodeSource)
+ */
+ protected CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource cs)
+ {
+ return new JcrCompilationUnit(config, cs, this);
+ }
+ }
+
+ public static class JcrCompilationUnit extends CompilationUnit
+ {
+
+ public JcrCompilationUnit()
+ {
+ super();
+ }
+
+ public JcrCompilationUnit(CompilerConfiguration configuration, CodeSource security, GroovyClassLoader loader,
+ GroovyClassLoader transformLoader)
+ {
+ super(configuration, security, loader, transformLoader);
+ }
+
+ public JcrCompilationUnit(CompilerConfiguration configuration, CodeSource security, GroovyClassLoader loader)
+ {
+ super(configuration, security, loader);
+ }
+
+ public JcrCompilationUnit(CompilerConfiguration configuration)
+ {
+ super(configuration);
+ }
+
+ public JcrCompilationUnit(GroovyClassLoader loader)
+ {
+ super(loader);
+ }
+
+ /**
+ * @see org.codehaus.groovy.control.CompilationUnit#addSource(java.net.URL)
+ */
+ @Override
+ public SourceUnit addSource(URL url)
+ {
+ return addSource(new JcrSourceUnit(url, configuration, classLoader, getErrorCollector()));
+ }
+ }
+
+ /** Adapter for JCR like URLs. */
+ public static class JcrSourceUnit extends SourceUnit
+ {
+ public JcrSourceUnit(File source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er)
+ {
+ super(source, configuration, loader, er);
+ }
+
+ public JcrSourceUnit(String name, ReaderSource source, CompilerConfiguration flags, GroovyClassLoader loader,
+ ErrorCollector er)
+ {
+ super(name, source, flags, loader, er);
+ }
+
+ public JcrSourceUnit(String name, String source, CompilerConfiguration configuration, GroovyClassLoader loader,
+ ErrorCollector er)
+ {
+ super(name, source, configuration, loader, er);
+ }
+
+ public JcrSourceUnit(URL source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er)
+ {
+ /* jCR path is in fragment of URL:
+ * jcr://repository/workspace#/path */
+ super("jcr".equals(source.getProtocol()) ? source.getRef() : source.getPath(), new URLReaderSource(source,
+ configuration), configuration, loader, er);
+ }
+ }
+
+ public JcrGroovyClassLoaderProvider()
+ {
+ super(AccessController.doPrivileged(new PrivilegedAction<JcrGroovyClassLoader>() {
+ public JcrGroovyClassLoader run()
+ {
+ return new JcrGroovyClassLoader(getClass().getClassLoader());
+ }
+ }));
+ }
+
/**
- * @see org.exoplatform.services.rest.ext.groovy.GroovyClassLoaderProvider#getGroovyClassLoader(org.exoplatform.services.rest.ext.groovy.ClassPath)
+ * @see org.exoplatform.services.rest.ext.groovy.GroovyClassLoaderProvider#getGroovyClassLoader(org.exoplatform.services.rest.ext.groovy.SourceFolder[])
*/
@Override
- 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++)
- {
- ClassPathEntry classPathEntry = classPathEntries[i];
- if (EntryType.SRC_DIR == classPathEntry.getType())
- {
- roots.add(classPathEntry.getPath());
- }
- else
- {
- files.add(classPathEntry.getPath());
- }
- }
- }
+ 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();
- GroovyClassLoader classLoader = AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>() {
- public GroovyClassLoader run()
+ JcrGroovyClassLoader classLoader = AccessController.doPrivileged(new PrivilegedAction<JcrGroovyClassLoader>() {
+ public JcrGroovyClassLoader run()
{
- return new GroovyClassLoader(parent);
+ return new JcrGroovyClassLoader(parent);
}
});
- classLoader.setResourceLoader(new JcrGroovyResourceLoader(roots.toArray(new URL[roots.size()]), files
- .toArray(new URL[files.size()]), classPath.getExtensions()));
+ classLoader.setResourceLoader(new JcrGroovyResourceLoader(roots));
return classLoader;
}
}
\ No newline at end of file
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyCompiler.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyCompiler.java 2010-12-27 13:35:46 UTC (rev 3731)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyCompiler.java 2010-12-27 13:37:04 UTC (rev 3732)
@@ -22,15 +22,12 @@
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyCodeSource;
-import org.codehaus.groovy.control.CompilationFailedException;
-import org.exoplatform.services.jcr.ext.resource.JcrURLConnection;
import org.exoplatform.services.jcr.ext.resource.UnifiedNodeReference;
+import org.exoplatform.services.jcr.ext.script.groovy.JcrGroovyClassLoaderProvider.JcrGroovyClassLoader;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import org.exoplatform.services.rest.ext.groovy.ClassPath;
-import org.exoplatform.services.rest.ext.groovy.ClassPathEntry;
-import org.exoplatform.services.rest.ext.groovy.ClassPathEntry.EntryType;
-import org.exoplatform.services.rest.ext.groovy.GroovyClassLoaderProvider;
+import org.exoplatform.services.rest.ext.groovy.SourceFile;
+import org.exoplatform.services.rest.ext.groovy.SourceFolder;
import org.picocontainer.Startable;
import java.io.IOException;
@@ -39,8 +36,6 @@
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -57,88 +52,128 @@
/** Logger. */
private static final Log LOG = ExoLogger.getLogger(JcrGroovyCompiler.class);
- protected final GroovyClassLoaderProvider classLoaderProvider;
+ protected final JcrGroovyClassLoaderProvider classLoaderProvider;
protected List<GroovyScriptAddRepoPlugin> addRepoPlugins;
- protected JcrGroovyCompiler(GroovyClassLoaderProvider classLoaderProvider)
+ protected JcrGroovyCompiler(JcrGroovyClassLoaderProvider classLoaderProvider)
{
this.classLoaderProvider = classLoaderProvider;
}
public JcrGroovyCompiler()
{
- classLoaderProvider = new JcrGroovyClassLoaderProvider();
+ this(new JcrGroovyClassLoaderProvider());
}
+ /**
+ * Compile Groovy source that located in <code>sourceReferences</code>.
+ * Compiled sources can be dependent to each other and dependent to Groovy
+ * sources that are accessible for this compiler.
+ *
+ * @param sourceReferences references to Groovy sources to be compiled
+ * @return result of compilation
+ * @throws IOException if any i/o errors occurs
+ */
public Class<?>[] compile(UnifiedNodeReference... sourceReferences) throws IOException
{
- // Add all compiled entries in class-path. Need to do this to resolve dependencies between compiled files.
- ClassPathEntry[] classPath = new ClassPathEntry[sourceReferences.length];
- for (int i = 0; i < classPath.length; i++)
- classPath[i] = new JcrClassPathEntry(EntryType.FILE, sourceReferences[i]);
- return doCompile(classLoaderProvider.getGroovyClassLoader(new ClassPath(classPath, null)), sourceReferences);
+ return compile(null, sourceReferences);
}
- public Class<?>[] compile(ClassPath classPath, UnifiedNodeReference... sourceReferences) throws IOException
+ /**
+ * Compile Groovy source that located in <code>sourceReferences</code>.
+ * Compiled sources can be dependent to each other and dependent to Groovy
+ * sources that are accessible for this compiler and with additional Groovy
+ * sources <code>src</code>. <b>NOTE</b> To be able load Groovy source files
+ * from specified folders the following rules must be observed:
+ * <ul>
+ * <li>Groovy source files must be located in folder with respect to package
+ * structure</li>
+ * <li>Name of Groovy source files must be the same as name of class located
+ * in file</li>
+ * <li>Groovy source file must have extension '.groovy'</li>
+ * </ul>
+ * <br/>
+ * Example: If source stream that we want validate contains the following
+ * code:
+ *
+ * <pre>
+ * package c.b.a
+ *
+ * import a.b.c.A
+ *
+ * class B extends A {
+ * // Do something.
+ * }
+ * </pre>
+ *
+ * Assume we store dependencies in JCR then URL of folder with Groovy sources
+ * may be like this: <code>jcr://repository/workspace#/groovy-library</code>.
+ * Then absolute path to JCR node that contains Groovy source must be as
+ * following: <code>/groovy-library/a/b/c/A.groovy</code>
+ *
+ * @param src additional Groovy source location that should be added in
+ * class-path when compile <code>sourceReferences</code>
+ * @param sourceReferences references to Groovy sources to be compiled
+ * @return result of compilation
+ * @throws IOException if any i/o errors occurs
+ */
+ public Class<?>[] compile(SourceFolder[] src, UnifiedNodeReference... sourceReferences) throws IOException
{
- ClassPathEntry[] compiled = new ClassPathEntry[sourceReferences.length];
- for (int i = 0; i < compiled.length; i++)
- compiled[i] = new JcrClassPathEntry(EntryType.FILE, sourceReferences[i]);
- ClassPathEntry[] classPathEntries = classPath.getEntries();
- if (classPathEntries == null)
- classPathEntries = new ClassPathEntry[0];
- ClassPathEntry[] fullClassPath = new ClassPathEntry[compiled.length + classPathEntries.length];
- System.arraycopy(compiled, 0, fullClassPath, 0, compiled.length);
- System.arraycopy(classPathEntries, 0, fullClassPath, compiled.length, classPathEntries.length);
- return doCompile(
- classLoaderProvider.getGroovyClassLoader(new ClassPath(fullClassPath, classPath.getExtensions())),
- sourceReferences);
+ SourceFile[] files = new SourceFile[sourceReferences.length];
+ for (int i = 0; i < sourceReferences.length; i++)
+ files[i] = new SourceFile(sourceReferences[i].getURL());
+ return doCompile((JcrGroovyClassLoader)classLoaderProvider.getGroovyClassLoader(src), files);
}
- private Class<?>[] doCompile(final GroovyClassLoader cl, final UnifiedNodeReference... sourceReferences)
- throws IOException
+ /**
+ * Compile Groovy source that located in <code>files</code>. Compiled sources
+ * can be dependent to each other and dependent to Groovy sources that are
+ * accessible for this compiler and with additional Groovy sources
+ * <code>src</code>. <b>NOTE</b> To be able load Groovy source files from
+ * specified folders the following rules must be observed:
+ * <ul>
+ * <li>Groovy source files must be located in folder with respect to package
+ * structure</li>
+ * <li>Name of Groovy source files must be the same as name of class located
+ * in file</li>
+ * <li>Groovy source file must have extension '.groovy'</li>
+ * </ul>
+ *
+ * @param srcadditional Groovy source location that should be added in
+ * class-path when compile <code>files</code>
+ * @param files Groovy sources to be compiled
+ * @return result of compilation
+ * @throws IOException if any i/o errors occurs
+ */
+ public Class<?>[] compile(SourceFolder[] src, SourceFile[] files) throws IOException
{
- Class<?>[] classes = new Class<?>[sourceReferences.length];
- for (int i = 0; i < sourceReferences.length; i++)
- {
- JcrURLConnection conn = null;
- try
- {
- final URL url = sourceReferences[i].getURL();
- conn = (JcrURLConnection)url.openConnection();
+ return doCompile((JcrGroovyClassLoader)classLoaderProvider.getGroovyClassLoader(src), files);
+ }
- final JcrURLConnection fConn = conn;
- Class<?> clazz;
- try
- {
- clazz = AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
- public Class<?> run() throws Exception
- {
- return cl.parseClass(createCodeSource(fConn.getInputStream(), url.toString()));
- }
- });
- }
- catch (PrivilegedActionException pae)
- {
- Throwable cause = pae.getCause();
- if (cause instanceof CompilationFailedException)
- throw (CompilationFailedException)cause;
- else if (cause instanceof IOException)
- throw (IOException)cause;
- else if (cause instanceof RuntimeException)
- throw (RuntimeException)cause;
- else
- throw new RuntimeException(cause);
- }
- classes[i] = clazz;
- }
- finally
+ /**
+ * Compile Groovy source that located in <code>files</code>. Compiled sources
+ * can be dependent to each other and dependent to Groovy sources that are
+ * accessible for this compiler.
+ *
+ * @param files Groovy sources to be compiled
+ * @return result of compilation
+ * @throws IOException if any i/o errors occurs
+ */
+ public Class<?>[] compile(SourceFile[] files) throws IOException
+ {
+ return doCompile((JcrGroovyClassLoader)classLoaderProvider.getGroovyClassLoader(), files);
+ }
+
+ @SuppressWarnings("rawtypes")
+ private Class<?>[] doCompile(final JcrGroovyClassLoader cl, final SourceFile[] files) throws IOException
+ {
+ Class[] classes = AccessController.doPrivileged(new PrivilegedAction<Class[]>() {
+ public Class[] run()
{
- if (conn != null)
- conn.disconnect();
+ return cl.parseClasses(files);
}
- }
+ });
return classes;
}
@@ -160,7 +195,7 @@
@Deprecated
public void setGroovyClassLoader(GroovyClassLoader gcl)
{
- classLoaderProvider.setGroovyClassLoader(gcl);
+ LOG.warn("Method setGroovyClassLoader is deprecated.");
}
/**
@@ -173,6 +208,7 @@
* @return GroovyCodeSource
*/
// Override this method if need other behavior.
+ @Deprecated
protected GroovyCodeSource createCodeSource(final InputStream in, final String name)
{
GroovyCodeSource gcs = AccessController.doPrivileged(new PrivilegedAction<GroovyCodeSource>() {
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyResourceLoader.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyResourceLoader.java 2010-12-27 13:35:46 UTC (rev 3731)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/JcrGroovyResourceLoader.java 2010-12-27 13:37:04 UTC (rev 3732)
@@ -61,24 +61,14 @@
return res;
}
- public JcrGroovyResourceLoader(URL[] roots, URL[] files, String[] extensions) throws MalformedURLException
- {
- super(normalizeJcrURL(roots), files, extensions);
- }
-
- public JcrGroovyResourceLoader(URL[] roots, URL[] files) throws MalformedURLException
- {
- this(roots, files, null);
- }
-
public JcrGroovyResourceLoader(URL[] roots) throws MalformedURLException
{
- this(roots, new URL[0]);
+ super(normalizeJcrURL(roots));
}
public JcrGroovyResourceLoader(URL root) throws MalformedURLException
{
- this(new URL[]{root}, new URL[0]);
+ this(new URL[]{root});
}
/**
@@ -89,7 +79,6 @@
{
if (LOG.isDebugEnabled())
LOG.debug("Process file: " + filename);
-
URL resource = null;
filename = filename.intern();
synchronized (filename)
@@ -98,12 +87,6 @@
boolean inCache = resource != null;
if (inCache && !checkResource(resource))
resource = null;
- 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++)
{
// In JCR URL path represented by fragment jcr://repository/workspace#/path
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyCompilerTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyCompilerTest.java 2010-12-27 13:35:46 UTC (rev 3731)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyCompilerTest.java 2010-12-27 13:37:04 UTC (rev 3732)
@@ -22,11 +22,11 @@
import groovy.lang.GroovyObject;
import org.exoplatform.services.jcr.ext.resource.UnifiedNodeReference;
-import org.exoplatform.services.rest.ext.groovy.ClassPath;
-import org.exoplatform.services.rest.ext.groovy.ClassPathEntry;
-import org.exoplatform.services.rest.ext.groovy.GroovyClassLoaderProvider;
-import org.exoplatform.services.rest.ext.groovy.ClassPathEntry.EntryType;
+import org.exoplatform.services.rest.ext.groovy.SourceFolder;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.jcr.Node;
/**
@@ -63,7 +63,7 @@
public void testSnaredDependencies() throws Exception
{
- GroovyClassLoaderProvider classLoaderProvider = new GroovyClassLoaderProvider();
+ JcrGroovyClassLoaderProvider classLoaderProvider = new JcrGroovyClassLoaderProvider();
classLoaderProvider.getGroovyClassLoader().setResourceLoader(
new JcrGroovyResourceLoader(new java.net.URL[]{new java.net.URL("jcr://db1/ws#/groovyRepo")}));
JcrGroovyCompiler compiler = new JcrGroovyCompiler(classLoaderProvider);
@@ -76,7 +76,7 @@
public void testDependenciesBetweenCompiled() throws Exception
{
- GroovyClassLoaderProvider classLoaderProvider = new GroovyClassLoaderProvider();
+ JcrGroovyClassLoaderProvider classLoaderProvider = new JcrGroovyClassLoaderProvider();
JcrGroovyCompiler compiler = new JcrGroovyCompiler(classLoaderProvider);
Class<?>[] classes =
compiler.compile(new UnifiedNodeReference("db1", "ws", scriptB),
@@ -90,13 +90,11 @@
public void testAddDependenciesInRuntime() throws Exception
{
- GroovyClassLoaderProvider classLoaderProvider = new GroovyClassLoaderProvider();
+ JcrGroovyClassLoaderProvider classLoaderProvider = new JcrGroovyClassLoaderProvider();
JcrGroovyCompiler compiler = new JcrGroovyCompiler(classLoaderProvider);
- ClassPathEntry[] classPathEntries =
- new ClassPathEntry[]{new JcrClassPathEntry(EntryType.FILE, new UnifiedNodeReference("db1", "ws", scriptA))};
- Class<?>[] classes = compiler.compile( //
- new ClassPath(classPathEntries, null), //
- new UnifiedNodeReference("db1", "ws", scriptB));
+ SourceFolder[] src =
+ new SourceFolder[]{new SourceFolder(new UnifiedNodeReference("db1", "ws", groovyRepo.getPath()).getURL())};
+ Class<?>[] classes = compiler.compile(src, new UnifiedNodeReference("db1", "ws", scriptB));
assertEquals(1, classes.length);
GroovyObject go = (GroovyObject)classes[0].newInstance();
assertEquals("groovy compiler test", go.invokeMethod("getMessage", new Object[0]));
@@ -104,7 +102,8 @@
public void testCombinedDependencies() throws Exception
{
- String scriptC = createScript(otherGroovyRepo, "org.exoplatform.test", "C.groovy", //
+ // Add file without respect to package structure to be sure direct link to source files works any way.
+ String scriptC = createScript(otherGroovyRepo, "org.exoplatform", "C", //
"package org.exoplatform.test\n" + //
"import org.exoplatform.*\n" + //
"class C extends B {}");
@@ -114,7 +113,7 @@
"import org.exoplatform.test.C\n" + //
"class D extends C {}");
- GroovyClassLoaderProvider classLoaderProvider = new GroovyClassLoaderProvider();
+ JcrGroovyClassLoaderProvider classLoaderProvider = new JcrGroovyClassLoaderProvider();
classLoaderProvider.getGroovyClassLoader().setResourceLoader(
new JcrGroovyResourceLoader(new java.net.URL[]{new java.net.URL("jcr://db1/ws#/groovyRepo")}));
@@ -123,5 +122,11 @@
compiler.compile(new UnifiedNodeReference("db1", "ws", scriptD),
new UnifiedNodeReference("db1", "ws", scriptC));
assertEquals(2, classes.length);
+ List<String> names = new ArrayList<String>(2);
+ for (Class c : classes)
+ names.add(c.getName());
+ assertTrue(names.contains("org.exoplatform.test.C"));
+ assertTrue(names.contains("org.exoplatform.test.other.D"));
+ //System.out.println(">>>>>>>>>>>>>>>>> "+names);
}
}
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java 2010-12-27 13:35:46 UTC (rev 3731)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java 2010-12-27 13:37:04 UTC (rev 3732)
@@ -193,7 +193,7 @@
String path = createScript(testRoot, "test.load", "Test000.groovy", //
"import test.load.User000\n" + //
"@javax.ws.rs.Path('test/load') class Test000 {\n" + //
- "def user = new User(name:'test')\n" + //
+ "def user = new User000(name:'test')\n" + //
"@javax.ws.rs.GET def m() {user}" + //
"}\n");
EnvironmentContext ctx = new EnvironmentContext();
@@ -206,7 +206,7 @@
assertEquals(before, after);
}
- public void testLoadNoExtClassPath_File() throws Exception
+ public void testLoadExtClassPath_File() throws Exception
{
String scriptPath = createScript(testRoot, "test.load", "Test001.groovy", //
"import test.load.User001\n" + //
@@ -232,7 +232,7 @@
assertEquals(before + 1, after);
}
- public void testLoadNoExtClassPath_SourceFolder() throws Exception
+ public void testLoadExtClassPath_SourceFolder() throws Exception
{
String scriptPath = createScript(testRoot, "test.load", "Test002.groovy", //
"import test.load.User002\n" + //
@@ -258,33 +258,6 @@
assertEquals(before + 1, after);
}
- public void testLoadNoExtClassPath_CustomExtension() throws Exception
- {
- String scriptPath = createScript(testRoot, "test.load", "Test003.groovy", //
- "import test.load.User003\n" + //
- "@javax.ws.rs.Path('test/load_003') class Test003 {\n" + //
- "def user = new User003(name:'test')\n" + //
- "@javax.ws.rs.GET def m() {user}" + //
- "}\n");
- createScript(testRoot, "test.load", "User003.otherGroovy",//
- "package test.load\n" + //
- "class User003 {def name}");
-
- EnvironmentContext ctx = new EnvironmentContext();
- ctx.put(SecurityContext.class, adminSecurityContext);
- String path =
- "/script/groovy/load/db1/ws" + scriptPath //
- + "?sources=" //
- + URLEncoder.encode(new UnifiedNodeReference(repository.getName(), workspace.getName(), testRoot.getPath())
- .getURL().toString(), "UTF-8") + //
- "&extension=.otherGroovy";
- int before = binder.getSize();
- ContainerResponse cres = launcher.service("POST", path, "", null, null, ctx);
- assertEquals(204, cres.getStatus());
- int after = binder.getSize();
- assertEquals(before + 1, after);
- }
-
public void testDelete() throws Exception
{
ContainerResponse cres =
@@ -429,28 +402,6 @@
assertEquals(200, cres.getStatus());
}
- public void testValidateExtClassPath_CustomExtension() throws Exception
- {
- MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
- headers.putSingle("Content-Type", "script/groovy");
- String script = "import test.validate.User003\n" + //
- "@javax.ws.rs.Path('test/validate') class Test {\n" + //
- "def user = new User003(name:'test')\n" + //
- "@javax.ws.rs.GET def m() {user}" + //
- " }\n";
- createScript(testRoot, "test.validate", "User003.otherGroovy",//
- "package test.validate\n" + //
- "class User003 {def name}");
- // Specify source folder location and customized extension '.otherGroovy'.
- String path =
- "/script/groovy/validate/Test?sources=" //
- + URLEncoder.encode(new UnifiedNodeReference(repository.getName(), workspace.getName(), testRoot.getPath())
- .getURL().toString(), "UTF-8") + //
- "&extension=.otherGroovy";
- ContainerResponse cres = launcher.service("POST", path, "", headers, script.getBytes(), null);
- assertEquals(200, cres.getStatus());
- }
-
public void testGroovyDependency() throws Exception
{
// Add script in dependency repository
13 years, 4 months