Skip to content

Commit

Permalink
Optimized classpath scanning to skip classes with $ signs in them sin…
Browse files Browse the repository at this point in the history
…ce these are typically not user classes (like closures etc.)
  • Loading branch information
graemerocher committed Jul 16, 2009
1 parent 1bd03f4 commit 0b1e0f4
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 24 deletions.
1 change: 0 additions & 1 deletion grails/Grails.iml
Expand Up @@ -26,7 +26,6 @@
<excludeFolder url="file://$MODULE_DIR$/target" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="library" name="groovy-1.6.0" level="application" />
<orderEntry type="jdk" jdkName="1.6" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="groovy-1.6.3" level="application" />
Expand Down
2 changes: 1 addition & 1 deletion grails/JSP21.iml
Expand Up @@ -12,7 +12,7 @@
</content>
<orderEntry type="library" name="groovy-1.6" level="application" />
<orderEntry type="library" name="groovy-1.6.0" level="application" />
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="1.6" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
Expand Down
22 changes: 13 additions & 9 deletions grails/ant/build/bundle.xml
Expand Up @@ -8,6 +8,8 @@
<fileset dir="${grails.target}" includes="grails-*-files.jar"/>
</delete>



<!-- Package up the files that are shared by both applications and plugins. -->
<jar destfile="${grails.target}/grails-shared-files.jar">
<fileset dir="${basedir}/src/grails/templates/ide-support/eclipse"/>
Expand Down Expand Up @@ -57,6 +59,17 @@
<delete>
<fileset dir="${grails.dist}" includes="*"/>
</delete>
<copy todir="${grails.build}">
<fileset dir="${grails.src}" includes="**/*.xsd" />
</copy>

<copy todir="${grails.build}/META-INF">
<fileset dir="${grails.src.jar}/META-INF">
<include name="*.handlers" />
<include name="*.schemas" />
</fileset>
</copy>

<jar destfile="${grails.dist}/grails-test-${grails.version}.jar" manifest="${grails.build}/META-INF/MANIFEST.MF">
<fileset dir="${grails.build}">
<include name="META-INF/**" />
Expand Down Expand Up @@ -130,15 +143,6 @@
<file file="${basedir}/scripts/log4j.properties"/>
</jar>

<copy todir="${grails.build}/META-INF">
<fileset dir="${grails.src.jar}/META-INF">
<include name="*.handlers" />
<include name="*.schemas" />
</fileset>
</copy>
<copy todir="${grails.build}">
<fileset dir="${grails.src}" includes="**/*.xsd" />
</copy>

<jar destfile="${grails.dist}/grails-gorm-${grails.version}.jar" manifest="${grails.build}/META-INF/MANIFEST.MF">
<fileset dir="${grails.build}">
Expand Down
51 changes: 41 additions & 10 deletions grails/grails.ipr
Expand Up @@ -513,17 +513,51 @@
<root url="jar://$PROJECT_DIR$/lib/org.springframework.js-2.0.3.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.binding-2.0.3.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.webflow-2.0.3.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/spring-2.5.6.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/spring-webmvc-2.5.6.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/spring-test-2.5.6.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/aspectjweaver.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/aspectjrt.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.beans-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.test-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.aspects-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.asm-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.transaction-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.aop-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.core-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.oxm-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.integration-tests-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.instrument.classloading-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.jdbc-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.context.support-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.context-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.web.servlet-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.jms-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.expression-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.instrument-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.web-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/org.springframework.orm-3.0.0.CI-325.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/aopalliance-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$SPRING_DIR$/tiger/src" />
<root url="file://$SPRING_DIR$/src" />
<root url="file://$SPRING_DIR$/mock" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.beans-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.expression-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.instrument.classloading-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.web-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.oxm-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.web.servlet-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.aspects-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.test-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.transaction-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.integration-tests-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.jms-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.context.support-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.context-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.jdbc-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.aop-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.core-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.asm-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.instrument-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.web.portlet-sources-3.0.0.CI-325.jar!/" />
<root url="jar:///Users/graemerocher/Downloads/spring-framework-3.0.0.CI-325/src/org.springframework.orm-sources-3.0.0.CI-325.jar!/" />
</SOURCES>
</library>
<library name="dom4j">
Expand Down Expand Up @@ -563,14 +597,11 @@
</library>
<library name="HSQLDB">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/hsqldb-1.8.0.5.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/hsqldb-1.8.0.10.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
<UsedPathMacros>
<macro name="SPRING_DIR" />
</UsedPathMacros>
</project>

2 changes: 1 addition & 1 deletion grails/src/jar/META-INF/spring.handlers
@@ -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
2 changes: 1 addition & 1 deletion grails/src/jar/META-INF/spring.schemas
@@ -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
@@ -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 &lt;context:component-scan/&gt; 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();
}
}
}
@@ -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());
}

}

0 comments on commit 0b1e0f4

Please sign in to comment.