alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (Compile.java)

This example Java source code file (Compile.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

classpath, compile, compiling, error, ioexception, must, object, outputstreamwriter, path_prop, printwriter, reflection_warning_prop, string, unchecked_math_prop, var

The Compile.java Java example source code

/**
 *   Copyright (c) Rich Hickey. All rights reserved.
 *   The use and distribution terms for this software are covered by the
 *   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
 *   which can be found in the file epl-v10.html at the root of this distribution.
 *   By using this software in any fashion, you are agreeing to be bound by
 * 	 the terms of this license.
 *   You must not remove this notice, or any other, from this software.
 **/


package clojure.lang;

import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.IOException;

// Compiles libs and generates class files stored within the directory
// named by the Java System property "clojure.compile.path". Arguments are
// strings naming the libs to be compiled. The libs and compile-path must
// all be within CLASSPATH.

public class Compile{

private static final String PATH_PROP = "clojure.compile.path";
private static final String REFLECTION_WARNING_PROP = "clojure.compile.warn-on-reflection";
private static final String UNCHECKED_MATH_PROP = "clojure.compile.unchecked-math";

private static final Var compile_path = RT.var("clojure.core", "*compile-path*");
private static final Var compile = RT.var("clojure.core", "compile");
private static final Var warn_on_reflection = RT.var("clojure.core", "*warn-on-reflection*");
private static final Var unchecked_math = RT.var("clojure.core", "*unchecked-math*");

public static void main(String[] args) throws IOException{

	OutputStreamWriter out = (OutputStreamWriter) RT.OUT.deref();
	PrintWriter err = RT.errPrintWriter();
	String path = System.getProperty(PATH_PROP);
	int count = args.length;

	if(path == null)
		{
		err.println("ERROR: Must set system property " + PATH_PROP +
		            "\nto the location for compiled .class files." +
		            "\nThis directory must also be on your CLASSPATH.");
		System.exit(1);
		}

    boolean warnOnReflection = System.getProperty(REFLECTION_WARNING_PROP, "false").equals("true");
    String uncheckedMathProp = System.getProperty(UNCHECKED_MATH_PROP);
    Object uncheckedMath = Boolean.FALSE;
    if("true".equals(uncheckedMathProp))
        uncheckedMath = Boolean.TRUE;
    else if("warn-on-boxed".equals(uncheckedMathProp))
        uncheckedMath = Keyword.intern("warn-on-boxed");

	try
		{
               Var.pushThreadBindings(RT.map(compile_path, path,
                       warn_on_reflection, warnOnReflection,
                       unchecked_math, uncheckedMath));

		for(String lib : args)
        {
            out.write("Compiling " + lib + " to " + path + "\n");
            out.flush();
            compile.invoke(Symbol.intern(lib));
        }
		}
	finally
		{
        Var.popThreadBindings();
		try
			{
			out.flush();
			}
		catch(IOException e)
			{
			e.printStackTrace(err);
			}
		}
}
}

Other Java examples (source code examples)

Here is a short list of links related to this Java Compile.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.