示例#1
0
 /**
  * 初期化処理。 <br>
  * - 環境を貰い、Velocityを初期化する。 <br>
  * - 注意事項:Eclipse の注釈処理のバグで jar を差し替えるとVelocityが jar 内の リソースを参照出来なくなる。=> Eclipse再起動が必要。
  */
 @Override
 public void init(ProcessingEnvironment env) {
   super.init(env);
   this.environment = env;
   Velocity.setProperty("runtime.log.logsystem.class", "");
   Velocity.setProperty("resource.loader", "class");
   Velocity.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName());
   Velocity.init();
 }
示例#2
0
  // Velocity init
  public static void initVelocity() {
    if (velocityCatch == null) {
      System.out.println("init VM");
      velocityCatch = new Object();

      Properties props = new Properties();
      props.setProperty("input.encoding", "UTF-8");
      props.setProperty("output.encoding", "UTF-8");

      if (getConfig().getChild("vmtemplatepath") != null) {
        props.setProperty("file.resource.loader.path", getConfig().getChildText("vmtemplatepath"));
      }
      if (System.getProperty("vmtemplatepath") != null) {
        props.setProperty("file.resource.loader.path", System.getProperty("vmtemplatepath"));
        // Velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,
        // System.getProperty("vmtemplatepath"));//oder new FIle()?
      }
      System.out.println("vmtemplatepath=" + props.getProperty("vmtemplatepath"));
      try {
        Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, VeloLog.getInstance());
        Velocity.init(props);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }
示例#3
0
 /** Instantiates a new exporter velocity. */
 public ExporterVelocity() {
   Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, new VelocityLogger());
   try {
     Velocity.init();
   } catch (final Exception e) {
   }
   velocityContext = new VelocityContext();
 }
  /** Default constructor. */
  AbsoluteFileResourceLoaderTestCase() {
    super("AbsoluteFileResourceLoaderTest");

    try {
      assureResultsDirectoryExists(RESULTS_DIR);

      // signify we want to use an absolute path
      Velocity.addProperty(Velocity.FILE_RESOURCE_LOADER_PATH, "");

      Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, TestLogChute.class.getName());

      Velocity.init();
    } catch (Exception e) {
      fail("Cannot setup AbsoluteFileResourceLoaderTest!");
    }
  }
示例#5
0
 static {
   try {
     Velocity.setProperty("resource.loader", "file,yadboro");
     Velocity.setProperty(
         "yadboro.resource.loader.class", ClydeVelocityResourceLoader.class.getName());
     Velocity.setProperty("input.encoding", "UTF-8");
     Velocity.setProperty("output.encoding", "UTF-8");
     Velocity.setProperty(
         "runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem");
     Velocity.setProperty("velocimacro.permissions.allow.inline.local.scope", "true");
     Velocity.init();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  private boolean executeAll(File velocitySources, File outputDirectory)
      throws MojoExecutionException {
    List<File> files = new ArrayList<File>();
    String canoPath;
    try {
      velocitySources = velocitySources.getCanonicalFile();
      listVeloFiles(velocitySources, files);

      canoPath = sourcePathRoot.getCanonicalPath();
      System.out.println("Velocity root path = " + canoPath);
      Velocity.setProperty("file.resource.loader.path", canoPath); // file.getParent());
      Velocity.init();

    } catch (Exception ex) {
      throw new MojoExecutionException("Failed to list files from '" + velocitySources + "'", ex);
    }

    getLog().info("Found " + files.size() + " files in '" + velocitySources + "'...");

    if (files.isEmpty()) return false;

    for (File file : files) {
      try {
        file = file.getCanonicalFile();

        String name = file.getName();
        if (name.endsWith("~") || name.endsWith(".bak")) {
          getLog().info("Skipping: '" + name + "'");
          continue;
        }

        File outFile = getOutputFile(file, velocitySources, outputDirectory);
        if (outFile.exists() && outFile.lastModified() > file.lastModified()) {
          getLog().info("Up-to-date: '" + name + "'");
          continue;
        }
        getLog().info("Executing template '" + name + "'...");

        // context = new VelocityContext();
        String cano = file.getCanonicalPath();
        cano = cano.substring(canoPath.length());
        if (cano.startsWith(File.separator)) cano = cano.substring(File.separator.length());

        org.apache.velocity.Template template = Velocity.getTemplate(cano); // file.getName());

        VelocityContext context = new VelocityContext(); // execution.getParameters());
        context.put("primitives", Primitive.getPrimitives());
        context.put("primitivesNoBool", Primitive.getPrimitivesNoBool());
        context.put("bridJPrimitives", Primitive.getBridJPrimitives());

        StringWriter out = new StringWriter();
        template.merge(context, out);
        out.close();

        outFile.getParentFile().mkdirs();

        FileWriter f = new FileWriter(outFile);
        f.write(out.toString());
        f.close();
        // getLog().info("\tGenerated '" + outFile.getName() + "'");

      } catch (Exception ex) {
        // throw
        new MojoExecutionException("Failed to execute template '" + file + "'", ex)
            .printStackTrace();
      }
    }

    return true;
  }
示例#7
0
 @PostConstruct
 public void init() {
   Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new Slf4jLogChute());
   Velocity.init();
 }