https://github.com/abertschi/arquillian-extension-aspectj
JBoss Arquillian extension for AspectJ
https://github.com/abertschi/arquillian-extension-aspectj
Last synced: about 2 months ago
JSON representation
JBoss Arquillian extension for AspectJ
- Host: GitHub
- URL: https://github.com/abertschi/arquillian-extension-aspectj
- Owner: abertschi
- Created: 2016-02-07T18:42:03.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-07-06T09:01:37.000Z (almost 9 years ago)
- Last Synced: 2025-02-01T09:22:57.096Z (4 months ago)
- Language: Java
- Homepage:
- Size: 114 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22arquillian-extension-aspectj%22)
[](https://travis-ci.org/abertschi/arquillian-extension-aspectj)
[](https://codecov.io/gh/abertschi/arquillian-extension-aspectj)
[](https://www.codacy.com/app/abertschi/arquillian-extension-aspectj?utm_source=github.com&utm_medium=referral&utm_content=abertschi/arquillian-extension-aspectj&utm_campaign=Badge_Grade)
[](https://www.apache.org/licenses/LICENSE-2.0.html)# arquillian-extension-aspectj
> A JBoss Arquillian extension for AspectJ.
This extension compile-time weaves aspects into your Arquillian deployment using the AspectJ compiler ("ajc").
## UsageAdd *arquillian-extension-aspectj* to your Maven project.
```xml
ch.abertschi.arquillian
arquillian-extension-aspectj
VERSION
test
```
Generate a configuration file *aspectj.json* and add it as a manifest resource to your deployment.### Configuration
Use the builder class *ch.abertschi.arquillian.descriptor.AspectjDescriptor* to generate a configuration file.
The simplest configuration looks like shown below:
```java
String json = AspectjDescriptor
.create()
.weaveRootArchive()
.addWeaveDependency()
.exportAsString();
```
This compile-time weaves the root archive of your deployment using applicable aspects found within the archive.
For *WebArchive* or *EnterpriseArchive* deployments though, you may select weaving libraries by name:```java
String json = AspectjDescriptor
.create()
.weave("**/lib/name-of-weaving-lib*")
.addWeaveDependency()
.exportAsString();
```Glob patterns applicable for [AntPathMatcher](http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html) can be used.
#### AspectJ libraries
Aspect libraries can manually be added to the Arquillian archive or resolved from the Internet with Maven Coordinates.
The [Shrinkwrap Resolvers project](https://github.com/shrinkwrap/resolver) is used in that case.```java
String json = AspectjDescriptor
.create()
.weave("**/lib/weaving-lib.jar")
.aspectLibrary("ch.abertschi:myaspects:1.0.0") // Resolve aspects from Maven Central
.addAspectLibrary()
.aspectLibrary("**/lib/myaspects.jar") // Use aspects already added to the archive
.addAspectLibrary()
.addWeaveDependency()
.exportAsString();
```#### Filtering
You can filter weaving and aspect libraries.
Filtering by glob pattern, by package name and by class type is supported.```java
String json = AspectjDescriptor
.create()
.weaveRootArchive()
.filter(Filters.include("**/*controller*"))
.filter(Filters.include(Login.class, Logout.class))
.filter(Filters.exclude(Debbuging.class.getPackage()))
.addWeaveDependency()
.exportAsString();
``````java
String json = AspectjDescriptor
.create()
.weaveRootArchive()
.aspectLibrary("ch.abertschi:myaspects:1.0.0")
.filter(Filters.exclude(DebuggingAspect.class.getPackage()))
.addAspectLibrary()
.addWeaveDependency()
.exportAsString();
```#### Caching
To speed up the compile-time compilation process, you may activate caching.
```java
String json = AspectjDescriptor
.create()
.weaveRootArchive()
.useCache()
.addWeaveDependency()
.exportAsString();
```
The current cache implementation caches compiled artifacts based on their size.## Arquillian test
For more examples, take a look at the [sample project](example/src/test/java/ch/abertschi/aspectj) and [test classes](src/test/java/ch/abertschi/arquillian).
```java
@RunWith(Arquillian.class)
public class JarDeploymentIT
{
@Inject
DummyGreeter greeter;@Deployment
public static Archive> deploy()
{
String json = AspectjDescriptor
.create()
.weaveRootArchive()
.addWeaveDependency()
.exportAsString();return ShrinkWrap.create(JavaArchive.class)
.addClass(JarDeploymentIT.class)
.addPackages(true, Greeting.class.getPackage())
.addAsManifestResource(new StringAsset(json), "aspectj.json")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}@Test
public void test_around_aspect()
{
String expected = "arquillian!";
System.out.println(greeter.getGreeting());
Assert.assertEquals(greeter.getGreeting(), expected); // will say arquillian! instead of aspect!
}
}
``````java
@Aspect
public class SayArquillianAspect
{
@Around("call(* ch.abertschi.arquillian.domain.Greeting.*(..))")
public Object doNothing()
{
return "arquillian!";
}
}
``````java
@Stateless
@Startup
public class Greeting
{
public String greet()
{
return "aspect!";
}
}
``````java
@Singleton
@Startup
public class DummyGreeter
{
@Inject
Greeting greeting;@PostConstruct
public void sayGreeting()
{
}public String getGreeting() {
return greeting.greet();
}
}
```## Behind a corporate proxy
This extension uses the Shrinkwrap Resolver Project to resolve necessary dependencies for AspectJ and referenced aspect libraries. If you encouter connection problems, you may configure the [shrinkwrap-resolver-maven-plugin](https://github.com/shrinkwrap/resolver) and set the following system properties.```xml
org.jboss.shrinkwrap.resolver
shrinkwrap-resolver-maven-plugin
propagate-execution-context
org.apache.maven.plugins
maven-surefire-plugin
true
```
## Bleeding Edge
Get snapshot artifacts from [https://oss.sonatype.org/content/repositories/snapshots](https://oss.sonatype.org/content/repositories/snapshots/ch/abertschi/arquillian/arquillian-extension-aspectj/)## Development note
Ajc compilations of the the following scenarios are implemented.
- [x] ajc compile JAR deployments
- [x] ajc compile WAR deployments (/WEB-INF/classes)
- [x] ajc compile JAR in WAR deployments (/WEB-INF/lib/)
- [x] ajc compile JAR in EAR deployments
- [ ] ajc compile WAR in EAR deployments
- [ ] ajc compile JAR in WAR in EAR deployments