Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run program "dartanalyzer": CreateProcess error=2, The system cannot find the file specified #24

Closed
phantrungphat opened this issue Jun 24, 2020 · 25 comments
Labels
bug Something isn't working fixed on develop

Comments

@phantrungphat
Copy link

phantrungphat commented Jun 24, 2020

Hi,
I'm facing a big problem.

my sonar-scanner.properties file:
sonar.host.url=//my server sonarqube
sonar.login=//my code to login
sonar.projectKey=//my projectKey
sonar.projectName=//my projectName
sonar.projectVersion=1.0.0
sonar.exclusions=.scannerwork/, .git/, vendor/, logs/, android/, ios/
sonar.projectBaseDir=Source
sonar.sources=lib
sonar.tests=test
sonar.sourceEncoding=UTF-8

When i run sonarqube: sonar-scanner -Dproject.settings=sonar-scanner.properties
i got errors:
INFO: Scanner configuration file: D:\Devops\Sonar-Scan\sonar-scanner-3.3.0.1492-windows\bin..\conf\sonar-scanner.properties
INFO: Project root configuration file: D:\JenkinsAgentIT2\workspace\MyProject\sonar-scanner.properties
INFO: SonarQube Scanner 3.3.0.1492
INFO: Java 1.8.0_121 Oracle Corporation (64-bit)
INFO: Windows NT (unknown) 10.0 amd64
INFO: User cache: C:\Users\Administrator.sonar\cache
INFO: SonarQube server 7.4.0
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Publish mode
INFO: Load global settings
INFO: Load global settings (done) | time=79ms
INFO: Server id: XXXXXXXXXXXXXX
INFO: User cache: C:\Users\Administrator.sonar\cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=48ms
INFO: Load/download plugins (done) | time=79ms
INFO: Loaded core extensions:
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=5ms
INFO: Load project repositories
INFO: Load project repositories (done) | time=57ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=32ms
INFO: Load active rules
INFO: Load active rules (done) | time=2158ms
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=25ms
INFO: Project key: my projectKey
INFO: Project base dir: D:\JenkinsAgentIT2\workspace\MyProject\Source
INFO: ------------- Scan MyProject
INFO: Base dir: D:\JenkinsAgentIT2\workspace\MyProject\Source
INFO: Working dir: D:\JenkinsAgentIT2\workspace\MyProject\Source.scannerwork
INFO: Source paths: lib
INFO: Test paths: test
INFO: Source encoding: UTF-8, default locale: en_US
INFO: Load server rules
INFO: Load server rules (done) | time=208ms
INFO: Index files
INFO: 253 files indexed
INFO: Quality profile for dart: dartanalyzer
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=5ms
INFO: Sensor Dart sensor [flutter]
INFO: Sensor Dart sensor [flutter] (done) | time=5864ms
INFO: Sensor dartanalyzer sensor [flutter]
INFO: Backup of original analysis_options.yaml file to analysis_options.yaml.sonar
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 12.142s
INFO: Final Memory: 291M/1042M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: Could not startup process 'dartanalyzer -h'.
ERROR: Caused by: Cannot run program "dartanalyzer": CreateProcess error=2, The system cannot find the file specified
ERROR: Caused by: CreateProcess error=2, The system cannot find the file specified
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.

I checked dartanalyzer -h in the same folder, it fines!
Usage: dartanalyzer [options...]

--dart-sdk                    The path to the Dart SDK.
--options                     Path to an analysis options file.
--package-root                The path to a package root directory (deprecated). This option cannot be used with --packages.
--[no-]declaration-casts      Disable declaration casts in strong mode (https://goo.gl/cTLz40)
                              This option is now ignored and will be removed in a future release.
--[no-]implicit-casts         Disable implicit casts in strong mode (https://goo.gl/cTLz40).
--no-implicit-dynamic         Disable implicit dynamic (https://goo.gl/m0UgXD).
--packages                    The path to the package resolution configuration file, which supplies a mapping of package names
                              to paths. This option cannot be used with --package-root.
--[no-]lints                  Show lint results.
--format                      Specifies the format in which errors are displayed; the only currently allowed value is 'machine'.
--version                     Print the analyzer version.
--enable-experiment           Enable one or more experimental features. If multiple features are being added, they should be comma separated.
--no-hints                    Do not show hint results.
--fatal-infos                 Treat infos as fatal.
--fatal-warnings              Treat non-type warnings as fatal.

-h, --help Display this help message. Add --verbose to show hidden options.
-v, --verbose Verbose output.
--default-language-version The default language version when it is not specified via other ways (internal, tests only).

Run "dartanalyzer -h -v" for verbose help output, including less commonly used options.
For more information, see https://www.dartlang.org/tools/analyzer.

Anyone can suggest me the solution, please :(

@salim-lachdhaf
Copy link

same issue here i'm using windows 7

@Pizzakath
Copy link

I have the same issue, i tried with either dark-sdk installed by flutter and installing dart-sdk manually, both times having dart-sdk in my PATH, still the same issue.

Of course, when i use manually any dartanalyzer commands like "dartanalyzer lib test" it works, so i dont know why it doesn't work, probably it's from the binary plugin ?

Any updates on this issue please ?

@RicardoHds
Copy link

Any update for this issue?

Same issue.

@victorgilc
Copy link
Contributor

Same issue, windows server 2012

@santitigaga
Copy link

I have the same issue in windows 10

@victorgilc
Copy link
Contributor

victorgilc commented Jul 27, 2020

I have the same issue in windows 10

I think it's something related to windows...Maybe add the .bat at the end of the command

@santitigaga
Copy link

santitigaga commented Jul 27, 2020

@victorgilc Yes it's true, the plugin tries to run 'dartanalyzer -h' but can't because it needs to call 'dartanalyze.bat -h'.
Maybe someone knows how to solve it?

@victorgilc
Copy link
Contributor

victorgilc commented Jul 27, 2020

@victorgilc Yes it's true, the plugin tries to run 'dartanalyzer -h' but can't because it needs to call ** 'dartanalyze.bat -h' **.
Maybe someone knows how to solve it?

Exactly, I did the patch locally, I'll try to create a pull request as soon I'm able to test it.

DartAnalyzerSensor.java:

private static final String ANALYZER_COMMAND = System.getProperty("os.name").toUpperCase().contains("WINDOWS")?"dartanalyzer.bat":"dartanalyzer";

@santitigaga
Copy link

@victorgilc your answer works for me but I have new issue, Any idea?
imagen

@victorgilc
Copy link
Contributor

victorgilc commented Jul 27, 2020

@victorgilc your answer works for me but I have new issue, Any idea?
imagen

Yeah, a lot of errors actually...I'll work on the fix. I'll let you know when it's finished. Please let me know if you finish it first lol. Now I'm facing something related to "tests.output"

@santitigaga
Copy link

Yes, @victorgilc, it is true, I solved it by changing the code of the code in the FlutterTestReportParser.java class with the help of PR #22. Am I a little uncomfortable there are several open pull requests, the approvers disappeared?

@victorgilc
Copy link
Contributor

Yes, @victorgilc, it is true, I solved it by changing the code of the code in the FlutterTestReportParser.java class with the help of PR #22. Am I a little uncomfortable there are several open pull requests, the approvers disappeared?

Maybe these guys didn't have time enough to approve in the last few days...At least it's open-source.

@sathishmscict
Copy link

Same issue here !

@victorgilc
Copy link
Contributor

I'm working on it. I'll try to finish it at the weekend. If someone wants to help me, I appreciate it.

@victorgilc
Copy link
Contributor

Well, I'm not finished yet, but there's something wrong with the following regex inside the class "DartAnalyzerReportParser.java": Pattern pattern = Pattern.compile("(.)•(.)•(.):(.):(.)•(.)");

With the "dartanalyzer" output, this regex isn't able to create any sonar issue.

@victorgilc
Copy link
Contributor

I opened a PR. please reach me for any concerns.

@zippy1978 zippy1978 added the bug Something isn't working label Aug 9, 2020
@victorgilc
Copy link
Contributor

The pull request that fixes this bug was merged to the development branch today.

@zippy1978
Copy link
Contributor

Issue is fixed in release 0.3.0 (it includes @victorgilc PR).
I'm closing the issue.

@epadilhaf3
Copy link

epadilhaf3 commented Aug 14, 2020

Hello guys, I hope you are doing well, I am using the release 0.3.1, during the scanner I found the related problem here in the previous posts.
I'm using it in a gitlab CI/CD pipeline to generate the analysis and push it to Sonarqube.

ERROR: Could not startup process 'dartanalyzer -h'.
org.buildobjects.process.StartupException: Could not startup process 'dartanalyzer -h'.
Caused by: java.io.IOException: Cannot run program "dartanalyzer": error=2, No such file or directory

Should we reopen the issue?

Thank you in advance!

@zippy1978
Copy link
Contributor

Hi @epadilhaf3,

Is Flutter properly installed on your runner ?

For example, here is what I use to run an analysis on Gitlab :

image: openjdk:8-jdk

variables:
  FLUTTER_VERSION: "1.20.1-stable"
  SONAR_SCANNER_VERSION: "3.2.0.1227"

before_script:
  - apt-get --quiet update --yes
  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 apt-transport-https
  - sh -c 'wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
  - sh -c 'wget -qO- https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
  - apt-get --quiet update --yes
  - apt-get --quiet install --yes dart
  - export PATH=$PATH:/usr/lib/dart/bin
  - wget --output-document=flutter-sdk.tar.xz https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_${FLUTTER_VERSION}.tar.xz
  - tar -xf flutter-sdk.tar.xz
  - export PATH=$PATH:$PWD/flutter/bin
  - wget --output-document=sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip
  - unzip sonar-scanner.zip
  - export PATH=$PATH:$PWD/sonar-scanner-$SONAR_SCANNER_VERSION-linux/bin

stages:
  - analyse

analyse:
  stage: analyse
  script:
    - flutter pub get
    - flutter test --machine > tests.output
    - flutter test --coverage
    - sonar-scanner -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_TOKEN

@epadilhaf3
Copy link

epadilhaf3 commented Aug 17, 2020

Hi @epadilhaf3,

Is Flutter properly installed on your runner ?

For example, here is what I use to run an analysis on Gitlab :

image: openjdk:8-jdk

variables:
  FLUTTER_VERSION: "1.20.1-stable"
  SONAR_SCANNER_VERSION: "3.2.0.1227"

before_script:
  - apt-get --quiet update --yes
  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 apt-transport-https
  - sh -c 'wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
  - sh -c 'wget -qO- https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
  - apt-get --quiet update --yes
  - apt-get --quiet install --yes dart
  - export PATH=$PATH:/usr/lib/dart/bin
  - wget --output-document=flutter-sdk.tar.xz https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_${FLUTTER_VERSION}.tar.xz
  - tar -xf flutter-sdk.tar.xz
  - export PATH=$PATH:$PWD/flutter/bin
  - wget --output-document=sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip
  - unzip sonar-scanner.zip
  - export PATH=$PATH:$PWD/sonar-scanner-$SONAR_SCANNER_VERSION-linux/bin

stages:
  - analyse

analyse:
  stage: analyse
  script:
    - flutter pub get
    - flutter test --machine > tests.output
    - flutter test --coverage
    - sonar-scanner -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_TOKEN

Hey @zippy1978, thank you for your response, I hope you are doing well.
Looking for best performance, I'm using an image to flutter stage, running commands like apt-get update in a pipeline could result in a slow deployment, please take a look on my .gitlab-ci.yaml file:

stages:
  - test
  - sonar_analysis

unit_test:
  stage: test
  image: cirrusci/flutter:stable
  script:
    - pub get
    - dartanalyzer lib test
    - pub run test --reporter expanded
    - pub run test_coverage
    - genhtml coverage/lcov.info -o coverage

  artifacts:
    paths:
      - coverage/

.sonar_template: &sonar_common
  stage: sonar_analysis
  image: sonarsource/sonar-scanner-cli
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
  cache:
    key: ${CI_JOB_NAME}
    paths:
      - .sonar/cache

sonar_push:
  <<: *sonar_common
  script:
    - sonar-scanner -Dsonar.projectKey=$CI_PROJECT_NAME -Dsonar.qualitygate.wait=true -Dsonar.branch.name=$CI_COMMIT_BRANCH

sonar_mr:
  <<: *sonar_common
  script:
    - sonar-scanner -Dsonar.projectKey=$CI_PROJECT_NAME -Dsonar.pullrequest.key=$CI_MERGE_REQUEST_IID -Dsonar.pullrequest.branch=$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME -Dsonar.pullrequest.base=master
  rules:
    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'

The complete log is the following:

INFO: Sensor dartanalyzer sensor [flutter]
ERROR: Could not startup process 'dartanalyzer -h'.
org.buildobjects.process.StartupException: Could not startup process 'dartanalyzer -h'.
	at org.buildobjects.process.Proc.<init>(Proc.java:91)
	at org.buildobjects.process.ProcBuilder.run(ProcBuilder.java:205)
	at fr.insideapp.sonarqube.dart.lang.issues.dartanalyzer.DartAnalyzerSensor.verifyIfDartAnalyzerExists(DartAnalyzerSensor.java:254)
	at fr.insideapp.sonarqube.dart.lang.issues.dartanalyzer.DartAnalyzerSensor.execute(DartAnalyzerSensor.java:68)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:400)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:395)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:358)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:73)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.io.IOException: Cannot run program "dartanalyzer": error=2, No such file or directory
	at java.base/java.lang.ProcessBuilder.start(Unknown Source)
	at java.base/java.lang.ProcessBuilder.start(Unknown Source)
	at java.base/java.lang.Runtime.exec(Unknown Source)
	at org.buildobjects.process.Proc.<init>(Proc.java:77)
	... 33 common frames omitted
Caused by: java.io.IOException: error=2, No such file or directory
	at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
	at java.base/java.lang.ProcessImpl.<init>(Unknown Source)
	at java.base/java.lang.ProcessImpl.start(Unknown Source)
	... 37 common frames omitted

Thank you again.

@zippy1978
Copy link
Contributor

Hi @epadilhaf3,

The problem is that when you move to stage "sonar_analysis", you switch to image "sonarsource/sonar-scanner-cli", where flutter is not installed.

@epadilhaf3
Copy link

Hi @epadilhaf3,

The problem is that when you move to stage "sonar_analysis", you switch to image "sonarsource/sonar-scanner-cli", where flutter is not installed.

Hey, thanks, I'll change it, and test.

@ninjacoder96
Copy link

any update on this?

@kuhnroyal
Copy link
Contributor

I don't think there is anything to do here. If you experience this message you need to make sure that you ran pub global activate dartanalyzer.
As a sidenote, Dartanalyzer has been pretty much replaced by dart/flutter analyze in recent Dart/Flutter versions. You can configure this via sonar.flutter.analyzer.mode according to the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed on develop
Projects
None yet
Development

No branches or pull requests