Skip to content

Commit 7c8faca

Browse files
fredroybakpaul
authored andcommitted
[Core, Simulation.Core] Registration: (re)enable deprecation warnings (#5155)
* enable deprecation warnings for RegisterObject * enable runtime deprecation warnings * re enable disabled tests * fix typo * fix units tests * expect a warning when loading pluginA * load plugins once (avoiding registering several times) * add more info when warning the user of a deprecated registration * set warnings only if dev mode is enabled (SOFA_WITH_DEVTOOLS enabled) * apply new mechanism registration to AugmentedLagrangianConstraint
1 parent 99df0a2 commit 7c8faca

File tree

10 files changed

+69
-69
lines changed

10 files changed

+69
-69
lines changed

Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/AugmentedLagrangianConstraint.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ namespace sofa::component::constraint::lagrangian::model
3131
using namespace sofa::defaulttype;
3232
using namespace sofa::helper;
3333

34-
int AugmentedLagrangianConstraintClass = core::RegisterObject("AugmentedLagrangianConstraint")
35-
.add< AugmentedLagrangianConstraint<Vec3Types> >()
36-
37-
;
38-
34+
void registerAugmentedLagrangianConstraint(sofa::core::ObjectFactory* factory)
35+
{
36+
factory->registerObjects(core::ObjectRegistrationData("AugmentedLagrangianConstraint")
37+
.add< AugmentedLagrangianConstraint<Vec3Types> >());
38+
}
3939

4040
template class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_MODEL_API BaseContactLagrangianConstraint<Vec3Types,AugmentedLagrangianContactParameters>;
4141
template class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_MODEL_API AugmentedLagrangianConstraint<Vec3Types>;

Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/init.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
namespace sofa::component::constraint::lagrangian::model
2727
{
2828

29+
extern void registerAugmentedLagrangianConstraint(sofa::core::ObjectFactory* factory);
2930
extern void registerBilateralLagrangianConstraint(sofa::core::ObjectFactory* factory);
3031
extern void registerFixedLagrangianConstraint(sofa::core::ObjectFactory* factory);
3132
extern void registerSlidingLagrangianConstraint(sofa::core::ObjectFactory* factory);
@@ -57,6 +58,7 @@ const char* getModuleVersion()
5758

5859
void registerObjects(sofa::core::ObjectFactory* factory)
5960
{
61+
registerAugmentedLagrangianConstraint(factory);
6062
registerBilateralLagrangianConstraint(factory);
6163
registerFixedLagrangianConstraint(factory);
6264
registerSlidingLagrangianConstraint(factory);

Sofa/Component/IO/Mesh/tests/STLExporter_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class STLExporter_test : public BaseSimulationTest {
6969
{
7070
sofa::simpleapi::importPlugin("Sofa.Component.StateContainer");
7171
sofa::simpleapi::importPlugin("Sofa.Component.Visual");
72+
sofa::simpleapi::importPlugin("Sofa.Component.IO.Mesh");
7273
}
7374

7475
void TearDown() override
@@ -98,7 +99,6 @@ class STLExporter_test : public BaseSimulationTest {
9899
"<?xml version='1.0'?> \n"
99100
"<Node name='Root' gravity='0 0 0' time='0' animate='0' > \n"
100101
" <DefaultAnimationLoop/> \n"
101-
" <RequiredPlugin name='Sofa.Component.IO.Mesh' /> \n"
102102
" <MechanicalObject position='0 1 2 3 4 5 6 7 8 9'/> \n"
103103
" <MeshOBJLoader name='loader' filename='mesh/liver-smooth.obj'/> \n"
104104
" <VisualModel src='@loader'/> \n"

Sofa/framework/Core/src/sofa/core/ObjectFactory.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,8 @@ bool ObjectFactory::registerObjectsFromPlugin(const std::string& pluginName)
775775
// do not register if it was already done before
776776
if(m_registeredPluginSet.count(pluginName) > 0)
777777
{
778-
// msg_warning("ObjectFactory") << pluginName << " has already registered its components.";
778+
// This warning should be generalized (i.e not only in dev mode) when runSofa will not auto-load modules/plugins by default anymore
779+
dmsg_warning("ObjectFactory") << pluginName << " has already registered its components.";
779780
return false;
780781
}
781782

@@ -837,8 +838,8 @@ RegisterObject& RegisterObject::addCreator(std::string classname, std::string te
837838

838839
RegisterObject::operator int() const
839840
{
840-
//std::cout << "Implicit object registration is deprecrated since v24.06. Check #4429 for more information." << std::endl;
841-
// msg_warning("RegisterObject") << "Implicit object registration is deprecrated since v24.06. Check #4429 for more information.";
841+
dmsg_warning("RegisterObject") << m_objectRegistrationdata.entry.className
842+
<< ": Implicit object registration is deprecated since v24.12. Check #4429 for more information.";
842843
return commitTo(ObjectFactory::getInstance());
843844
}
844845

Sofa/framework/Core/src/sofa/core/ObjectFactory.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,14 @@ class SOFA_CORE_API ObjectRegistrationData
377377

378378
/// This is the final operation that will actually commit the additions to the ObjectFactory.
379379
bool commitTo(sofa::core::ObjectFactory* objectFactory) const;
380+
381+
friend class RegisterObject;
380382
};
381383

382384

383385
// Legacy structure, to keep compatibility with olden code
384386
// using the singleton to get the instance of ObjectFactory
385-
class /* SOFA_ATTRIBUTE_DEPRECATED__REGISTEROBJECT() */ SOFA_CORE_API RegisterObject
387+
class SOFA_ATTRIBUTE_DEPRECATED__REGISTEROBJECT() SOFA_CORE_API RegisterObject
386388
{
387389
private:
388390
ObjectRegistrationData m_objectRegistrationdata;

Sofa/framework/Helper/test/system/PluginManager_test.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,22 @@ TEST_F(PluginManager_test, loadTestPluginAByPath)
122122
/// Check that existing plugins are correctly handled and returns no
123123
/// error/warning message.
124124
{
125-
EXPECT_MSG_NOEMIT(Warning, Error);
126-
125+
EXPECT_MSG_NOEMIT(Error, Warning);
126+
127127
std::cout << "PluginManager_test.loadTestPluginAByPath: "
128-
<< "pm.getPluginMap().size() = " << pm.getPluginMap().size()
129-
<< std::endl;
128+
<< "pm.getPluginMap().size() = " << pm.getPluginMap().size()
129+
<< std::endl;
130+
}
131+
{
132+
EXPECT_MSG_NOEMIT(Error);
133+
// Plugin A still uses the deprecated registration mechanism
134+
// and is expected to throw a warning when loaded
135+
EXPECT_MSG_EMIT(Warning);
136+
130137
ASSERT_EQ(pm.loadPluginByPath(pluginPath), PluginManager::PluginLoadStatus::SUCCESS);
138+
}
139+
{
140+
EXPECT_MSG_NOEMIT(Error, Warning);
131141
ASSERT_GT(pm.findPlugin(pluginAName).size(), 0u);
132142
}
133143

Sofa/framework/Simulation/Core/src/sofa/simulation/RequiredPlugin.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,16 @@ bool RequiredPlugin::loadPlugin()
136136
objectFactory->registerObjectsFromPlugin(name);
137137

138138
// fail-safe to check if potential components have been registered (implicitly or explicitly)
139-
// SOFA_ATTRIBUTE_DEPRECATED__REGISTEROBJECT()
140139
std::vector<sofa::core::ObjectFactory::ClassEntry::SPtr> entries;
141140
objectFactory->getEntriesFromTarget(entries, name);
142141

143142
if (entries.empty())
144143
{
145-
// msg_warning() << "No component has been registered from " << name << ".\n"
146-
// << "It could be because: \n"
147-
// << " - the entrypoint registerObjects() has not been implemented;\n"
148-
// << " - (deprecated) no sofa::core::RegisterObject() has been called;\n"
149-
// << " - your plugin does not add any component (i.e BaseObject) into the factory. In that case, RequiredPlugin is not useful for this kind of plugin.";
144+
msg_warning() << "No component has been registered from " << name << ".\n"
145+
<< "It could be because: \n"
146+
<< " - the entrypoint registerObjects() has not been implemented;\n"
147+
<< " - (deprecated since v24.12) no sofa::core::RegisterObject() has been called;\n"
148+
<< " - your plugin does not add any component (i.e BaseObject) into the factory. In that case, RequiredPlugin is not useful for this kind of plugin.";
150149
}
151150

152151
if (d_stopAfterFirstSuffixFound.getValue()) break;

Sofa/framework/Simulation/Core/test/RequiredPlugin_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct RequiredPlugin_test : public BaseSimulationTest
8585

8686
void testLoadPluginB()
8787
{
88-
EXPECT_MSG_EMIT(Warning); // // TestPluginB does not register any component
88+
EXPECT_MSG_EMIT(Warning); // TestPluginB does not register any component
8989

9090
std::stringstream scene;
9191
scene << "<?xml version='1.0'?>"
@@ -101,7 +101,7 @@ struct RequiredPlugin_test : public BaseSimulationTest
101101

102102
void testLoadPluginC()
103103
{
104-
EXPECT_MSG_NOEMIT(Warning); // // TestPluginC registers its component explicitly
104+
EXPECT_MSG_NOEMIT(Warning); // TestPluginC registers its component explicitly
105105

106106
std::stringstream scene;
107107
scene << "<?xml version='1.0'?>"
@@ -118,8 +118,8 @@ struct RequiredPlugin_test : public BaseSimulationTest
118118

119119
TEST_F(RequiredPlugin_test, testNotExistingPlugin ) { testNotExistingPlugin(); }
120120
TEST_F(RequiredPlugin_test, testNoParameter ) { testNoParameter(); }
121-
TEST_F(RequiredPlugin_test, DISABLED_testLoadPluginA) { testLoadPluginA(); } // disabled because testLoadPluginA() should throw a warning (but this warning is commented for the moment)
122-
TEST_F(RequiredPlugin_test, DISABLED_testLoadPluginB) { testLoadPluginB(); }// disabled because testLoadPluginB() should throw a warning (but this warning is commented for the moment)
121+
TEST_F(RequiredPlugin_test, testLoadPluginA) { testLoadPluginA(); }
122+
TEST_F(RequiredPlugin_test, testLoadPluginB) { testLoadPluginB(); }
123123
TEST_F(RequiredPlugin_test, testLoadPluginC) { testLoadPluginC(); }
124124

125125
}

Sofa/framework/Simulation/simutest/parallel_scenes_test.cpp

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ using sofa::simulation::Node ;
2929
#include <sofa/component/sceneutility/InfoComponent.h>
3030
using sofa::component::sceneutility::InfoComponent;
3131

32-
#include <sofa/helper/system/PluginManager.h>
33-
using sofa::helper::system::PluginManager ;
34-
3532
#include <sofa/simulation/common/SceneLoaderXML.h>
3633
using sofa::simulation::SceneLoaderXML ;
3734

@@ -47,10 +44,36 @@ class ParallelScenesTest : public virtual sofa::testing::BaseTest
4744
{
4845
}
4946

47+
void SetUp() override
48+
{
49+
EXPECT_MSG_NOEMIT(Error, Warning);
50+
51+
sofa::simpleapi::importPlugin("Sofa.Component.AnimationLoop");
52+
sofa::simpleapi::importPlugin("Sofa.Component.Collision.Detection.Algorithm");
53+
sofa::simpleapi::importPlugin("Sofa.Component.Collision.Detection.Intersection");
54+
sofa::simpleapi::importPlugin("Sofa.Component.Collision.Geometry");
55+
sofa::simpleapi::importPlugin("Sofa.Component.Collision.Response.Contact");
56+
sofa::simpleapi::importPlugin("Sofa.Component.Constraint.Lagrangian.Correction");
57+
sofa::simpleapi::importPlugin("Sofa.Component.Constraint.Lagrangian.Solver");
58+
sofa::simpleapi::importPlugin("Sofa.Component.Constraint.Projective");
59+
sofa::simpleapi::importPlugin("Sofa.Component.IO.Mesh");
60+
sofa::simpleapi::importPlugin("Sofa.Component.LinearSolver.Iterative");
61+
sofa::simpleapi::importPlugin("Sofa.Component.Mapping.Linear");
62+
sofa::simpleapi::importPlugin("Sofa.Component.Mass");
63+
sofa::simpleapi::importPlugin("Sofa.Component.ODESolver.Backward");
64+
sofa::simpleapi::importPlugin("Sofa.Component.SolidMechanics.FEM.Elastic");
65+
sofa::simpleapi::importPlugin("Sofa.Component.StateContainer");
66+
sofa::simpleapi::importPlugin("Sofa.Component.Topology.Container.Constant");
67+
sofa::simpleapi::importPlugin("Sofa.Component.Topology.Container.Dynamic");
68+
sofa::simpleapi::importPlugin("Sofa.Component.Topology.Container.Grid");
69+
sofa::simpleapi::importPlugin("Sofa.Component.Visual");
70+
sofa::simpleapi::importPlugin("Sofa.GL.Component.Rendering3D");
71+
sofa::simpleapi::importPlugin("Sofa.Component.LinearSystem");
72+
}
73+
5074
void executeInParallel(const char* sceneStr, const std::size_t nbScenes, const std::size_t nbSteps)
5175
{
52-
EXPECT_MSG_NOEMIT(Error);
53-
EXPECT_MSG_NOEMIT(Warning);
76+
EXPECT_MSG_NOEMIT(Error, Warning);
5477

5578
std::vector<sofa::simulation::NodeSPtr> groots;
5679
groots.resize(nbScenes);
@@ -104,21 +127,6 @@ class ParallelScenesTest : public virtual sofa::testing::BaseTest
104127
const std::string sceneStr = R"(
105128
<?xml version="1.0" ?>
106129
<Node name="lroot" gravity="0 -9.81 0" dt="0.02">
107-
<RequiredPlugin name="Sofa.Component.Collision.Detection.Algorithm"/> <!-- Needed to use components [BVHNarrowPhase BruteForceBroadPhase CollisionPipeline] -->
108-
<RequiredPlugin name="Sofa.Component.Collision.Detection.Intersection"/> <!-- Needed to use components [DiscreteIntersection] -->
109-
<RequiredPlugin name="Sofa.Component.Collision.Geometry"/> <!-- Needed to use components [SphereCollisionModel] -->
110-
<RequiredPlugin name="Sofa.Component.Collision.Response.Contact"/> <!-- Needed to use components [CollisionResponse] -->
111-
<RequiredPlugin name="Sofa.Component.Constraint.Projective"/> <!-- Needed to use components [FixedProjectiveConstraint] -->
112-
<RequiredPlugin name="Sofa.Component.IO.Mesh"/> <!-- Needed to use components [MeshGmshLoader MeshOBJLoader SphereLoader] -->
113-
<RequiredPlugin name="Sofa.Component.LinearSolver.Iterative"/> <!-- Needed to use components [CGLinearSolver] -->
114-
<RequiredPlugin name="Sofa.Component.Mapping.Linear"/> <!-- Needed to use components [BarycentricMapping] -->
115-
<RequiredPlugin name="Sofa.Component.Mass"/> <!-- Needed to use components [DiagonalMass] -->
116-
<RequiredPlugin name="Sofa.Component.ODESolver.Backward"/> <!-- Needed to use components [EulerImplicitSolver] -->
117-
<RequiredPlugin name="Sofa.Component.SolidMechanics.FEM.Elastic"/> <!-- Needed to use components [TetrahedralCorotationalFEMForceField] -->
118-
<RequiredPlugin name="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] -->
119-
<RequiredPlugin name="Sofa.Component.Topology.Container.Dynamic"/> <!-- Needed to use components [TetrahedronSetGeometryAlgorithms TetrahedronSetTopologyContainer] -->
120-
<RequiredPlugin name="Sofa.GL.Component.Rendering3D"/> <!-- Needed to use components [OglModel] -->
121-
122130
<CollisionPipeline name="CollisionPipeline" verbose="0" />
123131
<DefaultAnimationLoop/>
124132
<BruteForceBroadPhase/>
@@ -160,29 +168,6 @@ class ParallelScenesTest : public virtual sofa::testing::BaseTest
160168
const std::string sceneStr = R"(
161169
<?xml version="1.0" ?>
162170
<Node name="root" gravity="0 -1000 0" dt="0.04">
163-
<Node name="RequiredPlugins">
164-
<RequiredPlugin name="Sofa.Component.AnimationLoop"/> <!-- Needed to use components [FreeMotionAnimationLoop] -->
165-
<RequiredPlugin name="Sofa.Component.Collision.Detection.Algorithm"/> <!-- Needed to use components [BVHNarrowPhase BruteForceBroadPhase CollisionPipeline] -->
166-
<RequiredPlugin name="Sofa.Component.Collision.Detection.Intersection"/> <!-- Needed to use components [MinProximityIntersection] -->
167-
<RequiredPlugin name="Sofa.Component.Collision.Geometry"/> <!-- Needed to use components [LineCollisionModel PointCollisionModel TriangleCollisionModel] -->
168-
<RequiredPlugin name="Sofa.Component.Collision.Response.Contact"/> <!-- Needed to use components [CollisionResponse] -->
169-
<RequiredPlugin name="Sofa.Component.Constraint.Lagrangian.Correction"/> <!-- Needed to use components [UncoupledConstraintCorrection] -->
170-
<RequiredPlugin name="Sofa.Component.Constraint.Lagrangian.Solver"/> <!-- Needed to use components [LCPConstraintSolver] -->
171-
<RequiredPlugin name="Sofa.Component.IO.Mesh"/> <!-- Needed to use components [MeshOBJLoader] -->
172-
<RequiredPlugin name="Sofa.Component.LinearSolver.Iterative"/> <!-- Needed to use components [CGLinearSolver] -->
173-
<RequiredPlugin name="Sofa.Component.Mapping.Linear"/> <!-- Needed to use components [BarycentricMapping] -->
174-
<RequiredPlugin name="Sofa.Component.Mass"/> <!-- Needed to use components [UniformMass] -->
175-
<RequiredPlugin name="Sofa.Component.ODESolver.Backward"/> <!-- Needed to use components [EulerImplicitSolver] -->
176-
<RequiredPlugin name="Sofa.Component.SolidMechanics.FEM.Elastic"/> <!-- Needed to use components [HexahedronFEMForceField] -->
177-
<RequiredPlugin name="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] -->
178-
<RequiredPlugin name="Sofa.Component.Topology.Container.Constant"/> <!-- Needed to use components [MeshTopology] -->
179-
<RequiredPlugin name="Sofa.Component.Topology.Container.Grid"/> <!-- Needed to use components [SparseGridRamificationTopology] -->
180-
<RequiredPlugin name="Sofa.Component.Visual"/> <!-- Needed to use components [InteractiveCamera VisualStyle] -->
181-
<RequiredPlugin name="Sofa.GL.Component.Rendering3D"/> <!-- Needed to use components [OglModel] -->
182-
<RequiredPlugin name="Sofa.GL.Component.Shader"/> <!-- Needed to use components [LightManager SpotLight] -->
183-
<RequiredPlugin name="Sofa.Component.LinearSystem"/> <!-- Needed to use components [MatrixLinearSystem] -->
184-
</Node>
185-
186171
<FreeMotionAnimationLoop parallelCollisionDetectionAndFreeMotion="false" />
187172
<VisualStyle displayFlags="showVisual " /> <!--showBehaviorModels showCollisionModels-->
188173
<LCPConstraintSolver tolerance="1e-3" maxIt="1000" initial_guess="false" build_lcp="false" printLog="0" mu="0.2"/>

applications/projects/SceneChecking/tests/SceneChecker_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,12 @@ struct SceneChecker_test : public BaseSimulationTest
173173
EXPECT_MSG_NOEMIT(Warning);
174174

175175
const std::string lvl = (shouldWarn)?"17.06":"17.12";
176-
176+
177+
sofa::simpleapi::importPlugin("Sofa.Component.SceneUtility");
178+
177179
std::stringstream scene;
178180
scene << "<?xml version='1.0'?> \n"
179181
<< "<Node name='Root' gravity='0 -9.81 0' time='0' animate='0' > \n"
180-
<< " <RequiredPlugin name='Sofa.Component.SceneUtility'/> \n"
181182
<< " <APIVersion level='"<< lvl <<"'/> \n"
182183
<< " <ComponentDeprecated /> \n"
183184
<< "</Node> \n";

0 commit comments

Comments
 (0)