Package org.jostraca.util

Examples of org.jostraca.util.PropertySet


  /** Create a template object from a template path */
  public Template makeTemplate( TemplatePath pTemplatePath ) {
    TemplatePath tmpath = (TemplatePath) Internal.null_arg( pTemplatePath );
    t.track( "TemplatePath", pTemplatePath );

    PropertySet contextps = iContextPSM.merge();
    t.track( "build.TemplatePath.contextps.size", contextps.size() );

    // FIX: consider sending ps to tmpath instead to hide this
    String[] tmsearchpath = contextps.getList( Property.main_TemplatePath, Standard.COMMA );
    tmpath.resolve( tmsearchpath );

    // REVIEW: l10n
    iUserMessageHandler.info"Template:",      tmpath.getTemplateName() );
    iUserMessageHandler.debug( "Template Path:", tmpath.getTemplatePath() );
View Full Code Here


  public PropertySet loadBaseConfigFiles( File pSystemConfigFile ) {
    File    systemConfigFile   = (File) Internal.null_arg( pSystemConfigFile );
    boolean systemConfigExists = systemConfigFile.exists();

    iContextPSM.load( CONF_system, systemConfigFile, PropertySetManager.USE_DEFAULT_IF_FILE_DOES_NOT_EXIST );
    PropertySet system = iContextPSM.get( CONF_system );

    File configFolder = systemConfigFile.getParentFile();
    if( null == configFolder ) {
      configFolder = new File( "" );
    }
    PropertySet local           = new PropertySet();
    File        localConfigFile = new File( configFolder, system.get( Property.jostraca_LocalConfigFileName ) );
    if( localConfigFile.exists() && !localConfigFile.isDirectory() ) {
      local.load( localConfigFile  );
    }

    system.overrideWith( local );

    // only set jostraca.Location if using configuration from disk
View Full Code Here

  private List prepare( List pTemplatePaths ) {
    List templatePaths = (List) Internal.null_arg( pTemplatePaths );

    ArrayList    templates = new ArrayList();
    PropertySet  contextps = iContextPSM.merge();

    for( Iterator tpT = templatePaths.iterator(); tpT.hasNext(); ) {
      TemplatePath tp = (TemplatePath) tpT.next();
     
      tp.resolve( contextps.getList( Property.main_TemplatePath, Standard.COMMA ) );

      // REVIEW: l10n
      iUserMessageHandler.info"Template:",      tp.getTemplateName() );
      iUserMessageHandler.debug( "Template Path:", tp.getTemplatePath() );
View Full Code Here

   *  against any CodeWriter options that are files, if found.
   *  Return true if uptodate.
   */
  private boolean checkUpToDate( Template pTemplate ) {

    PropertySet tmps = pTemplate.getMergedPropertySet();

    // assume not uptodate
    boolean uptodate = false;

    try {
      TemplatePath tp = pTemplate.getTemplatePath();

      // some properties force regenerate
      if( tmps.isYes( Property.main_CompileCodeWriter )
          || tmps.isYes( Property.main_ExecuteCodeWriter )
          || tmps.isNo( Property.main_EnableMeta ) ) {
        uptodate = false;
        iUserMessageHandler.debug( "Not uptodate:",
                                   Property.main_CompileCodeWriter+":"+tmps.get( Property.main_CompileCodeWriter )
                                   + "  " + Property.main_ExecuteCodeWriter+":"+tmps.get( Property.main_ExecuteCodeWriter )
                                   + "  " + Property.main_EnableMeta+":"+tmps.get( Property.main_EnableMeta ) );
      }

      // check meta data
      else {
        PropertySet meta    = null;
        boolean     proceed = true;

        // load meta data
        if( proceed ) {
          try {
            meta = MetaUtil.loadMetaData( pTemplate );
          }
          catch( ProcessException te ) {
            if( ProcessException.CODE_load_meta == te.getCode() ) {
              // meta data could not be loaded - not an error
            }
            else {
              ErrorUtil.nonFatalMsg( te.getMessage() );
            }

            uptodate = false;
            iUserMessageHandler.debug( "Not uptodate:", "unable to read meta data from previous generate." );
            proceed = false;
          }
        }
         
        // if template properties are different, regenerate
        if( proceed ) {

          // FIX: props from template only
          String ctmps  = Tools.normaliseTemplatePropertySet( pTemplate.getPropertySet( Constants.CONF_template ) );
          String mtmps = meta.get( Property.jostraca_template_properties );
          t.track( "current template ps", ctmps );
          t.track( "prev template ps", mtmps );
          if( !ctmps.equals( mtmps ) ) {
            iUserMessageHandler.debug( "Not uptodate:", "template properties were different from previous generate." );
            uptodate = false;
            proceed  = false;

            //System.out.println( "ctmps:["+ctmps+"]" );
            //System.out.println( "mtmps:["+mtmps+"]" );
          }
        }

        // if cmd line is different, regenerate
        if( proceed ) {
          String co  = normaliseCmdLine( tmps.get( Property.main_CodeWriterOptions ) );
          String mco = normaliseCmdLine( meta.get( Property.main_CodeWriterOptions ) );
          t.track( "cmd line", co );
          t.track( "prev cmd line", mco );
          if( !co.equals( mco ) ) {
            iUserMessageHandler.debug( "Not uptodate:", "command line was different from previous generate." );
            uptodate = false;
            proceed  = false;
          }
        }

        // test resource files
        if( proceed ) {
          RootBuildResource rbr               = new RootBuildResource();
          String[]          generatedFiles    = meta.getList( Property.jostraca_GeneratedFiles, Standard.COMMA );
          int               numGF             = generatedFiles.length;

          // this assumes that we actually want to generate files, not just compile the template
          // however, the CodeBuilder should ensure that no unnecessary compilation is done in any case
          // this logic will probably cause unnecessary reparsing of the template, but it's good to err
          // on the side of regenerating to avoid false negatives
          if( 0 == numGF ) {
            iUserMessageHandler.debug( "Not uptodate:", "no files generated previously." );
            uptodate = false;
          }

          // there were previously generated files, so we can test the resources against them for uptodateness
          else {
            String[]          tm_resourceFiles  = meta.getList( Property.jostraca_FileBuildResources, Standard.COMMA );
            int               num_tmRF          = tm_resourceFiles.length;

            File[]            cmd_resourceFiles = parseResourceFiles( tmps.get( Property.main_CodeWriterOptions ),
                                                                      tmps.get( Property.main_WorkFolder ) );
            int               num_cmdRF         = cmd_resourceFiles.length;
View Full Code Here


  /** @see org.jostraca.TemplatePath */
  public PropertySet resolvePropertySet() {
    if( null == iPropertySet ) {
      iPropertySet = new PropertySet();
    }
    return iPropertySet;
  }
View Full Code Here

    }


    // settings to just parse template
    Generator   g  = new Generator();
    PropertySet ps = new PropertySet();
    ps.set( Property.main_MakeBackup,        Standard.NO  );
    ps.set( Property.main_CompileCodeWriter, Standard.NO );
    ps.set( Property.main_ExecuteCodeWriter, Standard.NO );
    g.setCmdPropertySet( ps );
    Template tm = g.generate( FileUtil.findFile( "org/jostraca/test/simple.jtm" ) );

    // get full properties
    PropertySet mergedps = tm.getMergedPropertySet();
    assertEquals( ".jostraca", mergedps.get( Property.main_WorkFolder ) );

    // this is how you can get the canonical template script language name
    assertEquals( "java", tm.getCodeWriterLang() );

    // get the codewriter path
    assertEquals( ".jostraca\\SimpleWriter.java", tm.getCodeWriterPath().toString() );
   
    // get the codewriter class file / executable file
    assertEquals( ".jostraca\\SimpleWriter.class", tm.getCodeWriterExecutablePath().toString() );

    ps = new PropertySet();
    ps.set( Property.main_MakeBackup,        Standard.NO  );
    ps.set( Property.main_CompileCodeWriter, Standard.YES );
    ps.set( Property.main_ExecuteCodeWriter, Standard.YES );
    g.setCmdPropertySet( ps );
    tm = g.generate( FileUtil.findFile( "org/jostraca/test/simple.jtm" ) );
View Full Code Here

  }


  protected void processImpl( Template pTemplate ) {
    Template    template   = pTemplate;
    PropertySet tmps       = template.getMergedPropertySet();

    boolean     successful = false;
    PrintStream sysOut     = null;
    PrintStream sysErr     = null;
    RecordingUserMessageHandler rumh = new RecordingUserMessageHandler();

    try {
      String   cw   = makeCodeWriter( tmps );
      String   cwo  = makeCodeWriterOptions( tmps, template );
      String[] args = ArgUtil.splitQuoted( cwo );

      String jcwp = getCodeWriterPath( tmps );
      jcwp = TextUtil.replace( jcwp, ".java", ".class" );
      File jcwpf = new File( jcwp );
      String cwp = jcwpf.getAbsolutePath();

      iUserMessageHandler.debug( UserText.get(UserText.TXT_generating), "class-file:"+cwp+Standard.SPACE+cwo );

      // NOTE: has to be _generate to prevent exit
      Class  cwClass        = ClassUtil.makeClassFromFile( cwp );
      Object cwInstance     = cwClass.newInstance();
      Method generateMethod = cwClass.getMethod( "_generate", new Class[] { (new String[] {}).getClass(), Boolean.TYPE } );

      // DO NOT use CommandLineUserMessageHandler here - causes infinite recursion
      MessageHandlerOutputStream  out  = new MessageHandlerOutputStream( UserMessageHandler.INFO,  rumh );
      MessageHandlerOutputStream  err  = new MessageHandlerOutputStream( UserMessageHandler.ERROR, rumh );

      // space out dots to avoid accidental replace on System DOT out search
      sysOut = System . out;
      sysErr = System . err;
   
      // set context if not null
      Object context = template.getContext();
      if( null != context ) {
        Method setContextMethod = cwClass.getMethod( "_setContext", new Class[] { Object.class } );
        setContextMethod.invoke( cwInstance, new Object[] { context } );
      }

      boolean throwWriterExceptions = tmps.isYes( Property.main_CodeWriter_throwExceptions );

      // DO NOT put System.out in MessageHandler as this will case infinite loop
      System.setOut( new PrintStream( out ) );
      System.setErr( new PrintStream( err ) );
View Full Code Here


  protected void compileAsFirst( List pTemplateList ) {
    List        tmlist  = pTemplateList;
    Template    firsttm = (Template) pTemplateList.get(0);
    PropertySet tmps    = firsttm.getMergedPropertySet();

    StringBuffer sourceFilesB = new StringBuffer( tmlist.size() * 33 );
    boolean      compile      = makeCompileList( tmlist, sourceFilesB );
    String       sourceFiles  = sourceFilesB.toString();

    if( compile ) {

      String compiler     = tmps.get( Property.main_ExternalCompiler );
      String compilerOpts = tmps.get( Property.main_ExternalCompilerOptions );

      if( !JavaUtil.hasClassPathArg(compilerOpts) ) {
        compilerOpts
          = JavaUtil.ARG_classpath + Standard.SPACE
          + JavaUtil.makeClassPath( tmps )
View Full Code Here

  }



  public void testCreate() throws Exception {
    PropertySet               ps   = new PropertySet();
    TemplateActionHandler     tah  = new TemplateActionHandlerStub();
    BasicTextElementProcessor btep = create( ps, tah );
  }
View Full Code Here

  }


  public void testProcessText() throws Exception {
    TemplateActionHandlerStub tahs  = new TemplateActionHandlerStub();
    PropertySet               ps    = new PropertySet();
    ps.load( new File( "../../../../conf/system.conf" ) );
    BasicTextElementProcessor btep = create( ps, tahs );
    String content   = "content";
    Block  textBlock = new Block( Block.TYPE_text, content );

    assertTrue( btep.isMatch( textBlock ) );
View Full Code Here

TOP

Related Classes of org.jostraca.util.PropertySet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.