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++) { |