use of groovy.lang.GroovyClassLoader in project camel by apache.
the class DefaultMavenArtifactProvider method addArtifactToCatalog.
@Override
public Set<String> addArtifactToCatalog(CamelCatalog camelCatalog, CamelConnectorCatalog camelConnectorCatalog, String groupId, String artifactId, String version) {
final Set<String> names = new LinkedHashSet<>();
try {
if (cacheDirectory != null) {
LOG.debug("Using cache directory: {}", cacheDirectory);
System.setProperty("grape.root", cacheDirectory);
}
Grape.setEnableAutoDownload(true);
final ClassLoader classLoader = new GroovyClassLoader();
Map<String, Object> param = new HashMap<>();
param.put("classLoader", classLoader);
param.put("group", groupId);
param.put("module", artifactId);
param.put("version", version);
// no need to download transitive dependencies as we only need to check the component or connector itself
param.put("validate", false);
param.put("transitive", false);
LOG.debug("Downloading {}:{}:{}", groupId, artifactId, version);
Grape.grab(param);
// the classloader can load content from the downloaded JAR
if (camelCatalog != null) {
scanCamelComponents(camelCatalog, classLoader, names);
}
if (camelConnectorCatalog != null) {
scanCamelConnectors(camelConnectorCatalog, classLoader, groupId, artifactId, version, names);
}
} catch (Exception e) {
LOG.warn("Error during add components from artifact " + groupId + ":" + artifactId + ":" + version + " due " + e.getMessage(), e);
}
return names;
}
use of groovy.lang.GroovyClassLoader in project grails-core by grails.
the class ConstraintsEvaluatingPropertyTests method ensureConstraintsPresent.
@SuppressWarnings("rawtypes")
private void ensureConstraintsPresent(String[] classSource, int classIndexToTest, int constraintCount) throws Exception {
// We need to do a real test here to make sure
GroovyClassLoader gcl = new GroovyClassLoader();
Class[] classes = new Class[classSource.length];
for (int i = 0; i < classSource.length; i++) {
classes[i] = gcl.parseClass(classSource[i]);
}
GrailsApplication ga = new DefaultGrailsApplication(classes[classIndexToTest]);
ga.initialise();
new MappingContextBuilder(ga).build(classes[classIndexToTest]);
GrailsDomainClass domainClass = (GrailsDomainClass) ga.getArtefact(DomainClassArtefactHandler.TYPE, classes[classIndexToTest].getName());
Map constraints = domainClass.getConstrainedProperties();
grails.gorm.validation.ConstrainedProperty p = (grails.gorm.validation.ConstrainedProperty) constraints.get("name");
Collection cons = p.getAppliedConstraints();
assertEquals("Incorrect number of constraints extracted: " + constraints, constraintCount, cons.size());
}
use of groovy.lang.GroovyClassLoader in project grails-core by grails.
the class GrailsLayoutDecoratorMapperTests method testDecoratedByActionConvention.
public void testDecoratedByActionConvention() throws Exception {
GrailsWebRequest webRequest = buildMockRequest(null);
webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
MockApplicationContext appCtx = (MockApplicationContext) webRequest.getApplicationContext();
appCtx.registerMockResource("/grails-app/views/layouts/test2/testAction.gsp", "<html><body><g:layoutBody /></body></html>");
MockHttpServletRequest request = (MockHttpServletRequest) webRequest.getCurrentRequest();
request.setMethod("GET");
request.setRequestURI("orders/list");
ServletContext context = webRequest.getServletContext();
GroovyClassLoader gcl = new GroovyClassLoader();
// create mock controller
GroovyObject controller = (GroovyObject) gcl.parseClass("class Test2Controller {\n" + "def controllerName = 'test2'\n" + "def actionUri = '/test2/testAction'\n" + "}").newInstance();
request.setAttribute(GrailsApplicationAttributes.CONTROLLER, controller);
GrailsLayoutDecoratorMapper m = new GrailsLayoutDecoratorMapper();
com.opensymphony.module.sitemesh.Config c = new com.opensymphony.module.sitemesh.Config(new MockServletConfig(context));
m.init(c, null, null);
HTMLPageParser parser = new HTMLPageParser();
String html = "<html><head><title>Test title</title></head><body>here is the body</body></html>";
Page page = parser.parse(html.toCharArray());
Decorator d = m.getDecorator(request, page);
assertNotNull(d);
assertEquals("/layouts/test2/testAction.gsp", d.getPage());
assertEquals("test2/testAction", d.getName());
}
use of groovy.lang.GroovyClassLoader in project grails-core by grails.
the class GrailsLayoutDecoratorMapperTests method testDecoratedByApplicationConvention.
public void testDecoratedByApplicationConvention() throws Exception {
GrailsWebRequest webRequest = buildMockRequest(null);
webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
MockApplicationContext appCtx = (MockApplicationContext) webRequest.getApplicationContext();
appCtx.registerMockResource("/grails-app/views/layouts/application.gsp", "<html><body><h1>Default Layout</h1><g:layoutBody /></body></html>");
MockHttpServletRequest request = (MockHttpServletRequest) webRequest.getCurrentRequest();
request.setMethod("GET");
request.setRequestURI("orders/list");
ServletContext context = webRequest.getServletContext();
GroovyClassLoader gcl = new GroovyClassLoader();
// create mock controller
GroovyObject controller = (GroovyObject) gcl.parseClass("class FooController {\n" + "def controllerName = 'foo'\n" + "def actionUri = '/foo/fooAction'\n" + "}").newInstance();
request.setAttribute(GrailsApplicationAttributes.CONTROLLER, controller);
GrailsLayoutDecoratorMapper m = new GrailsLayoutDecoratorMapper();
com.opensymphony.module.sitemesh.Config c = new com.opensymphony.module.sitemesh.Config(new MockServletConfig(context));
m.init(c, null, null);
HTMLPageParser parser = new HTMLPageParser();
String html = "<html><head><title>Foo title</title></head><body>here is the body</body></html>";
Page page = parser.parse(html.toCharArray());
Decorator d = m.getDecorator(request, page);
assertNotNull(d);
assertEquals("/layouts/application.gsp", d.getPage());
assertEquals("application", d.getName());
}
use of groovy.lang.GroovyClassLoader in project grails-maven by grails.
the class DefaultGrailsServices method readGrailsPluginProject.
public GrailsPluginProject readGrailsPluginProject() throws MojoExecutionException {
final GrailsPluginProject pluginProject = new GrailsPluginProject();
final File[] files = getBasedir().listFiles(new FilenameFilter() {
public boolean accept(final File file, final String s) {
return s.endsWith(FILE_SUFFIX) && s.length() > FILE_SUFFIX.length();
}
});
if (files == null || files.length != 1) {
throw new MojoExecutionException("Could not find a plugin descriptor. Expected to find exactly one file " + "called FooGrailsPlugin.groovy in '" + getBasedir().getAbsolutePath() + "'.");
}
final File descriptor = files[0];
pluginProject.setFileName(descriptor);
final String className = descriptor.getName().substring(0, descriptor.getName().length() - ".groovy".length());
final String pluginName = getLowerCaseHyphenSeparatedName(getLogicalName(className, "GrailsPlugin"));
pluginProject.setPluginName(pluginName);
final GroovyClassLoader classLoader = new GroovyClassLoader();
final AstPluginDescriptorReader reader = new AstPluginDescriptorReader(classLoader);
final GrailsPluginInfo info = reader.readPluginInfo(new org.codehaus.groovy.grails.io.support.FileSystemResource(descriptor));
final String version = info.getVersion();
if (version == null || version.trim().length() == 0) {
throw new MojoExecutionException("Plugin does not have a version!");
}
pluginProject.setVersion(version);
return pluginProject;
}
Aggregations