Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jrugged-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
</profiles>

<properties>
<spring.version>4.1.3.RELEASE</spring.version>
<spring.version>4.3.3.RELEASE</spring.version>
<jsp.version>2.0</jsp.version>
<junit.version>4.4</junit.version>
<servlet.version>3.0.1</servlet.version>
Expand Down
209 changes: 209 additions & 0 deletions jrugged-spring-V5/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2009-2019 Comcast Interactive Media, LLC.

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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.fishwife</groupId>
<artifactId>jrugged</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jrugged-spring-V5</artifactId>
<packaging>jar</packaging>
<name>jrugged-spring-V5</name>
<url>https://github.com/Comcast/jrugged</url>

<properties>
<spring.version>5.1.5.RELEASE</spring.version>
<guava.version>18.0</guava.version>
<mockito.version>1.10.19</mockito.version>
<hamcrest.version>1.2.1</hamcrest.version>
</properties>

<dependencies>
<dependency>
<groupId>org.fishwife</groupId>
<artifactId>jrugged-core</artifactId>
<version>4.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.fishwife</groupId>
<artifactId>jrugged-aspects</artifactId>
<version>4.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>1.1.0.RELEASE</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.7</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<wtpversion>1.5</wtpversion>
<ajdtVersion>none</ajdtVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* Copyright 2009-2019 Comcast Interactive Media, LLC.

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.fishwife.jrugged.spring;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Set;

import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

/**
* TypeFilter to find classes based on annotations on
* {@link java.lang.reflect.Method}s.
*/
public class AnnotatedMethodFilter implements TypeFilter {

private final Class<? extends Annotation> annotatedClass;

/**
* Create filter for classes with {@link java.lang.reflect.Method}s
* annotated with specified annotation.
*
* @param annotatedClass The annotated Class
*/
public AnnotatedMethodFilter(Class<? extends Annotation> annotatedClass) {
this.annotatedClass = annotatedClass;
}

/**
* {@inheritDoc}
*/
public boolean match(MetadataReader metadataReader,
MetadataReaderFactory metadataReaderFactory) throws IOException {
AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
Set<MethodMetadata> annotatedMethods = annotationMetadata
.getAnnotatedMethods(annotatedClass.getCanonicalName());
return !annotatedMethods.isEmpty();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* Copyright 2009-2019 Comcast Interactive Media, LLC.

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.fishwife.jrugged.spring;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;

public class AnnotatedMethodScanner {

private final ClassLoader classLoader;
private final ClassPathScanningCandidateComponentProvider provider;

public AnnotatedMethodScanner() {
classLoader = AnnotatedMethodScanner.class.getClassLoader();
provider = new ClassPathScanningCandidateComponentProvider(false);
}

// package private for testing only
AnnotatedMethodScanner(ClassLoader classLoader, ClassPathScanningCandidateComponentProvider provider) {
this.classLoader = classLoader;
this.provider = provider;
}

/**
* Find all methods on classes under scanBase that are annotated with annotationClass.
*
* @param scanBase Package to scan recursively, in dot notation (ie: org.jrugged...)
* @param annotationClass Class of the annotation to search for
* @return Set&lt;Method&gt; The set of all @{java.lang.reflect.Method}s having the annotation
*/
public Set<Method> findAnnotatedMethods(String scanBase, Class<? extends Annotation> annotationClass) {
Set<BeanDefinition> filteredComponents = findCandidateBeans(scanBase, annotationClass);
return extractAnnotatedMethods(filteredComponents, annotationClass);
}

Set<Method> extractAnnotatedMethods(
Set<BeanDefinition> filteredComponents,
Class<? extends Annotation> annoClass) {
Set<Method> annotatedMethods = new HashSet<Method>();
for (BeanDefinition bd : filteredComponents) {
try {
String className = bd.getBeanClassName();
Class<?> beanClass = classLoader.loadClass(className);
for (Method m : beanClass.getMethods()) {
if (m.getAnnotation(annoClass) != null) {
annotatedMethods.add(m);
}
}
} catch (ClassNotFoundException cnfe) {
// no-op
}
}

return annotatedMethods;
}

synchronized Set<BeanDefinition> findCandidateBeans(String scanBase,
Class<? extends Annotation> annotatedClass) {
provider.resetFilters(false);
provider.addIncludeFilter(new AnnotatedMethodFilter(annotatedClass));

String basePackage = scanBase.replace('.', '/');
return provider.findCandidateComponents(basePackage);
}
}
Loading