View | Details | Raw Unified | Return to bug 20699
Collapse All | Expand All

(-)ant/docs/manual/CoreTasks/rmic.html (-1 / +46 lines)
Lines 60-67 Link Here
60
  </tr>
60
  </tr>
61
  <tr>
61
  <tr>
62
    <td valign="top">base</td>
62
    <td valign="top">base</td>
63
    <td valign="top">the location to store the compiled files.
64
      Also serves as the parent directory for any non-Fileset includes, etc.
65
      (This functionality has remained unchanged.)</td>
66
    <td valign="top" align="center" rowspan="2">*1</td>
67
  </tr>
68
  <tr>
69
    <td valign="top">destdir</td>
63
    <td valign="top">the location to store the compiled files.</td>
70
    <td valign="top">the location to store the compiled files.</td>
64
    <td valign="top" align="center">Yes</td>
65
  </tr>
71
  </tr>
66
  <tr>
72
  <tr>
67
    <td valign="top">classname</td>
73
    <td valign="top">classname</td>
Lines 173-178 Link Here
173
    <td align="center" valign="top">No</td>
179
    <td align="center" valign="top">No</td>
174
  </tr>
180
  </tr>
175
  <tr>
181
  <tr>
182
   <td valign="top">sourcesOnClasspath</td> 
183
   <td valign="top">whether source folders are automatically included in the
184
     compile classpath; defaults to <code>yes</code>.</td>
185
   <td align="center" valign="top">No</td>
186
 </tr>
187
  <tr>
176
    <td valign="top">extdirs</td>
188
    <td valign="top">extdirs</td>
177
    <td valign="top">location of installed extensions.</td>
189
    <td valign="top">location of installed extensions.</td>
178
    <td align="center" valign="top">No</td>
190
    <td align="center" valign="top">No</td>
Lines 188-194 Link Here
188
    <td align="center" valign="top">No</td>
200
    <td align="center" valign="top">No</td>
189
  </tr>
201
  </tr>
190
</table>
202
</table>
203
204
<p>*1:<ul>
205
<li>Maintaining compatibility, <code>base</code>, when specified by itself, serves
206
as both the parent directory for any source files AND the output directory.</li>
207
<li><code>destdir</code> can be used to specify the output directory, allowing for
208
<code>base</code> to be used as the parent directory for any source files.</li>
209
<li>At least one of either <code>base</code> or <code>destdir</code> must be
210
specified and exist, or a execute-time error will occur.</li>
211
</ul></p>
212
191
<h3>Parameters specified as nested elements</h3>
213
<h3>Parameters specified as nested elements</h3>
214
215
<h4>fileset</h4>
216
<p>The rmic task supports any number of nested <a
217
href="../CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a> elements to specify
218
the files to be rmic'd.  Generated files will be saved to <code>destdir</code> if
219
specified, or it will attempt to default to <code>base</code>.  (<code>base</code>
220
does not serve as a parent directory to any <code>fileset</code> elements.)</p>
221
192
<h4>classpath and extdirs</h4>
222
<h4>classpath and extdirs</h4>
193
<p><code>Rmic</code>'s <i>classpath</i> and <i>extdirs</i> attributes are <a
223
<p><code>Rmic</code>'s <i>classpath</i> and <i>extdirs</i> attributes are <a
194
href="../using.html#path">PATH like structure</a> and can also be set via a nested
224
href="../using.html#path">PATH like structure</a> and can also be set via a nested
Lines 235-249 Link Here
235
</table>
265
</table>
236
266
237
<h3>Examples</h3>
267
<h3>Examples</h3>
268
238
<pre>  &lt;rmic classname=&quot;com.xyz.FooBar&quot; base=&quot;${build}/classes&quot;/&gt;</pre>
269
<pre>  &lt;rmic classname=&quot;com.xyz.FooBar&quot; base=&quot;${build}/classes&quot;/&gt;</pre>
239
<p>runs the rmic compiler for the class <code>com.xyz.FooBar</code>. The
270
<p>runs the rmic compiler for the class <code>com.xyz.FooBar</code>. The
240
compiled files will be stored in the directory <code>${build}/classes</code>.</p>
271
compiled files will be stored in the directory <code>${build}/classes</code>.</p>
272
241
<pre>  &lt;rmic base=&quot;${build}/classes&quot; includes=&quot;**/Remote*.class&quot;/&gt;</pre>
273
<pre>  &lt;rmic base=&quot;${build}/classes&quot; includes=&quot;**/Remote*.class&quot;/&gt;</pre>
242
<p>runs the rmic compiler for all classes with <code>.class</code>
274
<p>runs the rmic compiler for all classes with <code>.class</code>
243
files below <code>${build}/classes</code> whose classname starts with
275
files below <code>${build}/classes</code> whose classname starts with
244
<i>Remote</i>. The compiled files will be stored in the directory
276
<i>Remote</i>. The compiled files will be stored in the directory
245
<code>${build}/classes</code>.</p>
277
<code>${build}/classes</code>.</p>
246
278
279
<pre>  &lt;rmic destdir="bin/Client" includeAntRuntime="false" verify="true"&gt;
280
    &lt;fileset dir="bin/Server"&gt;
281
      &lt;include name="**/*.class"/&gt;
282
    &lt;/fileset&gt;
283
    &lt;classpath&gt;
284
      &lt;pathelement path="bin/Common"/&gt;
285
    &lt;/classpath&gt;
286
  &lt;/rmic&gt;</pre>
287
<p>runs the rmic compiler for all classes below <code>bin/Common</code> and are
288
verified to extend java.rmi.remote.  The generated files will be stored in the
289
directory <code>bin/Client</code>.  The classpath used by rmic will contain <code>
290
bin/Common</code> and <code>bin/Server</code>.
291
247
<hr>
292
<hr>
248
<p align="center">Copyright &copy; 2000-2005 The Apache Software Foundation. All rights
293
<p align="center">Copyright &copy; 2000-2005 The Apache Software Foundation. All rights
249
Reserved.</p>
294
Reserved.</p>
(-)ant/src/main/org/apache/tools/ant/taskdefs/Rmic.java (-52 / +155 lines)
Lines 20-31 Link Here
20
import java.io.File;
20
import java.io.File;
21
import java.io.IOException;
21
import java.io.IOException;
22
import java.rmi.Remote;
22
import java.rmi.Remote;
23
import java.util.Iterator;
23
import java.util.Vector;
24
import java.util.Vector;
24
import org.apache.tools.ant.BuildException;
25
import org.apache.tools.ant.BuildException;
25
import org.apache.tools.ant.DirectoryScanner;
26
import org.apache.tools.ant.DirectoryScanner;
26
import org.apache.tools.ant.Project;
27
import org.apache.tools.ant.Project;
27
import org.apache.tools.ant.taskdefs.rmic.RmicAdapter;
28
import org.apache.tools.ant.taskdefs.rmic.RmicAdapter;
28
import org.apache.tools.ant.taskdefs.rmic.RmicAdapterFactory;
29
import org.apache.tools.ant.taskdefs.rmic.RmicAdapterFactory;
30
import org.apache.tools.ant.types.FileSet;
29
import org.apache.tools.ant.types.FilterSetCollection;
31
import org.apache.tools.ant.types.FilterSetCollection;
30
import org.apache.tools.ant.types.Path;
32
import org.apache.tools.ant.types.Path;
31
import org.apache.tools.ant.types.Reference;
33
import org.apache.tools.ant.types.Reference;
Lines 84-89 Link Here
84
        = "Rmic failed; see the compiler error output for details.";
86
        = "Rmic failed; see the compiler error output for details.";
85
87
86
    private File baseDir;
88
    private File baseDir;
89
    private File destDir;
90
    private Vector filesets = new Vector();
91
87
    private String classname;
92
    private String classname;
88
    private File sourceBase;
93
    private File sourceBase;
89
    private String stubVersion;
94
    private String stubVersion;
Lines 99-104 Link Here
99
    private boolean debug  = false;
104
    private boolean debug  = false;
100
    private boolean includeAntRuntime = true;
105
    private boolean includeAntRuntime = true;
101
    private boolean includeJavaRuntime = false;
106
    private boolean includeJavaRuntime = false;
107
    private boolean sourcesOnClasspath = true;
102
108
103
    private Vector compileList = new Vector();
109
    private Vector compileList = new Vector();
104
110
Lines 114-124 Link Here
114
    /** loaded error message */
120
    /** loaded error message */
115
    public static final String ERROR_LOADING_CAUSED_EXCEPTION = ". Loading caused Exception: ";
121
    public static final String ERROR_LOADING_CAUSED_EXCEPTION = ". Loading caused Exception: ";
116
    /** base not exists message */
122
    /** base not exists message */
117
    public static final String ERROR_NO_BASE_EXISTS = "base does not exist: ";
123
    public static final String ERROR_NO_BASE_EXISTS = "base or destdir does not exist: ";
118
    /** base not a directory message */
124
    /** base not a directory message */
119
    public static final String ERROR_NOT_A_DIR = "base is not a directory:";
125
    public static final String ERROR_NOT_A_DIR = "base or destdir is not a directory:";
120
    /** base attribute not set message */
126
    /** base attribute not set message */
121
    public static final String ERROR_BASE_NOT_SET = "base attribute must be set!";
127
    public static final String ERROR_BASE_NOT_SET = "base or destdir attribute must be set!";
122
128
123
    private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
129
    private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
124
130
Lines 147-152 Link Here
147
    }
153
    }
148
154
149
    /**
155
    /**
156
     * Sets the base directory to output the generated files.
157
     * @param destdir the base directory to output the generated files.
158
     */
159
    public void setDestdir(File destdir) {
160
        this.destDir = destdir;
161
    }
162
163
    /**
164
     * Gets the base directory to output the generated files.
165
     * @return the base directory to output the generated files.
166
     */
167
    public File getDestdir() {
168
        return this.destDir;
169
    }
170
171
    /**
172
     * Gets the base directory to output the generated files,
173
     * favoring destdir if set, otherwise defaulting to basedir.
174
     * @return the actual directory to output to (either destdir or basedir)
175
     */
176
    public File getOutputDir() {
177
        if (getDestdir() != null) {
178
            return getDestdir();
179
        }
180
        return getBase();
181
    }
182
183
    /**
184
     * Adds a set of files to generate stubs for.
185
     * @param set The FileSet to add.
186
     */
187
    public void addFileset(FileSet set) {
188
        filesets.addElement(set);
189
    }
190
191
    /**
150
     * Sets the class to run <code>rmic</code> against;
192
     * Sets the class to run <code>rmic</code> against;
151
     * optional
193
     * optional
152
     * @param classname the name of the class for rmic to create code for
194
     * @param classname the name of the class for rmic to create code for
Lines 405-410 Link Here
405
    }
447
    }
406
448
407
    /**
449
    /**
450
     * Sets whether source folders are automatically included in the compile
451
     * classpath; optional, defaults to true
452
     * @param include true to include source folders
453
     */
454
    public void setSourcesOnClasspath(boolean include) {
455
        sourcesOnClasspath = include;
456
    }
457
458
    /**
459
     * Gets whether source folders are automatically included in the compile
460
     * classpath
461
     * @return true if source folders are automatically included
462
     */
463
    public boolean getSourcesOnClasspath() {
464
        return sourcesOnClasspath;
465
    }
466
467
    /**
408
     * Sets the extension directories that will be used during the
468
     * Sets the extension directories that will be used during the
409
     * compilation; optional.
469
     * compilation; optional.
410
     * @param extDirs the extension directories to be used
470
     * @param extDirs the extension directories to be used
Lines 496-514 Link Here
496
     * if there's a problem with baseDir or RMIC
556
     * if there's a problem with baseDir or RMIC
497
     */
557
     */
498
    public void execute() throws BuildException {
558
    public void execute() throws BuildException {
499
        if (baseDir == null) {
559
        if (compileList.size() > 0) {
560
            compileList.removeAllElements();
561
        }
562
563
        File outputDir = getOutputDir();
564
        if (outputDir == null) {
500
            throw new BuildException(ERROR_BASE_NOT_SET, getLocation());
565
            throw new BuildException(ERROR_BASE_NOT_SET, getLocation());
501
        }
566
        }
502
        if (!baseDir.exists()) {
567
        if (!outputDir.exists()) {
503
            throw new BuildException(ERROR_NO_BASE_EXISTS + baseDir, getLocation());
568
            throw new BuildException(ERROR_NO_BASE_EXISTS + outputDir, getLocation());
504
        }
569
        }
505
        if (!baseDir.isDirectory()) {
570
        if (!outputDir.isDirectory()) {
506
            throw new BuildException(ERROR_NOT_A_DIR + baseDir, getLocation());
571
            throw new BuildException(ERROR_NOT_A_DIR + outputDir, getLocation());
507
        }
572
        }
508
        if (verify) {
573
        if (verify) {
509
            log("Verify has been turned on.", Project.MSG_VERBOSE);
574
            log("Verify has been turned on.", Project.MSG_VERBOSE);
510
        }
575
        }
511
576
577
        if (getBase() != null) {
578
            FileSet implicitFs = getImplicitFileSet();
579
            implicitFs.setDir(getBase());
580
            filesets.add(implicitFs);
581
        }
582
583
        // Must be performed before the loader's classpath is set so any
584
        // classpaths can be used by isValidRmiRemote() (which occurs deep
585
        // within populateFilesToProcess(...).
586
        processSourcesOnClasspath();
587
512
        RmicAdapter adapter = RmicAdapterFactory.getRmic(getCompiler(), this);
588
        RmicAdapter adapter = RmicAdapterFactory.getRmic(getCompiler(), this);
513
589
514
        // now we need to populate the compiler adapter
590
        // now we need to populate the compiler adapter
Lines 517-572 Link Here
517
        Path classpath = adapter.getClasspath();
593
        Path classpath = adapter.getClasspath();
518
        loader = getProject().createClassLoader(classpath);
594
        loader = getProject().createClassLoader(classpath);
519
595
520
        try {
596
        populateFilesToProcess(adapter.getMapper());
597
598
        int fileCount = compileList.size();
599
        if (fileCount > 0) {
600
            log("RMI Compiling " + fileCount
601
            + " class" + (fileCount > 1 ? "es" : "") + " to " + outputDir,
602
                Project.MSG_INFO);
603
604
            // finally, lets execute the compiler!!
605
            if (!adapter.execute()) {
606
                throw new BuildException(ERROR_RMIC_FAILED, getLocation());
607
            }
608
        }
609
610
        /*
611
         * Move the generated source file to the base directory.  If
612
         * base directory and sourcebase are the same, the generated
613
         * sources are already in place.
614
         */
615
        if (null != sourceBase && !outputDir.equals(sourceBase)
616
            && fileCount > 0) {
617
            if (idl) {
618
                log("Cannot determine sourcefiles in idl mode, ",
619
                    Project.MSG_WARN);
620
                log("sourcebase attribute will be ignored.",
621
                    Project.MSG_WARN);
622
            } else {
623
                for (int j = 0; j < fileCount; j++) {
624
                moveGeneratedFile(outputDir, sourceBase,
625
                                      (String) compileList.elementAt(j),
626
                                      adapter);
627
                }
628
            }
629
        }
630
    }
631
632
    /**
633
     * Adds any source folders to the compile classpath.
634
     */
635
    protected void processSourcesOnClasspath() {
636
        // Moved from DefaultRmicAdapter, so that multiple
637
        // locations can be added.
638
        if (compileClasspath == null) {
639
            compileClasspath = new Path(getProject());
640
        }
641
642
        if (getSourcesOnClasspath()) {
643
            for (Iterator iter = filesets.iterator(); iter.hasNext();) {
644
                FileSet fs = (FileSet) iter.next();
645
                File fsBaseDir = fs.getDir(getProject());
646
                compileClasspath.setLocation(fsBaseDir);
647
            }
648
        }
649
    }
650
651
    /**
652
     * Sets the list of files to rmic, retrieved from all the filesets.
653
     * @param mapper FileNameMapper used to resolve files.
654
     */
655
    protected void populateFilesToProcess (FileNameMapper mapper) {
656
        for (Iterator iter = filesets.iterator(); iter.hasNext();) {
657
            FileSet fs = (FileSet) iter.next();
658
            File fsBaseDir = fs.getDir(getProject());
659
            String[] files;
660
521
            // scan base dirs to build up compile lists only if a
661
            // scan base dirs to build up compile lists only if a
522
            // specific classname is not given
662
            // specific classname is not given
523
            if (classname == null) {
663
            if (classname == null) {
524
                DirectoryScanner ds = this.getDirectoryScanner(baseDir);
664
                DirectoryScanner ds = fs.getDirectoryScanner(getProject());
525
                String[] files = ds.getIncludedFiles();
665
                files = ds.getIncludedFiles();
526
                scanDir(baseDir, files, adapter.getMapper());
527
            } else {
666
            } else {
528
                // otherwise perform a timestamp comparison - at least
667
                // otherwise perform a timestamp comparison - at least
529
                scanDir(baseDir,
668
                files =  new String[] {classname.replace('.',
530
                        new String[] {classname.replace('.',
669
                            File.separatorChar) + ".class"};
531
                                                        File.separatorChar)
532
                                          + ".class"},
533
                        adapter.getMapper());
534
            }
670
            }
535
671
536
            int fileCount = compileList.size();
672
            scanDir(fsBaseDir, files, mapper);
537
            if (fileCount > 0) {
538
                log("RMI Compiling " + fileCount
539
                    + " class" + (fileCount > 1 ? "es" : "") + " to " + baseDir,
540
                    Project.MSG_INFO);
541
542
                // finally, lets execute the compiler!!
543
                if (!adapter.execute()) {
544
                    throw new BuildException(ERROR_RMIC_FAILED, getLocation());
545
                }
546
            }
547
548
            /*
549
             * Move the generated source file to the base directory.  If
550
             * base directory and sourcebase are the same, the generated
551
             * sources are already in place.
552
             */
553
            if (null != sourceBase && !baseDir.equals(sourceBase)
554
                && fileCount > 0) {
555
                if (idl) {
556
                    log("Cannot determine sourcefiles in idl mode, ",
557
                        Project.MSG_WARN);
558
                    log("sourcebase attribute will be ignored.",
559
                        Project.MSG_WARN);
560
                } else {
561
                    for (int j = 0; j < fileCount; j++) {
562
                        moveGeneratedFile(baseDir, sourceBase,
563
                                          (String) compileList.elementAt(j),
564
                                          adapter);
565
                    }
566
                }
567
            }
568
        } finally {
569
            compileList.removeAllElements();
570
        }
673
        }
571
    }
674
    }
572
675
Lines 642-648 Link Here
642
                Project.MSG_VERBOSE);
745
                Project.MSG_VERBOSE);
643
        } else {
746
        } else {
644
            SourceFileScanner sfs = new SourceFileScanner(this);
747
            SourceFileScanner sfs = new SourceFileScanner(this);
645
            newFiles = sfs.restrict(files, baseDir, baseDir, mapper);
748
            newFiles = sfs.restrict(files, baseDir, getDestdir(), mapper);
646
        }
749
        }
647
750
648
        for (int i = 0; i < newFiles.length; i++) {
751
        for (int i = 0; i < newFiles.length; i++) {
(-)ant/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java (-4 / +1 lines)
Lines 130-138 Link Here
130
     */
130
     */
131
    protected Path getCompileClasspath() {
131
    protected Path getCompileClasspath() {
132
        Path classpath = new Path(attributes.getProject());
132
        Path classpath = new Path(attributes.getProject());
133
        // add dest dir to classpath so that previously compiled and
134
        // untouched classes are on classpath
135
        classpath.setLocation(attributes.getBase());
136
133
137
        // Combine the build classpath with the system classpath, in an
134
        // Combine the build classpath with the system classpath, in an
138
        // order determined by the value of build.sysclasspath
135
        // order determined by the value of build.sysclasspath
Lines 179-185 Link Here
179
        Path classpath = getCompileClasspath();
176
        Path classpath = getCompileClasspath();
180
177
181
        cmd.createArgument().setValue("-d");
178
        cmd.createArgument().setValue("-d");
182
        cmd.createArgument().setFile(attributes.getBase());
179
        cmd.createArgument().setFile(attributes.getOutputDir());
183
180
184
        if (attributes.getExtdirs() != null) {
181
        if (attributes.getExtdirs() != null) {
185
            cmd.createArgument().setValue("-extdirs");
182
            cmd.createArgument().setValue("-extdirs");

Return to bug 20699