aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/AnalysisTempFolderProvider.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ClassDerivedBeanDefinition.java62
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalTempFolderProvider.java61
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/LazyBeanFactoryPostProcessor.java35
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/PriorityBeanFactory.java123
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringComponentContainer.java227
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringGlobalContainer.java1
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/StartableBeanPostProcessor.java60
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/InputProjectProvider.java3
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/LanguagesProvider.java36
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringModuleScanContainer.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java3
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/WorkDirectoriesInitializer.java36
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorExtensionDictionary.java5
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorExtensionDictionary.java2
15 files changed, 61 insertions, 597 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/AnalysisTempFolderProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/AnalysisTempFolderProvider.java
index 753a6f3b711..8bc4ec75ce5 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/AnalysisTempFolderProvider.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/AnalysisTempFolderProvider.java
@@ -30,7 +30,7 @@ import org.springframework.context.annotation.Bean;
public class AnalysisTempFolderProvider {
static final String TMP_NAME = ".sonartmp";
- @Bean("TempFolder")
+ @Bean("AnalysisTempFolder")
public TempFolder provide(DefaultInputProject project) {
Path workingDir = project.getWorkDir();
Path tempDir = workingDir.normalize().resolve(TMP_NAME);
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ClassDerivedBeanDefinition.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ClassDerivedBeanDefinition.java
deleted file mode 100644
index 0743b81f1f6..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ClassDerivedBeanDefinition.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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.scanner.bootstrap;
-
-import java.lang.reflect.Constructor;
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.support.RootBeanDefinition;
-import org.springframework.lang.Nullable;
-
-/**
- * Taken from Spring's GenericApplicationContext.ClassDerivedBeanDefinition.
- */
-public class ClassDerivedBeanDefinition extends RootBeanDefinition {
- public ClassDerivedBeanDefinition(Class<?> beanClass) {
- super(beanClass);
- }
-
- public ClassDerivedBeanDefinition(ClassDerivedBeanDefinition original) {
- super(original);
- }
-
- /**
- * This method gets called from AbstractAutowireCapableBeanFactory#createBeanInstance when a bean is instantiated.
- * It first tries to look at annotations or any other methods provided by bean post processors. If a constructor can't be determined, it will fallback to this method.
- */
- @Override
- @Nullable
- public Constructor<?>[] getPreferredConstructors() {
- Class<?> clazz = getBeanClass();
- Constructor<?> primaryCtor = BeanUtils.findPrimaryConstructor(clazz);
- if (primaryCtor != null) {
- return new Constructor<?>[] {primaryCtor};
- }
- Constructor<?>[] publicCtors = clazz.getConstructors();
- if (publicCtors.length > 0) {
- return publicCtors;
- }
- return null;
- }
-
- @Override
- public RootBeanDefinition cloneBeanDefinition() {
- return new ClassDerivedBeanDefinition(this);
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalTempFolderProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalTempFolderProvider.java
index 4cc825c1930..7eb63a5b9a0 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalTempFolderProvider.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalTempFolderProvider.java
@@ -19,32 +19,30 @@
*/
package org.sonar.scanner.bootstrap;
-import java.io.IOException;
-import java.nio.file.DirectoryStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.concurrent.TimeUnit;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
-import org.sonar.api.Startable;
import org.sonar.api.impl.utils.DefaultTempFolder;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.TempFolder;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
+import static org.sonar.core.util.FileUtils.deleteQuietly;
import org.springframework.context.annotation.Bean;
-import static org.sonar.core.util.FileUtils.deleteQuietly;
+import java.io.IOException;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.concurrent.TimeUnit;
-public class GlobalTempFolderProvider implements Startable {
+public class GlobalTempFolderProvider {
private static final Logger LOG = Loggers.get(GlobalTempFolderProvider.class);
private static final long CLEAN_MAX_AGE = TimeUnit.DAYS.toMillis(21);
static final String TMP_NAME_PREFIX = ".sonartmp_";
private System2 system;
- private DefaultTempFolder tempFolder;
public GlobalTempFolderProvider() {
this(new System2());
@@ -54,26 +52,24 @@ public class GlobalTempFolderProvider implements Startable {
this.system = system;
}
- @Bean("TempFolder")
+ @Bean("GlobalTempFolder")
public TempFolder provide(ScannerProperties scannerProps) {
- if (tempFolder == null) {
- String workingPathName = StringUtils.defaultIfBlank(scannerProps.property(CoreProperties.GLOBAL_WORKING_DIRECTORY), CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE);
- Path workingPath = Paths.get(workingPathName);
+ String workingPathName = StringUtils.defaultIfBlank(scannerProps.property(CoreProperties.GLOBAL_WORKING_DIRECTORY), CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE);
+ Path workingPath = Paths.get(workingPathName);
- if (!workingPath.isAbsolute()) {
- Path home = findSonarHome(scannerProps);
- workingPath = home.resolve(workingPath).normalize();
- }
- try {
- cleanTempFolders(workingPath);
- } catch (IOException e) {
- LOG.error(String.format("failed to clean global working directory: %s", workingPath), e);
- }
- Path tempDir = createTempFolder(workingPath);
- tempFolder = new DefaultTempFolder(tempDir.toFile(), true);
+ if (!workingPath.isAbsolute()) {
+ Path home = findSonarHome(scannerProps);
+ workingPath = home.resolve(workingPath).normalize();
}
- return tempFolder;
+ try {
+ cleanTempFolders(workingPath);
+ } catch (IOException e) {
+ LOG.error(String.format("failed to clean global working directory: %s", workingPath), e);
+ }
+ Path tempDir = createTempFolder(workingPath);
+ return new DefaultTempFolder(tempDir.toFile(), true);
+
}
private static Path createTempFolder(Path workingPath) {
@@ -148,15 +144,4 @@ public class GlobalTempFolderProvider implements Startable {
}
}
- @Override
- public void start() {
- // nothing to do
- }
-
- @Override
- public void stop() {
- if (tempFolder != null) {
- tempFolder.stop();
- }
- }
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/LazyBeanFactoryPostProcessor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/LazyBeanFactoryPostProcessor.java
deleted file mode 100644
index 61fcb419d60..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/LazyBeanFactoryPostProcessor.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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.scanner.bootstrap;
-
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-
-public class LazyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
- @Override
- public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
- for (String beanName : beanFactory.getBeanDefinitionNames()) {
- BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
- beanDefinition.setLazyInit(true);
- }
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/PriorityBeanFactory.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/PriorityBeanFactory.java
deleted file mode 100644
index 6d5a73b2369..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/PriorityBeanFactory.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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.scanner.bootstrap;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import org.springframework.beans.factory.support.DefaultListableBeanFactory;
-
-public class PriorityBeanFactory extends DefaultListableBeanFactory {
- /**
- * Determines highest priority of the bean candidates.
- * Does not take into account the @Primary annotations.
- * This gets called from {@link DefaultListableBeanFactory#determineAutowireCandidate} when the bean factory is finding the beans to autowire. That method
- * checks for @Primary before calling this method.
- *
- * The strategy is to look at the @Priority annotations. If there are ties, we give priority to components that were added to child containers over their parents.
- * If there are still ties, null is returned, which will ultimately cause Spring to throw a NoUniqueBeanDefinitionException.
- */
- @Override
- @Nullable
- protected String determineHighestPriorityCandidate(Map<String, Object> candidates, Class<?> requiredType) {
- List<Bean> candidateBeans = candidates.entrySet().stream()
- .filter(e -> e.getValue() != null)
- .map(e -> new Bean(e.getKey(), e.getValue()))
- .collect(Collectors.toUnmodifiableList());
-
- List<Bean> beansAfterPriority = highestPriority(candidateBeans, b -> getPriority(b.getInstance()));
- if (beansAfterPriority.isEmpty()) {
- return null;
- } else if (beansAfterPriority.size() == 1) {
- return beansAfterPriority.get(0).getName();
- }
-
- List<Bean> beansAfterHierarchy = highestPriority(beansAfterPriority, b -> getHierarchyPriority(b.getName()));
- if (beansAfterHierarchy.size() == 1) {
- return beansAfterHierarchy.get(0).getName();
- }
-
- return null;
- }
-
- private static List<Bean> highestPriority(List<Bean> candidates, PriorityFunction function) {
- List<Bean> highestPriorityBeans = new ArrayList<>();
- Integer highestPriority = null;
-
- for (Bean candidate : candidates) {
- Integer candidatePriority = function.classify(candidate);
- if (candidatePriority == null) {
- candidatePriority = Integer.MAX_VALUE;
- }
- if (highestPriority == null) {
- highestPriority = candidatePriority;
- highestPriorityBeans.add(candidate);
- } else if (candidatePriority < highestPriority) {
- highestPriorityBeans.clear();
- highestPriority = candidatePriority;
- highestPriorityBeans.add(candidate);
- } else if (candidatePriority.equals(highestPriority)) {
- highestPriorityBeans.add(candidate);
- }
- }
- return highestPriorityBeans;
- }
-
- @CheckForNull
- private Integer getHierarchyPriority(String beanName) {
- DefaultListableBeanFactory factory = this;
- int i = 1;
- while (factory != null) {
- if (factory.containsBeanDefinition(beanName)) {
- return i;
- }
- factory = (DefaultListableBeanFactory) factory.getParentBeanFactory();
- i++;
- }
- return null;
- }
-
- private static class Bean {
- private final String name;
- private final Object instance;
-
- public Bean(String name, Object instance) {
- this.name = name;
- this.instance = instance;
- }
-
- public String getName() {
- return name;
- }
-
- public Object getInstance() {
- return instance;
- }
- }
-
- @FunctionalInterface
- private interface PriorityFunction {
- @Nullable
- Integer classify(Bean candidate);
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringComponentContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringComponentContainer.java
deleted file mode 100644
index 17325193d5b..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringComponentContainer.java
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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.scanner.bootstrap;
-
-import com.google.common.collect.Iterables;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.function.Supplier;
-import javax.annotation.CheckForNull;
-import org.jetbrains.annotations.Nullable;
-import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.api.utils.System2;
-import org.sonar.core.platform.ComponentKeys;
-import org.sonar.core.platform.Container;
-import org.sonar.core.platform.ExtensionContainer;
-import org.sonar.core.platform.PluginInfo;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
-
-import static java.util.Collections.emptyList;
-import static java.util.Optional.ofNullable;
-
-public class SpringComponentContainer implements ExtensionContainer {
- protected final AnnotationConfigApplicationContext context;
- @Nullable
- protected final SpringComponentContainer parent;
-
- private final PropertyDefinitions propertyDefinitions;
- private final ComponentKeys componentKeys = new ComponentKeys();
-
- protected SpringComponentContainer() {
- this(null, new PropertyDefinitions(System2.INSTANCE), emptyList());
- }
-
- protected SpringComponentContainer(List<?> externalExtensions) {
- this(null, new PropertyDefinitions(System2.INSTANCE), externalExtensions);
- }
-
- protected SpringComponentContainer(SpringComponentContainer parent) {
- this(parent, parent.propertyDefinitions, emptyList());
- }
-
- private SpringComponentContainer(@Nullable SpringComponentContainer parent, PropertyDefinitions propertyDefinitions, List<?> externalExtensions) {
- this.parent = parent;
- this.propertyDefinitions = propertyDefinitions;
- this.context = new AnnotationConfigApplicationContext(new PriorityBeanFactory());
- if (parent != null) {
- context.setParent(parent.context);
- }
- add(this);
- add(new StartableBeanPostProcessor());
- add(externalExtensions);
- add(propertyDefinitions);
- }
-
- /**
- * Beans need to have a unique name, otherwise they'll override each other.
- * The strategy is:
- * - For classes, use the classloader + fully qualified class name as the name of the bean
- * - For instances, use the Classloader + FQCN + toString()
- * - If the object is a collection, iterate through the elements and apply the same strategy for each of them
- */
- @Override
- public Container add(Object... objects) {
- for (Object o : objects) {
- if (o instanceof Class) {
- Class<?> clazz = (Class<?>) o;
- context.registerBean(componentKeys.ofClass(clazz), clazz);
- } else if (o instanceof Iterable) {
- add(Iterables.toArray((Iterable<?>) o, Object.class));
- } else {
- registerInstance(o);
- }
- }
- return this;
- }
-
- private <T> void registerInstance(T instance) {
- Supplier<T> supplier = () -> instance;
- Class<T> clazz = (Class<T>) instance.getClass();
- context.registerBean(componentKeys.ofInstance(instance), clazz, supplier);
- declareExtension("", instance);
- }
-
- /**
- * Extensions are usually added by plugins and we assume they don't support any injection-related annotations.
- * Spring contexts supporting annotations will fail if multiple constructors are present without any annotations indicating which one to use for injection.
- * For that reason, we need to create the beans ourselves, using ClassDerivedBeanDefinition, which will declare that all constructors can be used for injection.
- */
- private Container addExtension(Object o) {
- if (o instanceof Class) {
- Class<?> clazz = (Class<?>) o;
- ClassDerivedBeanDefinition bd = new ClassDerivedBeanDefinition(clazz);
- context.registerBeanDefinition(componentKeys.ofClass(clazz), bd);
- } else if (o instanceof Iterable) {
- ((Iterable<?>) o).forEach(this::addExtension);
- } else {
- ClassDerivedBeanDefinition bd = new ClassDerivedBeanDefinition(o.getClass());
- bd.setInstanceSupplier(() -> o);
- context.registerBeanDefinition(componentKeys.ofInstance(o), bd);
- }
- return this;
- }
-
- @Override
- public Container addSingletons(Iterable<?> components) {
- return add(components);
- }
-
- @Override
- public <T> T getComponentByType(Class<T> type) {
- try {
- return context.getBean(type);
- } catch (Exception t) {
- throw new IllegalStateException("Unable to load component " + type, t);
- }
- }
-
- @Override
- public <T> List<T> getComponentsByType(Class<T> type) {
- try {
- return new ArrayList<>(context.getBeansOfType(type).values());
- } catch (Exception t) {
- throw new IllegalStateException("Unable to load components " + type, t);
- }
- }
-
- public void execute() {
- RuntimeException r = null;
- try {
- startComponents();
- } catch (RuntimeException e) {
- r = e;
- } finally {
- try {
- stopComponents();
- } catch (RuntimeException e) {
- if (r == null) {
- r = e;
- }
- }
- }
- if (r != null) {
- throw r;
- }
- }
-
- public SpringComponentContainer startComponents() {
- doBeforeStart();
- context.refresh();
- doAfterStart();
- return this;
- }
-
- public SpringComponentContainer stopComponents() {
- if (context.isActive()) {
- context.close();
- }
- return this;
- }
-
- public SpringComponentContainer createChild() {
- return new SpringComponentContainer(this);
- }
-
- @Override
- @CheckForNull
- public SpringComponentContainer getParent() {
- return parent;
- }
-
- @Override
- public SpringComponentContainer addExtension(@Nullable PluginInfo pluginInfo, Object extension) {
- addExtension(extension);
- declareExtension(pluginInfo, extension);
- return this;
- }
-
- @Override
- public SpringComponentContainer addExtension(@Nullable String defaultCategory, Object extension) {
- addExtension(extension);
- declareExtension(defaultCategory, extension);
- return this;
- }
-
- @Override
- public SpringComponentContainer declareExtension(@Nullable PluginInfo pluginInfo, Object extension) {
- declareExtension(pluginInfo != null ? pluginInfo.getName() : "", extension);
- return this;
- }
-
- @Override
- public SpringComponentContainer declareExtension(@Nullable String defaultCategory, Object extension) {
- this.propertyDefinitions.addComponent(extension, ofNullable(defaultCategory).orElse(""));
- return this;
- }
-
- /**
- * This method aims to be overridden
- */
- protected void doBeforeStart() {
- // nothing
- }
-
- /**
- * This method aims to be overridden
- */
- protected void doAfterStart() {
- // nothing
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringGlobalContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringGlobalContainer.java
index fb0f25eaf76..4e85fc6c1cc 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringGlobalContainer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringGlobalContainer.java
@@ -43,6 +43,7 @@ import org.sonar.core.platform.PluginClassLoader;
import org.sonar.core.platform.PluginClassloaderFactory;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginRepository;
+import org.sonar.core.platform.SpringComponentContainer;
import org.sonar.core.util.DefaultHttpDownloader;
import org.sonar.core.util.UuidFactoryImpl;
import org.sonar.scanner.extension.ScannerCoreExtensionsInstaller;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/StartableBeanPostProcessor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/StartableBeanPostProcessor.java
deleted file mode 100644
index 3bb4cb5570a..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/StartableBeanPostProcessor.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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.scanner.bootstrap;
-
-import org.sonar.api.Startable;
-import org.sonar.api.utils.log.Loggers;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
-import org.springframework.lang.Nullable;
-
-public class StartableBeanPostProcessor implements DestructionAwareBeanPostProcessor {
- @Override
- @Nullable
- public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
- if (bean instanceof Startable) {
- ((Startable) bean).start();
- } else if (bean instanceof org.picocontainer.Startable) {
- ((org.picocontainer.Startable) bean).start();
- }
- return bean;
- }
-
- @Override
- public boolean requiresDestruction(Object bean) {
- return (bean instanceof Startable) || (bean instanceof org.picocontainer.Startable) || (bean instanceof AutoCloseable);
- }
-
- @Override
- public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException {
- try {
- if (bean instanceof Startable) {
- ((Startable) bean).stop();
- } else if (bean instanceof org.picocontainer.Startable) {
- ((org.picocontainer.Startable) bean).stop();
- } else if (bean instanceof AutoCloseable) {
- ((AutoCloseable) bean).close();
- }
- } catch (Exception e) {
- Loggers.get(StartableBeanPostProcessor.class)
- .warn("Dispose of component {} failed", bean.getClass().getCanonicalName(), e);
- }
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/InputProjectProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/InputProjectProvider.java
index b5629ce69ef..ac65a92484e 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/InputProjectProvider.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/InputProjectProvider.java
@@ -32,7 +32,7 @@ public class InputProjectProvider {
@Bean("DefaultInputProject")
public DefaultInputProject provide(ProjectBuildersExecutor projectBuildersExecutor, ProjectReactorValidator validator,
- ProjectReactor projectReactor, ScannerComponentIdGenerator scannerComponentIdGenerator) {
+ ProjectReactor projectReactor, ScannerComponentIdGenerator scannerComponentIdGenerator, WorkDirectoriesInitializer workDirectoriesInit) {
// 1 Apply project builders
projectBuildersExecutor.execute(projectReactor);
@@ -41,6 +41,7 @@ public class InputProjectProvider {
// 3 Create project
DefaultInputProject project = new DefaultInputProject(projectReactor.getRoot(), scannerComponentIdGenerator.getAsInt());
+ workDirectoriesInit.execute(project);
LOG.info("Project key: {}", project.key());
LOG.info("Base dir: {}", project.getBaseDir().toAbsolutePath().toString());
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/LanguagesProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/LanguagesProvider.java
deleted file mode 100644
index d1c3d972350..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/LanguagesProvider.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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.scanner.scan;
-
-import java.util.List;
-import java.util.Optional;
-import org.sonar.api.resources.Language;
-import org.sonar.api.resources.Languages;
-import org.springframework.context.annotation.Bean;
-
-public class LanguagesProvider {
- @Bean("Languages")
- public Languages provide(Optional<List<Language>> languages) {
- if (languages.isEmpty()) {
- return new Languages();
- }
- return new Languages(languages.get().toArray(new Language[0]));
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringModuleScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringModuleScanContainer.java
index 79a09172a31..4707354a706 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringModuleScanContainer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringModuleScanContainer.java
@@ -23,7 +23,7 @@ import javax.annotation.Priority;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.scan.filesystem.FileExclusions;
import org.sonar.scanner.bootstrap.ExtensionInstaller;
-import org.sonar.scanner.bootstrap.SpringComponentContainer;
+import org.sonar.core.platform.SpringComponentContainer;
import org.sonar.scanner.scan.filesystem.DefaultModuleFileSystem;
import org.sonar.scanner.scan.filesystem.ModuleInputComponentStore;
import org.sonar.scanner.sensor.ModuleSensorContext;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java
index 8320fa8a3fc..888f5661e8c 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java
@@ -33,6 +33,7 @@ import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.core.config.ScannerProperties;
import org.sonar.core.extension.CoreExtensionsInstaller;
+import org.sonar.core.language.LanguagesProvider;
import org.sonar.core.metric.ScannerMetrics;
import org.sonar.scanner.DefaultFileLinesContextFactory;
import org.sonar.scanner.ProjectInfo;
@@ -41,7 +42,7 @@ import org.sonar.scanner.bootstrap.ExtensionInstaller;
import org.sonar.scanner.bootstrap.ExtensionMatcher;
import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
import org.sonar.scanner.bootstrap.PostJobExtensionDictionary;
-import org.sonar.scanner.bootstrap.SpringComponentContainer;
+import org.sonar.core.platform.SpringComponentContainer;
import org.sonar.scanner.ci.CiConfigurationProvider;
import org.sonar.scanner.ci.vendors.AppVeyor;
import org.sonar.scanner.ci.vendors.AwsCodeBuild;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/WorkDirectoriesInitializer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/WorkDirectoriesInitializer.java
index b118a870ff7..11552502e00 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/WorkDirectoriesInitializer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/WorkDirectoriesInitializer.java
@@ -24,26 +24,42 @@ import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Iterator;
-import org.sonar.core.util.FileUtils;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
+import org.sonar.core.util.FileUtils;
import org.sonar.scanner.fs.InputModuleHierarchy;
/**
- * Clean and create working directories of each module.
+ * Clean and create working directories of each module, except the root.
* Be careful that sub module work dir might be nested in parent working directory.
*/
public class WorkDirectoriesInitializer {
public void execute(InputModuleHierarchy moduleHierarchy) {
- cleanAllWorkingDirs(moduleHierarchy, moduleHierarchy.root());
- mkdirsAllWorkingDirs(moduleHierarchy, moduleHierarchy.root());
+ // dont apply to root. Root is done by InputProjectProvider
+ for (DefaultInputModule sub : moduleHierarchy.children(moduleHierarchy.root())) {
+ cleanAllWorkingDirs(moduleHierarchy, sub);
+ }
+ for (DefaultInputModule sub : moduleHierarchy.children(moduleHierarchy.root())) {
+ mkdirsAllWorkingDirs(moduleHierarchy, sub);
+ }
+ }
+
+ public void execute(DefaultInputProject project) {
+ cleanWorkingDir(project);
+ mkdirWorkingDir(project);
}
private static void cleanAllWorkingDirs(InputModuleHierarchy moduleHierarchy, DefaultInputModule module) {
for (DefaultInputModule sub : moduleHierarchy.children(module)) {
cleanAllWorkingDirs(moduleHierarchy, sub);
}
- if (Files.exists(module.getWorkDir())) {
- deleteAllRecursivelyExceptLockFile(module.getWorkDir());
+ cleanWorkingDir(module);
+ }
+
+ private static void cleanWorkingDir(AbstractProjectOrModule projectOrModule) {
+ if (Files.exists(projectOrModule.getWorkDir())) {
+ deleteAllRecursivelyExceptLockFile(projectOrModule.getWorkDir());
}
}
@@ -51,10 +67,14 @@ public class WorkDirectoriesInitializer {
for (DefaultInputModule sub : moduleHierarchy.children(module)) {
mkdirsAllWorkingDirs(moduleHierarchy, sub);
}
+ mkdirWorkingDir(module);
+ }
+
+ private static void mkdirWorkingDir(AbstractProjectOrModule projectOrModule) {
try {
- Files.createDirectories(module.getWorkDir());
+ Files.createDirectories(projectOrModule.getWorkDir());
} catch (Exception e) {
- throw new IllegalStateException("Fail to create working dir: " + module.getWorkDir(), e);
+ throw new IllegalStateException("Fail to create working dir: " + projectOrModule.getWorkDir(), e);
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorExtensionDictionary.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorExtensionDictionary.java
index d723bb2ebf3..5764ba0c854 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorExtensionDictionary.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorExtensionDictionary.java
@@ -22,9 +22,8 @@ package org.sonar.scanner.sensor;
import java.util.Collection;
import java.util.stream.Collectors;
import org.sonar.api.batch.sensor.Sensor;
-import org.sonar.core.platform.ComponentContainer;
+import org.sonar.core.platform.ExtensionContainer;
import org.sonar.scanner.bootstrap.AbstractExtensionDictionary;
-import org.sonar.scanner.bootstrap.SpringComponentContainer;
import org.sonar.scanner.scan.branch.BranchConfiguration;
import org.sonar.scanner.scan.filesystem.MutableFileSystem;
@@ -35,7 +34,7 @@ public class ModuleSensorExtensionDictionary extends AbstractExtensionDictionary
private final MutableFileSystem fileSystem;
private final BranchConfiguration branchConfiguration;
- public ModuleSensorExtensionDictionary(SpringComponentContainer componentContainer, ModuleSensorContext sensorContext, ModuleSensorOptimizer sensorOptimizer,
+ public ModuleSensorExtensionDictionary(ExtensionContainer componentContainer, ModuleSensorContext sensorContext, ModuleSensorOptimizer sensorOptimizer,
MutableFileSystem fileSystem, BranchConfiguration branchConfiguration) {
super(componentContainer);
this.sensorContext = sensorContext;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorExtensionDictionary.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorExtensionDictionary.java
index 60b31745d19..b33c96fa848 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorExtensionDictionary.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorExtensionDictionary.java
@@ -24,7 +24,7 @@ import java.util.List;
import java.util.stream.Collectors;
import org.sonar.api.scanner.sensor.ProjectSensor;
import org.sonar.scanner.bootstrap.AbstractExtensionDictionary;
-import org.sonar.scanner.bootstrap.SpringComponentContainer;
+import org.sonar.core.platform.SpringComponentContainer;
import org.sonar.scanner.scan.branch.BranchConfiguration;
import org.sonar.scanner.scan.filesystem.MutableFileSystem;