find the largest classnames in Spring libraries. Also find FactoryFactories
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
/** | |
* Find the longest class names in Spring. | |
* Also find FactoryFactory classes. | |
* a goof-off project by @thom_nic | |
*/ | |
import java.util.jar.* | |
defaultTasks 'longest', 'factoryfactory' | |
apply plugin: 'java' | |
repositories { | |
mavenCentral() | |
} | |
def group = 'org.springframework' | |
def version = '4.0.5.RELEASE' | |
def jars = [ | |
'spring-context', | |
'spring-core', | |
'spring-beans', | |
'spring-test', | |
'spring-web', | |
'spring-aop', | |
'spring-webmvc', | |
'spring-jdbc', | |
'spring-tx', | |
'spring-context-support', | |
'spring-orm', | |
'spring-jms', | |
'spring-expression', | |
'spring-aspects', | |
'spring-oxm', | |
'spring-webmvc-portlet', | |
'spring-instrument', | |
'spring-messaging', | |
'spring-websocket', | |
'spring-instrument-tomcat', | |
'spring-framework-bom' | |
] | |
dependencies { | |
jars.each { | |
compile group: group, name: it, version: version | |
} | |
} | |
def iterateClassNames(cb) { | |
sourceSets.main.compileClasspath.each { | |
// println it.name | |
def jar = new JarFile( it ) | |
jar.entries().each { | |
if ( it.directory ) return | |
if ( ! it.name.endsWith( '.class' ) ) return | |
def n = it.name | |
n = n.substring( n.lastIndexOf( '/' )+1 )[0..-7] | |
cb n | |
} | |
} | |
} | |
task longest << { | |
def winners = new TreeSet( { a,b -> a.size() - b.size() } as Comparator ) | |
iterateClassNames { n -> | |
n.split( /\$/ ).each { | |
if ( it.matches(/\d+/) ) return // ignore anonymous subclasses | |
// println " $it" | |
winners << it | |
} | |
} | |
println "============ Top 5: ===============" | |
(1..5).each { | |
def v = winners.pollLast() | |
println "$v: ${v.size()}" | |
} | |
} | |
task factoryfactory << { | |
def factories = new HashSet() | |
iterateClassNames { | |
if ( it.matches( /.*Factory.*Factory.*/ ) ) factories << it | |
} | |
println "============ Factories: ===============" | |
factories.each { | |
println it | |
} | |
} |
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
:longest | |
============ Top 5: =============== | |
HasThisTypePatternTriedToSneakInSomeGenericOrParameterizedTypePatternMatchingStuffAnywhereVisitor: 97 | |
AbstractAnnotationConfigDispatcherServletInitializer: 52 | |
AbstractInterruptibleBatchPreparedStatementSetter: 49 | |
AbstractInterceptorDrivenBeanDefinitionDecorator: 48 | |
GenericInterfaceDrivenDependencyInjectionAspect: 47 | |
:factoryfactory | |
============ Factories: =============== | |
DefaultListableBeanFactory$DependencyObjectFactory | |
ObjectFactoryCreatingFactoryBean | |
SimpleBeanFactoryAwareAspectInstanceFactory | |
SingletonBeanFactoryLocator$BeanFactoryGroup | |
ConnectionFactoryUtils$ResourceFactory | |
DefaultListableBeanFactory$DependencyProviderFactory | |
ObjectFactoryCreatingFactoryBean$TargetBeanObjectFactory | |
JndiObjectFactoryBean$JndiObjectProxyFactory | |
DefaultListableBeanFactory$SerializedBeanFactoryReference | |
AbstractEntityManagerFactoryBean$SerializedEntityManagerFactoryBeanReference | |
BeanFactoryAspectInstanceFactory | |
SingletonBeanFactoryLocator$CountingBeanFactoryReference | |
TransactionAwarePersistenceManagerFactoryProxy$PersistenceManagerFactoryInvocationHandler | |
AbstractEntityManagerFactoryBean$ManagedEntityManagerFactoryInvocationHandler |
This is golden. :D
Top #1 is not a spring class. Your script found a class from spring dependencies. See
https://www.javadoc.io/doc/org.aspectj/aspectjweaver/1.8.10/org/aspectj/weaver/patterns/HasThisTypePatternTriedToSneakInSomeGenericOrParameterizedTypePatternMatchingStuffAnywhereVisitor.html
wow this attempt is rad.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a version that works with Gradle 5.3.1 and Spring 5.1.8.
Output: