forked from grails/grails
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimized classpath scanning to skip classes with $ signs in them sin…
…ce these are typically not user classes (like closures etc.)
- Loading branch information
1 parent
1bd03f4
commit 0b1e0f4
Showing
10 changed files
with
332 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
http\://grails.org/schema/gorm=org.codehaus.groovy.grails.orm.hibernate.cfg.GORMNamespaceHandler | ||
http\://www.grails.org/schema/context=org.codehaus.groovy.grails.context.annotation.GrailsContextNamespaceHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
http\://grails.org/schema/gorm/gorm.xsd=org/codehaus/groovy/grails/orm/hibernate/cfg/gorm.xsd | ||
http\://grails.org/schema/context/grails-context.xsd=org/codehaus/groovy/grails/context/annotation/grails-context.xsd |
70 changes: 70 additions & 0 deletions
70
...oovy/grails/context/annotation/ClosureClassIgnoringComponentScanBeanDefinitionParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* Copyright 2004-2005 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.codehaus.groovy.grails.context.annotation; | ||
|
||
import org.springframework.context.annotation.ComponentScanBeanDefinitionParser; | ||
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; | ||
import org.springframework.beans.factory.xml.ParserContext; | ||
import org.springframework.core.io.ResourceLoader; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; | ||
import org.springframework.util.AntPathMatcher; | ||
import org.w3c.dom.Element; | ||
import org.apache.commons.io.FilenameUtils; | ||
|
||
/** | ||
* Extends Spring's default <context:component-scan/> element to ignore Groovy's | ||
* generated closure classes | ||
* | ||
* @author Graeme Rocher | ||
* @since 1.2 | ||
*/ | ||
public class ClosureClassIgnoringComponentScanBeanDefinitionParser extends ComponentScanBeanDefinitionParser{ | ||
|
||
@Override | ||
protected ClassPathBeanDefinitionScanner configureScanner(ParserContext parserContext, Element element) { | ||
final ClassPathBeanDefinitionScanner scanner = super.configureScanner(parserContext, element); | ||
final PathMatchingResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(parserContext.getReaderContext().getResourceLoader()); | ||
resourceResolver.setPathMatcher(new AntPathMatcher(){ | ||
@Override | ||
public boolean match(String pattern, String path) { | ||
if(path.endsWith(".class")) { | ||
String filename = FilenameUtils.getBaseName(path); | ||
if(filename.indexOf("$")>-1) return false; | ||
} | ||
return super.match(pattern, path); | ||
} | ||
}); | ||
scanner.setResourceLoader(resourceResolver); | ||
return scanner; | ||
} | ||
|
||
class DelegatingResourceLoader implements ResourceLoader{ | ||
private ResourceLoader delegate; | ||
|
||
DelegatingResourceLoader(ResourceLoader loader) { | ||
this.delegate = loader; | ||
} | ||
|
||
public Resource getResource(String location) { | ||
System.out.println("location = " + location); | ||
return delegate.getResource(location); | ||
} | ||
|
||
public ClassLoader getClassLoader() { | ||
return delegate.getClassLoader(); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...src/java/org/codehaus/groovy/grails/context/annotation/GrailsContextNamespaceHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* Copyright 2004-2005 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.codehaus.groovy.grails.context.annotation; | ||
|
||
import org.springframework.beans.factory.xml.NamespaceHandlerSupport; | ||
|
||
/** | ||
* Provides custom implementation of component-scan that ignores Groovy closures | ||
* | ||
* @author Graeme Rocher | ||
* @since 1.2 | ||
*/ | ||
public class GrailsContextNamespaceHandler extends NamespaceHandlerSupport { | ||
|
||
public void init() { | ||
registerBeanDefinitionParser("component-scan", new ClosureClassIgnoringComponentScanBeanDefinitionParser()); | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.