Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AJDT » Converted AJ project differs from native AJ project(Eclipse not showing desired info after conversion)
Converted AJ project differs from native AJ project [message #986615] Wed, 21 November 2012 08:21 Go to next message
Erik Vande Velde is currently offline Erik Vande VeldeFriend
Messages: 62
Registered: September 2012
Member
I'm trying to convert the very simple hello world example (eclipse menu Help->Cheat Sheets...) to a project that's organized in a maven way, with three different modules: domain, core and testframework. Purpose: find out if the aspect target (in domain), aspect code (in core) and aspect target invoker (testcase in testframework) can be located in different modules, and how to configure this. The first problem I see is: when I convert a regular project (core) to an AspectJ project, the World.aj file is displayed with a different icon then the original World.aj in the CheatSheet project, and what's worse: the AspectJ Visualisation perspective doesn't recognize this aspect, it doesn't want to show it. Don't know if it's relevant: I'm using eclipse juno J2EE version for this. A screenshot, showing the different icons, is attached ...
Re: Converted AJ project differs from native AJ project [message #986800 is a reply to message #986615] Wed, 21 November 2012 16:52 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 369
Registered: July 2009
Senior Member
In maven, your AJ sources are expected to be in the src/aspectj folder. Make sure to read the documentation about the aspectj plugin here:

http://maven.apache.org/maven-1.x/plugins/aspectj/

And add this block as well:

    <build>
        <sourceDirectory>src/java</sourceDirectory>
        <aspectSourceDirectory>src/aspectj</aspectSourceDirectory>
    </build>


I would guess that moving your aspects to the new folder would solve most of your problems.
Re: Converted AJ project differs from native AJ project [message #986879 is a reply to message #986800] Thu, 22 November 2012 08:52 Go to previous messageGo to next message
Erik Vande Velde is currently offline Erik Vande VeldeFriend
Messages: 62
Registered: September 2012
Member
The problem here is that the <aspectSourceDirectory> tag doesn't exist for a 4.0.0 pom (see http://maven.apache.org/maven-v4_0_0.xsd), and the <plugins> tag doesn't exist in a 3.0.0 pom (see http://maven.apache.org/maven-v3_0_0.xsd). I guess this is the reason why we are using the org.codehaus.mojo aspectj plugin, which works with a 4.0.0 pom, instead of your suggested apache aspectj plugin. As maven doesn't allow more then one source folder it would also be impossible to have a traditional src/main/java source folder next to a src/main/aspectj, essentially meaning that the aspects should be contained in a separate module. Do you see a way to use the apache aspectj plug in with a maven v4.0.0 pom, or another way forward?

[Updated on: Fri, 23 November 2012 07:31]

Report message to a moderator

Re: Converted AJ project differs from native AJ project [message #986977 is a reply to message #986879] Thu, 22 November 2012 16:48 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 369
Registered: July 2009
Senior Member
You could use the codehaus aspectj-maven-plugin as well. Something like this would work in your build->Plugins section:

			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>aspectj-maven-plugin</artifactId>
				<configuration>
					<aspectLibraries>
						<aspectLibrary>
							<groupId>org.springframework</groupId>
							<artifactId>spring-aspects</artifactId>
						</aspectLibrary>
							other libraries, too
					</aspectLibraries>
				</configuration>
			</plugin>


I forgot to mention that you will need to install the AspectJ m2e configurator in your Eclipse. The update site is here:
http://dist.springsource.org/release/AJDT/configurator/
Re: Converted AJ project differs from native AJ project [message #987059 is a reply to message #986977] Fri, 23 November 2012 08:46 Go to previous messageGo to next message
Erik Vande Velde is currently offline Erik Vande VeldeFriend
Messages: 62
Registered: September 2012
Member
I installed the plugin you mentioned. At first the aspect visualisation perspective didn't link the World aspect defined in the core module, to the advised HelloWorld class in the domain module. That was easily fixed by configuring the aspectj build path of the domain module, putting the core project in the aspect path of domain. After that the advice is indeed applied to the domain class, but the three projects get a red exclamation mark next to them, because of circular dependencies. The core module with the advice naturally depends on the domain module, as the aspect refers to the domain object it advices, but now the domain points back to the core module so the domain class can be advised by the core aspect. When I change my domain pom file like you suggested, including
<aspectLibrary>
<groupId>com.fugro.gwf.lab.aspectj</groupId>
<artifactId>com.fugro.gwf.lab.aspectj.core</artifactId>
</aspectLibrary>
My project doesn't compile any more because of the same circular dependencies.
So these are my new questions:
1) What is the purpose of my newly installed AJDT configurator plugin?
2) How to avoid the circular dependencies mentioned above in a maven build?
Re: Converted AJ project differs from native AJ project [message #987128 is a reply to message #987059] Fri, 23 November 2012 17:01 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 369
Registered: July 2009
Senior Member
Quote:
1) What is the purpose of my newly installed AJDT configurator plugin?

The configurator communicates with m2e and properly adds the AspectJ nature to your project. It also populates the aspect and in paths of the project. Essentially, it configures all of the aspect-y parts of the project.

Quote:
2) How to avoid the circular dependencies mentioned above in a maven build?

This is a little bit trickier. You need to think about the best modularization. The typical way of doing this is to use abstract aspects. With abstract aspects, you can define abstract pointcuts in your core module and then have a sub-aspect in your non-core module that implements the pointcuts. You also need to make sure that the advice body in your core aspect doesn't refer to any classes in your non-core project. It could look something like this:

// in core module
public abstract aspect Core {
  abstract pointcut accountActivation();

  before() : accountActivation() {
    doSomething();
  }

  protected abstract void doSomething();
}


// in non-core module
public aspect NonCore extends Core {
  pointcut accountActivation() : execution(...);

  protected void doSomething() { ... }
}



With this kind of setup you can separate out core from non-core. Unless there is a way that you can specify your pointcut w/o referencing anything in non-core, then you will need to have an aspect in non-core as well.
Re: Converted AJ project differs from native AJ project [message #987347 is a reply to message #987128] Mon, 26 November 2012 09:03 Go to previous messageGo to next message
Erik Vande Velde is currently offline Erik Vande VeldeFriend
Messages: 62
Registered: September 2012
Member
This means that non-core contains at least one regular class and at least one aspect. To work together with the Aspectj visualizer in eclipse the aspect needs to be in src/main/aspectj, the regular class belongs in src/main/java. But maven can only handle one source directory, so I'm stuck once again. I tried to put both the aspect and the class under src/main/aspectj, and use that folder as the single maven source folder, but in that case the aspect is not rendered with the familiar aspectj-icon in eclipse when I convert the project in a aspectj project. The only thing that works for me today is: put the classes under src/main/java, and aspects under src/main/aspectj. A maven clean install just compiles, ignoring the aspects. Then I import the projects in eclipse (after a maven eclipse:eclipse on the command line), convert them to aspectj projects, add the src/main/aspectj directories as source folders, and everything works in eclipse. But of course this won't work from the command line, because only eclipse can see these aspectj folders, maven is not interested in them. I attached my code to this message. A simple challenge for you Andrew, or some other aspectj wizard of course: make this very simple code compile and run (applying the aspect) from maven and eclipse. In eclipse it should show how the aspect is applied in the visualizer. I'm afraid I still can't do it, but I would love it if someone else can ...

[Updated on: Mon, 26 November 2012 09:05]

Report message to a moderator

Re: Converted AJ project differs from native AJ project [message #987459 is a reply to message #987347] Mon, 26 November 2012 17:03 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 369
Registered: July 2009
Senior Member
Thanks for the test project. I see what is happening, but first a few comments on your project:

1. You should be using these dependencies in your pom instead of the com.springsource ones:

		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjrt</artifactId>
			<version>1.6.12</version>
		</dependency>
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjweaver</artifactId>
			<version>1.6.12</version>
		</dependency>
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjtools</artifactId>
			<version>1.6.12</version>
		</dependency>


2. Using the aspectj-maven-plugin, all of your aspects need to be in src/main/java (apologies for the mixed information from before). They need to sit right next to your java files.

Now, the problem with the visualizer is that there is a limitation in AJDT with cross-project Aspect markers. Because of the way the cross-cutting model is generated, only one-way relationships are available to AJDT (ie- from the class being woven to the aspect, not the other way around). This is because when the Aspect is being compiled, it has no knowledge of how it is going to be woven. And the visualizer needs to have a two way relationship to show the item. Unfortunately, the only way around this is to move your aspects and target files into the same project.
Re: Converted AJ project differs from native AJ project [message #988263 is a reply to message #987459] Thu, 29 November 2012 08:13 Go to previous messageGo to next message
Erik Vande Velde is currently offline Erik Vande VeldeFriend
Messages: 62
Registered: September 2012
Member
1) We are using the com.springsource dependencies because the real project is OSGi based, so we need to use OSGi bundles instead of 'simple jars'
2) I reworked the test project a bit, removing the circular dependencies by making the pointcut more generic (using sayHello(..)) instead of HelloWorld.sayHello(..))
3) The resulting test project is attached. My procedure for building it from maven, and then eclipse is:
a. start with 'mvn clean install'
b. do a 'mvn eclipse:eclipse'
c. import the 3 projects in eclipse (juno j2ee)
=> now the aspect in the core module is shown with a 'hollow J icon' next to it
d. convert the domain and core module into an aspectj project (from the configure menu)
e. Change the aspectj build path of the domain, add the core project to the aspect path
=> when you now run the HelloWorldTest junit test of the testframework module, it just displays 'hello'
f. In the core module: remove the src/main/java dir from the build path (right click the folder, remove from build path'
g. Right click that same folder, and select 'use as source folder'
=> now the aspect has the desired 'AJ' icon next to it
=> the visualizer shows that the HelloWorld class of domain is advized by world.aj
=> the test displays 'World, Hello'
4) So my question: why do I need the last two steps to activate my aspect ??
Re: Converted AJ project differs from native AJ project [message #988383 is a reply to message #988263] Thu, 29 November 2012 16:58 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 369
Registered: July 2009
Senior Member
I see...you are using mvn eclipse:eclipse and you are not using m2e. mvn eclipse:eclipse has trouble recognizing AspectJ projects. m2e, however does not have trouble with this as long as you have the AspectJ configurator installed. But, first, you must install m2e (from the eclipse juno update site).
Re: Converted AJ project differs from native AJ project [message #988484 is a reply to message #988383] Fri, 30 November 2012 08:06 Go to previous messageGo to next message
Erik Vande Velde is currently offline Erik Vande VeldeFriend
Messages: 62
Registered: September 2012
Member
I already have m2e installed, so what's the impact on my build procedure above? I skip the mvn eclipse:eclipse step, but what should I do instead to make things work?
Re: Converted AJ project differs from native AJ project [message #988613 is a reply to message #988484] Fri, 30 November 2012 17:13 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 369
Registered: July 2009
Senior Member
You should not be running mvn eclipse:eclipse. So, remove your projects from the workspace, run mvn eclipse:clean, and then import them as "existing maven projects".
Re: Converted AJ project differs from native AJ project [message #988790 is a reply to message #988613] Mon, 03 December 2012 08:37 Go to previous messageGo to next message
Erik Vande Velde is currently offline Erik Vande VeldeFriend
Messages: 62
Registered: September 2012
Member
In that case the aspect is indeed immediately shown with the 'AJ' icon, but unfortunately with a yellow marker saying 'advice defined in com.fugro.gwf.lab.aspectj.core.World has not been applied [Xlint:adviceDidNotMatch]'. I already expected from the discussion above that the aspectj markers might be missing, but the aspect is not applied to the HelloWorld class when I run the test case. So the dirty workaround with eclipse:eclipse above leads to better results (the aspect is applied, which is the main purpose) then the cleaner approach with the 'import as maven project'. Do you have any idea what I should do to get the advise applied in the m2e scenario?
Re: Converted AJ project differs from native AJ project [message #988961 is a reply to message #988790] Tue, 04 December 2012 05:15 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 369
Registered: July 2009
Senior Member
It looks like you are hitting a limitation of AspectJ. You have 2 projects, one with aspects and one with plain java that places the aspects on the aspect path.

The java project knows about the aspect project and if you head to something that gets woven by an aspect, you will see a marker and be able to properly navigate to it.

However, the aspect project does not know about the java project (since it is downstream). The aspect project does not know that it has been applied to a java project and that its aspect is indeed being used. There is a warning marker, but it is spurious.
Re: Converted AJ project differs from native AJ project [message #989202 is a reply to message #988961] Wed, 05 December 2012 08:41 Go to previous messageGo to next message
Erik Vande Velde is currently offline Erik Vande VeldeFriend
Messages: 62
Registered: September 2012
Member
So I added the core module (the one with the aspect) to the 'aspect path' of the domain module (the one with the classes to be advised) , and then everything works OK. Thanks for your assistance Andrew, it's much appreciated ...
Re: Converted AJ project differs from native AJ project [message #989350 is a reply to message #989202] Wed, 05 December 2012 18:45 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 369
Registered: July 2009
Senior Member
Glad it's working for you now.
Re: Converted AJ project differs from native AJ project [message #994328 is a reply to message #986615] Thu, 27 December 2012 02:36 Go to previous messageGo to next message
cindy john is currently offline cindy johnFriend
Messages: 1
Registered: December 2012
Junior Member
I'm trying to convert the very simple hello world example
Re: Converted AJ project differs from native AJ project [message #994544 is a reply to message #994328] Thu, 27 December 2012 16:23 Go to previous message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 369
Registered: July 2009
Senior Member
Cindy,

Can you be more specific about what your problem is?
Previous Topic:Force.com IDE plugin for Eclipse juno
Next Topic:include JSP from other project
Goto Forum:
  


Current Time: Sat Nov 22 10:40:11 GMT 2014

Powered by FUDForum. Page generated in 0.14793 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software