@@ -917,6 +917,45 @@ public void removeDependencyIfExist(Project project, Component component) {
917
917
}
918
918
}
919
919
920
+ /**
921
+ * Intelligently adds dependencies for components that are not already a dependency
922
+ * of the specified project and removes the dependency relationship for components
923
+ * that are not in the list of specified components.
924
+ * @param project the project to bind components to
925
+ * @param components the complete list of components that should be dependencies of the project
926
+ */
927
+ public void reconcileDependencies (Project project , List <Component > components ) {
928
+ // Holds a list of all Components that are existing dependencies of the specified project
929
+ final List <Component > existingProjectDependencies = new ArrayList <>();
930
+ getAllDependencies (project ).forEach (item -> existingProjectDependencies .add (item .getComponent ()));
931
+ reconcileDependencies (project , existingProjectDependencies , components );
932
+ }
933
+
934
+ /**
935
+ * Intelligently adds dependencies for components that are not already a dependency
936
+ * of the specified project and removes the dependency relationship for components
937
+ * that are not in the list of specified components.
938
+ * @param project the project to bind components to
939
+ * @param existingProjectDependencies the complete list of existing dependent components
940
+ * @param components the complete list of components that should be dependencies of the project
941
+ */
942
+ public void reconcileDependencies (Project project , List <Component > existingProjectDependencies , List <Component > components ) {
943
+ // Removes components as dependencies to the project for all
944
+ // components not included in the list provided
945
+ for (Component existingDependency : existingProjectDependencies ) {
946
+ boolean keep = false ;
947
+ for (Component component : components ) {
948
+ if (component .getId () == existingDependency .getId ()) {
949
+ keep = true ;
950
+ }
951
+ }
952
+ if (!keep ) {
953
+ removeDependencyIfExist (project , existingDependency );
954
+ }
955
+ }
956
+ components .forEach (component -> createDependencyIfNotExist (project , component , null , null ));
957
+ }
958
+
920
959
/**
921
960
* Returns a List of all Dependency for the specified Project.
922
961
* This method if designed NOT to provide paginated results.
0 commit comments