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" + //
"(a)javax.ws.rs.Path('test/load') class Test000 {\n" + //
- "def user = new User(name:'test')\n" + //
+ "def user = new User000(name:'test')\n" + //
"(a)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" + //
- "(a)javax.ws.rs.Path('test/load_003') class Test003 {\n" +
//
- "def user = new User003(name:'test')\n" + //
- "(a)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" + //
- "(a)javax.ws.rs.Path('test/validate') class Test {\n" + //
- "def user = new User003(name:'test')\n" + //
- "(a)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