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

(-)apache-ant-1.6.5/docs/manual/CoreTasks/rmic.html (-1 / +45 lines)
Lines 53-60 Link Here
53
  </tr>
53
  </tr>
54
  <tr>
54
  <tr>
55
    <td valign="top">base</td>
55
    <td valign="top">base</td>
56
    <td valign="top">the location to store the compiled files.
57
        Also serves as the parent directory for any non-Fileset includes, etc.
58
        (This functionality has remained unchanged.)</td>
59
    <td valign="top" align="center" rowspan="2">*1</td>
60
  </tr>
61
  <tr>
62
    <td valign="top">destdir</td>
56
    <td valign="top">the location to store the compiled files.</td>
63
    <td valign="top">the location to store the compiled files.</td>
57
    <td valign="top" align="center">Yes</td>
58
  </tr>
64
  </tr>
59
  <tr>
65
  <tr>
60
    <td valign="top">classname</td>
66
    <td valign="top">classname</td>
Lines 163-168 Link Here
163
    <td align="center" valign="top">No</td>
169
    <td align="center" valign="top">No</td>
164
  </tr>
170
  </tr>
165
  <tr>
171
  <tr>
172
    <td valign="top">sourcesOnClasspath</td> 
173
    <td valign="top">whether source folders are automatically included in the
174
        compile classpath; defaults to <code>yes</code>.</td>
175
    <td align="center" valign="top">No</td>
176
  </tr>
177
  <tr>
166
    <td valign="top">extdirs</td>
178
    <td valign="top">extdirs</td>
167
    <td valign="top">location of installed extensions.</td>
179
    <td valign="top">location of installed extensions.</td>
168
    <td align="center" valign="top">No</td>
180
    <td align="center" valign="top">No</td>
Lines 178-184 Link Here
178
    <td align="center" valign="top">No</td>
190
    <td align="center" valign="top">No</td>
179
  </tr>
191
  </tr>
180
</table>
192
</table>
193
194
<p>*1:<ul>
195
<li>Maintaining compatibility, <code>base</code>, when specified by itself, serves
196
as both the parent directory for any source files AND the output directory.</li>
197
<li><code>destdir</code> can be used to specify the output directory, allowing for
198
<code>base</code> to be used as the parent directory for any source files.</li>
199
<li>At least one of either <code>base</code> or <code>destdir</code> must be
200
specified and exist, or a execute-time error will occur.</li>
201
</ul></p>
202
181
<h3>Parameters specified as nested elements</h3>
203
<h3>Parameters specified as nested elements</h3>
204
205
<h4>fileset</h4>
206
<p>The rmic task supports any number of nested <a
207
href="../CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a> elements to specify
208
the files to be rmic'd.  Generated files will be saved to <code>destdir</code> if
209
specified, or it will attempt to default to <code>base</code>.  (<code>base</code>
210
does not serve as a parent directory to any <code>fileset</code> elements.)</p>
211
182
<h4>classpath and extdirs</h4>
212
<h4>classpath and extdirs</h4>
183
<p><code>Rmic</code>'s <i>classpath</i> and <i>extdirs</i> attributes are <a
213
<p><code>Rmic</code>'s <i>classpath</i> and <i>extdirs</i> attributes are <a
184
href="../using.html#path">PATH like structure</a> and can also be set via a nested
214
href="../using.html#path">PATH like structure</a> and can also be set via a nested
Lines 225-239 Link Here
225
</table>
255
</table>
226
256
227
<h3>Examples</h3>
257
<h3>Examples</h3>
258
228
<pre>  &lt;rmic classname=&quot;com.xyz.FooBar&quot; base=&quot;${build}/classes&quot;/&gt;</pre>
259
<pre>  &lt;rmic classname=&quot;com.xyz.FooBar&quot; base=&quot;${build}/classes&quot;/&gt;</pre>
229
<p>runs the rmic compiler for the class <code>com.xyz.FooBar</code>. The
260
<p>runs the rmic compiler for the class <code>com.xyz.FooBar</code>. The
230
compiled files will be stored in the directory <code>${build}/classes</code>.</p>
261
compiled files will be stored in the directory <code>${build}/classes</code>.</p>
262
231
<pre>  &lt;rmic base=&quot;${build}/classes&quot; includes=&quot;**/Remote*.class&quot;/&gt;</pre>
263
<pre>  &lt;rmic base=&quot;${build}/classes&quot; includes=&quot;**/Remote*.class&quot;/&gt;</pre>
232
<p>runs the rmic compiler for all classes with <code>.class</code>
264
<p>runs the rmic compiler for all classes with <code>.class</code>
233
files below <code>${build}/classes</code> whose classname starts with
265
files below <code>${build}/classes</code> whose classname starts with
234
<i>Remote</i>. The compiled files will be stored in the directory
266
<i>Remote</i>. The compiled files will be stored in the directory
235
<code>${build}/classes</code>.</p>
267
<code>${build}/classes</code>.</p>
236
268
269
<pre>  &lt;rmic destdir="bin/Client" includeAntRuntime="false" verify="true"&gt;
270
    &lt;fileset dir="bin/Server"&gt;
271
      &lt;include name="**/*.class"/&gt;
272
    &lt;/fileset&gt;
273
    &lt;classpath&gt;
274
      &lt;pathelement path="bin/Common"/&gt;
275
    &lt;/classpath&gt;
276
  &lt;/rmic&gt;</pre>
277
<p>runs the rmic compiler for all classes below <code>bin/Common</code> and are
278
verified to extend java.rmi.remote.  The generated files will be stored in the
279
directory <code>bin/Client</code>.  The classpath used by rmic will contain <code>
280
bin/Common</code> and <code>bin/Server</code>.
237
<hr>
281
<hr>
238
<p align="center">Copyright &copy; 2000-2004 The Apache Software Foundation. All rights
282
<p align="center">Copyright &copy; 2000-2004 The Apache Software Foundation. All rights
239
Reserved.</p>
283
Reserved.</p>
(-)apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/Rmic.java (-26 / +117 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 83-88 Link Here
83
        = "Rmic failed; see the compiler error output for details.";
85
        = "Rmic failed; see the compiler error output for details.";
84
86
85
    private File baseDir;
87
    private File baseDir;
88
    private File destDir;
89
    private Vector filesets = new Vector();
90
    
86
    private String classname;
91
    private String classname;
87
    private File sourceBase;
92
    private File sourceBase;
88
    private String stubVersion;
93
    private String stubVersion;
Lines 98-103 Link Here
98
    private boolean debug  = false;
103
    private boolean debug  = false;
99
    private boolean includeAntRuntime = true;
104
    private boolean includeAntRuntime = true;
100
    private boolean includeJavaRuntime = false;
105
    private boolean includeJavaRuntime = false;
106
    private boolean sourcesOnClasspath = true;
101
107
102
    private Vector compileList = new Vector();
108
    private Vector compileList = new Vector();
103
109
Lines 137-142 Link Here
137
    }
143
    }
138
144
139
    /**
145
    /**
146
     * Sets the base directory to output the generated files.
147
     * @param destdir the base directory to output the generated files.
148
     */
149
    public void setDestdir(File destdir) {
150
        this.destDir = destdir;
151
    }
152
153
    /**
154
     * Gets the base directory to output the generated files.
155
     * @return the base directory to output the generated files.
156
     */
157
    public File getDestdir() {
158
        return this.destDir;
159
    }
160
    
161
    /**
162
     * Gets the base directory to output the generated files,
163
     * favoring destdir if set, otherwise defaulting to basedir.
164
     */
165
    public File getOutputDir(){
166
        if (getDestdir() != null) return getDestdir();
167
        return getBase();
168
    }
169
    
170
    /**
171
     * Adds a set of files to generate stubs for.
172
     */
173
    public void addFileset(FileSet set) {
174
        filesets.addElement(set);
175
    }
176
177
    /**
140
     * Sets the class to run <code>rmic</code> against;
178
     * Sets the class to run <code>rmic</code> against;
141
     * optional
179
     * optional
142
     * @param classname the name of the class for rmic to create code for
180
     * @param classname the name of the class for rmic to create code for
Lines 395-400 Link Here
395
    }
433
    }
396
434
397
    /**
435
    /**
436
     * Sets whether source folders are automatically included in the compile
437
     * classpath; optional, defaults to false
438
     * @param include true to include source folders
439
     */
440
    public void setSourcesOnClasspath(boolean include) {
441
        sourcesOnClasspath = include;
442
    }
443
444
    /**
445
     * Sets whether source folders are automatically included in the compile
446
     * classpath
447
     * @param true if source folders are automatically included
448
     */
449
    public boolean getSourcesOnClasspath() {
450
        return sourcesOnClasspath;
451
    }
452
453
    /**
398
     * Sets the extension directories that will be used during the
454
     * Sets the extension directories that will be used during the
399
     * compilation; optional.
455
     * compilation; optional.
400
     * @param extDirs the extension directories to be used
456
     * @param extDirs the extension directories to be used
Lines 484-500 Link Here
484
     * class and getting to do the work
540
     * class and getting to do the work
485
     */
541
     */
486
    public void execute() throws BuildException {
542
    public void execute() throws BuildException {
487
        if (baseDir == null) {
543
        if(compileList.size() > 0){
488
            throw new BuildException("base attribute must be set!", getLocation());
544
            compileList.removeAllElements();
489
        }
490
        if (!baseDir.exists()) {
491
            throw new BuildException("base does not exist!", getLocation());
492
        }
545
        }
493
546
547
        File outputDir = getOutputDir();
548
        if (outputDir == null) {
549
            throw new BuildException("base or destdir attribute must be set!", getLocation());
550
        }
551
        if (!outputDir.exists() || (baseDir != null && !baseDir.exists()) ) {
552
            throw new BuildException("base or destdir location does not exist!", getLocation());
553
        }
494
        if (verify) {
554
        if (verify) {
495
            log("Verify has been turned on.", Project.MSG_VERBOSE);
555
            log("Verify has been turned on.", Project.MSG_VERBOSE);
496
        }
556
        }
497
557
558
        if (getBase() != null) {
559
            FileSet implicitFs = getImplicitFileSet();
560
            implicitFs.setDir(getBase());
561
            filesets.add(implicitFs);
562
        }
563
        
564
        // Must be performed before the loader's classpath is set so any
565
        // classpaths can be used by isValidRmiRemote() (which occurs deep
566
        // within populateFilesToProcess(...).
567
        processSourcesOnClasspath();
568
498
        RmicAdapter adapter = RmicAdapterFactory.getRmic(getCompiler(), this);
569
        RmicAdapter adapter = RmicAdapterFactory.getRmic(getCompiler(), this);
499
570
500
        // now we need to populate the compiler adapter
571
        // now we need to populate the compiler adapter
Lines 503-528 Link Here
503
        Path classpath = adapter.getClasspath();
574
        Path classpath = adapter.getClasspath();
504
        loader = getProject().createClassLoader(classpath);
575
        loader = getProject().createClassLoader(classpath);
505
576
506
        try {
577
        populateFilesToProcess(adapter.getMapper());
507
            // scan base dirs to build up compile lists only if a
508
            // specific classname is not given
509
            if (classname == null) {
510
                DirectoryScanner ds = this.getDirectoryScanner(baseDir);
511
                String[] files = ds.getIncludedFiles();
512
                scanDir(baseDir, files, adapter.getMapper());
513
            } else {
514
                // otherwise perform a timestamp comparison - at least
515
                scanDir(baseDir,
516
                        new String[] {classname.replace('.',
517
                                                        File.separatorChar)
518
                                          + ".class"},
519
                        adapter.getMapper());
520
            }
521
578
522
            int fileCount = compileList.size();
579
            int fileCount = compileList.size();
523
            if (fileCount > 0) {
580
            if (fileCount > 0) {
524
                log("RMI Compiling " + fileCount
581
                log("RMI Compiling " + fileCount
525
                    + " class" + (fileCount > 1 ? "es" : "") + " to " + baseDir,
582
                + " class" + (fileCount > 1 ? "es" : "") + " to " + outputDir,
526
                    Project.MSG_INFO);
583
                    Project.MSG_INFO);
527
584
528
                // finally, lets execute the compiler!!
585
                // finally, lets execute the compiler!!
Lines 536-542 Link Here
536
             * base directory and sourcebase are the same, the generated
593
             * base directory and sourcebase are the same, the generated
537
             * sources are already in place.
594
             * sources are already in place.
538
             */
595
             */
539
            if (null != sourceBase && !baseDir.equals(sourceBase)
596
        if (null != sourceBase && !outputDir.equals(sourceBase)
540
                && fileCount > 0) {
597
                && fileCount > 0) {
541
                if (idl) {
598
                if (idl) {
542
                    log("Cannot determine sourcefiles in idl mode, ",
599
                    log("Cannot determine sourcefiles in idl mode, ",
Lines 545-558 Link Here
545
                        Project.MSG_WARN);
602
                        Project.MSG_WARN);
546
                } else {
603
                } else {
547
                    for (int j = 0; j < fileCount; j++) {
604
                    for (int j = 0; j < fileCount; j++) {
548
                        moveGeneratedFile(baseDir, sourceBase,
605
                    moveGeneratedFile(outputDir, sourceBase,
549
                                          (String) compileList.elementAt(j),
606
                                          (String) compileList.elementAt(j),
550
                                          adapter);
607
                                          adapter);
551
                    }
608
                    }
552
                }
609
                }
553
            }
610
            }
554
        } finally {
611
    }
555
            compileList.removeAllElements();
612
    
613
    protected void processSourcesOnClasspath() {
614
        // Moved from DefaultRmicAdapter, so that multiple
615
        // locations can be added.
616
        if(compileClasspath == null){
617
            compileClasspath = new Path(getProject());
618
        }
619
        
620
        if (getSourcesOnClasspath()) {
621
            for (Iterator iter = filesets.iterator(); iter.hasNext();) {
622
                FileSet fs = (FileSet) iter.next();
623
                File fsBaseDir = fs.getDir(getProject());
624
                compileClasspath.setLocation(fsBaseDir);
625
            }
626
        }
627
    }
628
    
629
    protected void populateFilesToProcess (FileNameMapper mapper) {
630
        for (Iterator iter = filesets.iterator(); iter.hasNext();) {
631
            FileSet fs = (FileSet) iter.next();
632
            File fsBaseDir = fs.getDir(getProject());
633
            String[] files;
634
            
635
            // scan base dirs to build up compile lists only if a
636
            // specific classname is not given
637
            if (classname == null) {
638
                DirectoryScanner ds = fs.getDirectoryScanner(getProject());
639
                files = ds.getIncludedFiles();
640
            } else {
641
                // otherwise perform a timestamp comparison - at least
642
                files =  new String[] {classname.replace('.',
643
                            File.separatorChar) + ".class"};
644
            }
645
            
646
            scanDir(fsBaseDir, files, mapper);
556
        }
647
        }
557
    }
648
    }
558
649
Lines 628-634 Link Here
628
                Project.MSG_VERBOSE);
719
                Project.MSG_VERBOSE);
629
        } else {
720
        } else {
630
            SourceFileScanner sfs = new SourceFileScanner(this);
721
            SourceFileScanner sfs = new SourceFileScanner(this);
631
            newFiles = sfs.restrict(files, baseDir, baseDir, mapper);
722
            newFiles = sfs.restrict(files, baseDir, getOutputDir(), mapper);
632
        }
723
        }
633
724
634
        for (int i = 0; i < newFiles.length; i++) {
725
        for (int i = 0; i < newFiles.length; i++) {
(-)apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java (-5 / +19 lines)
Lines 96-104 Link Here
96
     */
96
     */
97
    protected Path getCompileClasspath() {
97
    protected Path getCompileClasspath() {
98
        Path classpath = new Path(attributes.getProject());
98
        Path classpath = new Path(attributes.getProject());
99
        // add dest dir to classpath so that previously compiled and
100
        // untouched classes are on classpath
101
        classpath.setLocation(attributes.getBase());
102
99
103
        // Combine the build classpath with the system classpath, in an
100
        // Combine the build classpath with the system classpath, in an
104
        // order determined by the value of build.sysclasspath
101
        // order determined by the value of build.sysclasspath
Lines 144-150 Link Here
144
        Path classpath = getCompileClasspath();
141
        Path classpath = getCompileClasspath();
145
142
146
        cmd.createArgument().setValue("-d");
143
        cmd.createArgument().setValue("-d");
147
        cmd.createArgument().setFile(attributes.getBase());
144
        cmd.createArgument().setFile(attributes.getOutputDir());
148
145
149
        if (attributes.getExtdirs() != null) {
146
        if (attributes.getExtdirs() != null) {
150
            if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) {
147
            if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) {
Lines 293-299 Link Here
293
290
294
            if (!attributes.getIiop() && !attributes.getIdl()) {
291
            if (!attributes.getIiop() && !attributes.getIdl()) {
295
                // JRMP with simple naming convention
292
                // JRMP with simple naming convention
296
                if ("1.2".equals(attributes.getStubVersion())) {
293
                if (isJRMP12Plus()) {
297
                    target = new String[] {
294
                    target = new String[] {
298
                        base + getStubClassSuffix() + ".class"
295
                        base + getStubClassSuffix() + ".class"
299
                    };
296
                    };
Lines 371-375 Link Here
371
            }
368
            }
372
            return target;
369
            return target;
373
        }
370
        }
371
        
372
        protected boolean isJRMP12Plus() {
373
            // Find if the user specified a version.
374
            if(attributes.getStubVersion() != null) {
375
                if ("1.2".equals(attributes.getStubVersion())){
376
                    return true;
377
                }else{
378
                    return false;
379
                }
380
            }else{
381
                // Set the default for the current JRE.
382
                if (JavaEnvUtils.compareJavaVersion(JavaEnvUtils.JAVA_1_5) >= 0) {
383
                    return true;
384
                }
385
            }
386
            return false;
387
        }
374
    }
388
    }
375
}
389
}
(-)apache-ant-1.6.5/src/main/org/apache/tools/ant/util/JavaEnvUtils.java (+29 lines)
Lines 63-68 Link Here
63
    /** Version constant for Java 1.5 */
63
    /** Version constant for Java 1.5 */
64
    public static final String JAVA_1_5 = "1.5";
64
    public static final String JAVA_1_5 = "1.5";
65
65
66
    protected static final String[] JAVA_VERSIONS = new String[] {
67
        JAVA_1_0, JAVA_1_1, JAVA_1_2, JAVA_1_3, JAVA_1_4, JAVA_1_5};
68
66
    /** Whether this is the Kaffe VM */
69
    /** Whether this is the Kaffe VM */
67
    private static boolean kaffeDetected;
70
    private static boolean kaffeDetected;
68
71
Lines 132-137 Link Here
132
    }
135
    }
133
136
134
    /**
137
    /**
138
     * Compares the current Java version to the passed in String -
139
     * assumes the argument is one of the constants defined in this
140
     * class.
141
     * @param version the version to check against the current version.
142
     * @return < 0 if older, 0 if same, > 0 if newer.
143
     * (like Comparable.CompareTo(T)).
144
     * @since Ant 1.7 // TODO: Verify this.
145
     */
146
    public static int compareJavaVersion(String version) {
147
        int curVer = getJavaVersionIdx(javaVersion);
148
        int tstVer = getJavaVersionIdx(version);
149
        return curVer - tstVer;
150
    }
151
    
152
    protected static int getJavaVersionIdx(String version) {
153
        int result = -1;
154
        for (int i=0; i < JAVA_VERSIONS.length; i++) {
155
            if (JAVA_VERSIONS[i].equals(version)){
156
                result = i;
157
                break;
158
            }
159
        }
160
        return result;
161
    }
162
163
    /**
135
     * Checks whether the current Java VM is Kaffe.
164
     * Checks whether the current Java VM is Kaffe.
136
     * @return true if the current Java VM is Kaffe.
165
     * @return true if the current Java VM is Kaffe.
137
     * @since Ant 1.6.3
166
     * @since Ant 1.6.3

Return to bug 20699