#소나큐브 (2)

설치환경

윈도우 8

이클립스 Luna

 

목차 

1. SonarQube 이클립스 플러그인 설치

2. SonarQube Download 및 서버 실행

3. 분석하고자하는 프로젝트와 SonarQube 프로젝트 연동하기

4. 분석 결과 보기

 

 

1. SonarQube 이클립스 플러그인 설치

플러그인 설치는 쉬우니까 아래 영문 가이드 보시면서 하시면 될것 같네요.

 

SonarQube 공식 이클립스 설치 가이드 문서

http://docs.sonarqube.org/display/SONAR/Installing+SonarQube+in+Eclipse

 

  1. Go to Help > Eclipse Marketplace... and search for "SonarQube"
    or
    Use offline update site: https://bintray.com/artifact/download/sonarsource/Distribution/org.sonar.ide.eclipse.site-3.5.0.20150804-1512-RELEASE.zip
    or
    Go to Help > Install New Software... This should display the Install dialog box. Paste the Update Site URL (http://downloads.sonarsource.com/eclipse/eclipse/) into the field Work with and press Enter. This should display the list of available plugins and components:



  2. Check the component you wish to install (see Features details).
  3. Click Next. Eclipse will then check to see if there is any issue which would prevent a successful installation.
  4. Click Finish to begin the installation process. Eclipse will then download and install the necessary components.
  5. Once the installation process is finished, Eclipse will ask if you want to restart the IDE. It is strongly recommended that you restart the IDE.

 

2. SonarQube Download 및 서버 실행 

아래 링크로 가시면 zip 파일을 다운로드 하실 수 있습니다.

 

http://www.sonarqube.org/downloads/

 

다운받은 zip파일을 바탕화면(원하는 곳)에 압축을 풀어주세요.

 

폴더 들어가면 bin폴더가 있고 그 안에 StartSonar.bat라는 파일이 있습니다.

 

이 파일을 실행시켜서 서버를 띄워주세요.

 

만약 서버 실행시 에러가 발생하면 아래 링크를 참조해주세요.

 

http://blog.naver.com/stork838/220442651809

 

마지막으로 서버가 제대로 실행 되었는지 확인

http://localhost:9000 ( 다른 설정을 건드리지 않았다면 기본적으로 이 주소로 접속이 가능해야 함 )

 

3. 분석하고자하는 프로젝트와 SonarQube 프로젝트 연동하기

a. 일단 서버에 접속이 잘 되는지 확인이 됐다면 admin으로 로그인 합니다.

( admin / admin 으로 접속 가능 )

 

b. Go to Settings -> System -> Provisioning

c. Create new project (Create 버튼은 우상단에 위치해있습니다. )

d. 프로젝트 생성시 key와 프로젝트명을 적절하게 아무거나 써주시면 됩니다. 나중에 이클립스에서 연동할 때 이 이름이 쓰입니다.

 

e. 이클립스에서 프로젝트에서 우클릭 -> Configure -> Associate with SonaQube

 

f. Sona Project 입력란에 아까 생성한 Sona 프로젝트명을 입력하면 자동완성기능으로 드랍다운 옵션이 보입니다.

g. 소나 프로젝트를 선택하고 완료하면 자동으로 분석을 시작합니다.

 

4. 분석 결과 보기

분석이 진행되는 동안 아래와 같은 메시지가 이클립스 콘솔창에 나옵니다.

 

Retrieve remote issues of project myproject...
Project not found on remote SonarQube server [myproject]      ---- A
Start SonarQube analysis on myproject...
INFO: SonarQube Server 5.1.2
11:20:19.564 INFO  - Incremental mode
11:20:19.935 INFO  - Load global repositories
11:20:20.786 INFO  - Load global repositories (done) | time=857ms
11:20:20.791 INFO  - Server id: 20150806110249
11:20:20.797 INFO  - User cache: C:\Users\user\.sonar\cache
11:20:20.813 INFO  - Install plugins
11:20:20.863 INFO  - Include plugins:
11:20:20.864 INFO  - Exclude plugins: devcockpit, jira, pdfreport, views, report, buildstability, buildbreaker
11:20:20.866 INFO  - Download sonar-core-plugin-5.1.2.jar
11:20:20.946 INFO  - Download sonar-email-notifications-plugin-5.1.2.jar
11:20:21.249 INFO  - Download sonar-java-plugin-3.0.jar
11:20:21.745 INFO  - Download sonar-scm-git-plugin-1.0.jar
11:20:21.963 INFO  - Download sonar-l10n-en-plugin-5.1.2.jar
11:20:21.987 INFO  - Download sonar-scm-svn-plugin-1.0.jar
11:20:23.923 INFO  - Load project repositories
11:20:24.658 INFO  - Load project repositories (done) | time=735ms
11:20:24.659 INFO  - Load project settings
11:20:25.575 INFO  - Apply project exclusions
11:20:25.613 INFO  - -------------  Scan myproject
11:20:25.624 INFO  - Load module settings
11:20:26.068 INFO  - Base dir: E:\ㅁㄴㅇㄹ
11:20:26.068 INFO  - Working dir: E:\ㅁㄴㅇㄹ
11:20:26.072 INFO  - Source paths: src
11:20:26.073 INFO  - Test paths: src
11:20:26.079 INFO  - Binary dirs: build/classes
11:20:26.079 INFO  - Source encoding: UTF-8, default locale: ko_KR
11:20:26.084 INFO  - Index files
11:20:26.098 INFO  - Excluded sources:
11:20:26.099 INFO  -   **/*Test.*
11:20:26.099 INFO  -   **/test/**/*
11:20:26.099 INFO  - Included tests:
11:20:26.099 INFO  -   **/*Test.*
11:20:26.099 INFO  -   **/test/**/*
11:20:27.123 INFO  - 370 files indexed
11:20:27.124 INFO  - 430 files ignored because of inclusion/exclusion patterns
11:20:27.150 INFO  - Quality profile for java: Sonar way
11:20:27.226 INFO  - Sensor JavaSquidSensor
11:20:30.695 INFO  - Java Main Files AST scan...
11:20:30.695 INFO  - 370 source files to be analyzed
11:20:40.706 INFO  - 26/370 files analyzed, current is E:\sdf.java
11:20:50.706 INFO  - 84/370 files analyzed, current is E:\dfg.java
11:21:00.706 INFO  - 187/370 files analyzed, current is E:\fgh.java
11:21:10.708 INFO  - 281/370 files analyzed, current is E:\rtyService.java
11:21:20.711 INFO  - 329/370 files analyzed, current is E:\erwtDao.java
11:21:27.080 INFO  - Java Main Files AST scan done: 56385 ms
11:21:27.080 INFO  - 370/370 source files analyzed
11:21:27.098 INFO  - Java bytecode scan...
11:21:29.109 INFO  - Java bytecode scan done: 2011 ms
11:21:29.109 INFO  - Java Test Files AST scan...
11:21:29.109 INFO  - 0 source files to be analyzed
11:21:29.110 INFO  - Java Test Files AST scan done: 1 ms
11:21:29.111 INFO  - 0/0 source files analyzed
11:21:29.121 INFO  - Package design analysis...
11:21:29.655 INFO  - Package design analysis done: 534 ms
11:21:30.485 INFO  - Sensor JavaSquidSensor (done) | time=63259ms
11:21:30.486 INFO  - Sensor Lines Sensor
11:21:30.576 INFO  - Sensor Lines Sensor (done) | time=90ms
11:21:30.576 INFO  - Sensor SurefireSensor
11:21:30.579 INFO  - parsing E:\sdf\surefire-reports
11:21:30.580 WARN  - Reports path not found: E:\dfg\surefire-reports     ------ B
11:21:30.580 INFO  - Sensor SurefireSensor (done) | time=4ms
11:21:31.576 INFO  - Export issues to E:\dfg\sonar-report.json
11:21:32.193 INFO  - ANALYSIS SUCCESSFUL

 

위 빨간 줄로 보이는 부분은 무시하셔도 됩니다. 아래를 좀 더 읽어보시면 그 이유가 나옵니다.

 

5. 수동으로 분석하기 

이클립스 프로젝트가 Sona 프로젝트와 연동이 되면 프로젝트 우클릭 메뉴에 SonaQube 메뉴가 뜨게됩니다.

해당 메뉴로 들어가면 Analysis가 있으니 이를 이용하시면 됩니다.

 

참고로 저는 진행하는 동안 아래와 같은 오류메시지를 보았습니다.

콘솔창에는 ANALYSIS SUCCESSFUL이라고 떴지만 동시에 팝업창으로

An internal error occurred during: "SonarQube Analysis".
Unable to create markers

라고 나오네요.

 

원인을 찾아서 다시 이어서 글을 쓰도록 하겠습니다.

 

 

그럼 다들 즐프~

 

------------- updated 2015-08-07 -------------

이클립스에서는 preview 나 incremental 분석만 가능하다고 합니다.

자세한 내용은 아래 링크를 참고하세요.

http://docs.sonarqube.org/display/SONAR/Working+with+SonarQube+in+Eclipse.

 

그 말인 즉슨, 분석이 로컬로 이루어지고 SonarQube DB에 저장되지 않는다는 말입니다.

자세한 내용은 아래 링크를 참고하시기 바래요.

http://docs.sonarqube.org/display/SONAR/Concepts#Concepts-AnalysisModes

 

SonarQube 서버에 데이터를 저장하고 웹페이지에서 결과를 보려면 SonarQube Runner를 다운 받아서 실행해야 합니다.

자세한 내용은 아래 링크를 참고하세요.

http://docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Runner

 

 

5. 수동으로 분석하기 - 2

지난 번 포스팅에서 수동으로 분석하기를 할때 단순히 이클립스에서 Analyze했었는데 그렇게 하면 서버에 기록도 남지 않는다는 것을 알았죠. 그래서 좀 더 조사를 해서 진도를 좀 빼 보았습니다.

 

우선 요기 바로 위에 세개의 링크 중에서 마지막 링크로 가셔서 소나큐브 러너를 다운받으시고 원하는 위치에 압축을 풀어주세요.

그 리고 내컴퓨터 > 속성 >  고급시스템설정 > 환경변수 로 이동하셔서 ( 윈도우 8 기준입니다. ) 아래처럼 SONAR_RUNNER_HOME 변수를 새로만들기를 이용해서 등록해주시고, Path에 사진에 보이시는 것처럼 등록해주세요.

 

 

 

 

그리고 소나 서버가 기동되어있다는 가정하에, 분석하고자하는 프로젝트의 루트 디렉토리로 이동해주세요.

예를들면 d:\eclipse\workspace\myproject 가 되겠죠?

 

그리고 파일을 하나 생성합니다.

 

sonar-project.properties 라는 파일을 생성하고 아래 내용을 넣어주세요. 본인의 설정에 맞게 projectKey와 projectName 그리고 제일 아래의 소스 인코딩 값을 바꿔주세요.

 

 

# must be unique in a given SonarQube instance
sonar.projectKey=myproject

# this is the name displayed in the SonarQube UI
sonar.projectName=myproject project
sonar.projectVersion=1.0
 
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set.
# If not set, SonarQube starts looking for source code from the directory containing
# the sonar-project.properties file.
sonar.sources=.
 
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8

 

 

이제 저장을 하고 나와서 cmd창을 열어서 프로젝트 루트 디렉토리로 이동합니다.

 

그리고 소나 러너를 실행시킵니다.

 

기본적으로 sonar-runner 라고 하면 되는데 -X 옵션을 주면 debug 모드로 진행상황을 확인하실 수 있습니다.

 

아마 프로젝트가 svn과 연결되어있지 않은 상태라면 ( .svn 디렉토리가 프로젝트 루트디렉토리에 없다면 ) 실행이 잘 될겁니다.

 

실행이 잘 되었다면 로그 마지막 부분에 아래처럼 나오고 소나 러너는 종료됩니다.

 

INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
Total time: 25.866s
Final Memory: 15M/499M
INFO: ------------------------------------------------------------------------

 

이제 소나큐브 웹으로가서 분석된 자료를 확인해보겠습니다.

 

 

 

 

이런식으로 결과를 확인하실 수 있습니다. 각 수치가 뭘 의미하는지에 대해서는 자료를 좀 찾아봐야 할것 같습니다.

 

그부분은 여러분들이 각자 알아서 해보시면 될것 같네요.

 

참고로 저는 svn 연동해놓은 프로젝트도 시도해보았는데 svn 관련 에러가 발생했습니다.

 

이 부분에 대해서는 추후 업데이트 할 때 연이어서 글을 남기도록 하겠습니다.

 

 이상 케이치였습니다.

 

윈도우에서 소나큐브 서버를 실행시키기 위해서

$SonarQube Home$/bin/windows-x86-64/StartSonar.bat 파일을 실행시키면 cmd창에 아래처럼 에러가 뜨는데요


wrapper  | --> Wrapper Started as Console
wrapper  | Launching a JVM...
jvm 1    | Error occurred during initialization of VM
jvm 1    | GC triggered before VM initialization completed. Try increasing NewSize, current value 1536K.
wrapper  | JVM exited while loading the application.
wrapper  | JVM Restarts disabled.  Shutting down.
wrapper  | <-- p="" stopped="" wrapper="">

계속하려면 아무 키나 누르십시오 . . .



처음에는 sonar.properties에서 한참 찾다가 어떤 분이 포스팅한 글을 보고 해결했습니다.


위와 같은 에러나 가오면
$SonarQube Home$/conf/wrapper.conf 에서 아래 설정을 찾아서 값을 올려주면 됩니다.


(default)
wrapper.java.initmemory=3
wrapper.java.maxmemory=32


 

(after changing)

wrapper.java.initmemory=128
wrapper.java.maxmemory=256



그럼 즐프 하세요~ ^-^