Bug 133848

Summary: -sourcepath should also be supported for jars and zip files
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: maxime_daniel, philippe_mulet
Version: 3.2   
Target Milestone: 3.2 RC1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix
none
New patch
none
Regression tests updated none

Description Olivier Thomann CLA 2006-03-29 09:58:11 EST
-sourcepath support is ok for directory, but it doesn't seem to work for jar or zip files.
Comment 1 Olivier Thomann CLA 2006-03-29 09:58:56 EST
In org.eclipse.jdt.internal.compiler.batch.ClasspathJar, we are only looking for .class files. Never for source files.
org.eclipse.jdt.internal.compiler.batch.ClasspathDirectory is correctly checking source files and class files.
Comment 2 Olivier Thomann CLA 2006-03-29 10:05:32 EST
-sourcepath sourcepath
    Specify the source code path to search for class or interface definitions. As with the user class path, source path entries are separated by semicolons (;) and can be directories, JAR archives, or ZIP archives. If packages are used, the local path name within the directory or archive must reflect the package name.

    Note:   Classes found through the classpath are subject to automatic recompilation if their sources are found. 
Comment 3 Olivier Thomann CLA 2006-04-04 16:23:59 EDT
Created attachment 37664 [details]
Proposed fix

To verify, try to compile the following code:
public class X extends p.Bar {
}

where p.Bar is located within a zip or a jar file and you run the batch using:

D:/tests_sources/X.java 
-d d:\tests_sources
-classpath d:\tests_sources
-sourcepath d:\tests_sources\lib.zip
-time
-g
-1.5
-preserveAllLocals
Comment 4 Olivier Thomann CLA 2006-04-04 16:27:48 EDT
Maxime and Philippe,

Let me know if you believe that this should be fixed. The attached patch works well and in fact javac 1.5 doesn't handle this case well and javac 6.0 fails to create p.Bar in the right folder. It creates a folder called "lib.zip(p" in which it puts Bar.class. So at runtime, the class p.Bar is not found.
Comment 5 Maxime Daniel CLA 2006-04-05 04:13:16 EDT
javac 1.5 compiles referenced types in place. If you use the following setup:
src/Used.java
User.java
public class User {
  Used m;
}

and do javac -sourcepath src User.java, you get the following new files:
src/Used.class
User.class

I believe that this would call for a clarification of the use of the -sourcepath option if it were to accept archives (notwithstanding its interaction with other options).
Comment 6 Olivier Thomann CLA 2006-04-05 09:40:33 EDT
Fixing this would make -sourcepath compatible with what javac supports (in theory).

-sourcepath sourcepath
    Specify the source code path to search for class or interface definitions. As with the user class path, source path entries are separated by semicolons (;) and can be directories, JAR archives, or ZIP archives. If packages are used, the local path name within the directory or archive must reflect the package name.

    Note that classes found through the classpath are subject to automatic recompilation if their sources are found.

It could be convenient to compile using a zip that contains the source code. Might be slower though.
Comment 7 Olivier Thomann CLA 2006-04-05 22:10:59 EDT
Philippe,

Do you want this to be fixed?
Technically we are ok with the description in the print usage of the batch compiler, but this is not equivalent to the same option for javac. So to have a better compatibility between the two compilers, it could be a plus.

If we don't fix it, we might verify that elements on the -sourcepath option are directories and reject jar/zip files.
Comment 8 Olivier Thomann CLA 2006-04-11 14:52:40 EDT
Maxime,

Could you please review the patch?
Comment 9 Philipe Mulet CLA 2006-04-11 15:38:45 EDT
+1 for 3.2RC1
Comment 10 Olivier Thomann CLA 2006-04-11 23:26:17 EDT
Created attachment 38355 [details]
New patch

Maxime,

This new patch defines a subclass of ClasspathJar called ClasspathSourceJar to handle the case of the -sourcepath.
I also updated the print usage.
All generated files are put in the output folder. This makes a more consistent behavior.
I will release if all tests passed.
Comment 11 Olivier Thomann CLA 2006-04-11 23:29:48 EDT
Created attachment 38356 [details]
Regression tests updated

Updated BatchCompilerTests
Comment 12 Olivier Thomann CLA 2006-04-12 00:09:09 EDT
Fixed and released in HEAD.
Comment 13 Maxime Daniel CLA 2006-04-12 02:59:51 EDT
(In reply to comment #8)
> Maxime,
> 
> Could you please review the patch?
> 
I think I would have a couple of questions. Would you sametime me this afternoon?
Comment 14 David Audel CLA 2006-04-13 11:05:13 EDT
Verified for 3.2 RC1 using build I20060413-0010