diff --git a/Changelog.md b/Changelog.md index 34ab4c54..4cc50ad8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,32 @@ ## Gazebo Fuel Tools 9.x +### Gazebo Fuel Tools 9.1.0 (2024-08-06) + +1. Make `CollectionIdentifier::UniqueName` consistent + * [Pull request #430](https://github.com/gazebosim/gz-fuel-tools/pull/430) + +1. Add Url accessor to Identifiers + * [Pull request #429](https://github.com/gazebosim/gz-fuel-tools/pull/429) + +1. Migrate curl_formadd from form API to mime API (deprecated in Ubuntu Noble) + * [Pull request #415](https://github.com/gazebosim/gz-fuel-tools/pull/415) + +1. Add package.xml + * [Pull request #408](https://github.com/gazebosim/gz-fuel-tools/pull/408) + +1. CLI for creating config.yaml + * [Pull request #413](https://github.com/gazebosim/gz-fuel-tools/pull/413) + +1. Clean all ASAN reported memory problems (curl related) + * [Pull request #416](https://github.com/gazebosim/gz-fuel-tools/pull/416) + +1. Add Private function to world identifier + * [Pull request #414](https://github.com/gazebosim/gz-fuel-tools/pull/414) + +1. Use config.yaml file from default cache location, if it exists + * [Pull request #410](https://github.com/gazebosim/gz-fuel-tools/pull/410) + ### Gazebo Fuel Tools 9.0.3 (2024-04-09) 1. Use relative install path for gz tool data diff --git a/include/gz/fuel_tools/CollectionIdentifier.hh b/include/gz/fuel_tools/CollectionIdentifier.hh index 9e7d5cca..da0170ea 100644 --- a/include/gz/fuel_tools/CollectionIdentifier.hh +++ b/include/gz/fuel_tools/CollectionIdentifier.hh @@ -92,6 +92,10 @@ namespace gz::fuel_tools /// \return Unique collection name. public: std::string UniqueName() const; + /// \brief Returns a URL for the collection. + /// \remarks this is Server/Owner/Name. + public: gz::common::URI Url() const; + /// \brief Returns all the collection information as a string. Convenient /// for debugging. /// \param[in] _prefix Optional prefix for every line of the string. diff --git a/include/gz/fuel_tools/ModelIdentifier.hh b/include/gz/fuel_tools/ModelIdentifier.hh index 70eb9d2a..534a6ef2 100644 --- a/include/gz/fuel_tools/ModelIdentifier.hh +++ b/include/gz/fuel_tools/ModelIdentifier.hh @@ -84,6 +84,10 @@ namespace gz::fuel_tools /// \return Unique model name. public: std::string UniqueName() const; + /// \brief Returns a URL for the model. + /// \remarks this is Server/Owner/Name. + public: gz::common::URI Url() const; + /// \brief set the name of the model. /// \param[in] _name The name to set. Must be ascii and pass [-_a-z0-9]+. /// \return true if successful. diff --git a/include/gz/fuel_tools/WorldIdentifier.hh b/include/gz/fuel_tools/WorldIdentifier.hh index 62c8d738..d14bdee2 100644 --- a/include/gz/fuel_tools/WorldIdentifier.hh +++ b/include/gz/fuel_tools/WorldIdentifier.hh @@ -131,6 +131,10 @@ namespace gz::fuel_tools /// \return Unique world name. public: std::string UniqueName() const; + /// \brief Returns a URL for the world. + /// \remarks this is Server/Owner/Name. + public: gz::common::URI Url() const; + // /// \brief Sets the SHA 2 256 hash of the world // /// \param[in] _hash a 256 bit SHA 2 hash // /// \returns true if successful diff --git a/src/CollectionIdentifier.cc b/src/CollectionIdentifier.cc index 949e4be6..d6c2f235 100644 --- a/src/CollectionIdentifier.cc +++ b/src/CollectionIdentifier.cc @@ -71,9 +71,20 @@ CollectionIdentifier::~CollectionIdentifier() = default; ////////////////////////////////////////////////// std::string CollectionIdentifier::UniqueName() const { - return common::joinPaths(this->dataPtr->server.Url().Str(), - this->dataPtr->owner, "collections", - this->dataPtr->name); + return common::copyToUnixPath(common::joinPaths( + uriToPath(this->dataPtr->server.Url()), + this->dataPtr->owner, "collections", + this->dataPtr->name)); +} + +////////////////////////////////////////////////// +gz::common::URI CollectionIdentifier::Url() const +{ + return common::URI( + common::joinPaths(this->dataPtr->server.Url().Str(), + this->dataPtr->owner, + "collections", + this->dataPtr->name), true); } ////////////////////////////////////////////////// diff --git a/src/CollectionIdentifier_TEST.cc b/src/CollectionIdentifier_TEST.cc index e18b393a..633603a3 100644 --- a/src/CollectionIdentifier_TEST.cc +++ b/src/CollectionIdentifier_TEST.cc @@ -44,29 +44,54 @@ TEST(CollectionIdentifier, SetFields) ///////////////////////////////////////////////// /// \brief Unique Name -// See https://github.com/gazebosim/gz-fuel-tools/issues/231 TEST(CollectionIdentifier, UniqueName) { gz::fuel_tools::ServerConfig srv1; - srv1.SetUrl(common::URI("https://localhost:8001")); + srv1.SetUrl(common::URI("https://localhost:8001", true)); gz::fuel_tools::ServerConfig srv2; - srv2.SetUrl(common::URI("https://localhost:8002")); + srv2.SetUrl(common::URI("https://localhost:8002", true)); gz::fuel_tools::ServerConfig srv3; - srv3.SetUrl(common::URI("https://localhost:8003")); + srv3.SetUrl(common::URI("https://localhost:8003", true)); CollectionIdentifier id; id.SetName("hello"); id.SetOwner("alice"); id.SetServer(srv1); - EXPECT_EQ("https://localhost:8001/alice/collections/hello", id.UniqueName()); + EXPECT_EQ("localhost%3A8001/alice/collections/hello", id.UniqueName()); id.SetServer(srv2); - EXPECT_EQ("https://localhost:8002/alice/collections/hello", id.UniqueName()); + EXPECT_EQ("localhost%3A8002/alice/collections/hello", id.UniqueName()); id.SetServer(srv3); - EXPECT_EQ("https://localhost:8003/alice/collections/hello", id.UniqueName()); + EXPECT_EQ("localhost%3A8003/alice/collections/hello", id.UniqueName()); +} + +///////////////////////////////////////////////// +/// \brief Unique Name +TEST(CollectionIdentifier, Url) +{ + gz::fuel_tools::ServerConfig srv1; + srv1.SetUrl(common::URI("https://localhost:8001", true)); + + gz::fuel_tools::ServerConfig srv2; + srv2.SetUrl(common::URI("https://localhost:8002", true)); + + gz::fuel_tools::ServerConfig srv3; + srv3.SetUrl(common::URI("https://localhost:8003", true)); + + CollectionIdentifier id; + id.SetName("hello"); + id.SetOwner("alice"); + id.SetServer(srv1); + EXPECT_EQ("https://localhost:8001/alice/collections/hello", id.Url().Str()); + + id.SetServer(srv2); + EXPECT_EQ("https://localhost:8002/alice/collections/hello", id.Url().Str()); + + id.SetServer(srv3); + EXPECT_EQ("https://localhost:8003/alice/collections/hello", id.Url().Str()); } ///////////////////////////////////////////////// @@ -124,7 +149,7 @@ TEST(CollectionIdentifier, AsString) std::string str = "Name: \n"\ "Owner: \n"\ - "Unique name: https://fuel.gazebosim.org/collections/\n" + "Unique name: fuel.gazebosim.org/collections/\n" "Server:\n" " URL: https://fuel.gazebosim.org\n" " Version: 1.0\n" diff --git a/src/ModelIdentifier.cc b/src/ModelIdentifier.cc index 1eb42ede..8c428fe3 100644 --- a/src/ModelIdentifier.cc +++ b/src/ModelIdentifier.cc @@ -155,6 +155,16 @@ std::string ModelIdentifier::UniqueName() const this->dataPtr->name)); } +////////////////////////////////////////////////// +common::URI ModelIdentifier::Url() const +{ + return common::URI( + common::joinPaths(this->dataPtr->server.Url().Str(), + this->dataPtr->owner, + "models", + this->dataPtr->name), true); +} + ////////////////////////////////////////////////// std::string ModelIdentifier::Name() const { diff --git a/src/ModelIdentifier_TEST.cc b/src/ModelIdentifier_TEST.cc index deabbcd3..9b63bcdd 100644 --- a/src/ModelIdentifier_TEST.cc +++ b/src/ModelIdentifier_TEST.cc @@ -80,6 +80,32 @@ TEST(ModelIdentifier, UniqueName) EXPECT_EQ("localhost%3A8003/alice/models/hello", id.UniqueName()); } +///////////////////////////////////////////////// +/// \brief Url +TEST(ModelIdentifier, Url) +{ + gz::fuel_tools::ServerConfig srv1; + srv1.SetUrl(common::URI("https://localhost:8001", true)); + + gz::fuel_tools::ServerConfig srv2; + srv2.SetUrl(common::URI("https://localhost:8002", true)); + + gz::fuel_tools::ServerConfig srv3; + srv3.SetUrl(common::URI("https://localhost:8003", true)); + + ModelIdentifier id; + id.SetName("hello"); + id.SetOwner("alice"); + id.SetServer(srv1); + EXPECT_EQ("https://localhost:8001/alice/models/hello", id.Url().Str()); + + id.SetServer(srv2); + EXPECT_EQ("https://localhost:8002/alice/models/hello", id.Url().Str()); + + id.SetServer(srv3); + EXPECT_EQ("https://localhost:8003/alice/models/hello", id.Url().Str()); +} + ///////////////////////////////////////////////// /// \brief Copy constructor deep copies TEST(ModelIdentifier, CopyConstructorDeepCopy) diff --git a/src/WorldIdentifier.cc b/src/WorldIdentifier.cc index 02d36313..085fc611 100644 --- a/src/WorldIdentifier.cc +++ b/src/WorldIdentifier.cc @@ -91,6 +91,16 @@ std::string WorldIdentifier::UniqueName() const this->dataPtr->name)); } +////////////////////////////////////////////////// +gz::common::URI WorldIdentifier::Url() const +{ + return common::URI( + common::joinPaths(this->dataPtr->server.Url().Str(), + this->dataPtr->owner, + "worlds", + this->dataPtr->name), true); +} + ////////////////////////////////////////////////// std::string WorldIdentifier::Name() const { diff --git a/src/WorldIdentifier_TEST.cc b/src/WorldIdentifier_TEST.cc index 4e293f41..332e222f 100644 --- a/src/WorldIdentifier_TEST.cc +++ b/src/WorldIdentifier_TEST.cc @@ -72,6 +72,33 @@ TEST(WorldIdentifier, UniqueName) EXPECT_EQ("localhost%3A8003/alice/worlds/hello", id.UniqueName()); } +///////////////////////////////////////////////// +/// \brief Url +TEST(WorldIdentifier, Url) +{ + gz::fuel_tools::ServerConfig srv1; + srv1.SetUrl(gz::common::URI("https://localhost:8001/", true)); + + gz::fuel_tools::ServerConfig srv2; + srv2.SetUrl(gz::common::URI("https://localhost:8002", true)); + + gz::fuel_tools::ServerConfig srv3; + srv3.SetUrl(gz::common::URI("https://localhost:8003/", true)); + + WorldIdentifier id; + id.SetName("hello"); + id.SetOwner("alice"); + + id.SetServer(srv1); + EXPECT_EQ("https://localhost:8001/alice/worlds/hello", id.Url().Str()); + + id.SetServer(srv2); + EXPECT_EQ("https://localhost:8002/alice/worlds/hello", id.Url().Str()); + + id.SetServer(srv3); + EXPECT_EQ("https://localhost:8003/alice/worlds/hello", id.Url().Str()); +} + ///////////////////////////////////////////////// /// \brief Copy constructor deep copies TEST(WorldIdentifier, CopyConstructorDeepCopy)