Title: [505] trunk/rails-integration: Fixing preparsing
- Revision
- 505
- Author
- tantalon
- Date
- 2007-04-26 05:42:15 -0400 (Thu, 26 Apr 2007)
Log Message
Fixing preparsing
Modified Paths
Diff
Modified: trunk/rails-integration/plugins/war/lib/packer.rb (504 => 505)
--- trunk/rails-integration/plugins/war/lib/packer.rb 2007-04-26 09:41:17 UTC (rev 504)
+++ trunk/rails-integration/plugins/war/lib/packer.rb 2007-04-26 09:42:15 UTC (rev 505)
@@ -34,7 +34,7 @@
classpath = classpath_files.to_a.join(config.os_path_separator)
# compile the files
os_dir = dir.gsub(File::SEPARATOR, config.os_separator)
- unless system("java -cp #{classpath} org.jruby.webapp.ASTSerializerMain #{'--replace' unless config.keep_source} #{os_dir}")
+ unless system("cd #{os_dir} && java -cp #{classpath} org.jruby.webapp.ASTSerializerMain #{'--replace' unless config.keep_source}")
raise "Error: failed to preparse files in #{dir}, returned with error code #{$?}"
end
end
@@ -115,7 +115,7 @@
gem_files = Rake::FileList.new(File.join(gem.full_gem_path, '**', '*'))
copy_tree(gem_files, gem_target, gem.full_gem_path)
# compile the .rb files to .rb.ast.ser
- compile_tree(gem_target,config)
+ compile_tree(File.join(gem_target, 'lib'), config)
end
# handle dependencies
Modified: trunk/rails-integration/src/main/java/org/jruby/webapp/ASTSerializerMain.java (504 => 505)
--- trunk/rails-integration/src/main/java/org/jruby/webapp/ASTSerializerMain.java 2007-04-26 09:41:17 UTC (rev 504)
+++ trunk/rails-integration/src/main/java/org/jruby/webapp/ASTSerializerMain.java 2007-04-26 09:42:15 UTC (rev 505)
@@ -11,62 +11,47 @@
public class ASTSerializerMain {
private static final String DEFAULT_SUFFIX = ".ast.ser";
- private static boolean replace = false;
+ private boolean replace = false;
public static void main(String[] args) {
+ ASTSerializerMain main = new ASTSerializerMain();
// usage
int argIndex = 0;
if (args.length == 0) usage();
+
// replace?
if (args[argIndex].equals("--replace")) {
argIndex++;
- replace = true;
+ main.replace = true;
}
- // check the source
- if (args.length == argIndex) usage();
- File source = new File(args[argIndex++]);
- if (!source.exists()) {
- System.err.println("The source file could not be found");
- System.exit(1);
- }
- // check the target
- File target = null;
- if (args.length != argIndex) {
- target = new File(args[argIndex++]);
- if (source.isDirectory() != target.isDirectory()) {
- System.err.println("If source is a file, target must also be a file");
- System.err.println("If source is a directory, target must also be a directory");
- System.exit(1);
- }
- }
+
// preparse the file
- if (source.isFile()) {
- preparse(source, target);
- } else if (source.isDirectory()) {
- preparseAll(source, target);
- }
+ main.preparseAll(new File("."));
+
// done
System.exit(0);
}
- private static void preparseAll(File source, File target) {
- if (target == null) target = source;
- File[] children = source.listFiles();
- for(int i=0; i<children.length; i++) {
- File child = children[i];
- if (child.isDirectory()) {
- preparseAll(child, new File(target, child.getName()));
- } else if(child.getName().endsWith(".rb")) {
- preparse(child, new File(target, child.getName() + DEFAULT_SUFFIX));
+ public void preparseAll(File folder) {
+ File[] sources = folder.listFiles();
+ for(int i=0; i<sources.length; i++) {
+ File source = sources[i];
+ if (source.isDirectory()) {
+ preparseAll(source);
+ } else if(source.isFile() && source.getName().endsWith(".rb")) {
+ preparse(source);
}
}
}
- private static void preparse(File source, File target) {
- if (target == null) {
- target = new File(source.getPath() + DEFAULT_SUFFIX);
+ public void preparse(File source) {
+ String sourcePath = source.getPath();
+ if (sourcePath.startsWith("." + File.separatorChar)) {
+ source = new File(sourcePath.substring(2));
}
+
try {
+ File target = new File(source.getPath() + DEFAULT_SUFFIX);
ASTSerializer.serialize(source, target);
if (replace) source.delete();
} catch (NullPointerException e) {
@@ -77,9 +62,8 @@
}
private static void usage() {
- System.out.println("Usage: ASTSerializerMain [--replace] source [target]");
- System.out.println("Preparses the Ruby file source, and stores the result in target");
- System.out.println("Target defaults to source.ast.ser");
+ System.out.println("Usage: ASTSerializerMain [--replace]");
+ System.out.println("Preparses the Ruby files in the current directory");
System.exit(1);
}
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel