void compile(const std::string& path) { Page page; FileInputStream srcStream(path); PageReader pageReader(page, path); pageReader.emitLineDirectives(_emitLineDirectives); pageReader.parse(srcStream); Path p(path); config().setString("inputFileName", p.getFileName()); config().setString("inputFilePath", p.toString()); DateTime now; config().setString("dateTime", DateTimeFormatter::format(now, DateTimeFormat::SORTABLE_FORMAT)); std::string clazz; if (page.has("page.class")) { clazz = page.get("page.class"); p.setBaseName(clazz); } else { clazz = p.getBaseName() + "Handler"; clazz[0] = Poco::Ascii::toUpper(clazz[0]); } std::auto_ptr<CodeWriter> pCodeWriter(createCodeWriter(page, clazz)); if (!_outputDir.empty()) { p = Path(_outputDir, p.getBaseName()); } p.setExtension("cpp"); std::string implPath = p.toString(); std::string implFileName = p.getFileName(); if (!_headerOutputDir.empty()) { p = Path(_headerOutputDir, p.getBaseName()); } p.setExtension("h"); std::string headerPath = p.toString(); std::string headerFileName = p.getFileName(); config().setString("outputFileName", implFileName); config().setString("outputFilePath", implPath); FileOutputStream implStream(implPath); OutputLineEndingConverter implLEC(implStream); writeFileHeader(implLEC); pCodeWriter->writeImpl(implLEC, _headerPrefix + headerFileName); config().setString("outputFileName", headerFileName); config().setString("outputFilePath", headerPath); FileOutputStream headerStream(headerPath); OutputLineEndingConverter headerLEC(headerStream); writeFileHeader(headerLEC); pCodeWriter->writeHeader(headerLEC, headerFileName); }
void write(const std::string& path, const Page& page, const std::string& clazz) { Path p(path); config().setString("inputFileName", p.getFileName()); config().setString("inputFilePath", p.toString()); DateTime now; config().setString("dateTime", DateTimeFormatter::format(now, DateTimeFormat::SORTABLE_FORMAT)); if (page.has("page.class")) { p.setBaseName(clazz); } std::unique_ptr<CodeWriter> pCodeWriter(createCodeWriter(page, clazz)); if (!_outputDir.empty()) { p = Path(_outputDir, p.getBaseName()); } if (!_base.empty()) { p.setBaseName(_base); } p.setExtension("cpp"); std::string implPath = p.toString(); std::string implFileName = p.getFileName(); if (!_headerOutputDir.empty()) { p = Path(_headerOutputDir, p.getBaseName()); } p.setExtension("h"); std::string headerPath = p.toString(); std::string headerFileName = p.getFileName(); config().setString("outputFileName", implFileName); config().setString("outputFilePath", implPath); FileOutputStream implStream(implPath); OutputLineEndingConverter implLEC(implStream); writeFileHeader(implLEC); pCodeWriter->writeImpl(implLEC, _headerPrefix + headerFileName); config().setString("outputFileName", headerFileName); config().setString("outputFilePath", headerPath); FileOutputStream headerStream(headerPath); OutputLineEndingConverter headerLEC(headerStream); writeFileHeader(headerLEC); pCodeWriter->writeHeader(headerLEC, headerFileName); }
void FileTest::testDirectory() { File d("testdir"); try { d.remove(true); } catch (...) { } TemporaryFile::registerForDeletion("testdir"); bool created = d.createDirectory(); assert (created); assert (d.isDirectory()); assert (!d.isFile()); std::vector<std::string> files; d.list(files); assert (files.empty()); File f = Path("testdir/file1", Path::PATH_UNIX); f.createFile(); f = Path("testdir/file2", Path::PATH_UNIX); f.createFile(); f = Path("testdir/file3", Path::PATH_UNIX); f.createFile(); d.list(files); assert (files.size() == 3); std::set<std::string> fs; fs.insert(files.begin(), files.end()); assert (fs.find("file1") != fs.end()); assert (fs.find("file2") != fs.end()); assert (fs.find("file3") != fs.end()); File dd(Path("testdir/testdir2/testdir3", Path::PATH_UNIX)); dd.createDirectories(); assert (dd.exists()); assert (dd.isDirectory()); File ddd(Path("testdir/testdirB/testdirC/testdirD", Path::PATH_UNIX)); ddd.createDirectories(); assert (ddd.exists()); assert (ddd.isDirectory()); d.remove(true); }
void AnthaxiaApp::initialize(Application& self) { Settings::loadSettings("procsim.rc"); Poco::AutoPtr<AbstractConfiguration> pConfig; if (Path("logging.cfg").isFile()) { pConfig = new PropertyFileConfiguration("logging.cfg"); } else { pConfig = new MapConfiguration(); } LoggingConfigurator configurator; configurator.configure(pConfig); Poco::LogStream log_stream(Poco::Logger::get("core.AnthaxiaApp")); LOG_DEBUG("Logging initialized; continue initialization of the rest"); addSubsystem( new PluginManager() ); // Make sure the model control is instantiated (void)ModelControl::getInstance(); // Make sure the service system is present (void)ServiceSystem::getServiceSystem(); registerModelControlService(); Application::initialize(self); }
void copyResources() { logger().information("Copying resources"); Path path(config().getString("PocoDoc.output", "doc")); if (config().hasProperty("PocoDoc.resources")) { std::string pages = config().getString("PocoDoc.resources"); StringTokenizer tokenizer(pages, ",\n", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); std::set<std::string> pageSet; for (StringTokenizer::Iterator it = tokenizer.begin(); it != tokenizer.end(); ++it) { Glob::glob(*it, pageSet); } for (std::set<std::string>::const_iterator it = pageSet.begin(); it != pageSet.end(); ++it) { try { copyResource(Path(*it), path); } catch (Poco::Exception& exc) { logger().log(exc); } } } }
void URIStreamOpenerTest::testStreamOpenerRelative() { TemporaryFile tempFile; std::string path = tempFile.path(); std::ofstream ostr(path.c_str()); assert (ostr.good()); ostr << "Hello, world!" << std::endl; ostr.close(); URI uri(Path(path).toString(Path::PATH_UNIX)); std::string uriString = uri.toString(); URIStreamOpener opener; std::istream* istr = opener.open(uri); assert (istr != 0); assert (istr->good()); delete istr; }
std::string BundleStreamFactoryTest::findBundle(const std::string& name) { std::string bundles("bundles"); std::string cwd(Path::current()); Path cwdPath(cwd); Path p(cwdPath, bundles); bool found = false; while (!found && p.depth() > 0) { File f(p); if (f.exists()) found = true; else p.popDirectory(); } if (found) return Path(p, name).toString(); else throw Poco::FileNotFoundException(name); }