ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 5268] New: - Should allow execution of javac with no sourcepath set
Date Tue, 04 Dec 2001 16:57:02 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5268>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5268

Should allow execution of javac with no sourcepath set

           Summary: Should allow execution of javac with no sourcepath set
           Product: Ant
           Version: 1.4.1
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Core tasks
        AssignedTo: ant-dev@jakarta.apache.org
        ReportedBy: robert.bune@bigfoot.com


Using javac on the command line it is possible to enforce package dependencies
by compiling the packages in each layer independantly and omiting the sourcepath
so that javac can not resolve any unwanted class references. This is not
possible with Ant as you are forced to include the srcdir attribute or nested
src elements.

For example consider the following two classes. The architecture specifies that
MyClass1 is in application layer 1 and should not reference any classes in layer
2, but MyClass2 is in layer 1 and is permitted to reference layer 1. To help
enforce this layer 1 is compiled first, followed by layer 2.

MyClass1.java
-------------
package my.layer1;
import my.layer2.MyClass2;         // Invalid dependency
public class MyClass1 {
  public MyClass1() {
    MyClass2 c = new MyClass2();
  }
}

MyClass2.java
-------------
package my.layer2;
import my.layer1.MyClass1;         // Valid dependency
public class MyClass2 {
  public MyClass2() {
    MyClass1 c = new MyClass1();
  }
}

build.xml
---------
<project name="Test" basedir="." default="init" >

  <target name="init">
    <echo message="basedir=${basedir}" />
    <echo message="java.home=${java.home}" />
  </target>

  <target name="clean" depends="init">
    <delete dir="classes" />
  </target>

  <target name="compile" depends="clean">
    <mkdir dir="classes" />
    <javac srcdir="src" destdir="classes" includes="my/layer1/**"/>
    <javac srcdir="src" destdir="classes" includes="my/layer2/**"/>
  </target>

  <target name="compile2" depends="clean">
    <mkdir dir="classes" />
    <exec dir="src" executable="javac">
      <arg line="-classpath classes my/layer1/MyClass1.java"/>
    </exec>
    <exec dir="src" executable="javac">
      <arg line="-classpath classes my/layer2/MyClass2.java"/>
    </exec>
  </target>
  
</project>

Executing the compile target completes without error, and actually compiles
class MyClass2 as part of the first javac task. If instead you execute compile2
the build will fail on the first exec task when attempting to compile the import
statement in MyClass1.

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message