This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 85707 - compile-single using <depend> can delete *.class files it will not recompile
Summary: compile-single using <depend> can delete *.class files it will not recompile
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Project (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Jesse Glick
URL:
Keywords:
Depends on: 115918 116230 221116
Blocks: 36033 50111
  Show dependency tree
 
Reported: 2006-09-25 18:29 UTC by dkkopp
Modified: 2012-11-05 18:22 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dkkopp 2006-09-25 18:29:48 UTC
I am using NetBeans 6.0 m3. When I try to compile a single file, the deps-jar 
task does a dependency check and deletes other class files for classes that 
depend on the one I am compiling. However, the compile-single action only 
compiles the file I am on. Therefore, compile-single is useless. Based on a 
discussion on the nbusers mailing list, I would like to suggest two possible 
courses of action.

       a) Allow for deleting the out of date class files to be turned off 
       b) Compile the deleted class files from their java source again 

As it is right now, my fellow developers want to revert back to NetBeans 5.0, 
even though it does not have Subversion support.
Comment 1 Jesse Glick 2006-09-25 19:43:23 UTC
Wrong component. Please use 'ide' if unsure which component to file a bug report in.
Comment 2 Jesse Glick 2006-09-25 19:56:23 UTC
(a) is a workaround requiring GUI changes, which is not really acceptable. (b)
is not a good idea either, since one of the primary use cases for compile-single
to begin with is to permit the user to compile only certain classes or packages
and leave others completely untouched. So I would rather suggest

(c) Modify the -do-compile-single and -do-compile-test-single targets to always
recompile the selected file(s), regardless of any existing .class files, and not
call <depend>.

Right now I am not sure what build-impl.xsl modification to suggest; would like
to retain <depend> in -init-macrodef-javac, but Ant's <macrodef> and
<sequential> are too weak to permit a subtask to be conditionally run. Could
perhaps pass a bogus destdir to <depend>, making it a no-op, but this is rather
ugly. Also need to use <pathconvert> or the like to forcibly remove the target
.class file corresponding to the source, since <javac> cannot be forced to
recompile a source for which the .class file exists.

Workaround for current builds is trivial: edit build.xml to override
-init-macrodef-javac to be the same but not include <depend>. Or, override
-do-compile-{,test-}single to call <javac> rather than <j2seproject3:javac> and
insert appropriate attributes instead.
Comment 3 dkkopp 2006-09-26 12:51:16 UTC
The depend clause of init-macrodef-javac will only work properly if the user 
is doing a project build. Even then, it may not work "correctly" because of 
the issue of public static final primitive fields, as described in the Ant 
documentation. It is completely useless if the user is doing a clean/build 
cycle, and is positively harmful if they are doing a compile-single.

It appears that the solution to this would require for the depends task to be 
modified to pass back to Ant a list of all of the files it impacted.
Comment 4 Jesse Glick 2006-09-26 23:50:17 UTC
Re. compile-time constants (primitives or String's) - yes, these can break any
classfile-based dependency tracker, but in practice changes to the values of, or
removals of, existing constants are relatively uncommon compared to other kinds
of code edits. (Creators of public APIs should be especially wary of such
changes because they can have unexpected effects on unrecompiled binary client
code.) When in doubt do a clean build.

Re. clean-build cycle - useless but (AFAIK) harmless.

Re. modifying <depend> task - not going to happen.

I reiterate that the best approach would probably be to skip using <depend> at
all for the -single targets. The question remains how best to express this in
build-impl.xml. Perhaps use the original macrodef to mean just javac but add a
new macrodef to mean javac plus depend; should be compatible for 5.x users with
modified build.xml's.
Comment 5 Jesse Glick 2006-09-26 23:50:43 UTC
Make sure this is not forgotten...
Comment 6 dkkopp 2006-09-27 12:42:17 UTC
Jesse, I agree with your suggested fix. I think that would work really well.
Comment 7 Tomas Zezula 2006-09-27 13:15:31 UTC
I am going to fix it as Jesse sugested (adding new macrodefs with depend).
Comment 8 Jesse Glick 2007-03-23 00:47:19 UTC
I can take this one.
Comment 9 Jesse Glick 2007-03-23 01:33:57 UTC
Note that there is a subtle danger. If you have class A, and class B depends on
A, and you F11; then make an incompatible change in class A and press F9 on it;
then press F11 - you will quietly get a JAR file with an unloadable version of
B.class: B is not recompiled. It seems that <depend> really expects to be used
each time you compile. I guess the upshot is: if you want dependency tracking,
use only F11, never F9.
Comment 10 Jesse Glick 2007-03-23 01:52:27 UTC
Looks like I also need to change run-single (and debug-single) to depend on
compile, not compile-single. Else they will recompile the selected file
needlessly. Anyway consistent with recent change of test-single to depend on
compile-test rather than compile-test-single (issue #97053). The main argument
for run-single -> compile-single is anyway mostly obsoleted by issue #49026.
Comment 11 Jesse Glick 2007-03-23 02:10:11 UTC
Checking in test/unit/src/org/netbeans/modules/java/j2seproject/BuildImplTest.java;
/shared/data/ccvs/repository/java/j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/BuildImplTest.java,v
 <--  BuildImplTest.java
new revision: 1.10; previous revision: 1.9
done
Checking in src/org/netbeans/modules/java/j2seproject/resources/build-impl.xsl;
/shared/data/ccvs/repository/java/j2seproject/src/org/netbeans/modules/java/j2seproject/resources/build-impl.xsl,v
 <--  build-impl.xsl
new revision: 1.87; previous revision: 1.86
done