diff options
author | Mike Gerwitz <mike.gerwitz@rtspecialty.com> | 2018-11-08 00:01:31 -0500 |
---|---|---|
committer | Mike Gerwitz <mike.gerwitz@rtspecialty.com> | 2018-11-08 09:26:07 -0500 |
commit | 5cb78cc47dfc5f8234e502749112f7bce9a816dd (patch) | |
tree | 269489e11f55aa847d69fa211b9f0ff5b224ace5 | |
parent | 970c3531c55a6b920bcb601d8cdcc6c5953c3729 (diff) | |
download | tame-5cb78cc47dfc5f8234e502749112f7bce9a816dd.tar.gz tame-5cb78cc47dfc5f8234e502749112f7bce9a816dd.tar.bz2 tame-5cb78cc47dfc5f8234e502749112f7bce9a816dd.zip |
dslc: Invoke with static rater path
This frees us from requiring a rater/ directory in the working
directory. However, it is important that we continue using it if it
exists, since there are additional things that haven't yet been moved
into the tame repo.
* bin/dslc.in: Provide path to rater/ directory.
* src/current/src/com/lovullo/dslc/DslCompiler.java: Use provided rater/ path.
-rw-r--r-- | bin/dslc.in | 16 | ||||
-rw-r--r-- | src/current/src/com/lovullo/dslc/DslCompiler.java | 38 |
2 files changed, 34 insertions, 20 deletions
diff --git a/bin/dslc.in b/bin/dslc.in index e9dac7c..226ba92 100644 --- a/bin/dslc.in +++ b/bin/dslc.in @@ -22,7 +22,21 @@ declare -r mypath=$( dirname "$( readlink -f "$0" )" ) declare -r dslc_jar="$mypath/../src/current/src/dslc.jar" +# TODO: decouple from old rater/ directory +rater-path() +{ + # use rater/ in cwd if available to maintain previous behavior + if [ -d "$(pwd)/rater" ]; then + echo "$(pwd)/rater" + return + fi + + # otherwise use our own + echo "$mypath/../rater" +} + CLASSPATH="$CLASSPATH:@DSLC_CLASSPATH@:$dslc_jar" \ "@JAVA@" @JAVA_OPTS@ \ - com.lovullo.dslc.DslCompiler + com.lovullo.dslc.DslCompiler \ + "$( rater-path )" diff --git a/src/current/src/com/lovullo/dslc/DslCompiler.java b/src/current/src/com/lovullo/dslc/DslCompiler.java index 2f51945..52456d7 100644 --- a/src/current/src/com/lovullo/dslc/DslCompiler.java +++ b/src/current/src/com/lovullo/dslc/DslCompiler.java @@ -54,10 +54,12 @@ public class DslCompiler private Path _pathRoot; - public _DslCompiler() + public _DslCompiler( String path_root ) + throws IOException { - _xsd = _createXsd(); - _xsl = new HashMap<String,Transformer>(); + _pathRoot = Paths.get( path_root ).toRealPath(); + _xsd = _createXsd(); + _xsl = new HashMap<String,Transformer>(); } @@ -84,9 +86,6 @@ public class DslCompiler System.exit( 4 ); } - // root path of TAME - _pathRoot = Paths.get( "rater/tame" ).toRealPath(); - // transform to dest File destfile = new File( dest ); try @@ -140,7 +139,7 @@ public class DslCompiler String relroot = new String( new char[ dircount ] ).replace( "\0", "../" ); Transformer t = _xsl.get( cmd ); - t.setParameter( "__path-root", _pathRoot.toString() ); + t.setParameter( "__path-root", _pathRoot.toString() + "/tame" ); t.setParameter( "__srcpkg", srcpkg ); t.setParameter( "__relroot", relroot ); t.setParameter( "__rseed", (int)( Math.random() * 10e6 ) ); @@ -193,7 +192,7 @@ public class DslCompiler try { final Schema schema = - factory.newSchema( new File( "rater/rater.xsd" ) ); + factory.newSchema( new File( _pathRoot.toString() + "/rater.xsd" ) ); return schema.newValidator(); } @@ -219,7 +218,9 @@ public class DslCompiler "net.sf.saxon.TransformerFactoryImpl", null ); - final Source xsl = new StreamSource( "rater/" + src + ".xsl" ); + final Source xsl = new StreamSource( + _pathRoot.toString() + "/" + src + ".xsl" + ); return factory.newTransformer( xsl ); } @@ -245,23 +246,22 @@ public class DslCompiler new InputStreamReader( System.in ) ); - String src = ( args.length > 0 ) ? args[0] : ""; + String src = ""; + String path_root = ( args.length > 0 ) ? args[0] : ""; - _DslCompiler dslc = new _DslCompiler(); + if ( path_root == "" ) + { + throw new Exception( "Missing rater/ root path" ); + } + + _DslCompiler dslc = new _DslCompiler( path_root ); try { - if ( src != "" ) + while ( ( src = stdin.readLine() ) != null ) { compileSrc( dslc, src ); } - else - { - while ( ( src = stdin.readLine() ) != null ) - { - compileSrc( dslc, src ); - } - } } catch ( IOException e ) { |