"""
There are 3 main files, SConstruct, config.py, run.py.
	SConstruct: 
		Builds the .java file, in the buildresource parameter, OR, the src directory. If you don't specify 
		buildresource parameter src directory is assumed.
	config.py:
		Has main functions, and the directory structure of the app. 
		The directory structure is as follows.
		src: This dir. has all the src files, to build.
		lib: contains all the lib files, which are included in the classpath at the time of compilation and running.
		bin: contains, the compiled class files.
		tools: contains the files for scons-local, and other tools like junit, or testng, etc. which you wish to 
		       include in your app.
	run.py:
		Calls SConstruct for building the .java file passed as parameter, on successfull build, runs the java class.
"""


"""
Builds the input .java file, or src directory, Class files go into bin directory(config.outputDir), you can change that(paths), 
in config.py
"""

import config	#the configuration of paths(input, output, lib) and utility functions.
import os
import sys


buildResource = ARGUMENTS.get("buildresource",config.sourceDir)

if not (buildResource.endswith(".java")):
    if not (buildResource == "src"):
        print "The Input File should be .java file, or src directory, for building e.g."
	print "python tools/scons/scons-local-0.98.4/scons.py buildresource=src/com/somecompany/HiSCons.java"
        print "OR python tools/scons/scons-local-0.98.4/scons.py buildresource=src , for building the whole src directory"
        sys.exit(4)

libFiles = config.walkDirs(config.libDir)

path = os.environ['PATH']
env = Environment(JAVACLASSPATH = libFiles, JAVASOURCEPATH = config.sourceDir)
env['ENV']['PATH'] = path
env.Java(target = config.outputDir, source = buildResource)
