Beispiel #1
0
 private String getColor(int logLevel) {
   if (logLevel == Level.OFF.intValue()) {
     return "#000"; // black
   }
   if (logLevel >= Level.SEVERE.intValue()) {
     return "#F00"; // bright red
   }
   if (logLevel >= Level.WARNING.intValue()) {
     return "#E56717"; // dark orange
   }
   if (logLevel >= Level.INFO.intValue()) {
     return "#20b000"; // green
   }
   if (logLevel >= Level.CONFIG.intValue()) {
     return "#2B60DE"; // blue
   }
   if (logLevel >= Level.FINE.intValue()) {
     return "#F0F"; // purple
   }
   if (logLevel >= Level.FINER.intValue()) {
     return "#F0F"; // purple
   }
   if (logLevel >= Level.FINEST.intValue()) {
     return "#F0F"; // purple
   }
   return "#000"; // black
 }
  protected int mapLevelToAnt(final Level level) {
    if (Level.CONFIG.equals(level)) return Project.MSG_DEBUG;
    if (Level.FINE.equals(level)) return Project.MSG_VERBOSE;
    if (Level.FINER.equals(level)) return Project.MSG_DEBUG;
    if (Level.FINEST.equals(level)) return Project.MSG_DEBUG;
    if (Level.INFO.equals(level)) return Project.MSG_INFO;
    if (Level.SEVERE.equals(level)) return Project.MSG_ERR;
    if (Level.WARNING.equals(level)) return Project.MSG_WARN;

    return Project.MSG_WARN;
  }
/** @author Kamnev Georgiy */
public class LocalRepoCommands extends BaseCLIFun {
  // <editor-fold defaultstate="collapsed" desc="log Функции">
  private static final Logger logger = Logger.getLogger(LocalRepoCommands.class.getName());
  private static final Level logLevel = logger.getLevel();
  private static final boolean isLogSevere =
      logLevel == null ? true : logLevel.intValue() <= Level.SEVERE.intValue();

  private static final boolean isLogWarning =
      logLevel == null ? true : logLevel.intValue() <= Level.WARNING.intValue();

  private static final boolean isLogInfo =
      logLevel == null ? true : logLevel.intValue() <= Level.INFO.intValue();

  private static final boolean isLogFine =
      logLevel == null ? true : logLevel.intValue() <= Level.FINE.intValue();

  private static final boolean isLogFiner =
      logLevel == null ? true : logLevel.intValue() <= Level.FINER.intValue();

  private static final boolean isLogFinest =
      logLevel == null ? true : logLevel.intValue() <= Level.FINEST.intValue();

  private static void logFine(String message, Object... args) {
    logger.log(Level.FINE, message, args);
  }

  private static void logFiner(String message, Object... args) {
    logger.log(Level.FINER, message, args);
  }

  private static void logFinest(String message, Object... args) {
    logger.log(Level.FINEST, message, args);
  }

  private static void logInfo(String message, Object... args) {
    logger.log(Level.INFO, message, args);
  }

  private static void logWarning(String message, Object... args) {
    logger.log(Level.WARNING, message, args);
  }

  private static void logSevere(String message, Object... args) {
    logger.log(Level.SEVERE, message, args);
  }

  private static void logException(Throwable ex) {
    logger.log(Level.SEVERE, null, ex);
  }
  // </editor-fold>

  //    public final UpMain upmain;
  //
  //    public LocalRepoCommands( UpMain upmain ){
  //        if( upmain==null )throw new IllegalArgumentException( "upmain==null" );
  //        this.upmain = upmain;
  //    }

  //    public void println(){
  //        upmain.getOutput().println();
  //    }
  //
  //    public void println(Object obj){
  //        upmain.getOutput().println(obj);
  //    }
  //
  //    public BasicTemplate.EasyTemplate template(String template){
  //        return upmain.getOutput().template(template);
  //    }

  @Fun
  @Name(name = "localRepo")
  @Help(shortDesc = "create local repo")
  public LocalUplaunchRepo localRepo(
      @Name(name = "path") @Help(shortDesc = "location of repo") String path) {
    if (path == null) return null;

    File froot = FileSystems.get(path);
    File dir = froot;
    if (dir != null && !dir.isExists()) {
      dir.mkdirs();
    }

    LocalUplaunchRepo luprepo = new LocalUplaunchRepo();
    luprepo.setRoot(froot);

    return luprepo;
  }

  public static final Map<RepoConfig, LocalUplaunchRepo> configRepoMap =
      new WeakHashMap<RepoConfig, LocalUplaunchRepo>();

  // TODO doc it
  @Fun(operator = true)
  @Name(name = "config")
  public RepoConfig getConfig(LocalUplaunchRepo repo) {
    if (repo == null) throw new IllegalArgumentException("repo==null");
    RepoConfig rc = repo.getConfig();
    if (rc != null) {
      configRepoMap.put(rc, repo);
    }
    return rc;
  }

  // TODO doc it
  @Fun(operator = true)
  @Name(name = "print")
  public void print(RepoConfig config) {
    if (config == null) throw new IllegalArgumentException("config==null");

    String title = "";

    LocalUplaunchRepo urepo = configRepoMap.get(config);
    if (urepo != null) {
      String repoName = RepositoriesCommands.repoNameMap.get(urepo);
      if (repoName != null) {
        title = template("repo ${repoName} config\n").bind("repoName", repoName).eval();
      } else {
        title = "repo config\n";
      }
    }

    println(title);

    try {
      BeanInfo bi = Introspector.getBeanInfo(config.getClass());
      for (PropertyDescriptor pd : bi.getPropertyDescriptors()) {
        if (pd.getPropertyType() == null) continue;

        Method m = pd.getReadMethod();
        if (m == null) continue;

        try {
          Object val = m.invoke(config);
          template("${property:40} = ${value}")
              .bind("property", pd.getName())
              .bind("value", val)
              .println();
        } catch (IllegalAccessException ex) {
          Logger.getLogger(LocalRepoCommands.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalArgumentException ex) {
          Logger.getLogger(LocalRepoCommands.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvocationTargetException ex) {
          Logger.getLogger(LocalRepoCommands.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
    } catch (IntrospectionException ex) {
      Logger.getLogger(LocalRepoCommands.class.getName()).log(Level.SEVERE, null, ex);
    }

    //        template(
    //            "${title}"
    //                + "checkDepsOnInstall         = ${conf.checkDepsOnInstall}\n"
    //                + "checkDepsOnUnInstall       = ${conf.checkDepsOnUnInstall}\n"
    //                + "useFileLock                = ${conf.useFileLock}\n"
    //                + "updateIndex                = ${conf.updateIndex}\n"
    //                + "checkExistsComponentDir    = ${conf.checkExistsComponentDir}\n"
    //                + "emptyDirAsComponent        = ${conf.emptyDirAsComponent}\n"
    //                + "deleteEmptyDirsOnUnInstall = ${conf.deleteEmptyDirsOnUnInstall}\n"
    //                + "checkConfigChanges         = ${conf.checkConfigChanges}\n"
    //                + "refreshConfigOnChangeRoot  = ${conf.refreshConfigOnChangeRoot}\n"
    //        )
    //            .align()
    //            .bind("conf", config)
    //            .bind("title", title)
    //            .println();
  }

  public static class ConfigSet {
    public RepoConfig config;
    public String property;

    public ConfigSet(RepoConfig config, String property) {
      this.config = config;
      this.property = property;
    }
  }

  @Fun(operator = true)
  @Name(name = "set")
  public ConfigSet configSet_set(RepoConfig config, String property) {
    if (config == null) throw new IllegalArgumentException("config==null");
    if (property == null) throw new IllegalArgumentException("property==null");
    return new ConfigSet(config, property);
  }

  @Fun(operator = true)
  @Name(name = "=")
  public LocalUplaunchRepo configSet_apply(ConfigSet confSet, String value) {
    if (confSet == null) throw new IllegalArgumentException("confSet==null");
    if (value == null) throw new IllegalArgumentException("value==null");

    RepoConfig conf = confSet.config;
    String prop = confSet.property;

    TypeCastGraph tcast = new ExtendedCastGraph();

    try {
      BeanInfo bi = Introspector.getBeanInfo(conf.getClass());
      for (PropertyDescriptor pd : bi.getPropertyDescriptors()) {
        if (pd.getPropertyType() == null) continue;
        if (!pd.getName().equals(prop)) continue;

        Method m = pd.getWriteMethod();
        if (m == null) continue;

        Class t = pd.getPropertyType();
        Object val = tcast.cast(value, t);

        m.invoke(conf, val);
      }
    } catch (IntrospectionException ex) {
      Logger.getLogger(LocalRepoCommands.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
      Logger.getLogger(LocalRepoCommands.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalArgumentException ex) {
      Logger.getLogger(LocalRepoCommands.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InvocationTargetException ex) {
      Logger.getLogger(LocalRepoCommands.class.getName()).log(Level.SEVERE, null, ex);
    }

    return configRepoMap.get(conf);
  }

  // TODO doc it
  @Fun(operator = true)
  @Name(name = "refreshConfigOnChangeRoot")
  public LocalUplaunchRepo configSet_refreshConfigOnChangeRoot(RepoConfig config, boolean val) {
    if (config == null) throw new IllegalArgumentException("config==null");

    config.setRefreshConfigOnChangeRoot(val);

    LocalUplaunchRepo repo = configRepoMap.get(config);
    return repo;
  }

  // TODO doc it
  @Fun(operator = true)
  @Name(name = "checkConfigChanges")
  public LocalUplaunchRepo configSet_checkConfigChanges(RepoConfig config, boolean val) {
    if (config == null) throw new IllegalArgumentException("config==null");

    config.setCheckConfigChanges(val);

    LocalUplaunchRepo repo = configRepoMap.get(config);
    return repo;
  }

  // TODO doc it
  @Fun(operator = true)
  @Name(name = "deleteEmptyDirsOnUnInstall")
  public LocalUplaunchRepo configSet_deleteEmptyDirsOnUnInstall(RepoConfig config, boolean val) {
    if (config == null) throw new IllegalArgumentException("config==null");

    config.setDeleteEmptyDirsOnUnInstall(val);

    LocalUplaunchRepo repo = configRepoMap.get(config);
    return repo;
  }

  // TODO doc it
  @Fun(operator = true)
  @Name(name = "emptyDirAsComponent")
  public LocalUplaunchRepo configSet_emptyDirAsComponent(RepoConfig config, boolean val) {
    if (config == null) throw new IllegalArgumentException("config==null");

    config.setEmptyDirAsComponent(val);

    LocalUplaunchRepo repo = configRepoMap.get(config);
    return repo;
  }

  // TODO doc it
  @Fun(operator = true)
  @Name(name = "checkExistsComponentDir")
  public LocalUplaunchRepo configSet_checkExistsComponentDir(RepoConfig config, boolean val) {
    if (config == null) throw new IllegalArgumentException("config==null");

    config.setCheckExistsComponentDir(val);

    LocalUplaunchRepo repo = configRepoMap.get(config);
    return repo;
  }

  // TODO doc it
  @Fun(operator = true)
  @Name(name = "checkDepsOnInstall")
  public LocalUplaunchRepo configSetCDepsOnInst(RepoConfig config, boolean val) {
    if (config == null) throw new IllegalArgumentException("config==null");

    config.setCheckDepsOnInstall(val);

    LocalUplaunchRepo repo = configRepoMap.get(config);
    return repo;
  }

  // TODO doc it
  @Fun(operator = true)
  @Name(name = "checkDepsOnUnInstall")
  public LocalUplaunchRepo configSetCDepsOnUnInst(RepoConfig config, boolean val) {
    if (config == null) throw new IllegalArgumentException("config==null");

    config.setCheckDepsOnUnInstall(val);

    LocalUplaunchRepo repo = configRepoMap.get(config);
    return repo;
  }

  // TODO doc it
  @Fun(operator = true)
  @Name(name = "deps")
  public LocalUplaunchRepo configSetCDeps(RepoConfig config, boolean val) {
    if (config == null) throw new IllegalArgumentException("config==null");

    config.setCheckDepsOnUnInstall(val);
    config.setCheckDepsOnInstall(val);

    LocalUplaunchRepo repo = configRepoMap.get(config);
    return repo;
  }

  // TODO doc it
  @Fun(operator = true)
  @Name(name = "updateIndex")
  public LocalUplaunchRepo configSet_updateIndex(RepoConfig config, boolean val) {
    if (config == null) throw new IllegalArgumentException("config==null");

    config.setUpdateIndex(val);

    LocalUplaunchRepo repo = configRepoMap.get(config);
    return repo;
  }

  // TODO doc it
  @Fun(operator = true)
  @Name(name = "useFileLock")
  public LocalUplaunchRepo configSet_useFileLock(RepoConfig config, boolean val) {
    if (config == null) throw new IllegalArgumentException("config==null");

    config.setUseFileLock(val);

    LocalUplaunchRepo repo = configRepoMap.get(config);
    return repo;
  }

  // TODO doc it
  @Fun(operator = true)
  @Name(name = "commit")
  public LocalUplaunchRepo configCommit(RepoConfig config) {
    if (config == null) throw new IllegalArgumentException("config==null");

    config.commit();

    LocalUplaunchRepo repo = configRepoMap.get(config);
    return repo;
  }
}
 private static boolean isLogFinest() {
   Level ll = logLevel();
   return ll == null ? false : ll.intValue() <= Level.FINEST.intValue();
 }
/** @author Kamnev Georgiy ([email protected]) */
public class FunctionSetHelper {
  // <editor-fold defaultstate="collapsed" desc="log Функции">
  private static final Logger logger = Logger.getLogger(FunctionSetHelper.class.getName());
  private static final Level logLevel = logger.getLevel();

  private static final boolean isLogSevere =
      logLevel == null ? true : logLevel.intValue() <= Level.SEVERE.intValue();

  private static final boolean isLogWarning =
      logLevel == null ? true : logLevel.intValue() <= Level.WARNING.intValue();

  private static final boolean isLogInfo =
      logLevel == null ? true : logLevel.intValue() <= Level.INFO.intValue();

  private static final boolean isLogFine =
      logLevel == null ? true : logLevel.intValue() <= Level.FINE.intValue();

  private static final boolean isLogFiner =
      logLevel == null ? true : logLevel.intValue() <= Level.FINER.intValue();

  private static final boolean isLogFinest =
      logLevel == null ? true : logLevel.intValue() <= Level.FINEST.intValue();

  private static void logFine(String message, Object... args) {
    logger.log(Level.FINE, message, args);
  }

  private static void logFiner(String message, Object... args) {
    logger.log(Level.FINER, message, args);
  }

  private static void logFinest(String message, Object... args) {
    logger.log(Level.FINEST, message, args);
  }

  private static void logInfo(String message, Object... args) {
    logger.log(Level.INFO, message, args);
  }

  private static void logWarning(String message, Object... args) {
    logger.log(Level.WARNING, message, args);
  }

  private static void logSevere(String message, Object... args) {
    logger.log(Level.SEVERE, message, args);
  }

  private static void logException(Throwable ex) {
    logger.log(Level.SEVERE, null, ex);
  }
  // </editor-fold>

  private Iterable<Function> funitr;
  private FunctionSet fset;
  private Memory mem;

  public FunctionSetHelper(final Memory mem) {
    if (mem == null) throw new IllegalArgumentException("mem==null");
    this.mem = mem;
    this.funitr =
        new Iterable<Function>() {
          @Override
          public Iterator<Function> iterator() {
            List<Function> l = new ArrayList<Function>();
            for (Object o : mem.values()) {
              if (o instanceof Function) {
                l.add((Function) o);
              } else if (o instanceof FunctionSet) {
                for (Function f : ((FunctionSet) o).getFunctions()) {
                  l.add(f);
                }
              }
            }
            return l.iterator();
          }
        };
  }

  public FunctionSetHelper(Iterable<Function> funitr) {
    if (funitr == null) throw new IllegalArgumentException("funitr==null");
    this.funitr = funitr;
  }

  public FunctionSetHelper(Map<String, Set<Function>> map) {
    if (map == null) throw new IllegalArgumentException("map==null");
    final Map<String, Set<Function>> mp = map;
    this.funitr =
        new Iterable<Function>() {
          @Override
          public Iterator<Function> iterator() {
            List<Function> lfun = new ArrayList<Function>();
            for (Map.Entry<String, Set<Function>> en : mp.entrySet()) {
              lfun.addAll(en.getValue());
            }
            return lfun.iterator();
          }
        };
  }

  public FunctionSetHelper(FunctionSet fset) {
    this.fset = fset;
  }

  public Function first() {
    for (Function f : functions()) {
      return f;
    }
    return null;
  }

  // <editor-fold defaultstate="collapsed" desc="print()">
  public FunctionSetHelper print() {
    OutputStreamWriter w = new OutputStreamWriter(System.out);
    print(w);
    try {
      w.flush();
    } catch (IOException ex) {
      Logger.getLogger(FunctionSetHelper.class.getName()).log(Level.SEVERE, null, ex);
    }

    return this;
  }

  public FunctionSetHelper print(Writer w) {
    if (w == null) throw new IllegalArgumentException("w==null");

    SourceDump sdump = new SourceDump();
    int i = -1;
    for (Function f : functions()) {
      try {
        i++;
        //                String decl = f==null ? "null" : sdump.getDeclareOf(f);

        w.write(Integer.toString(i));
        w.write(". ");
        //                w.write(decl);
        w.write("\n");
      } catch (IOException ex) {
        Logger.getLogger(FunctionSetHelper.class.getName()).log(Level.SEVERE, null, ex);
      }
    }

    return this;
  }
  // </editor-fold>

  // <editor-fold defaultstate="collapsed" desc="functions()">
  public Iterable<Function> functions() {
    if (fset != null) return fset.getFunctions();
    if (funitr != null) return funitr;
    return Iterators.empty();
  }
  // </editor-fold>

  // <editor-fold defaultstate="collapsed" desc="filter">
  public Iterable<Function> filter(Iterable<Function> src, Predicate<Function> f) {
    if (src == null) throw new IllegalArgumentException("src==null");
    if (f == null) throw new IllegalArgumentException("f==null");
    return Iterators.predicate(src, f);
  }
  // </editor-fold>

  // <editor-fold defaultstate="collapsed" desc="argumentsCount">
  public Predicate<Function> argumentsCountFilter(final Predicate<Integer> countPred) {
    if (countPred == null) throw new IllegalArgumentException("countPred==null");
    return new Predicate<Function>() {
      @Override
      public boolean validate(Function t) {
        if (t == null) return false;
        return countPred.validate(t.getParameters().length);
      }
    };
  }

  public Predicate<Function> argumentsCountFilter(final int count) {
    return argumentsCountFilter(
        new Predicate<Integer>() {
          @Override
          public boolean validate(Integer t) {
            return count == t;
          }
        });
  }

  public FunctionSetHelper argumentsCount(int count) {
    return new FunctionSetHelper(filter(functions(), argumentsCountFilter(count)));
  }
  // </editor-fold>

  // <editor-fold defaultstate="collapsed" desc="assignFromFilter()">
  public Predicate<Class> assignFromFilter(final Class type) {
    if (type == null) throw new IllegalArgumentException("type==null");
    return new Predicate<Class>() {
      @Override
      public boolean validate(Class t) {
        if (t == null) return false;
        return t.isAssignableFrom(type);
      }
    };
  }

  public Predicate<Class> assignFromFilter2(final Class type) {
    if (type == null) throw new IllegalArgumentException("type==null");
    return new Predicate<Class>() {
      @Override
      public boolean validate(Class t) {
        if (t == null) return false;
        return type.isAssignableFrom(t);
      }
    };
  }
  // </editor-fold>

  // <editor-fold defaultstate="collapsed" desc="functionArguments()">
  public Predicate<Function> functionArgumentsFilter(final Predicate<Class>... argTypes) {
    if (argTypes == null) throw new IllegalArgumentException("argTypes==null");
    for (int ai = 0; ai < argTypes.length; ai++) {
      if (argTypes[ai] == null) throw new IllegalArgumentException("argTypes[" + ai + "]==null");
    }

    return new Predicate<Function>() {
      @Override
      public boolean validate(Function f) {
        if (f == null) return false;
        Class[] params = f.getParameters();
        if (params.length != argTypes.length) return false;
        for (int i = 0; i < params.length; i++) {
          boolean m = argTypes[i].validate(params[i]);
          if (!m) return false;
        }
        return true;
      }
    };
  }

  public FunctionSetHelper functionArguments(final Predicate<Class>... argTypes) {
    return new FunctionSetHelper(filter(functions(), functionArgumentsFilter(argTypes)));
  }
  // </editor-fold>

  // <editor-fold defaultstate="collapsed" desc="functionArgument()">
  public Predicate<Function> functionArgumentFilter(
      final int argumentIndex, final Predicate<Class> argType) {
    if (argType == null) throw new IllegalArgumentException("argType==null");
    return new Predicate<Function>() {
      @Override
      public boolean validate(Function f) {
        if (f == null) return false;
        Class[] params = f.getParameters();
        if (argumentIndex >= params.length || argumentIndex < 0) return false;
        return argType.validate(params[argumentIndex]);
      }
    };
  }

  public FunctionSetHelper functionArgument(
      final int argumentIndex, final Predicate<Class> argType) {
    return new FunctionSetHelper(
        filter(functions(), functionArgumentFilter(argumentIndex, argType)));
  }
  // </editor-fold>

  // <editor-fold defaultstate="collapsed" desc="named()">
  public FunctionSetHelper named(final String name) {
    if (name == null) throw new IllegalArgumentException("name==null");
    if (mem == null) return new FunctionSetHelper(Iterators.<Function>empty());

    Object o = mem.get(name);
    if (o instanceof Function) {
      FunctionSetHelper fs = new FunctionSetHelper(Iterators.<Function>single((Function) o));
      fs.mem = mem;
      return fs;
    }

    if (o instanceof FunctionSet) {
      FunctionSetHelper fs = new FunctionSetHelper(((FunctionSet) o).getFunctions());
      fs.mem = mem;
      return fs;
    }

    return new FunctionSetHelper(Iterators.<Function>empty());
  }
  // </editor-fold>

  // <editor-fold defaultstate="collapsed" desc="operators()">
  public Predicate<Function> operatorFilter() {
    return new Predicate<Function>() {
      @Override
      public boolean validate(Function f) {
        if (f == null) return false;
        if (f instanceof IsOperator) {
          return ((IsOperator) f).isOperator();
        }
        return false;
      }
    };
  }

  public FunctionSetHelper operators() {
    return new FunctionSetHelper(filter(functions(), operatorFilter()));
  }
  // </editor-fold>

  // <editor-fold defaultstate="collapsed" desc="count()">
  public int count() {
    Iterable<Function> itrf = functions();
    long c = Iterators.count(itrf);

    return new Long(c).intValue();
  }
  // </editor-fold>

  public Predicate<Function> in(final Iterable<Function> src) {
    if (src == null) throw new IllegalArgumentException("src==null");
    return new Predicate<Function>() {
      @Override
      public boolean validate(Function f) {
        if (f == null) return false;
        return Iterators.in(f, src);
      }
    };
  }

  public Predicate<Function> not(final Predicate<Function> src) {
    if (src == null) throw new IllegalArgumentException("src==null");
    return new Predicate<Function>() {
      @Override
      public boolean validate(Function f) {
        if (f == null) return false;
        return !src.validate(f);
      }
    };
  }

  public Predicate<Function> and(final Predicate<Function>... src) {
    if (src == null) throw new IllegalArgumentException("src==null");
    return new Predicate<Function>() {
      @Override
      public boolean validate(Function f) {
        if (src == null) return false;
        if (src.length == 0) return false;
        for (Predicate<Function> p : src) {
          if (!p.validate(f)) return false;
        }
        return true;
      }
    };
  }

  public Predicate<Function> or(final Predicate<Function>... src) {
    if (src == null) throw new IllegalArgumentException("src==null");
    return new Predicate<Function>() {
      @Override
      public boolean validate(Function f) {
        if (src == null) return false;
        if (src.length == 0) return false;
        for (Predicate<Function> p : src) {
          if (p.validate(f)) return true;
        }
        return false;
      }
    };
  }
}
Beispiel #6
0
/** @author [email protected] */
public abstract class UnaryAst extends Ast {
  // <editor-fold defaultstate="collapsed" desc="log Функции">
  private static final Logger logger = Logger.getLogger(UnaryAst.class.getName());
  private static final Level logLevel = logger.getLevel();

  private static final boolean isLogSevere =
      logLevel == null ? true : logLevel.intValue() <= Level.SEVERE.intValue();

  private static final boolean isLogWarning =
      logLevel == null ? true : logLevel.intValue() <= Level.WARNING.intValue();

  private static final boolean isLogInfo =
      logLevel == null ? true : logLevel.intValue() <= Level.INFO.intValue();

  private static final boolean isLogFine =
      logLevel == null ? true : logLevel.intValue() <= Level.FINE.intValue();

  private static final boolean isLogFiner =
      logLevel == null ? true : logLevel.intValue() <= Level.FINER.intValue();

  private static final boolean isLogFinest =
      logLevel == null ? true : logLevel.intValue() <= Level.FINEST.intValue();

  private static void logFine(String message, Object... args) {
    logger.log(Level.FINE, message, args);
  }

  private static void logFiner(String message, Object... args) {
    logger.log(Level.FINER, message, args);
  }

  private static void logFinest(String message, Object... args) {
    logger.log(Level.FINEST, message, args);
  }

  private static void logInfo(String message, Object... args) {
    logger.log(Level.INFO, message, args);
  }

  private static void logWarning(String message, Object... args) {
    logger.log(Level.WARNING, message, args);
  }

  private static void logSevere(String message, Object... args) {
    logger.log(Level.SEVERE, message, args);
  }

  private static void logException(Throwable ex) {
    logger.log(Level.SEVERE, null, ex);
  }

  private static void logEntering(String method, Object... params) {
    logger.entering(UnaryAst.class.getName(), method, params);
  }

  private static void logExiting(String method) {
    logger.exiting(UnaryAst.class.getName(), method);
  }

  private static void logExiting(String method, Object result) {
    logger.exiting(UnaryAst.class.getName(), method, result);
  }
  // </editor-fold>

  protected Ast leaf;

  public synchronized Ast getLeaf() {
    return leaf;
  }

  public synchronized void setLeaf(Ast leaf) {
    this.leaf = leaf;
  }

  @Override
  public synchronized Ast[] getChildren() {
    if (leaf != null) return new Ast[] {leaf};
    return new Ast[] {};
  }
}
public class ReportPreferencePage extends FieldEditorPreferencePage
    implements IWorkbenchPreferencePage {

  private String[][] logLvlValues =
      new String[][] {
        new String[] {Messages.getString("ReportLogLevel.0"), Level.INFO.toString()},
        new String[] {Messages.getString("ReportLogLevel.1"), Level.WARNING.toString()},
        new String[] {Messages.getString("ReportLogLevel.2"), Level.FINEST.toString()},
        new String[] {Messages.getString("ReportLogLevel.3"), Level.SEVERE.toString()},
        new String[] {Messages.getString("ReportLogLevel.4"), Level.ALL.toString()}
      };
  private DirectoryFieldEditor localTemplateEditor;

  public ReportPreferencePage() {
    super(GRID);
    setDescription(Messages.getString("ReportPreferencePage.0")); // $NON-NLS-1$
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
   */
  @Override
  public void init(IWorkbench arg0) {
    setPreferenceStore(Activator.getDefault().getPreferenceStore());
  }

  /* (non-Javadoc)
   * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
   */
  @Override
  protected void createFieldEditors() {

    BooleanFieldEditor reportLoggingEditor =
        new BooleanFieldEditor(
            PreferenceConstants.REPORT_LOGGING_ENABLED,
            Messages.getString("ReportPreferencePage.1"),
            getFieldEditorParent());
    addField(reportLoggingEditor);

    ComboFieldEditor logLvlFieldEditor =
        new ComboFieldEditor(
            PreferenceConstants.REPORT_LOGGING_LVL,
            Messages.getString("ReportPreferencePage.2"),
            logLvlValues,
            getFieldEditorParent());
    addField(logLvlFieldEditor);

    DirectoryFieldEditor logFileNameEditor =
        new DirectoryFieldEditor(
            PreferenceConstants.REPORT_LOG_FILE,
            Messages.getString("ReportPreferencePage.3"),
            getFieldEditorParent());
    addField(logFileNameEditor);

    localTemplateEditor =
        new DirectoryFieldEditor(
            PreferenceConstants.REPORT_LOCAL_TEMPLATE_DIRECTORY,
            Messages.getString("ReportPreferencePage.8"),
            getFieldEditorParent());
    addField(localTemplateEditor);

    BooleanFieldEditor useCacheEditor =
        new BooleanFieldEditor(
            PreferenceConstants.REPORT_USE_CACHE,
            Messages.getString("ReportPreferencePage.7"),
            getFieldEditorParent());
    addField(useCacheEditor);
  }

  @Override
  public void propertyChange(PropertyChangeEvent event) {
    super.propertyChange(event);
    if (event.getProperty().equals(FieldEditor.VALUE)) {
      checkState();
    }

    if (event.getSource() == localTemplateEditor) {
      Activator.getDefault()
          .getIReportTemplateDirectoryService()
          .setDirectory((String) event.getNewValue());
    }
  }

  @Override
  protected void checkState() {
    super.checkState();
    if (!isValid()) {
      return;
    }
  }
}
/** @author Kamnev Georgiy ([email protected]) */
public class ReadedCachedIndex extends HttpRepoEvent {
  // <editor-fold defaultstate="collapsed" desc="log Функции">
  private static final Logger logger = Logger.getLogger(ReadedCachedIndex.class.getName());
  private static final Level logLevel = logger.getLevel();

  private static final boolean isLogSevere =
      logLevel == null ? true : logLevel.intValue() <= Level.SEVERE.intValue();

  private static final boolean isLogWarning =
      logLevel == null ? true : logLevel.intValue() <= Level.WARNING.intValue();

  private static final boolean isLogInfo =
      logLevel == null ? true : logLevel.intValue() <= Level.INFO.intValue();

  private static final boolean isLogFine =
      logLevel == null ? true : logLevel.intValue() <= Level.FINE.intValue();

  private static final boolean isLogFiner =
      logLevel == null ? true : logLevel.intValue() <= Level.FINER.intValue();

  private static final boolean isLogFinest =
      logLevel == null ? true : logLevel.intValue() <= Level.FINEST.intValue();

  private static void logFine(String message, Object... args) {
    logger.log(Level.FINE, message, args);
  }

  private static void logFiner(String message, Object... args) {
    logger.log(Level.FINER, message, args);
  }

  private static void logFinest(String message, Object... args) {
    logger.log(Level.FINEST, message, args);
  }

  private static void logInfo(String message, Object... args) {
    logger.log(Level.INFO, message, args);
  }

  private static void logWarning(String message, Object... args) {
    logger.log(Level.WARNING, message, args);
  }

  private static void logSevere(String message, Object... args) {
    logger.log(Level.SEVERE, message, args);
  }

  private static void logException(Throwable ex) {
    logger.log(Level.SEVERE, null, ex);
  }
  // </editor-fold>

  private HttpRepo.CachedRepoIndex cachedRepoIndex;
  private RepoIndex index;

  public ReadedCachedIndex(
      HttpRepo repo, HttpRepo.CachedRepoIndex cachedRepoIndex, RepoIndex index) {
    super(repo);
    this.cachedRepoIndex = cachedRepoIndex;
    this.index = index;
  }

  public HttpRepo.CachedRepoIndex getCachedRepoIndex() {
    return cachedRepoIndex;
  }

  public RepoIndex getIndex() {
    return index;
  }
}
Beispiel #9
0
/** @author Kamnev Georgiy ([email protected]) */
public class AddArgument implements Argument {
  // <editor-fold defaultstate="collapsed" desc="log Функции">
  private static final Logger logger = Logger.getLogger(AddArgument.class.getName());
  private static final Level logLevel = logger.getLevel();
  private static final boolean isLogSevere =
      logLevel == null ? true : logLevel.intValue() <= Level.SEVERE.intValue();

  private static final boolean isLogWarning =
      logLevel == null ? true : logLevel.intValue() <= Level.WARNING.intValue();

  private static final boolean isLogInfo =
      logLevel == null ? true : logLevel.intValue() <= Level.INFO.intValue();

  private static final boolean isLogFine =
      logLevel == null ? true : logLevel.intValue() <= Level.FINE.intValue();

  private static final boolean isLogFiner =
      logLevel == null ? true : logLevel.intValue() <= Level.FINER.intValue();

  private static final boolean isLogFinest =
      logLevel == null ? true : logLevel.intValue() <= Level.FINEST.intValue();

  private static void logFine(String message, Object... args) {
    logger.log(Level.FINE, message, args);
  }

  private static void logFiner(String message, Object... args) {
    logger.log(Level.FINER, message, args);
  }

  private static void logFinest(String message, Object... args) {
    logger.log(Level.FINEST, message, args);
  }

  private static void logInfo(String message, Object... args) {
    logger.log(Level.INFO, message, args);
  }

  private static void logWarning(String message, Object... args) {
    logger.log(Level.WARNING, message, args);
  }

  private static void logSevere(String message, Object... args) {
    logger.log(Level.SEVERE, message, args);
  }

  private static void logException(Throwable ex) {
    logger.log(Level.SEVERE, null, ex);
  }
  // </editor-fold>

  public AddArgument() {}

  public AddArgument(String value) {
    this.value = value;
  }

  public AddArgument(int index, String value) {
    this.value = value;
    this.index = index;
  }

  private final Lock lock = new ReentrantLock();

  private String value;

  public String getValue() {
    try {
      lock.lock();
      return value;
    } finally {
      lock.unlock();
    }
  }

  public void setValue(String value) {
    try {
      lock.lock();
      this.value = value;
    } finally {
      lock.unlock();
    }
  }

  private int index = -1;

  public int getIndex() {
    try {
      lock.lock();
      return index;
    } finally {
      lock.unlock();
    }
  }

  public void setIndex(int index) {
    try {
      lock.lock();
      this.index = index;
    } finally {
      lock.unlock();
    }
  }

  @Override
  public List<String> build(List<String> args) {
    try {
      lock.lock();
      List<String> res = new ArrayList<String>();
      if (args != null) {
        res.addAll(args);
      }

      if (value != null && res != null) {
        if (index >= 0) {
          if (index >= res.size()) {
            res.add(value);
          } else {
            res.add(index, value);
          }
        } else {
          res.add(value);
        }
      }
      return res;
    } finally {
      lock.unlock();
    }
  }
}
Beispiel #10
0
public class Jul2Slf4jHandler extends Handler {

  private static final String FQCN = java.util.logging.Logger.class.getName();
  private static final String UNKNOWN_LOGGER_NAME = "unknown.jul.logger";

  private static final int TRACE_LEVEL_THRESHOLD = Level.FINEST.intValue();
  private static final int DEBUG_LEVEL_THRESHOLD = Level.FINE.intValue();
  private static final int INFO_LEVEL_THRESHOLD = Level.INFO.intValue();
  private static final int WARN_LEVEL_THRESHOLD = Level.WARNING.intValue();

  @Nullable private final ILoggerFactory _loggerFactory;

  public Jul2Slf4jHandler() {
    this(null);
  }

  public Jul2Slf4jHandler(@Nullable ILoggerFactory loggerFactory) {
    _loggerFactory = loggerFactory;
  }

  @Override
  public void close() {}

  @Override
  public void flush() {}

  @Nullable
  protected Logger getSLF4JLogger(@Nonnull LogRecord record) {
    final String name = record.getLoggerName();
    return logger(name != null ? name : UNKNOWN_LOGGER_NAME);
  }

  protected void callLocationAwareLogger(LocationAwareLogger lal, LogRecord record) {
    final int julLevelValue = record.getLevel().intValue();
    final int slf4jLevel;
    if (julLevelValue <= TRACE_LEVEL_THRESHOLD) {
      slf4jLevel = LocationAwareLogger.TRACE_INT;
    } else if (julLevelValue <= DEBUG_LEVEL_THRESHOLD) {
      slf4jLevel = LocationAwareLogger.DEBUG_INT;
    } else if (julLevelValue <= INFO_LEVEL_THRESHOLD) {
      slf4jLevel = LocationAwareLogger.INFO_INT;
    } else if (julLevelValue <= WARN_LEVEL_THRESHOLD) {
      slf4jLevel = LocationAwareLogger.WARN_INT;
    } else {
      slf4jLevel = LocationAwareLogger.ERROR_INT;
    }
    final String i18nMessage = getMessageI18N(record);
    lal.log(null, FQCN, slf4jLevel, i18nMessage, null, record.getThrown());
  }

  protected void callPlainSLF4JLogger(@Nonnull Logger slf4jLogger, LogRecord record) {
    final String i18nMessage = getMessageI18N(record);
    final int julLevelValue = record.getLevel().intValue();
    if (julLevelValue <= TRACE_LEVEL_THRESHOLD) {
      slf4jLogger.trace(i18nMessage, record.getThrown());
    } else if (julLevelValue <= DEBUG_LEVEL_THRESHOLD) {
      slf4jLogger.debug(i18nMessage, record.getThrown());
    } else if (julLevelValue <= INFO_LEVEL_THRESHOLD) {
      slf4jLogger.info(i18nMessage, record.getThrown());
    } else if (julLevelValue <= WARN_LEVEL_THRESHOLD) {
      slf4jLogger.warn(i18nMessage, record.getThrown());
    } else {
      slf4jLogger.error(i18nMessage, record.getThrown());
    }
  }

  @Nullable
  protected String getMessageI18N(@Nonnull LogRecord record) {
    String message = record.getMessage();
    if (message != null) {
      final ResourceBundle bundle = record.getResourceBundle();
      if (bundle != null) {
        try {
          message = bundle.getString(message);
        } catch (final MissingResourceException ignored) {
        }
      }
      final Object[] params = record.getParameters();
      if (params != null && params.length > 0) {
        message = MessageFormat.format(message, params);
      }
    }
    return message;
  }

  @Override
  public void publish(@Nullable LogRecord record) {
    if (record != null) {
      final Logger slf4jLogger = getSLF4JLogger(record);
      if (slf4jLogger instanceof LocationAwareLogger) {
        callLocationAwareLogger((LocationAwareLogger) slf4jLogger, record);
      } else {
        callPlainSLF4JLogger(slf4jLogger, record);
      }
    }
  }

  @Nonnull
  protected Logger logger(@Nonnull String name) {
    return _loggerFactory != null ? _loggerFactory.getLogger(name) : LoggerFactory.getLogger(name);
  }
}
Beispiel #11
0
/** @author Kamnev Georgiy ([email protected]) */
public class FileVar {
  // <editor-fold defaultstate="collapsed" desc="log Функции">
  private static final Logger logger = Logger.getLogger(FileVar.class.getName());
  private static final Level logLevel = logger.getLevel();
  private static final boolean isLogSevere =
      logLevel == null ? true : logLevel.intValue() <= Level.SEVERE.intValue();

  private static final boolean isLogWarning =
      logLevel == null ? true : logLevel.intValue() <= Level.WARNING.intValue();

  private static final boolean isLogInfo =
      logLevel == null ? true : logLevel.intValue() <= Level.INFO.intValue();

  private static final boolean isLogFine =
      logLevel == null ? true : logLevel.intValue() <= Level.FINE.intValue();

  private static final boolean isLogFiner =
      logLevel == null ? true : logLevel.intValue() <= Level.FINER.intValue();

  private static final boolean isLogFinest =
      logLevel == null ? true : logLevel.intValue() <= Level.FINEST.intValue();

  private static void logFine(String message, Object... args) {
    logger.log(Level.FINE, message, args);
  }

  private static void logFiner(String message, Object... args) {
    logger.log(Level.FINER, message, args);
  }

  private static void logFinest(String message, Object... args) {
    logger.log(Level.FINEST, message, args);
  }

  private static void logInfo(String message, Object... args) {
    logger.log(Level.INFO, message, args);
  }

  private static void logWarning(String message, Object... args) {
    logger.log(Level.WARNING, message, args);
  }

  private static void logSevere(String message, Object... args) {
    logger.log(Level.SEVERE, message, args);
  }

  private static void logException(Throwable ex) {
    logger.log(Level.SEVERE, null, ex);
  }
  // </editor-fold>

  private final File file;

  public FileVar(File file) {
    if (file == null) throw new IllegalArgumentException("file==null");
    this.file = file;
  }

  public File getFile() {
    return file;
  }

  public FileSystem getFileSystem() {
    return file.getFileSystem();
  }

  public FileVar getParent() {
    File f = file.getParent();
    if (f != null) return new FileVar(f);
    return null;
  }

  public FileVar getChild(String name) {
    File f = file.getChild(name);
    if (f != null) return new FileVar(f);
    return null;
  }

  public FileVar getCanonical() {
    File f = file.getCanonical();
    if (f != null) return new FileVar(f);
    return null;
  }

  public FileVar getAbsolute() {
    File f = file.getAbsolute();
    if (f != null) return new FileVar(f);
    return null;
  }

  public boolean isDirectory() {
    return file.isDirectory();
  }

  public boolean isFile() {
    return file.isFile();
  }

  public boolean isExists() {
    return file.isExists();
  }

  public DateVar getModifyDate() {
    //        return file.getModifyDate();
    return new DateVar(file.getModifyDate());
  }

  public long getLength() {
    return file.getLength();
  }

  public String getSizeRound() {
    return new ByteSize(file.getLength()).toStringRoundMin(2);
  }

  public boolean isReadable() {
    return file.isReadable();
  }

  public boolean isWritable() {
    return file.isWritable();
  }

  public boolean isExecutable() {
    return file.isExecutable();
  }

  public String getName() {
    return file.getName();
  }

  public String getPath() {
    return file.getPath();
  }

  public boolean isAbsolute() {
    return file.isAbsolute();
  }

  public boolean isRoot() {
    return file.isRoot();
  }
}
/** @author Kamnev Georgiy ([email protected]) */
public class ComponentCheckChangesBegin extends HttpBegin {
  // <editor-fold defaultstate="collapsed" desc="log Функции">
  private static final Logger logger = Logger.getLogger(ComponentCheckChangesBegin.class.getName());
  private static final Level logLevel = logger.getLevel();

  private static final boolean isLogSevere =
      logLevel == null ? true : logLevel.intValue() <= Level.SEVERE.intValue();

  private static final boolean isLogWarning =
      logLevel == null ? true : logLevel.intValue() <= Level.WARNING.intValue();

  private static final boolean isLogInfo =
      logLevel == null ? true : logLevel.intValue() <= Level.INFO.intValue();

  private static final boolean isLogFine =
      logLevel == null ? true : logLevel.intValue() <= Level.FINE.intValue();

  private static final boolean isLogFiner =
      logLevel == null ? true : logLevel.intValue() <= Level.FINER.intValue();

  private static final boolean isLogFinest =
      logLevel == null ? true : logLevel.intValue() <= Level.FINEST.intValue();

  private static void logFine(String message, Object... args) {
    logger.log(Level.FINE, message, args);
  }

  private static void logFiner(String message, Object... args) {
    logger.log(Level.FINER, message, args);
  }

  private static void logFinest(String message, Object... args) {
    logger.log(Level.FINEST, message, args);
  }

  private static void logInfo(String message, Object... args) {
    logger.log(Level.INFO, message, args);
  }

  private static void logWarning(String message, Object... args) {
    logger.log(Level.WARNING, message, args);
  }

  private static void logSevere(String message, Object... args) {
    logger.log(Level.SEVERE, message, args);
  }

  private static void logException(Throwable ex) {
    logger.log(Level.SEVERE, null, ex);
  }
  // </editor-fold>

  public ComponentCheckChangesBegin(HttpRepo repo) {
    super(repo);
  }

  public ComponentCheckChangesBegin(HttpRepo repo, HttpRequest request) {
    super(repo, request);
  }

  public ComponentCheckChangesBegin(
      HttpRepo repo, HttpRequest request, HttpResponse response, ComponentID cid) {
    super(repo, request, response);
    this.cid = cid;
  }

  private ComponentID cid;

  public ComponentID getCid() {
    return cid;
  }
}
/** @author [email protected] */
public class EditorConfigParser {
  // <editor-fold defaultstate="collapsed" desc="log Функции">
  private static final Logger logger = Logger.getLogger(EditorConfigParser.class.getName());
  private static final Level logLevel = logger.getLevel();

  private static final boolean isLogSevere =
      logLevel == null ? true : logLevel.intValue() <= Level.SEVERE.intValue();

  private static final boolean isLogWarning =
      logLevel == null ? true : logLevel.intValue() <= Level.WARNING.intValue();

  private static final boolean isLogInfo =
      logLevel == null ? true : logLevel.intValue() <= Level.INFO.intValue();

  private static final boolean isLogFine =
      logLevel == null ? true : logLevel.intValue() <= Level.FINE.intValue();

  private static final boolean isLogFiner =
      logLevel == null ? true : logLevel.intValue() <= Level.FINER.intValue();

  private static final boolean isLogFinest =
      logLevel == null ? true : logLevel.intValue() <= Level.FINEST.intValue();

  private static void logFine(String message, Object... args) {
    logger.log(Level.FINE, message, args);
  }

  private static void logFiner(String message, Object... args) {
    logger.log(Level.FINER, message, args);
  }

  private static void logFinest(String message, Object... args) {
    logger.log(Level.FINEST, message, args);
  }

  private static void logInfo(String message, Object... args) {
    logger.log(Level.INFO, message, args);
  }

  private static void logWarning(String message, Object... args) {
    logger.log(Level.WARNING, message, args);
  }

  private static void logSevere(String message, Object... args) {
    logger.log(Level.SEVERE, message, args);
  }

  private static void logException(Throwable ex) {
    logger.log(Level.SEVERE, null, ex);
  }

  private static void logEntering(String method, Object... params) {
    logger.entering(EditorConfigParser.class.getName(), method, params);
  }

  private static void logExiting(String method) {
    logger.exiting(EditorConfigParser.class.getName(), method);
  }

  private static void logExiting(String method, Object result) {
    logger.exiting(EditorConfigParser.class.getName(), method, result);
  }
  // </editor-fold>

  //    pu
}
Beispiel #14
0
 public static boolean isVerbose() {
   return Level.FINEST.equals(LOGGER.getLevel());
 }