aboutsummaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
Diffstat (limited to 'media')
-rw-r--r--media/CMakeLists.txt54
-rw-r--r--media/Makefile30
2 files changed, 54 insertions, 30 deletions
diff --git a/media/CMakeLists.txt b/media/CMakeLists.txt
new file mode 100644
index 00000000..d2cb912c
--- /dev/null
+++ b/media/CMakeLists.txt
@@ -0,0 +1,54 @@
+set(ICON_FILES
+ icons/tigervnc_16.png
+ icons/tigervnc_22.png
+ icons/tigervnc_24.png
+ icons/tigervnc_32.png
+ icons/tigervnc_48.png)
+
+find_program(CONVERT_EXECUTABLE convert)
+
+if(CONVERT_EXECUTABLE)
+ add_custom_target(icons-target ALL DEPENDS ${ICON_FILES})
+
+ if(UNIX AND NOT APPLE)
+ foreach(SIZE 16 22 24 32 48)
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/icons/tigervnc_${SIZE}.png
+ DESTINATION ${DATA_DIR}/icons/hicolor/${SIZE}x${SIZE}/apps
+ RENAME tigervnc.png)
+ endforeach()
+ install(FILES icons/tigervnc.svg
+ DESTINATION ${DATA_DIR}/icons/hicolor/scalable/apps)
+ endif()
+endif()
+
+add_custom_command(OUTPUT icons COMMAND mkdir icons)
+
+add_custom_command(OUTPUT icons/tigervnc_16.png
+ COMMAND ${CONVERT_EXECUTABLE} -background transparent
+ ${CMAKE_CURRENT_SOURCE_DIR}/tigervnc_16.svg icons/tigervnc_16.png
+ DEPENDS icons ${CMAKE_CURRENT_SOURCE_DIR}/tigervnc_16.svg
+ COMMENT "Generating icons/tigervnc_16.png")
+
+add_custom_command(OUTPUT icons/tigervnc_22.png
+ COMMAND ${CONVERT_EXECUTABLE} -size 22x22 xc:none -gravity center -background transparent
+ ${CMAKE_CURRENT_SOURCE_DIR}/tigervnc_20.svg -composite icons/tigervnc_22.png
+ DEPENDS icons ${CMAKE_CURRENT_SOURCE_DIR}/tigervnc_20.svg
+ COMMENT "Generating icons/tigervnc_22.png")
+
+add_custom_command(OUTPUT icons/tigervnc_24.png
+ COMMAND ${CONVERT_EXECUTABLE} -size 24x24 xc:none -gravity center -background transparent
+ ${CMAKE_CURRENT_SOURCE_DIR}/tigervnc_20.svg -composite icons/tigervnc_24.png
+ DEPENDS icons ${CMAKE_CURRENT_SOURCE_DIR}/tigervnc_20.svg
+ COMMENT "Generating icons/tigervnc_24.png")
+
+add_custom_command(OUTPUT icons/tigervnc_32.png
+ COMMAND ${CONVERT_EXECUTABLE} -size 32x32 xc:none -gravity center -background transparent
+ ${CMAKE_CURRENT_SOURCE_DIR}/tigervnc_28.svg -composite icons/tigervnc_32.png
+ DEPENDS icons ${CMAKE_CURRENT_SOURCE_DIR}/tigervnc_28.svg
+ COMMENT "Generating icons/tigervnc_32.png")
+
+add_custom_command(OUTPUT icons/tigervnc_48.png
+ COMMAND ${CONVERT_EXECUTABLE} -size 48x48 xc:none -gravity center -background transparent
+ ${CMAKE_CURRENT_SOURCE_DIR}/tigervnc_42.svg -composite icons/tigervnc_48.png
+ DEPENDS icons ${CMAKE_CURRENT_SOURCE_DIR}/tigervnc_42.svg
+ COMMENT "Generating icons/tigervnc_48.png")
diff --git a/media/Makefile b/media/Makefile
deleted file mode 100644
index e2f016b1..00000000
--- a/media/Makefile
+++ /dev/null
@@ -1,30 +0,0 @@
-all: icons
-
-.PHONY: clean
-clean: clean-icons
-
-ICONS := \
- icons/tigervnc_16.png \
- icons/tigervnc_22.png \
- icons/tigervnc_24.png \
- icons/tigervnc_32.png \
- icons/tigervnc_48.png
-
-.PHONY: icons clean-icons
-icons: $(ICONS)
-
-clean-icons:
- rm -f $(ICONS)
-
-icons/tigervnc_16.png: tigervnc_16.svg
- convert -background transparent "$<" "$@"
-
-icons/tigervnc_22.png: tigervnc_20.svg
- convert -size 22x22 xc:none -gravity center -background transparent "$<" -composite "$@"
-icons/tigervnc_24.png: tigervnc_20.svg
- convert -size 24x24 xc:none -gravity center -background transparent "$<" -composite "$@"
-icons/tigervnc_32.png: tigervnc_28.svg
- convert -size 32x32 xc:none -gravity center -background transparent "$<" -composite "$@"
-icons/tigervnc_48.png: tigervnc_42.svg
- convert -size 48x48 xc:none -gravity center -background transparent "$<" -composite "$@"
-
' href='#n196'>196 197 198 199 200 201 202 203 204 205 206
/*
 * SonarSource :: IT :: SonarQube Scanner
 * Copyright (C) 2009-2019 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 com.sonarsource.scanner.it;

import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.SonarScanner;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.stream.Collectors;
import org.assertj.core.api.Condition;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonarqube.ws.WsMeasures.Measure;

import static java.lang.Integer.parseInt;
import static org.assertj.core.api.Assertions.assertThat;

public class ScannerTest extends ScannerTestCase {

  @Rule
  public TemporaryFolder temp = new TemporaryFolder();

  @After
  public void cleanup() {
    orchestrator.resetData();
  }

  @Test
  public void basedir_contains_sources() {
    SonarScanner build = newScanner(new File("projects/basedir-with-source"));
    orchestrator.executeBuild(build);

    Map<String, Measure> projectMeasures = getMeasures("java:basedir-with-source", "files", "ncloc");
    assertThat(parseInt(projectMeasures.get("files").getValue())).isEqualTo(1);
    assertThat(parseInt(projectMeasures.get("ncloc").getValue())).isGreaterThan(1);
  }

  /**
   * Replace the maven format groupId:artifactId by a single key
   */
  @Test
  public void should_support_simple_project_keys() {
    SonarScanner build = newScanner(new File("projects/simple-sample"))
      .setProjectKey("SAMPLE");
    orchestrator.executeBuild(build);

    Map<String, Measure> projectMeasures = getMeasures("SAMPLE", "files", "ncloc");
    assertThat(parseInt(projectMeasures.get("files").getValue())).isEqualTo(2);
    assertThat(parseInt(projectMeasures.get("ncloc").getValue())).isGreaterThan(1);
  }

  /**
   * SONARPLUGINS-1230
   */
  @Test
  public void should_override_working_dir_with_relative_path() {
    SonarScanner build = newScanner(new File("projects/override-working-dir"))
      .setProperty("sonar.working.directory", ".overridden-relative-sonar");
    orchestrator.executeBuild(build);

    assertThat(new File("projects/override-working-dir/.sonar")).doesNotExist();
    assertThat(new File("projects/override-working-dir/.overridden-relative-sonar")).exists().isDirectory();
  }

  /**
   * SONARPLUGINS-1230
   */
  @Test
  public void should_override_working_dir_with_absolute_path() {
    File projectHome = new File("projects/override-working-dir");
    SonarScanner build = newScanner(projectHome)
      .setProperty("sonar.working.directory", new File(projectHome, ".overridden-absolute-sonar").getAbsolutePath());
    orchestrator.executeBuild(build);

    assertThat(new File("projects/override-working-dir/.sonar")).doesNotExist();
    assertThat(new File("projects/override-working-dir/.overridden-absolute-sonar")).exists().isDirectory();
  }

  /**
   * SONARPLUGINS-1856
   */
  @Test
  public void should_fail_if_source_dir_does_not_exist() {
    SonarScanner build = newScanner(new File("projects/bad-source-dirs"));

    BuildResult result = orchestrator.executeBuildQuietly(build);
    assertThat(result.getStatus()).isNotEqualTo(0);
    // with the following message
    assertThat(result.getLogs()).contains("Invalid value of sonar.sources for bad-source-dirs");
  }

  /**
   * SONARPLUGINS-2256
   */
  @Test
  public void should_warn_when_analysis_is_platform_dependent() {
    SonarScanner build = newScanner(new File("projects/simple-sample"))
      // ORCH-243
      .setSourceEncoding("");
    String log = orchestrator.executeBuild(build).getLogs();

    // Note: we can't really check the locale value and the charset because the ones used during the Sonar analysis may not be the ones
    // used to launch the tests. But we can check that the analysis is platform dependent (i.e. "sonar.sourceEncoding" hasn't been set).
    assertThat(log).contains("Default locale:");
    assertThat(log).contains(", source code encoding:");
    assertThat(log).contains("(analysis is platform dependent)");
  }

  /**
   * SONARUNNER-153
   */
  @Test
  public void should_enable_verbose() {
    // this line should appear in all versions (LTS-DEV) in debug only
    String expectedLog = "Available languages:";
    SonarScanner build = newScanner(new File("projects/simple-sample"))
      .setProperty("sonar.verbose", "true");
    String logs = orchestrator.executeBuild(build).getLogs();
    assertThat(logs).contains(expectedLog);
  }

  @Test
  public void should_use_environment_props() {
    SonarScanner build = newScanner(new File("projects/simple-sample-no-properties"))
      .setEnvironmentVariable("SONARQUBE_SCANNER_PARAMS", "{"
        + "\"sonar.projectKey\" : \"sample\"," +
        "\"sonar.projectName\" : \"Sample, with comma\"," +
        "\"sonar.projectDescription\" : \"This is a sample\"," +
        "\"sonar.projectVersion\" : \"1.2.3\"," +
        "\"sonar.sources\" : \"src\" }");
    orchestrator.executeBuild(build);
  }

  @Test
  public void should_skip_analysis() {
    SonarScanner build = newScanner(new File("projects/simple-sample"))
      .setProperty("sonar.host.url", "http://foo")
      .setEnvironmentVariable("SONARQUBE_SCANNER_PARAMS", "{ \"sonar.scanner.skip\":\"true\" }");

    BuildResult result = orchestrator.executeBuild(build);
    assertThat(result.getLogs()).contains("SonarQube Scanner analysis skipped");
  }

  @Test
  public void should_fail_if_unable_to_connect() {
    SonarScanner build = newScanner(new File("projects/simple-sample"))
      .setProperty("sonar.host.url", "http://foo");

    BuildResult result = orchestrator.executeBuildQuietly(build);
    // expect build failure
    assertThat(result.getStatus()).isNotEqualTo(0);
    // with the following message
    assertThat(result.getLogs()).contains("SonarQube server [http://foo] can not be reached");
  }

  // SONARPLUGINS-3574
  @Test
  public void run_from_external_location() throws IOException {
    File tempDir = temp.newFolder();
    SonarScanner build = newScanner(tempDir)
      .setProperty("sonar.projectBaseDir", new File("projects/simple-sample").getAbsolutePath())
      .addArguments("-e");
    orchestrator.executeBuild(build);

    assertThat(getComponent("sample").getDescription()).isEqualTo("This is a sample");
    Map<String, Measure> projectMeasures = getMeasures("sample", "files", "ncloc", "classes", "violations");
    assertThat(projectMeasures.values().stream().filter(measure -> measure.getValue() != null).collect(Collectors.toList())).hasSize(4);
  }

  @Test
  public void verify_env_variable() {
    SonarScanner build = newScanner(new File("projects/simple-sample"))
      .setEnvironmentVariable("SONAR_SCANNER_OPTS", "-Xmx2m");
    BuildResult executeBuild = orchestrator.executeBuildQuietly(build);
    assertThat(executeBuild.getStatus()).isNotEqualTo(0);
    String logs = executeBuild.getLogs();
    assertThat(logs).is(new Condition<String>("Contain error message about OOM") {
      @Override
      public boolean matches(String value) {
        return value.contains("java.lang.OutOfMemoryError")
          || value.contains("GC overhead limit exceeded") || value.contains("Java heap space");
      }
    });
  }

}