Skip to content
Closed
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
1 change: 1 addition & 0 deletions src/it/WeaveDirectoriesNoSources/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = clean process-classes
60 changes: 60 additions & 0 deletions src/it/WeaveDirectoriesNoSources/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.mojo.aspectj.it</groupId>
<artifactId>weave-directories-no-sources</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>@aspectjVersion@</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<source>1.8</source>
<target>1.8</target>
<!-- Compile to a different directory to simulate pre-compiled classes -->
<outputDirectory>${project.build.directory}/unwoven-classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>weave-classes</id>
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<complianceLevel>1.8</complianceLevel>
<!-- Empty sources - we only want to weave pre-compiled classes with aspects from aspectDirectory -->
<sources/>
<!-- Weave the classes compiled by maven-compiler-plugin -->
<weaveDirectories>
<weaveDirectory>${project.build.directory}/unwoven-classes</weaveDirectory>
</weaveDirectories>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
13 changes: 13 additions & 0 deletions src/it/WeaveDirectoriesNoSources/src/main/aspect/foo/Azpect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package foo;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class Azpect {
@Before("execution(* foo.Clazz.doSomething(..))")
public void beforeDoSomething(JoinPoint joinPoint) {
System.out.println("Before doSomething");
}
}
7 changes: 7 additions & 0 deletions src/it/WeaveDirectoriesNoSources/src/main/java/foo/Clazz.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package foo;

public class Clazz {
public void doSomething() {
System.out.println("Doing something");
}
}
19 changes: 19 additions & 0 deletions src/it/WeaveDirectoriesNoSources/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.io.*;

File targetClasses = new File(basedir, "target/classes");
File clazzFile = new File(targetClasses, "foo/Clazz.class");

// Verify that the weaved classes exist - this proves the plugin ran and didn't skip
if (!clazzFile.exists()) {
throw new RuntimeException("Clazz.class was not found in target/classes - plugin execution was skipped!");
}

// Check that the build log shows the aspectj plugin ran
File buildLog = new File(basedir, "build.log");
String logContent = buildLog.text;
if (!logContent.contains("aspectj:")) {
throw new RuntimeException("AspectJ plugin did not run - it was skipped!");
}

System.out.println("SUCCESS: AspectJ plugin executed with empty sources and weaveDirectories configured");
return true;
12 changes: 11 additions & 1 deletion src/main/java/org/codehaus/mojo/aspectj/AbstractAjcCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,17 @@ private boolean hasArgumentsChanged(File outDir) throws MojoExecutionException {
* Not entirely safe, assembleArguments() must be run
*/
private boolean hasSourcesToCompile() {
return resolvedIncludes.size() > 0;
return resolvedIncludes.size() > 0 || hasWeavableContent();
}

/**
* Checks if there are weave directories or dependencies configured for weaving.
*
* @return true if there are weave directories or dependencies configured, false otherwise
*/
private boolean hasWeavableContent() {
return (weaveDirectories != null && weaveDirectories.length > 0)
|| (weaveDependencies != null && weaveDependencies.length > 0);
}

private boolean hasSourcesChanged(File outDir) {
Expand Down