com.atlassian.maven.plugin.clover.CloverInstrumentMojo Maven / Gradle / Ivy
Show all versions of clover-maven-plugin Show documentation
package com.atlassian.maven.plugin.clover;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import com.atlassian.maven.plugin.clover.internal.AbstractCloverInstrumentMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
/**
* Fork a custom build lifecycle in which all sources will be instrumented by Clover and next execute this
* lifecycle till the install
phase. All instrumented classes will be stored in a separate directory. Similarly,
* artifacts produced will have the 'clover' classifier.
* This goal is forking a lifecycle because we don't want the Clover instrumentation to affect the main lifecycle
* build. This will prevent instrumented sources to be put in production by error. Thus running
* mvn install
on a project where this instrument
goal has been specified will run the
* build twice: once for building the project as usual and another time for instrumenting the sources with Clover
* and generating the Clover database.
*
* Attention: Maven does not support multiple classifiers for an artifact.
* In case your project creates artifacts with classifiers, it may happen that the 'clover' classifier will be lost and
* an instrumented artifact will be installed as non-instrumented one.
*
* Example: clover:instrument + jar:test-jar + install:install
*
*
* [INFO] --- maven-jar-plugin:2.6:test-jar (default) @ moneybags ---
* [INFO] Building jar: .../moneybags-1.0-SNAPSHOT-clover-tests.jar <<< file with double classifier was created
* [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ moneybags ---
* [INFO] Installing .../moneybags-1.0-SNAPSHOT-clover-tests.jar to
* ~/.m2/.../moneybags-1.0-SNAPSHOT-tests.jar <<< but 'clover' classifier was lost
*
*
* In order to avoid this, you can use the instrument-test
goal, which runs a forked lifecycle till
* the test
phase.
*/
@Execute(phase = LifecyclePhase.INSTALL, goal = "instrument", lifecycle = "clover")
@Mojo(name = "instrument")
public class CloverInstrumentMojo extends AbstractCloverInstrumentMojo {
/**
* {@inheritDoc}
*
* @see com.atlassian.maven.plugin.clover.internal.AbstractCloverMojo#execute()
*/
public void execute() throws MojoExecutionException {
super.execute();
}
@Override
protected boolean shouldRedirectArtifacts() {
return true;
}
@Override
protected boolean shouldRedirectOutputDirectories() {
return true;
}
}