All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonarsource.scanner.lib.ScannerEngineFacade Maven / Gradle / Ivy

The newest version!
/*
 * SonarScanner Java Library
 * Copyright (C) 2011-2024 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.sonarsource.scanner.lib;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import org.sonarsource.scanner.lib.internal.JreCacheHit;

public abstract class ScannerEngineFacade implements AutoCloseable {

  private final Map bootstrapProperties;
  private final boolean isSonarCloud;
  private final String serverVersion;
  private final boolean wasEngineCacheHit;
  private final JreCacheHit wasJreCacheHit;

  ScannerEngineFacade(Map bootstrapProperties, boolean isSonarCloud, @Nullable String serverVersion,
    boolean wasEngineCacheHit, @Nullable JreCacheHit wasJreCacheHit) {
    this.bootstrapProperties = bootstrapProperties;
    this.isSonarCloud = isSonarCloud;
    this.serverVersion = serverVersion;
    this.wasEngineCacheHit = wasEngineCacheHit;
    this.wasJreCacheHit = wasJreCacheHit;
  }

  public String getServerVersion() {
    if (isSonarCloud) {
      throw new UnsupportedOperationException("Server version is not available for SonarCloud.");
    }
    return serverVersion;
  }

  public boolean isSonarCloud() {
    return isSonarCloud;
  }

  public boolean analyze(Map analysisProps) {
    Map allProps = new HashMap<>();
    allProps.putAll(bootstrapProperties);
    allProps.putAll(analysisProps);
    initAnalysisProperties(allProps);
    addStatsProperties(allProps);
    return doAnalyze(allProps);
  }

  private void addStatsProperties(Map allProps) {
    if (wasJreCacheHit != null) {
      allProps.put("sonar.scanner.wasJreCacheHit", wasJreCacheHit.name());
    }
    allProps.put("sonar.scanner.wasEngineCacheHit", String.valueOf(wasEngineCacheHit));
  }

  abstract boolean doAnalyze(Map allProps);

  private static void initAnalysisProperties(Map p) {
    new Dirs().init(p);
  }

  public Map getBootstrapProperties() {
    return bootstrapProperties;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy