From ca06b89d80a886866b84250408c5214f0a775efc Mon Sep 17 00:00:00 2001 From: Travis Collins Date: Wed, 5 Feb 2025 16:14:01 -0700 Subject: SQRP-169 Write the ScaDependencies to an in-memory ScaHolder --- .../org/sonar/ce/common/batch/package-info.java | 23 ------------- .../java/org/sonar/ce/common/sca/ScaHolder.java | 28 ++++++++++++++++ .../org/sonar/ce/common/sca/ScaHolderImpl.java | 39 ++++++++++++++++++++++ .../org/sonar/ce/common/sca/ScaStepProvider.java | 4 +-- 4 files changed, 69 insertions(+), 25 deletions(-) delete mode 100644 server/sonar-ce-common/src/main/java/org/sonar/ce/common/batch/package-info.java create mode 100644 server/sonar-ce-common/src/main/java/org/sonar/ce/common/sca/ScaHolder.java create mode 100644 server/sonar-ce-common/src/main/java/org/sonar/ce/common/sca/ScaHolderImpl.java (limited to 'server/sonar-ce-common') diff --git a/server/sonar-ce-common/src/main/java/org/sonar/ce/common/batch/package-info.java b/server/sonar-ce-common/src/main/java/org/sonar/ce/common/batch/package-info.java deleted file mode 100644 index 42774becbfb..00000000000 --- a/server/sonar-ce-common/src/main/java/org/sonar/ce/common/batch/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2025 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.ce.common.batch; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-ce-common/src/main/java/org/sonar/ce/common/sca/ScaHolder.java b/server/sonar-ce-common/src/main/java/org/sonar/ce/common/sca/ScaHolder.java new file mode 100644 index 00000000000..07c8a5a576c --- /dev/null +++ b/server/sonar-ce-common/src/main/java/org/sonar/ce/common/sca/ScaHolder.java @@ -0,0 +1,28 @@ +/* + * SonarQube + * Copyright (C) 2009-2025 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.ce.common.sca; + +import java.util.List; +import org.sonar.db.sca.ScaDependencyDto; + +public interface ScaHolder { + void setDependencies(List dependencies); + List getDependencies(); +} diff --git a/server/sonar-ce-common/src/main/java/org/sonar/ce/common/sca/ScaHolderImpl.java b/server/sonar-ce-common/src/main/java/org/sonar/ce/common/sca/ScaHolderImpl.java new file mode 100644 index 00000000000..798f948e565 --- /dev/null +++ b/server/sonar-ce-common/src/main/java/org/sonar/ce/common/sca/ScaHolderImpl.java @@ -0,0 +1,39 @@ +/* + * SonarQube + * Copyright (C) 2009-2025 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.ce.common.sca; + +import org.sonar.db.sca.ScaDependencyDto; + +import java.util.List; +import java.util.Optional; + +public class ScaHolderImpl implements ScaHolder { + private List dependencies = null; + + @Override + public void setDependencies(List dependencies) { + this.dependencies = List.copyOf(dependencies); + } + + @Override + public List getDependencies() { + return Optional.ofNullable(this.dependencies).orElseThrow(() -> new IllegalStateException("SCA dependencies have not been populated")); + } +} diff --git a/server/sonar-ce-common/src/main/java/org/sonar/ce/common/sca/ScaStepProvider.java b/server/sonar-ce-common/src/main/java/org/sonar/ce/common/sca/ScaStepProvider.java index 1e57f01a499..6a9d3e21823 100644 --- a/server/sonar-ce-common/src/main/java/org/sonar/ce/common/sca/ScaStepProvider.java +++ b/server/sonar-ce-common/src/main/java/org/sonar/ce/common/sca/ScaStepProvider.java @@ -25,9 +25,9 @@ import org.sonar.ce.task.step.ComputationStep; /** * When an implementation of this interface is available in the ioc container, the Compute Engine will use the value returned by - * {@link #get(ScannerReportReader)} as an extra step for software composition analysis. + * {@link #get(ScannerReportReader, ScaHolder)} as an extra step for software composition analysis. */ @ComputeEngineSide public interface ScaStepProvider { - ComputationStep get(ScannerReportReader reportReader); + ComputationStep get(ScannerReportReader reportReader, ScaHolder scaHolder); } -- cgit v1.2.3