Search in sources :

Example 1 with TranslateTemplateTask

use of cn.bran.japid.compiler.TranslateTemplateTask in project Japid by branaway.

the class JapidCommands method reloadChanged.

/**
	 * @param root
	 *            the package root "/"
	 * @return
	 */
public static List<File> reloadChanged(String root) {
    try {
        DirUtil.mkdir(root);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    TranslateTemplateTask t = new TranslateTemplateTask();
    File rootDir = new File(root);
    t.setPackageRoot(rootDir);
    t.setInclude(new File(rootDir, DirUtil.JAPIDVIEWS_ROOT));
    t.clearImports();
    t.importStatic(JapidPlayAdapter.class);
    t.importStatic(Validation.class);
    t.importStatic(JavaExtensions.class);
    t.addAnnotation(NoEnhance.class);
    if (DirUtil.hasLayouts(root))
        t.addImport(DirUtil.JAPIDVIEWS_ROOT + "._layouts.*");
    if (DirUtil.hasJavaTags(root))
        t.addImport(DirUtil.JAPIDVIEWS_ROOT + "._javatags.*");
    if (DirUtil.hasTags(root))
        t.addImport(DirUtil.JAPIDVIEWS_ROOT + "._tags.*");
    t.addImport("models.*");
    t.addImport("controllers.*");
    t.addImport(play.mvc.Scope.class.getName() + ".*");
    t.addImport(play.i18n.Messages.class);
    t.addImport(play.i18n.Lang.class);
    t.addImport(play.mvc.Http.class.getName() + ".*");
    t.addImport(Validation.class.getName());
    t.addImport(play.data.validation.Error.class.getName());
    //		t.addImport("static  japidviews._javatags.JapidWebUtil.*");
    List<String> javatags = DirUtil.scanJavaTags(root);
    for (String f : javatags) {
        t.addImport("static " + f + ".*");
    }
    try {
        t.execute();
    } catch (JapidCompilationException e) {
        //			Play.classes.remove(className);
        throw e;
    }
    List<File> changedFiles = t.getChangedFiles();
    return changedFiles;
}
Also used : Validation(play.data.validation.Validation) TranslateTemplateTask(cn.bran.japid.compiler.TranslateTemplateTask) JapidCompilationException(cn.bran.japid.compiler.JapidCompilationException) JapidCompilationException(cn.bran.japid.compiler.JapidCompilationException) IOException(java.io.IOException) VirtualFile(play.vfs.VirtualFile) File(java.io.File)

Example 2 with TranslateTemplateTask

use of cn.bran.japid.compiler.TranslateTemplateTask in project Japid by branaway.

the class JapidRenderer method reloadChanged.

/**
	 * @param root
	 *            the package root "/"
	 * @return the updated Java files.
	 */
static List<File> reloadChanged(String root) {
    try {
        mkdir(root);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    TranslateTemplateTask t = new TranslateTemplateTask();
    t.setUsePlay(usePlay);
    File rootDir = new File(root);
    t.setPackageRoot(rootDir);
    t.setInclude(new File(japidviews));
    if (DirUtil.hasLayouts(root))
        t.addImport("japidviews._layouts.*");
    if (DirUtil.hasJavaTags(root))
        t.addImport("japidviews._javatags.*");
    if (DirUtil.hasTags(root))
        t.addImport("japidviews._tags.*");
    for (String imp : importlines) {
        t.addImport(imp);
    }
    t.execute();
    // List<File> changedFiles = t.getChangedFiles();
    return t.getChangedTargetFiles();
// return changedFiles;
}
Also used : TranslateTemplateTask(cn.bran.japid.compiler.TranslateTemplateTask) File(java.io.File) IOException(java.io.IOException)

Example 3 with TranslateTemplateTask

use of cn.bran.japid.compiler.TranslateTemplateTask in project japid42 by branaway.

the class JapidRenderer method reloadChanged.

/**
	 * @param roots
	 *            the package root
	 * @return the updated Java files.
	 */
static List<File> reloadChanged(String... roots) {
    List<File> files = new ArrayList<File>();
    if (roots == null)
        return files;
    //
    for (String r : roots) {
        File root = new File(r);
        if (!root.exists()) {
            JapidFlags.warn("root directory does not exist: " + root.getAbsolutePath());
            continue;
        }
        TranslateTemplateTask t = new TranslateTemplateTask();
        t.addImport("japidviews.*");
        t.addImport("java.util.*");
        if (usePlay) {
            t.addImport("controllers.*");
            t.addImport("models.*");
            t.addImport("play.data.validation.Validation");
            t.addImport("play.i18n.Lang");
            t.addImport("play.mvc.Http.Context.Implicit");
            t.addImport("play.mvc.Http.Flash");
            t.addImport("play.mvc.Http.Request");
            t.addImport("play.mvc.Http.Response");
            t.addImport("play.mvc.Http.Session");
            t.addImport("play.data.Form");
            t.addImport("play.data.Form.Field");
        }
        for (String imp : imports) {
            t.addImport(imp);
        }
        t.setUsePlay(usePlay);
        t.setPackageRoot(root);
        t.setInclude(new File(r + SEP + JAPIDVIEWS + SEP));
        // _layouts and _tags are deprecated
        // if (DirUtil.hasLayouts(r))
        // t.addImport("japidviews._layouts.*");
        // if (DirUtil.hasTags(r))
        // t.addImport("japidviews._tags.*");
        t.execute();
        files.addAll(t.getChangedTargetFiles());
    }
    return files;
}
Also used : TranslateTemplateTask(cn.bran.japid.compiler.TranslateTemplateTask) ArrayList(java.util.ArrayList) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 4 with TranslateTemplateTask

use of cn.bran.japid.compiler.TranslateTemplateTask in project Japid by branaway.

the class JapidPlayRenderer method reloadChanged.

/**
	 * @param root
	 *            the package root "/"
	 * @return the updated Java files.
	 */
static List<File> reloadChanged(String root) {
    try {
        mkdir(root);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    TranslateTemplateTask t = new TranslateTemplateTask();
    t.setUsePlay(usePlay);
    File rootDir = new File(root);
    t.setPackageRoot(rootDir);
    t.setInclude(new File(japidviews));
    if (DirUtil.hasLayouts(root))
        t.addImport("japidviews._layouts.*");
    if (DirUtil.hasJavaTags(root))
        t.addImport("japidviews._javatags.*");
    if (DirUtil.hasTags(root))
        t.addImport("japidviews._tags.*");
    for (String imp : importlines) {
        t.addImport(imp);
    }
    // since we're bound together with play:
    t.importStatic(JapidPlayAdapter.class);
    t.importStatic(Validation.class);
    t.importStatic(JavaExtensions.class);
    t.addImport("models.*");
    t.addImport("controllers.*");
    t.addImport(play.mvc.Scope.class.getName() + ".*");
    t.addImport(play.i18n.Messages.class);
    t.addImport(play.i18n.Lang.class);
    t.addImport(play.mvc.Http.class.getName() + ".*");
    t.addImport(Validation.class.getName());
    t.addImport(play.data.validation.Error.class.getName());
    List<String> javatags = DirUtil.scanJavaTags(root);
    for (String f : javatags) {
        t.addImport("static " + f + ".*");
    }
    t.execute();
    // List<File> changedFiles = t.getChangedFiles();
    return t.getChangedTargetFiles();
// return changedFiles;
}
Also used : Validation(play.data.validation.Validation) TranslateTemplateTask(cn.bran.japid.compiler.TranslateTemplateTask) VirtualFile(play.vfs.VirtualFile) File(java.io.File) JapidTemplateException(cn.bran.japid.exceptions.JapidTemplateException) CompilationException(play.exceptions.CompilationException) JapidCompilationException(cn.bran.japid.compiler.JapidCompilationException) IOException(java.io.IOException)

Aggregations

TranslateTemplateTask (cn.bran.japid.compiler.TranslateTemplateTask)4 File (java.io.File)4 IOException (java.io.IOException)3 JapidCompilationException (cn.bran.japid.compiler.JapidCompilationException)2 Validation (play.data.validation.Validation)2 VirtualFile (play.vfs.VirtualFile)2 JapidTemplateException (cn.bran.japid.exceptions.JapidTemplateException)1 ArrayList (java.util.ArrayList)1 JarFile (java.util.jar.JarFile)1 CompilationException (play.exceptions.CompilationException)1