Can't see source of valid source-attached jars
Try the following:
Now if you look into the class files with javap, you'll see they're referencing the correct path to Hello.scala (that is, it's not in any subdirectories).
However, attach hello.jar to some Scala Eclipse project, and source-attach hello-sources.jar, and you'll see that the IDE can't find the source file.
However, if you replace the last command above with:
and source-attach this new hello-sources.jar instead, then Scala Eclipse will be able to display the code fine.
Note that in general, you can't rely on a direct mapping between source file directory placement and (top-level) classes' packages, unlike in Java.
cat > Hello.scala << EOF
package foo.bar
object Hello extends App
EOF
fsc Hello.scala
jar cf hello.jar foo/
jar cf hello-sources.jar Hello.scala
Now if you look into the class files with javap, you'll see they're referencing the correct path to Hello.scala (that is, it's not in any subdirectories).
However, attach hello.jar to some Scala Eclipse project, and source-attach hello-sources.jar, and you'll see that the IDE can't find the source file.
However, if you replace the last command above with:
mkdir -p src/foo/bar/
mv Hello.scala src/foo/bar/
cd src/
jar cf hello-sources.jar foo/
and source-attach this new hello-sources.jar instead, then Scala Eclipse will be able to display the code fine.
Note that in general, you can't rely on a direct mapping between source file directory placement and (top-level) classes' packages, unlike in Java.
Leave a comment
on 2011-07-27 17:38 *
By Yang Zhang
Description changed from Try the following:
cat > H... to Try the following:
on 2011-07-27 19:19 *
By David Bernard
I link the discussion we had about this behavior in the mailing-list
Can't open source files of a source-attached jar
IMO, this is not a bug but an enhancement.
Eclipse assume that source of .class are in the directory layout that map
package, because .class only include the filename and not the relative path
to sourcedirectory, and because it's the java convention, (ScalaIDE reuse as
is this feature). IIRC there is a bug about this into eclipse 'JDT bug
tracker.
Note that I don't test the behavior of package object. ;-)
IMO, this is not a bug but an enhancement.
on 2011-07-27 19:37 *
By Mirco Dotta
David, can you confirm that Eclipse java projects have the same limitation and that this is an Eclipse convention (if that is the case, I'm guessing there might be good reason for not doing it, e.g., performances). If that is the case, I think we should invalidate the ticket and the enhancement request should be filed to the Eclipse folks directly. What do you think?
on 2011-07-27 21:15 *
By David Bernard
Currently :
I'll do the same test as Yank on Java project, to confirm. But From my experience it's more than a convention, it mandatory by eclipse to find source form a .class (I'd got similar issue with play! framework, few month ago ticket on Play! full discussion)
Except if a contributor want to create the Aspect to customize this behavior, you can change the type and close.
- JDT failed to compile *.java if package statement doesn't match folder layout under source folder
- I failed to find the ticket in eclipse's bugzilla about this.
I'll do the same test as Yank on Java project, to confirm. But From my experience it's more than a convention, it mandatory by eclipse to find source form a .class (I'd got similar issue with play! framework, few month ago ticket on Play! full discussion)
Except if a contributor want to create the Aspect to customize this behavior, you can change the type and close.
on 2011-10-06 06:30 *
By Yang Zhang
Really glad to see that this is being pursued!
Just to throw some support behind this, I found at least a couple other duplicates:
http://scala-ide-portfolio.assembla.com/spaces/scala-ide/tickets/1000042--source-not-found--error
http://scala-ide-portfolio.assembla.com/spaces/scala-ide/tickets/1000085-scala-directory-layout-not-supported-in-source-jars
This is a feature that your users are repeatedly expressing interest in, as it does make debugging frustrating. Thanks for pursuing this and looking forward to any updates.
[BTW, I'd be surprised if this were an issue in Eclipse's bugzilla since the Java world expects this directory structure. We (your users) are already willing to adhere to the Java directory structure for our own Scala code for now. The issue is in dealing with third-party jars that we did not author and that do not conform to the package directory structure, of which there are plenty: Akka, Play, Circumflex, ....]
Just to throw some support behind this, I found at least a couple other duplicates:
http://scala-ide-portfolio.assembla.com/spaces/scala-ide/tickets/1000042--source-not-found--error
http://scala-ide-portfolio.assembla.com/spaces/scala-ide/tickets/1000085-scala-directory-layout-not-supported-in-source-jars
This is a feature that your users are repeatedly expressing interest in, as it does make debugging frustrating. Thanks for pursuing this and looking forward to any updates.
[BTW, I'd be surprised if this were an issue in Eclipse's bugzilla since the Java world expects this directory structure. We (your users) are already willing to adhere to the Java directory structure for our own Scala code for now. The issue is in dealing with third-party jars that we did not author and that do not conform to the package directory structure, of which there are plenty: Akka, Play, Circumflex, ....]
on 2012-01-30 17:03 *
By skyluc
Version changed from 2.0.0-beta09-29 to 2.0.0-final-29
Eclipse version changed from Indigo to All
Assigned to changed from Mirco Dotta to -none-
Milestone changed from Helium to Backlog
Permission type changed from None to Public
Status changed from New to Accepted