Clover アドオンの有効化

このページの内容

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

このページでは、Bamboo のジョブ用にアトラシアンの Clover アドオンを有効にして設定する方法について説明します。

Bamboo を Clover と統合すると、次のことが可能になります。

  • 各ビルド結果のコード カバレッジの詳細 (つまり、テストでカバーされたコードの割合) を表示する
  • ジョブの一定期間におけるコード カバレッジの傾向を表示する
  • ジョブのコード カバレッジの要約を表示する

 

このページの内容

Clover アドオンを有効にする

  1. ジョブの設定」の説明に従って、目的のジョブに移動します。
  2. [Actions (アクション)] > [Configure Job (ジョブを設定)] の順に選択します。
  3. [Miscellaneous (その他)] タブをクリックします。
  4. Select Use Clover to collect Code Coverage for this build and set the following:

    1. Automatically integrate Clover into this build
      You will need to provide a Clover license, unless this has been configured globally in the Administration panel (Administration > Plugins > Clover Plugin).
    2. Generate a Clover Historical Report
      Displays the current coverage results compared with previous Clover code coverage reports.
    3. Generate a JSON report
      Provides the Clover results in a format ready for embedding into applications or external report views.
    4. Use plan-defined Clover license key
      Override the global Clover license for this particular plan.
    5. Clover is already integrated into this build
      Use this option when you already have Clover-for-Ant, Clover-for-Maven or another Clover integration configured to generate a report.
    6. Clover XML Location
      Specify the location where Bamboo will look for the XML report file from Clover. Please specify the file path relative to your plan's root directory (e.g /home/bamboouser/bamboo-home/xml-data/build-dir/MY_PLAN/), i.e. do not specify an absolute path.

       target/site/clover/clover.xml 

Screenshot: Settings to enable Clover for a job:


 

As Clover integration (automatic and manual) produces instrumented classes, we recommend that you ensure that your job does not install them to production (for instance: 'mvn deploy' to public repository, 'scp' to an application server running on production, etc ...). Having instrumented code in such locations is usually not desired.

Common practices to ensure proper separation of instrumented and non-instrumented classes are:

  • create a dedicated plan or job with Clover integration enabled
  • enable automatic Clover integration for jobs running tests only (e.g. "mvn verify")
  • use different location of local artifact cache if you need to install artifacts (e.g. ~/.m2/repository-clover and "mvn install")
  • use different URL for uploading artifacts if necessary (e.g. a separate repository for "mvn deploy")

 

Clover の自動統合

自動統合は、Ant、Maven 2.x、Maven 3.x、および Grails タスクと連携します。

  1. Clover コード カバレッジ設定で、[Use Clover to collect Code Coverage for this build (Clover を使用してこのビルドのコード カバレッジを収集する)] を選択します。
  2. [Automatically integrate Clover into this build (このビルドに Clover を自動的に統合する)] を選択します。
  3. Enter the global license key for Clover (go to Administration > Plugins > Clover Plugin), or enable Use plan-defined Clover license key and paste the key into the text field that appears.

さらに、次のことが可能です。

  • [Generate a Clover Historical Report (Clover 履歴レポートを生成する)] を選択して、現在のカバレッジ結果を以前の Clover コード カバレッジ レポートと比較します。
  • [Generate a JSON report (JSON レポートを生成する)] を選択して、アプリまたは外部レポート ビューに組み込める形式で Clover 結果を取得します

 

自動統合時の動作...

When automatic Clover integration is enabled, Bamboo:

  • Creates an artifact named Clover Report (System), which is visible on the 'Artifacts' tab for the job.

そして、各ビルドの実行時に次のことが行われます。

  • Extracts the Clover license (either the global or plan license key) into a temporary file and passes it to:
    • Ant タスク (-Dclover.license.path=/<bamboo-home>/xml-data/build-dir/<your-job>/.clover/clover.license として)
    • Maven タスク (-Dmaven.clover.licenseLocation=/<bamboo-home>/xml-data/build-dir/<your-job>/.clover/clover.license として)
  • Enhances tasks by adding
      • Ant - targets like "with.clover", "clover.report"
      • Maven - goals like "clover2:setup", "clover2:aggregate", "clover2:clover", "clover2:save-history"; it also adds "verify" phase if original command does not call "compile" or later phase
      • Grails - options like "-clover.on"
  • Generates Clover XML and HTML reports (by default)
  • Generates statistics and charts for a plan summary

 

In order to protect you against publishing instrumented code, automatic Clover integration will not run if the Maven task runs the "install" or "deploy" phases. In such case, you will find no Clover report and a build log will contain an appropriate warning message. In order to get coverage reports for such job, either edit the Maven task to run the build till the "verify" phase (or earlier) or configure Clover manually.

 

Clover の手動統合

Clover の手動統合は、Clover の呼び出しが可能なあらゆる種類のタスク (Ant、Maven 2.x、Maven 3.x、Command、Grails) と連携します。 

  1. Clover コード カバレッジ設定で、[Use Clover to collect Code Coverage for this build (Clover を使用してこのビルドのコード カバレッジを収集する)] を選択します。
  2. [Clover is already integrated into this build (Clover はこのビルドに統合済み)] を選択します。
  3. 参照場所を指定します。  Clover によって生成された XML レポート ファイルはここで Bamboo によって参照されます。
  4. On the 'Artifacts' tab, click Create Definition and complete the form as follows:

    Name
    This should begin with with "Clover Report".

    Location
    This should point to the HTML report directory (e.g. target/site/clover)

    Copy Pattern
    Use **/*.*

  5. ビルド スクリプトで Clover を設定して、XML と HTML の両方のレポートが生成されるようにします。

    Example for Ant...
    <clover-report initstring="target/clover/database/clover.db">			
        <current outfile="target/site/clover/clover.xml" />
        <current outfile="target/site/clover">
            <format type="html"/>
        </current>
    </clover-report>
    Example for Maven...
    <plugin>
        <groupId>com.atlassian.maven.plugins</groupId>
        <artifactId>maven-clover2-plugin</artifactId>
        <configuration>
            <generateHtml>true</generateHtml>
            <generateXml>true</generateXml>
        </configuration>
    </plugin>
  6. ビルド スクリプトで Clover ライセンスを設定するか、ジョブ設定の適切なタスク パラメーターとして Clover ライセンスを渡します。

    1. Clover ライセンス キーをファイル (/opt/bamboo/clover.license など) に保存します。
    2. 次の方法で、ライセンス キーの場所をビルド タスクに渡します。
      • ビルド スクリプトで場所を定義する
      • 計画設定の Ant/Maven タスクの Java プロパティとして渡す
    How to declare the license location in pom.xml...
    <plugin>
        <groupId>com.atlassian.maven.plugins</groupId>
        <artifactId>maven-clover2-plugin</artifactId>
        <version>3.1.8</version>
        <configuration>
            <licenseLocation>/opt/bamboo/clover.license</licenseLocation>
            <generateXml>true</generateXml>
            <generateHtml>true</generateHtml>
        </configuration>
    </plugin>
    How to declare the license location in build.xml...
    <project>
      <property name="clover.license.path" location="/opt/bamboo/clover.license"/>
      <!-- ... -->
    </project>
    How to pass the license location for Ant...
    clean with.clover test clover.report -Dclover.license.path=/opt/bamboo/clover.license
    How to pass the license location for Maven...
    mvn clean clover2:setup verify clover2:aggregate clover2:clover -Dmaven.clover.licenseLocation=/opt/bamboo/clover.license

     

     

ビルドのたびに、Bamboo は Clover XML ファイルを解析して、計画要約の統計とチャートを生成します。計画要約ページとジョブ要約ページに [Clover] タブが表示されます。 

Clover の結果を参照する

Clover HTML レポートとジョブに関する Clover 統計: 「計画の Clover コード カバレッジの表示」をご確認ください。 

計画の Clover コード カバレッジの要約:「ビルドの Clover コード カバレッジの表示」をご確認ください。

複数の計画にわたる Clover コード カバレッジの統計:「複数の計画にわたるレポートの生成」をご確認ください。

Clover が動作するマシンを制限する

Clover がライセンスされているマシンの数よりも多くのリモート エージェントがある場合は、次の機能を使用して Clover が動作するマシンを制限できます。
  1. Clover でビルドを実行する EC2 イメージごとに、イメージの設定に「clover=true」などの機能を追加します。
    これを行うには、[管理] > [Elastic Bamboo] > [設定] に移動します。エラスティック イメージを選択して、[Add Capability (機能を追加)] をクリックします。
  2. 「clover=true」などの一致要件を各ジョブの設定に追加します。
    これを行うには、[アクション] > [プランを構成] > [ジョブ] の順に移動します。Clover を実行するジョブを選択して、[要件] をクリックし、次に [Add Extra Requirement (要件を追加)] をクリックします。

トラブルシューティング

自動または手動の Clover 統合と生成されたプロセス

通常は、自動 Clover 統合を使用するか、maven-clover2-plugin に依存関係を手動で追加するだけで十分です。

ただし、ビルドが別の JVM プロセスを生成する場合 (例: フォークされた JVM で実行されるユニット テスト、その場でインスタンス化されたコンテナーでのテスト、別のサーバーにデプロイされたコードの呼び出しテスト)、その生成されたプロセスの依存関係を Clover JAR に手動で追加する必要があります。

ナレッジ ベース記事の「NoClassDefFoundError com_atlassian_clover/CoverageRecorder」をご確認ください。

自動 Clover 統合とサブディレクトリでの構築

サブディレクトリでビルドを実行して (たとえば Maven タスクの構成で "作業サブディレクトリ" フィールドを設定して)、自動 Clover 統合がある場合、"Clover レポート (システム)" アーティファクトのロケーションを修正しなければならない場合があります。修正しないと、自動 Clover 統合で既定のパス (たとえば Maven との統合の場合は "target/site/clover") が使用されるため、HTML レポートが空になる可能性があります。

This issue has been fixed in Bamboo 5.7.

自動 Clover 統合とマルチモジュール Maven プロジェクト

モジュール間に依存関係があるマルチモジュール Maven プロジェクトを持ち、自動 Clover 統合を使用している場合、Clover がまだ有効になっていなかったビルド フェーズで、依存アーティファクトのインストゥルメント化された JAR がテスト実行に利用されることがあります。詳細は BAM-13208 をご確認ください。このような場合は次をお勧めします。

  • 自動 Clover 統合が有効になっている別のジョブを作成します。
  • このジョブに何もしない Maven タスクを作成します ("クリーン" ゴールと呼ぶなど)。
  • Bamboo は Clover に関連するゴールを自動的に追加します (clover2:setup verify clover2:aggregate clover2:clover)。

This issue has been fixed in Bamboo 5.9.

Clover Results Collector is unable to find the XML report file

In the build log you may see a warning like: 

Failed to execute plugin 'Clover Results Collector' with error: No file matches the specified pattern ...

 

The are several possible reasons, see this article for more details: Failed to execute plugin 'Clover Results Collector'.


 

最終更新日 2018 年 4 月 24 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.