Maven testcases are not invoking AspectJ Aspects - aop

I have added the Junit test case to call a method with Annotation which in turn have the Around aspect. When i run the mvn test command, The Aspect is not getting invoked for some reason.
But when i build the jar using mvn package and run the jar, the Aspects are getting invoked.
Here is the code - https://github.com/chandru-kumar/aop-example
Can anyone help on this? How can i make the Aspects invoked for mvn test?

Your tests would work if you would test against the application classes, which have been compiled by the AspectJ compiler. But you are trying to test the aspect against a test class. That is also possible, but in that case you need to tell AspectJ Maven to actually take care of compiling test classes, too:
<execution>
<goals>
<goal>test-compile</goal>
<goal>compile</goal>
</goals>
</execution>
P.S.: Thanks for providing an MCVE. Most StackOverflow newbies forget that. It helped me to easily identify the problem, in this case without even cloning the repository. But sometimes it is not that simple, then I need to compile and run the example program. Anyway, keep up the good practice! 👍

Related

How to use Processing 3 on IntelliJ IDEA?

I'd like to use the IntelliJ IDEA IDE to develop some app using Processing 3. How can I do that ?
There are only tutorials on how to use Processing 2, but I think things have changed enough so that those tutorials do not work anymore.
Thank you
It's hard to answer general "how do I do this" type questions. Stack Overflow is designed more for "I tried X, expected Y, but got Z instead" type questions. You'll have much better luck if you try something out and post an MCVE along with a specific question if you get stuck. You say you think things have changed enough so that those tutorials don't work anymore- could you test that assumption by trying it out?
Because those tutorials will still work. A few things have changed, such as the removal of the ability to embed a PApplet directly into a Swing application. But 90% of the rest of the tutorials should work fine.
Step 1: Add the Processing library to your classpath. This includes the core and any JOGL dependencies you need.
Step 2: Create a class that extends PApplet and add your code there.
Step 3: Call PApplet.main("YourSketchNameHere"); to launch your sketch.
Here is a little example that shows those steps:
import processing.core.PApplet;
public class ProcessingTest extends PApplet{
public void settings(){
size(200, 200);
}
public void draw(){
background(0);
ellipse(mouseX, mouseY, 20, 20);
}
public static void main(String... args){
PApplet.main("ProcessingTest");
}
}
Please try something out and post a specific question if you get stuck. Good luck.
Shameless self-promotion: I wrote a tutorial on using Processing as a Java library, available here.
I up voted Kevin's answer but also went ahead and created a gradle project that you can use with or without an IDE or processing.
Git Commit to processing project
Edit
doesn't work for video libraries. i tried to get the libraries needed but that is not my best area and have resorted to use P3 for those projects.
The easiest way for me is to create a new maven project and add proessing through maven.
After that you create your class that extends PApplet (I named it Main).
In Run > Edit Configuratins add the main class name and the same name for program arguments.
Create a maven project in Intellij. In one folder (example "libs") you put all libs which are probably not yet available via mavencentral, but with the help of maven you can handle the installation automatically.
libs
Then inside the pom.xml you add a maven-install-plugin, which will install your libs for you inside your local repository.
<profiles>
<profile>
<id>Assembly Gui</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>${maven-install-plugin.version}</version>
<executions>
<execution>
<id>install-controlP5-lib</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>validate</phase>
<configuration>
<groupId>sojamo.de</groupId>
<artifactId>controlP5</artifactId>
<version>${controlP5.version}</version>
<packaging>jar</packaging>
<file>${basedir}/libs/controlP5-2.3.0.jar</file>
<generatePom>true</generatePom>
</configuration>
</execution>
<execution>
<id>install-appleJar-lib</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>validate</phase>
<configuration>
<groupId>processing.org</groupId>
<artifactId>appleJar</artifactId>
<version>${appleJar.version}</version>
<packaging>jar</packaging>
<file>${basedir}/libs/apple.jar</file>
<generatePom>true</generatePom>
</configuration>
</execution>
</executions>
</plugin>
Note that both libs are "installed" during the "validate" phase, so the order is
clean
validate (here your processing libs are installed)
compile (and here they can be retrieved later from your local repo)
test
...
Because the maven-install-plugin was inserted as a profile (active as default), you can switch it off inside Intellij for saving a bit of time during builds once it runned at least once.
Profiles in Intellij
Download the .jar files from their official site
keep in mind that the Maven version is outdated
Create any Java (or Kotlin) project in IntelliJ
for this tutorial I've used Maven
Inside IntelliJ, go to File > Project Structure
or pressCTRL + ALT + SHIFT + S at the same time
Inside Project Settings > Libraries: Click Plus icon
navigate to the downloaded folders
Add everything inside processing-X.Y.Z/core/library
for other dependencies, look into modes library
e.g.: for SVG export, add processing-X.Y.Z/modes/java/libraries/svg/library
To make it easier to use Processing within an external IDE, I implemented a rudimentary wrapper. This will avoid the necessity to inject the Processing-Object to each created class that want to use Processing methods.
Have a look: Using Processing within external IDE

Hudson and Maven tests run twice

Parsing POMs
Discovered a new module be.howest:someproject someproject
It seems to find a new module on the first time I make a hudson job. Well, nothing really to worry, but it seems to execute everything twice, and I don't really know why. Another thing is: it gives this odd error (at least to me):
[WARNING] Removing: cobertura from forked lifecycle, to prevent recursive invocation.
[WARNING] Removing: findbugs from forked lifecycle, to prevent recursive invocation.
To me this looks like it tried to execute twice, but why is escaping me.
Also, it has a module under the build, which is something i'm not very familiar with, but I wouldn't bother too much (and consider it normal) if it didn't do my tests twice.
right now it is running two phases: clean and test. I changed it to clean package, because I included javadoc in the package lifecycle, but nothing has changed.
Hudson console log: http://pastebin.com/2GRmc2yP
Pom.xml: http://pastebin.com/HL9Qd821
Maven will execute tests first without any instrumentation, then it will execute cobertura plugin that will instrument the classes and re-run all the tests. Thus, the tests will be executed twice.
It is cobertura which makes the tests run the second time.

How can I bind the execution of a Maven plugin to a different Maven plugin's execution?

I am using the maven-eclipse-plugin to configure my eclipse workspace with the configure-workspace goal of the plugin.
I need to perform some additional setup within the workspace that standard eclipse plugins do not appear to accomplish. Setup MAVEN_HOME and setup an external build tool for example. I have some corporately built plugins that can perform these tasks. What I would like to do is bind the execution of this plugin to the execution of eclipse:workspace-configure.
I have tried to do this by:
<executions>
<execution>
<goals>
<goal>eclipse:configure-workspace</goal>
</goals>
</execution>
</executions>
But have had no luck. Is this possible?
I am using the maven-eclipse-plugin to configure my eclipse workspace with the configure-workspace goal of the plugin.
The goal eclipse:configure-workspace doesn't do much things, it just adds the classpath variable M2_REPO to Eclipse.
What I would like to do is bind the execution of this plugin to the execution of eclipse:workspace-configure
Not possible, you can only bind a plugin goal to a phase. Your best option is IMO to create an init script that would call the goals sequentially.
You can't bind an maven plugin to an other. You can configure to run one plugin after an other. For example to run the eclipse plugin first and you coperate after that. You need to define them directly within the same phase. On the other hand the example you give can't really work cause you're trying to bind a goal which with the plugin name. You have to use the configure-workspace only in the goal.

How can I configure Maven to commit to a Mercurial repository when I install:install

Maven's SCM plug-in doesn't appear to provide a "commit" goal. scm:checkin performs a commit AND push. I need to avoid the push.
I'm simply interested in doing an hg commit during install:install. I'm not using the release plugin and don't need it yet. I'm simply working locally in a multi-module environment and want to ensure that my source repository aligns with my Maven locally-installed snapshots for each module. In other words, every time I install a new snapshot of a module, I want the related code committed to hg to make every snapshot directly correlate to an hg revision (or range of revisions when multiple commits occur between snapshots).
The following will bind scm:checkin to the install phase. As long as the repository is a file:// scheme (at least for Mercurial, according to the code), a push is not performed during scm:checkin.
Define properties used in the following steps:
<properties>
<message>maven install:install auto-checkin.</message>
<repository.local>file:///path/to/local/repository</repository.local>
<repository.type>hg</repository.type>
</properties>
The <message> can be anything you choose. It isn't ideal to be completely fixed as commits should include meaningful messages as to what changes were made. But, I do believe there should be a standard message included in auto-commits to identify it as such. Just modify the <message> property from step 1. before each install.
This is just a standard scm node for a Maven-based project. Since this is concerned only with a local repository, the URLs are all the same.
<scm>
<connection>scm:${repository.type}:${repository.local}</connection>
<developerConnection>scm:${repository.type}:${repository.local}</developerConnection>
<url>scm:${repository.type}:${repository.local}</url>
</scm>
This is plug-in that runs during the install phase that performs the commit. It'll simply execute the proper scm checkin based on the definition in step 2.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>checkin</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
One problem is that I receive the following.
DEPRECATED: Binding aggregator mojos
to lifecycle phases in the POM is
considered dangerous. This feature has
been deprecated. Please adjust your
POM files accordingly.
I'm looking into how to resolve it but, for now, it works and I'm going with it.
What about setting the connectionUrl on the checkin to a throw-away repository on the local box? So your checkout would come from the "central" repo, but your 'checkin' would go only to the working repository (the commit that you want) and the (apparently) unavoidable push would go to file:///tmp/whocares.
Alternately there's probably a single line of code in the scm plugin to comment out to avoid that push.
Maven's scm plugin doesn't appear to provide a "commit" goal. scm:checkin performs a commit AND push. I need to avoid the push.
Then the scm plugin is maybe not what you're looking for :)
I'm simply interested in doing an hg commit during install:install. I'm not using the release plugin and don't need it yet.
To be honest, this is a pretty odd usage. While I understand what you described, it doesn't really make sense to me to "sync" a SNAPSHOT with a revision number. Even if you don't commit code between two SNAPSHOT builds, I don't understand how this can this be a problem. In other words, I don't see what is the added value of forcing the commit. And using the release plugin won't solve anything in my opinion.
To summarize, I don't think that the scm plugin will allow you to achieve your goal (at least not without hacking). I don't know if there is mercurial support in Ant but, if there is, maybe you should look in this direction instead (and use the antrun plugin).

How do you use the maven-simian-plugin in Maven2?

I'm looking for a Maven2 reporting plugin for Simian and the closest thing to such a reporting I found is this. The problem is, the documentation for it appears to be for Maven 1 instead. Why is a Maven 1 plugin stored in a Maven 2 repository? I suppose that means I can use it... but how to use? The site mentions reporting but if I don't have a src/main/site, does that mean I can't use it? I was kinda hoping for something like mvn simian:simian similar to mvn checkstyle:checkstyle and mvn pmd:pmd. I don't want to generate site just for the reports. Sites take too long to generate when all I want is a quite xml report.
The Simian plugin listed on central is actually for Maven 1 (if you inspect the contents you'll see a project.xml and a plugin.jelly). So that explains why it doesn't work. This is rubbish and should be removed in my opinion.
As far as I can make out there isn't a publically available Maven 2 plugin, this may have something to do with the licence (Simian isn't open source).
As an alternative, have a look at PMD's CPD plugin, it may not be as fully featured as simian but I know it works in a Maven 2 build and detects copypasta pretty well.
To configure PMD, add something like the following to your POM:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</reporting>