use of org.grails.io.support.FileSystemResource in project grails-core by grails.
the class GrailsASTUtils method getSourceUrl.
/**
* Find URL of SourceUnit
*
* source.getSource().getURI() fails in Groovy-Eclipse compiler
*
* @param source
* @return URL of SourceUnit
*/
public static URL getSourceUrl(SourceUnit source) {
URL url = null;
final String filename = source.getName();
if (filename == null) {
return null;
}
Resource resource = new FileSystemResource(filename);
if (resource.exists()) {
try {
url = resource.getURL();
} catch (IOException e) {
// ignore
}
}
return url;
}
use of org.grails.io.support.FileSystemResource in project grails-core by grails.
the class TestForTransformation method handleTestForAnnotation.
protected void handleTestForAnnotation(ClassNode classNode, SourceUnit source, AnnotationNode testForAnnotationNode, boolean junit3Test) {
Expression value = testForAnnotationNode.getMember("value");
ClassExpression ce;
if (value instanceof ClassExpression) {
ce = (ClassExpression) value;
testFor(classNode, ce);
return;
}
if (junit3Test) {
return;
}
List<AnnotationNode> annotations = classNode.getAnnotations(MY_TYPE);
// bail out, in this case it was already applied as a local transform
if (annotations.size() > 0)
return;
annotations = classNode.getAnnotations(TestMixinTransformation.MY_TYPE);
// bail out, another TestMixin transform already defines behavior
if (annotations.size() > 0)
return;
// no explicit class specified try by convention
String fileName = source.getName();
String className = GrailsResourceUtils.getClassName(new FileSystemResource(fileName));
if (className == null) {
return;
}
String targetClassName = null;
if (className.endsWith("Tests")) {
targetClassName = className.substring(0, className.indexOf("Tests"));
} else if (className.endsWith("Test")) {
targetClassName = className.substring(0, className.indexOf("Test"));
} else if (className.endsWith("Spec")) {
targetClassName = className.substring(0, className.indexOf("Spec"));
}
if (targetClassName == null) {
return;
}
Resource targetResource = getResourceLocator().findResourceForClassName(targetClassName);
if (targetResource == null) {
return;
}
try {
if (GrailsResourceUtils.isDomainClass(targetResource.getURL())) {
testFor(classNode, new ClassExpression(new ClassNode(targetClassName, 0, ClassHelper.OBJECT_TYPE)));
} else {
for (String artefactType : artefactTypeToTestMap.keySet()) {
if (targetClassName.endsWith(artefactType)) {
testFor(classNode, new ClassExpression(new ClassNode(targetClassName, 0, ClassHelper.OBJECT_TYPE)));
break;
}
}
}
} catch (IOException e) {
// ignore
}
}
use of org.grails.io.support.FileSystemResource in project grails-core by grails.
the class GrailsAwareInjectionOperation method call.
@Override
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException {
URL url = null;
final String filename = source.getName();
Resource resource = new FileSystemResource(filename);
if (resource.exists()) {
try {
url = resource.getURL();
} catch (IOException e) {
// ignore
}
}
ClassInjector[] classInjectors1 = getLocalClassInjectors();
if (classInjectors1 == null || classInjectors1.length == 0) {
classInjectors1 = getClassInjectors();
}
for (ClassInjector classInjector : classInjectors1) {
if (classInjector.shouldInject(url)) {
classInjector.performInjection(source, context, classNode);
}
}
}
Aggregations