Skip to content

Instantly share code, notes, and snippets.

@thom-nic
Last active November 16, 2023 07:35
  • Star 47 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save thom-nic/2c74ed4075569da0f80b to your computer and use it in GitHub Desktop.
find the largest classnames in Spring libraries. Also find FactoryFactories
/**
* 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
}
}
: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
@TangoEnSkai
Copy link

wow this attempt is rad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment