Author: tolusha
Date: 2010-10-29 07:35:39 -0400 (Fri, 29 Oct 2010)
New Revision: 3367
Added:
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/TestScript.java
Removed:
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/Script.java
Modified:
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/JarJarTest.java
Log:
EXOJCR-986: Enable the security manager by default in all the projects, fix bug
Modified:
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/JarJarTest.java
===================================================================
---
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/JarJarTest.java 2010-10-29
10:10:09 UTC (rev 3366)
+++
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/JarJarTest.java 2010-10-29
11:35:39 UTC (rev 3367)
@@ -39,7 +39,7 @@
super(s);
}
- private void testTop(Script script)
+ private void testTop(TestScript script)
{
Mapping m1 = new Mapping();
m1.addMapping("a", "b");
@@ -55,12 +55,12 @@
public void testTopClassLitteral() throws Exception
{
- testTop(new Script("classlitteral1.groovy"));
- testTop(new Script("classlitteral_1.groovy"));
- testTop(new Script("import1.groovy"));
+ testTop(new TestScript("classlitteral1.groovy"));
+ testTop(new TestScript("classlitteral_1.groovy"));
+ testTop(new TestScript("import1.groovy"));
}
- private void testPrefix(Script script) throws Exception
+ private void testPrefix(TestScript script) throws Exception
{
Mapping m1 = new Mapping();
m1.addMapping("prefix1", "prefix2");
@@ -86,8 +86,8 @@
public void testPrefixClassLitteral() throws Exception
{
- testPrefix(new Script("classlitteral2.groovy"));
- testPrefix(new Script("classlitteral_2.groovy"));
- testPrefix(new Script("import2.groovy"));
+ testPrefix(new TestScript("classlitteral2.groovy"));
+ testPrefix(new TestScript("classlitteral_2.groovy"));
+ testPrefix(new TestScript("import2.groovy"));
}
}
Deleted:
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/Script.java
===================================================================
---
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/Script.java 2010-10-29
10:10:09 UTC (rev 3366)
+++
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/Script.java 2010-10-29
11:35:39 UTC (rev 3367)
@@ -1,120 +0,0 @@
-/*
- * 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.script.groovy.jarjar;
-
-import groovy.lang.GroovyCodeSource;
-import groovy.lang.GroovyObject;
-import junit.framework.Assert;
-import junit.framework.AssertionFailedError;
-
-import org.codehaus.groovy.control.CompilationFailedException;
-import org.exoplatform.commons.utils.PrivilegedSystemHelper;
-import org.exoplatform.commons.utils.SecurityHelper;
-
-import java.io.IOException;
-import java.net.URL;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-
-/**
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
- * @version $Revision$
- */
-public class Script
-{
-
- /** . */
- private final String name;
-
- public Script(String name)
- {
- this.name = name;
- }
-
- public Object execute(Mapping mapping)
- {
-
- //
- final JarJarClassLoader loader =
-
JarJarClassLoader.createJarJarClassLoaderInPrivilegedMode(Thread.currentThread().getContextClassLoader());
-
- //
- mapping.configure(loader);
-
- // Obtain script class
- URL url = PrivilegedSystemHelper.getResource("jarjar/" + name);
- Assert.assertNotNull(url);
- GroovyCodeSource gcs;
- try
- {
- gcs = new GroovyCodeSource(url);
- }
- catch (IOException e)
- {
- AssertionFailedError err = new AssertionFailedError();
- err.initCause(e);
- throw err;
- }
-
- Class testClass;
- try
- {
- final GroovyCodeSource gGcs = gcs;
- testClass = SecurityHelper.doPriviledgedExceptionAction(new
PrivilegedExceptionAction<Class>()
- {
- public Class run() throws Exception
- {
- return loader.parseClass(gGcs);
- }
- });
- }
- catch (PrivilegedActionException pae)
- {
- Throwable cause = pae.getCause();
- if (cause instanceof CompilationFailedException)
- {
- throw (CompilationFailedException)cause;
- }
- else if (cause instanceof RuntimeException)
- {
- throw (RuntimeException)cause;
- }
- else
- {
- throw new RuntimeException(cause);
- }
- }
-
- // Instantiate script
- GroovyObject testObject;
- try
- {
- testObject = (GroovyObject)testClass.newInstance();
- }
- catch (Exception e)
- {
- AssertionFailedError err = new AssertionFailedError();
- err.initCause(e);
- throw err;
- }
-
- // Invoke finally
- return testObject.invokeMethod("run", new Object[0]);
- }
-}
Copied:
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/TestScript.java
(from rev 3366,
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/Script.java)
===================================================================
---
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/TestScript.java
(rev 0)
+++
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/TestScript.java 2010-10-29
11:35:39 UTC (rev 3367)
@@ -0,0 +1,89 @@
+/*
+ * 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.script.groovy.jarjar;
+
+import groovy.lang.GroovyCodeSource;
+import groovy.lang.GroovyObject;
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+
+import org.exoplatform.commons.utils.PrivilegedSystemHelper;
+
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestScript
+{
+
+ /** . */
+ private final String name;
+
+ public TestScript(String name)
+ {
+ this.name = name;
+ }
+
+ public Object execute(Mapping mapping)
+ {
+
+ //
+ JarJarClassLoader loader =
+
JarJarClassLoader.createJarJarClassLoaderInPrivilegedMode(Thread.currentThread().getContextClassLoader());
+
+ //
+ mapping.configure(loader);
+
+ // Obtain script class
+ URL url = PrivilegedSystemHelper.getResource("jarjar/" + name);
+ Assert.assertNotNull(url);
+ GroovyCodeSource gcs;
+ try
+ {
+ gcs = new GroovyCodeSource(url);
+ }
+ catch (IOException e)
+ {
+ AssertionFailedError err = new AssertionFailedError();
+ err.initCause(e);
+ throw err;
+ }
+
+ Class testClass = loader.parseClass(gcs);;
+
+ // Instantiate script
+ GroovyObject testObject;
+ try
+ {
+ testObject = (GroovyObject)testClass.newInstance();
+ }
+ catch (Exception e)
+ {
+ AssertionFailedError err = new AssertionFailedError();
+ err.initCause(e);
+ throw err;
+ }
+
+ // Invoke finally
+ return testObject.invokeMethod("run", new Object[0]);
+ }
+}