コード例 #1
0
ファイル: parser.cpp プロジェクト: Ericsson/CodeCompass
int main(int argc, char* argv[])
{
  std::string compassRoot = cc::util::binaryPathToInstallDir(argv[0]);

  const std::string PARSER_PLUGIN_DIR = compassRoot + "/lib/parserplugin";
  const std::string SQL_DIR = compassRoot + "/share/codecompass/sql";

  cc::util::initLogger();

  //--- Process command line arguments ---//

  po::options_description desc = commandLineArguments();

  po::variables_map vm;
  po::store(po::command_line_parser(argc, argv)
    .options(desc).allow_unregistered().run(), vm);

  //--- Skip parser list ---//

  std::vector<std::string> skipParserList;
  if (vm.count("skip"))
    skipParserList = vm["skip"].as<std::vector<std::string>>();

  //--- Load parsers ---//

  cc::parser::PluginHandler pHandler(PARSER_PLUGIN_DIR);
  pHandler.loadPlugins(skipParserList);

  //--- Add arguments of parsers ---//

  po::options_description pluginOptions = pHandler.getOptions();
  desc.add(pluginOptions);

  po::store(po::parse_command_line(argc, argv, desc), vm);

  if (argc < 2 || vm.count("help"))
  {
    std::cout << desc << std::endl;
    return 0;
  }

  if (vm.count("loglevel"))
  {
    trivial::severity_level loglevel
      = vm["loglevel"].as<trivial::severity_level>();
    boost::shared_ptr<boost::log::core> logger = boost::log::core::get();
    logger->set_filter(boost::log::expressions::attr<
      trivial::severity_level>("Severity") >= loglevel);
    logger->add_global_attribute("Severity",
      boost::log::attributes::mutable_constant<trivial::severity_level>(
        loglevel));
  }

  if (vm.count("list"))
  {
    std::cout << "Available plugins:" << std::endl;

    for (const std::string& pluginName : pHandler.getPluginNames())
      std::cout << " - " << pluginName << std::endl;

    return 0;
  }

  try
  {
    po::notify(vm);
  }
  catch (const po::error& e)
  {
    LOG(error) << "Error in command line arguments: " << e.what();
    return 1;
  }
  
  //--- Check database and project directory existence ---//
  
  bool isNewDb = cc::util::connectDatabase(
    vm["database"].as<std::string>(), false) == nullptr;
  bool isNewProject = !checkProjectDir(vm);

  if ((isNewProject ^ isNewDb) && !vm.count("force"))
  {
    LOG(error) << "Database and working directory existence are inconsistent. "
      "Use -f for reparsing!";
    return 1;
  }

  if (!isNewDb && !vm.count("force"))
  {
    LOG(info)
      << "Project already exists, incremental parsing in action"
      << (vm.count("dry-run") ? " (DRY RUN)" : "") << ".";
  }

  if (isNewDb && vm.count("dry-run"))
  {
    LOG(error) << "Dry-run can be only used with incremental parsing, "
      "no project found. Try turning --dry-run off.";
    return 1;
  }

  //--- Prepare workspace and project directory ---//
  
  std::string projDir = prepareProjectDir(vm);
  if (projDir.empty())
    return 1;

  //--- Create and init database ---//

  std::shared_ptr<odb::database> db = cc::util::connectDatabase(
    vm["database"].as<std::string>(), true);

  std::unordered_map<std::string, cc::parser::IncrementalStatus> fileStatus;

  if (!db)
  {
    LOG(error) << "Couldn't connect to database. Check the connection string. "
      "Connection string format: \"" +
      cc::util::getDbDriver() + ":<opt1>=<val1>;<opt2>=<val2>...\"";
    return 1;
  }

  if (vm.count("force"))
    cc::util::removeTables(db, SQL_DIR);

  if (vm.count("force") || isNewDb)
    cc::util::createTables(db, SQL_DIR);

  //--- Start parsers ---//

  cc::parser::SourceManager srcMgr(db);
  cc::parser::ParserContext ctx(db, srcMgr, compassRoot, vm);
  pHandler.createPlugins(ctx);

  // TODO: Handle errors returned by preparse().
  std::vector<std::string> topologicalOrder = pHandler.getTopologicalOrder();
  for (auto it = topologicalOrder.rbegin(); it != topologicalOrder.rend(); ++it)
  {
    LOG(info) << "[" << *it << "] preparse started!";
    if (!pHandler.getParser(*it)->preparse(vm.count("dry-run")))
    {
      LOG(error) << "[" << *it << "] preparse failed!";
      return 2;
    }
  }

  if (vm.count("dry-run"))
  {
    incrementalList(ctx);
  }
  else
  {
    incrementalCleanup(ctx);

    // TODO: Handle errors returned by parse().
    for (const std::string& parserName : pHandler.getTopologicalOrder())
    {
      LOG(info) << "[" << parserName << "] parse started!";
      pHandler.getParser(parserName)->parse();
    }
  }

  //--- Add indexes to the database ---//

  if (vm.count("force") || isNewDb)
    cc::util::createIndexes(db, SQL_DIR);

  //--- Create project config file ---//

  boost::property_tree::ptree pt;

  if (vm.count("label"))
  {
    boost::property_tree::ptree labels;

    for (const std::string& label : vm["label"].as<std::vector<std::string>>())
    {
      std::size_t pos = label.find('=');

      if (pos == std::string::npos)
        LOG(warning)
          << "Label doesn't contain '=' for separating label and the path: "
          << label;
      else
        labels.put(label.substr(0, pos), label.substr(pos + 1));
    }

    pt.add_child("labels", labels);
  }

  std::string database
    = cc::util::connStrComponent(vm["database"].as<std::string>(), "database");

  pt.put(
    "database",
    database.empty() ? vm["name"].as<std::string>() : database);

  if (vm.count("description"))
    pt.put("description", vm["description"].as<std::string>());

  boost::property_tree::write_json(projDir + "/project_info.json", pt);

  // TODO: Print statistics.

  return 0;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: rafalka/rs232testng
int main(int argc, char *argv[])
{
    int res = -1;

    fprintf(stderr,"No i dupa\n");

    try
    {
    QApplication a(argc, argv);
    modulename = a.applicationName().toAscii().constData();

    int        valInt=123456;
    QString    valString="Ala ma kota na punkcie psa";
    QStringList valStrList;

    valStrList << "Ala" << "Ma" << "Kota" << "Na" << "Punkcie" << "Psa";

    CONF_START_GROUP( debug );
    CONF_STORE_VAL( valInt );
    CONF_STORE_VAL( valString );
    CONF_STORE_VAL( valStrList );

    CONF_READ_VAL( valInt, -1 );
    CONF_READ_VAL( valString, "No i dupa" );

    CONF_END_GROUP( debug );


    rs232testng w;

    HtmlDisplayOutputProvider   htmlOut;
    ProviderManager             outMgr( OutputModifierFactory::instance() );
    ProviderManager             srcMgr( SourceProviderFactory::instance() );
    ProviderManager             inMgr(  InputProviderFactory::instance() );
    TextEnterInputProvider      textIn;

    QStreamManager              stramMgr;

    Q_ASSERT( QObject::connect( &htmlOut, SIGNAL( streamChanged(StreamItem*) ),
            &stramMgr,   SLOT( onOutStreamChanged(StreamItem*) ) ) );

    Q_ASSERT( QObject::connect( &outMgr, SIGNAL( streamChanged(StreamItem*) ),
            &stramMgr,   SLOT( onOutModStreamChanged(StreamItem*) ) ) );

    Q_ASSERT( QObject::connect( &srcMgr, SIGNAL( streamChanged(StreamItem*) ),
            &stramMgr,   SLOT( onSourceStreamChanged(StreamItem*) ) ) );

    Q_ASSERT( QObject::connect( &inMgr, SIGNAL( streamChanged(StreamItem*) ),
            &stramMgr,   SLOT( onInModStreamChanged(StreamItem*) ) ) );

    Q_ASSERT( QObject::connect( &textIn, SIGNAL( streamChanged(StreamItem*) ),
            &stramMgr,   SLOT( onInStreamChanged(StreamItem*) ) ) );

    htmlOut.SetupUI( w.getOutputArea() );
    outMgr.SetupUI(  w.getOutputManagerArea() );
    srcMgr.SetupUI(  w.getSourceManagerArea() );
    textIn.SetupUI(  w.getInputArea() );
    inMgr.SetupUI(   w.getInputManagerArea() );



    w.show();




/*
    QStreamManager stramMgr(w.ui.editIn, w.ui.editOut);



    Q_ASSERT( QObject::connect( &srcMgr, SIGNAL( providerChanged(SourceProvider*) ),
            &stramMgr,   SLOT( onSourceProviderChanged(SourceProvider*) ) ) );
*/
    res = a.exec();

    }
    /*
    catch (Error &err) {
        _ERRMSG2( "ERROR %d: %s\n", err.code() , err.msg() );
        res = err.code();
    }
    */
    catch (std::exception &err) {
        _ERRMSG1( "ERROR %s\n", err.what() );
        res = -1;
    }
    catch (...) {
        _ERRMSG("Internal error\n");
        res = -1;
    }
    return res;
}