Finders.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
3 
4  This file is part of the TerraLib - a Framework for building GIS enabled
5  applications.
6 
7  TerraLib is free software: you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation, either version 3 of the License,
10  or (at your option) any later version.
11 
12  TerraLib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with TerraLib. See COPYING. If not, write to
19  TerraLib Team at <terralib-team@terralib.org>.
20  */
21 
22 /*!
23  \file terralib/core/plugin/Finders.cpp
24 
25  \brief General utilities for searching for plugins.
26 
27  \author Gilberto Ribeiro de Queiroz
28  \author Matheus Cavassan Zaglia
29  */
30 
31 // TerraLib
32 #include "Finders.h"
33 #include "../filesystem/FileSystem.h"
34 #include "../utils/Platform.h"
35 #include "Exception.h"
36 #include "Serializers.h"
37 #include "Utils.h"
38 
39 // Boost
40 #include <boost/algorithm/string/predicate.hpp>
41 #include <boost/filesystem.hpp>
42 
43 static std::vector<std::string> GetDefaultLookupDirs();
44 
45 static std::vector<te::core::PluginInfo> GetPluginsInfo(const std::vector<std::string>& lookup_dirs)
46 {
47  std::vector<te::core::PluginInfo> found_plugins;
48 
49  for (const std::string& plugins_dir : lookup_dirs)
50  {
51  if (plugins_dir.empty() || !te::core::FileSystem::isDirectory(plugins_dir))
52  continue;
53 
54  boost::filesystem::path p(plugins_dir);
55 
56  std::vector<std::string> dir =
58  for (std::string file : dir)
59  {
61  continue;
62  if (boost::algorithm::ends_with(file, ".teplg.json"))
63  {
65 
66  found_plugins.push_back(pinfo);
67  }
68  }
69  }
70 
71  return found_plugins;
72 }
73 
74 std::vector<te::core::PluginInfo> te::core::DefaultPluginFinder()
75 {
76  // Retrieve the list of default directories to look up.
77  std::vector<std::string> lookup_dirs = GetDefaultLookupDirs();
78 
79  return GetPluginsInfo(lookup_dirs);
80 }
81 
82 static std::vector<std::string> GetDefaultLookupDirs()
83 {
84  std::vector<std::string> plugin_directories;
85 
86  // Add application current directory as a search path
87  plugin_directories.push_back(
89 
90  // Let's check if there is a directory called "share/terralib/plugins" in the
91  // application path
92  std::string plg_dir = te::core::FindInTerraLibPath("share/terralib/plugins");
93 
94  if (!plg_dir.empty())
95  plugin_directories.push_back(plg_dir);
96 
97  return plugin_directories;
98 }
99 
100 std::vector<te::core::PluginInfo> te::core::PluginFinder(const std::vector<std::string>& dirs)
101 {
102  // Getting default plugins info
103  std::vector<te::core::PluginInfo> info = DefaultPluginFinder();
104 
105  // Getting addtional plug-ins info from configuration files
106  std::vector<te::core::PluginInfo> add_info = GetPluginsInfo(dirs);
107 
108  if (!add_info.empty())
109  info.insert(info.end(), add_info.begin(), add_info.end());
110 
111  return info;
112 }
static std::vector< std::string > GetDefaultLookupDirs()
Definition: Finders.cpp:82
TECOREEXPORT std::vector< PluginInfo > PluginFinder(const std::vector< std::string > &dirs)
Definition: Finders.cpp:100
static bool isDirectory(const std::string &path)
Checks if a given path in UTF-8 is a directory.
Definition: FileSystem.cpp:87
static std::vector< std::string > listDirectory(const std::string &path)
Lists a directory from a given path in UTF-8.
Definition: FileSystem.cpp:178
Basic information about a plugin.
General utilities for serializing plugin information.
static std::vector< te::core::PluginInfo > GetPluginsInfo(const std::vector< std::string > &lookup_dirs)
Definition: Finders.cpp:45
General utilities for plugins.
te::gm::Polygon * p
TECOREEXPORT PluginInfo JSONPluginInfoSerializer(const std::string &file_name)
A plugin finder that search for plugins in some special directories defined by compile time macros...
Definition: Serializers.cpp:44
static std::string systemCompletePath(const std::string &path)
Composes an absolute path for the given path in UTF-8.
Definition: FileSystem.cpp:56
TECOREEXPORT std::string FindInTerraLibPath(const std::string &path)
Returns the path relative to a directory or file in the context of TerraLib.
TECOREEXPORT std::vector< PluginInfo > DefaultPluginFinder()
Definition: Finders.cpp:74
General utilities for searching for plugins.
static bool isRegularFile(const std::string &path)
Checks if a given path in UTF-8 is a regular file.
Definition: FileSystem.cpp:98
file(WRITE ${CMAKE_BINARY_DIR}/config_qhelp.cmake"configure_file (${TERRALIB_ABSOLUTE_ROOT_DIR}/doc/qhelp/help.qhcp.in ${CMAKE_BINARY_DIR}/share/terraview/help/help.qhcp @ONLY)") add_custom_command(OUTPUT del_dir COMMAND $