Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Handle cycle dependencies using JDT(How does Eclipse do this "magic"?)
Handle cycle dependencies using JDT [message #730626] Wed, 28 September 2011 14:06 Go to next message
Eclipse UserFriend
Hi guys,

Does someone know how I could use JDT to compile a simple example of cycle dependency like the one I'm describing below?


Proj1
   Class1 {
      Class2 c2;
   }


Proj2
   Class2 {
      Class1 c1;
   }


I know Eclipse does this "magic" using JDT but I'd like to know how it happens behind the scenes. Has someone already done that or could point me out where I can find some examples to help me out?

* let's disregard the reasons I have these cycles ok? Razz

I'd apreciate any help

Thanks in advance
--
[Raphael Moita]
Re: Handle cycle dependencies using JDT [message #730729 is a reply to message #730626] Wed, 28 September 2011 22:34 Go to previous messageGo to next message
Eclipse UserFriend
What do you mean by 'Eclipse does this "magic" using JDT'? Are Proj1 and Proj2 separate Java Projects in eclipse? As Proj1 depends on Proj2, Proj2 has to be added as dependent of Proj1 and vice versa and Eclipse/JDT will report a build cycle error in this case. One way to get rid of this problem is to add Proj2 can be added as dependent of Proj1 and Proj1's output folder can be added as class folder for Proj2.
Is this what you are asking or have I misunderstood your question completely.
Re: Handle cycle dependencies using JDT [message #730883 is a reply to message #730729] Thu, 29 September 2011 08:50 Go to previous messageGo to next message
Eclipse UserFriend
Hi Santyam,

Thanks for replying my question ... I meant by "magic" the way JDT compiles classes with errors, in this case the cycle errors.

The example I provided before I have two separated projects (Proj2 and Proj1), Proj1 uses a class from Proj2 and vice-versa. Using Eclipse IDE it is solved automatically setting some dependencies as you said.

What I want to figure out is the way Eclipse/JDT does it and do the same "magic" outside of Eclipse to use in some scripts ANT.

Please let me know if I was clear enough at this time

Thanks!
Re: Handle cycle dependencies using JDT [message #731110 is a reply to message #730883] Thu, 29 September 2011 22:44 Go to previous messageGo to next message
Eclipse UserFriend
You can look at the source code of org.eclipse.jdt.internal.core.JavaProject.validateCycles(Map). Basically, it just checks all the project dependencies.
Re: Handle cycle dependencies using JDT [message #731111 is a reply to message #731110] Thu, 29 September 2011 22:44 Go to previous messageGo to next message
Eclipse UserFriend
No Message Body
Re: Handle cycle dependencies using JDT [message #731332 is a reply to message #731110] Fri, 30 September 2011 12:50 Go to previous messageGo to next message
Eclipse UserFriend
I checks all the project dependencies and do what else? Is there any documentation/samples codes of this specific part. I haven't found any official documentation.
Re: Handle cycle dependencies using JDT [message #731792 is a reply to message #731332] Mon, 03 October 2011 02:06 Go to previous messageGo to next message
Eclipse UserFriend
Do you want to just find cycles or do something else? If it is to just find cycles, look at the source code of org.eclipse.jdt.internal.core.JavaProject.validateCycles(Map) (http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/tree/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java)
Re: Handle cycle dependencies using JDT [message #731905 is a reply to message #731792] Mon, 03 October 2011 08:53 Go to previous messageGo to next message
Eclipse UserFriend
No, I don't want to find cycles cause I know where they are. What I want is to build projetcs with these cycles just like Eclipse does using JDT, BUT I don't want to use eclipse to do that.

For example, getting the first sample I put in the first mail.

Proj1
   Class1 {
      Class2 c2;
   }


Proj2
   Class2 {
      Class1 c1;
   }


Eclipse/JDT, in someway, compiles both projects even they have a circular dependency with each other. I believe that what I'm looking for is something that can compile partially Proj1 and then solve all the depenednecies Proj2 has with it, from that point on I could compile Proj2 and solve also the Proj1 dependecies and then proceed a full compilation on it.
Re: Handle cycle dependencies using JDT [message #732160 is a reply to message #731905] Tue, 04 October 2011 02:03 Go to previous messageGo to next message
Eclipse UserFriend
Eclipse/JDT comes with it's own compiler. However, at the compiler level, it is equivalent to just two classes like Class1 { Class2 c2; } and Class2 { Class1 c1; }. JDT compiler doesn't need a generated class file to resolve the other. It could keep on building the structures when and needed. For eg: while compiling Class1, it looks at the source code of Class2, gets all the methods and fields and then could resolve it's fields and then go to Class2.
Re: Handle cycle dependencies using JDT [message #732320 is a reply to message #732160] Tue, 04 October 2011 09:55 Go to previous messageGo to next message
Eclipse UserFriend
yes Satyam ... but I think you forgot that Class1 belongs to Proj1 and Class2 to Proj2. It makes the compilation process a bit tricker! Smile

If you are considering it could you please tell me how I could compile both projetcs with a real java/JDT command?

[Updated on: Tue, 04 October 2011 10:16] by Moderator

Re: Handle cycle dependencies using JDT [message #733475 is a reply to message #732320] Tue, 04 October 2011 16:10 Go to previous messageGo to next message
Eclipse UserFriend
In article <j6f2i7$lqd$1@news.eclipse.org>, forums-noreply@eclipse.org
says...
>
> yes Satyam ... but I think you forgot that Class1 belongs to Proj1 and Class2 to Proj2. It makes the compilation process a bit triker! :)
>
> If you are considering it could you please tell me how I could compile both projetcs with a real java/JDT command?

For javac, the trick is simply to set either the -sourcepath option or
the -classpath option so that the compiler can find the *source* for
Class2 class whilst compiling Class1, or vice versa.

Possibly something similar is used by JDT.

Namaste, Bruce
Re: Handle cycle dependencies using JDT [message #754076 is a reply to message #733475] Mon, 31 October 2011 12:36 Go to previous messageGo to next message
Eclipse UserFriend
Hi Bruce,

Thanks for the help and realy sorry for the long delay to reply your post. The only problem doing that is that the source I'm setting to just resolve the compilation erros (sourcepath="${src2}") is also being compiled and copied to bin folder.

<target name="compile" depends="clean">
   <javac destdir="${classes}" failonerror="true" sourcepath="${src2}">
      <src path="${src}" />			
   </javac>
</target>


or ...

<path id="depclasspath">
   <pathelement path="${src2}"/>
</path>

<target name="compile" depends="clean">
   <javac destdir="${classes}" failonerror="true" sourcepathref="depclasspath" verbose="true">
      <src path="${src}" />
   </javac>		
</target>


Do you know how to avoid that?

Namaste,
--
Raphael
Re: Handle cycle dependencies using JDT [message #754515 is a reply to message #754076] Wed, 02 November 2011 16:49 Go to previous messageGo to next message
Eclipse UserFriend
In article <j8mi2n$brl$1@news.eclipse.org>, forums-noreply@eclipse.org
says...

>
>
> Do you know how to avoid that?
>
> Namaste,

Hi Raphael,

Unfortunately that's the way the javac works.

The only suggestion I have is to delete the "extra" class files after
the compilation step.

We avoid the problem by using a layered architecture that limits bi-
directional relationships to a single bundle (jar file).

Namaste, Bruce
Re: Handle cycle dependencies using JDT [message #754581 is a reply to message #754515] Thu, 03 November 2011 07:37 Go to previous message
Eclipse UserFriend
Hi Bruce,

Removing extra classes in my case is not such simple task cause I get the dependencies in runtime form its MANIFEST.MF and than I set these dependencies as source paths in the javac to resolve the compilation issues, so, at the end I don't know which of those compiled classes are extra classes to remove.

Do you get me?

Thanks dude
--
Raphael
Previous Topic:How to distinguish UI / non-UI thread in eclipse development
Next Topic:Saving the Project in the background without closing open dialogs
Goto Forum:
  


Current Time: Wed Jul 02 21:13:38 EDT 2025

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

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

Back to the top