Skip to content

Commit

Permalink
Bump in edifice: ign-common4 (#163)
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <[email protected]>
  • Loading branch information
chapulina authored Feb 21, 2021
1 parent 0f0b1ee commit dddb1ef
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/ci/packages.apt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ curl
libcurl4-openssl-dev
libgflags-dev
libignition-cmake2-dev
libignition-common3-dev
libignition-common4-dev
libignition-msgs7-dev
libignition-tools-dev
libjsoncpp-dev
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ ign_find_package(ZIP REQUIRED PRIVATE)

#--------------------------------------
# Find ignition-common
ign_find_package(ignition-common3 REQUIRED PRIVATE)
set(IGN_COMMON_MAJOR_VER ${ignition-common3_VERSION_MAJOR})
ign_find_package(ignition-common4 REQUIRED PRIVATE)
set(IGN_COMMON_MAJOR_VER ${ignition-common4_VERSION_MAJOR})

#--------------------------------------
# Find ignition-msgs
Expand Down
2 changes: 1 addition & 1 deletion bitbucket-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pipelines:
git libcurl4-openssl-dev libjsoncpp-dev libzip-dev libgflags-dev libtinyxml2-dev
lcov curl libyaml-dev
libignition-cmake2-dev
libignition-common3-dev
libignition-common4-dev
libignition-math6-dev
# libignition-msgs5-dev
# Ignition tools
Expand Down
2 changes: 1 addition & 1 deletion configure.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ call %win_lib% :download_unzip_install libyaml-0.1.7-vc15-x64-md.zip
call %win_lib% :download_unzip_install libzip-1.4.0_zlip-1.2.11_vc15-x64-dll-MD.zip
call %win_lib% :install_ign_project ign-cmake ign-cmake2
call %win_lib% :install_ign_project ign-tools ign-tools1
call %win_lib% :install_ign_project ign-common ign-common3
call %win_lib% :install_ign_project ign-common main
call %win_lib% :install_ign_project ign-msgs main

:: Set configuration variables
Expand Down
1 change: 0 additions & 1 deletion include/ignition/fuel_tools/FuelClient.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <vector>
#include <ignition/common/URI.hh>

#include "ignition/fuel_tools/Helpers.hh"
#include "ignition/fuel_tools/ModelIter.hh"
#include "ignition/fuel_tools/RestClient.hh"
#include "ignition/fuel_tools/Result.hh"
Expand Down
15 changes: 15 additions & 0 deletions include/ignition/fuel_tools/Helpers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define IGNITION_FUEL_TOOLS_HELPERS_HH_

#include <string>
#include <ignition/common/URI.hh>
#include <ignition/fuel_tools/Export.hh>

// Use safer functions on Windows
Expand All @@ -34,5 +35,19 @@
#define ign_strdup strdup
#endif

namespace ignition
{
namespace fuel_tools
{
/// \brief Convert a URI to a string suitable to use as a path on disk.
/// It strips the scheme and authority's `//` prefix.
/// \param[in] _uri URI to convert.
/// \return String suitable to use in file paths
IGNITION_FUEL_TOOLS_VISIBLE
std::string uriToPath(const ignition::common::URI &_uri);
}
}

// IGNITION_FUEL_TOOLS_HELPERS_HH_
#endif

2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set (sources
ClientConfig.cc
CollectionIdentifier.cc
FuelClient.cc
Helpers.cc
ign.cc
Interface.cc
JSONParser.cc
Expand All @@ -22,6 +23,7 @@ set (gtest_sources
FuelClient_TEST.cc
ign_src_TEST.cc
Interface_TEST.cc
Helpers_TEST.cc
JSONParser_TEST.cc
LocalCache_TEST.cc
ModelIdentifier_TEST.cc
Expand Down
5 changes: 5 additions & 0 deletions src/ClientConfig_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,17 @@ TEST(ServerConfig, Url)
EXPECT_EQ("http://banana:8080", srv.Url().Str());
EXPECT_EQ("http", srv.Url().Scheme());
EXPECT_EQ("banana:8080", srv.Url().Path().Str());
EXPECT_FALSE(srv.Url().Authority());
}

// Trailing /
{
ServerConfig srv;
srv.SetUrl(common::URI("http://banana:8080/"));
EXPECT_EQ("http://banana:8080", srv.Url().Str());
EXPECT_EQ("http", srv.Url().Scheme());
EXPECT_EQ("banana:8080", srv.Url().Path().Str());
EXPECT_FALSE(srv.Url().Authority());
}

// Set from URI
Expand All @@ -408,6 +412,7 @@ TEST(ServerConfig, Url)
EXPECT_EQ("http://banana:8080", srv.Url().Str());
EXPECT_EQ("http", srv.Url().Scheme());
EXPECT_EQ("banana:8080", srv.Url().Path().Str());
EXPECT_FALSE(srv.Url().Authority());
}
}

Expand Down
21 changes: 13 additions & 8 deletions src/FuelClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "ignition/fuel_tools/ClientConfig.hh"
#include "ignition/fuel_tools/CollectionIdentifier.hh"
#include "ignition/fuel_tools/FuelClient.hh"
#include "ignition/fuel_tools/Helpers.hh"
#include "ignition/fuel_tools/JSONParser.hh"
#include "ignition/fuel_tools/LocalCache.hh"
#include "ignition/fuel_tools/ModelIdentifier.hh"
Expand Down Expand Up @@ -71,7 +72,9 @@ class ignition::fuel_tools::FuelClientPrivate
// Name
"([^\\/]+)\\/*"
// Version
"([0-9]*|tip)"};
"([0-9]*|tip)"
// Trailing /
"/?"};

/// \brief A world URL,
/// E.g.: https://fuel.ignitionrobotics.org/1.0/OpenRobotics/worlds/Empty/1
Expand All @@ -90,7 +93,9 @@ class ignition::fuel_tools::FuelClientPrivate
// Name
"([^\\/]+)\\/*"
// Version
"([0-9]*|tip)"};
"([0-9]*|tip)"
// Trailing /
"/?"};

/// \brief A model file URL,
/// E.g.: https://server.org/1.0/owner/models/modelname/files/meshes/mesh.dae
Expand All @@ -113,7 +118,9 @@ class ignition::fuel_tools::FuelClientPrivate
// "files"
"files\\/+"
// File path
"(.*)"};
"(.*)"
// Trailing /
"/?"};

/// \brief A world file URL,
/// E.g.: https://server.org/1.0/owner/worlds/worldname/files/meshes/mesh.dae
Expand All @@ -136,7 +143,9 @@ class ignition::fuel_tools::FuelClientPrivate
// "files"
"files\\/+"
// File path
"(.*)"};
"(.*)"
// Trailing /
"/?"};

/// \brief A collection URL,
/// E.g.:
Expand Down Expand Up @@ -750,8 +759,6 @@ bool FuelClient::ParseModelUrl(const common::URI &_modelUrl,
std::string modelName;
std::string modelVersion;

std::regex_match(urlStr, match, *this->dataPtr->urlModelRegex);

if (std::regex_match(urlStr, match, *this->dataPtr->urlModelRegex) &&
match.size() >= 5u)
{
Expand Down Expand Up @@ -818,8 +825,6 @@ bool FuelClient::ParseWorldUrl(const common::URI &_worldUrl,
std::string worldName;
std::string worldVersion;

std::regex_match(urlStr, match, *this->dataPtr->urlWorldRegex);

if (std::regex_match(urlStr, match, *this->dataPtr->urlWorldRegex) &&
match.size() >= 5u)
{
Expand Down
6 changes: 4 additions & 2 deletions src/FuelClient_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,14 @@ TEST_F(FuelClientTest, ParseModelURL)
// * with client config
// * with server API version different from config
// * with model version
// * with trailing /
{
ClientConfig config;

FuelClient client(config);
ModelIdentifier id;
const std::string url{
"https://fuel.ignitionrobotics.org/5.0/german/models/Cardboard Box/6"};
"https://fuel.ignitionrobotics.org/5.0/german/models/Cardboard Box/6/"};
EXPECT_TRUE(client.ParseModelUrl(ignition::common::URI(url), id));

EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
Expand Down Expand Up @@ -801,13 +802,14 @@ TEST_F(FuelClientTest, ParseWorldUrl)
// * with client config
// * without server API version
// * with world version `tip`
// * with trailing /
{
ClientConfig config;

FuelClient client(config);
WorldIdentifier id;
const common::URI url{
"https://fuel.ignitionrobotics.org/german/worlds/Cardboard Box/tip"};
"https://fuel.ignitionrobotics.org/german/worlds/Cardboard Box/tip/"};
EXPECT_TRUE(client.ParseWorldUrl(url, id));

EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
Expand Down
57 changes: 57 additions & 0 deletions src/Helpers.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <ignition/common/Console.hh>
#include <ignition/common/Filesystem.hh>

#include "ignition/fuel_tools/Helpers.hh"

using namespace ignition;
using namespace fuel_tools;

//////////////////////////////////////////////////
std::string ignition::fuel_tools::uriToPath(const common::URI &_uri)
{
auto path = _uri.Path().Str();
if (_uri.Path().IsAbsolute())
{
path = path.substr(1);
}
common::changeFromUnixPath(path);

if (!_uri.Authority())
{
return path;
}

auto authority = _uri.Authority()->Str();
if (authority.find("//") == 0)
{
authority = authority.substr(2);
}

if (authority.empty())
{
return path;
}

if (path.empty())
{
return authority;
}

return common::joinPaths(authority, path);
}
72 changes: 72 additions & 0 deletions src/Helpers_TEST.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include <gtest/gtest.h>
#include <ignition/common/Filesystem.hh>
#include "ignition/fuel_tools/Helpers.hh"

using namespace ignition;
using namespace fuel_tools;

/////////////////////////////////////////////////
TEST(HelpersTEST, UriToPathNoAuthority)
{
{
common::URI uri{"http://localhost:8000"};
EXPECT_EQ("localhost:8000", uriToPath(uri));
}

{
common::URI uri{"http://localhost:8000/some/path"};
EXPECT_EQ(common::joinPaths("localhost:8000", "some", "path"),
uriToPath(uri));
}

{
common::URI uri{"http://localhost:8000/some/path/"};
EXPECT_EQ(common::separator(common::joinPaths("localhost:8000", "some",
"path")), uriToPath(uri));
}
}

/////////////////////////////////////////////////
TEST(HelpersTEST, UriToPathHasAuthority)
{
{
common::URI uri{"http://localhost:8000", true};
EXPECT_EQ("localhost:8000", uriToPath(uri));
}

{
common::URI uri{"http://localhost:8000/some/path", true};
EXPECT_EQ(common::joinPaths("localhost:8000", "some", "path"),
uriToPath(uri));
}

{
common::URI uri{"http://localhost:8000/some/path/", true};
EXPECT_EQ(common::separator(common::joinPaths("localhost:8000", "some",
"path")), uriToPath(uri));
}
}

//////////////////////////////////////////////////
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
8 changes: 5 additions & 3 deletions src/LocalCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <ignition/common/Util.hh>

#include "ignition/fuel_tools/ClientConfig.hh"
#include "ignition/fuel_tools/Helpers.hh"
#include "ignition/fuel_tools/LocalCache.hh"
#include "ignition/fuel_tools/Zip.hh"

Expand Down Expand Up @@ -231,7 +232,8 @@ ModelIter LocalCache::AllModels()
for (auto &server : this->dataPtr->config->Servers())
{
std::string path = common::joinPaths(
this->dataPtr->config->CacheLocation(), server.Url().Path().Str());
this->dataPtr->config->CacheLocation(), uriToPath(server.Url()));

auto srvModels = this->dataPtr->ModelsInServer(path);
for (auto &mod : srvModels)
{
Expand All @@ -254,7 +256,7 @@ WorldIter LocalCache::AllWorlds() const
for (auto &server : this->dataPtr->config->Servers())
{
std::string path = common::joinPaths(
this->dataPtr->config->CacheLocation(), server.Url().Path().Str());
this->dataPtr->config->CacheLocation(), uriToPath(server.Url()));

// Make sure the server info is correct
auto srvWorlds = this->dataPtr->WorldsInServer(path);
Expand Down Expand Up @@ -386,7 +388,7 @@ bool LocalCache::SaveModel(
std::string cacheLocation = this->dataPtr->config->CacheLocation();

std::string modelRootDir = common::joinPaths(cacheLocation,
_id.Server().Url().Path().Str(), _id.Owner(), "models", _id.Name());
uriToPath(_id.Server().Url()), _id.Owner(), "models", _id.Name());
std::string modelVersionedDir =
common::joinPaths(modelRootDir, _id.VersionStr());

Expand Down
Loading

0 comments on commit dddb1ef

Please sign in to comment.