com.jayway.maven.plugins.android.AbstractIntegrationtestMojo Maven / Gradle / Ivy
/*
* Copyright (C) 2009 Jayway AB
*
* Licensed 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.
*/
package com.jayway.maven.plugins.android;
import java.io.File;
import java.util.Set;
import com.jayway.maven.plugins.android.asm.AndroidTestFinder;
import static com.jayway.maven.plugins.android.common.AndroidExtension.APK;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
/**
* For integrationtest related Mojos.
*
* @author [email protected]
*/
public abstract class AbstractIntegrationtestMojo extends AbstractAndroidMojo {
/**
* -Dmaven.test.skip is commonly used with Maven to skip tests. We honor it too.
*
* @parameter expression="${maven.test.skip}" default-value=false
* @readonly
*/
private boolean mavenTestSkip;
/**
* -DskipTests is commonly used with Maven to skip tests. We honor it too.
*
* @parameter expression="${skipTests}" default-value=false
* @readonly
*/
private boolean mavenSkipTests;
/**
* Enables or disables integration test related goals. If true
they will be run; if false
,
* they will be skipped. If auto
, they will run if any of the classes inherit from any class in
* junit.framework.**
or android.test.**
.
*
* @parameter expression="${android.enableIntegrationTest}" default-value="auto"
*/
private String enableIntegrationTest;
/**
* Whether or not to execute integration test related goals. Reads from configuration parameter
* enableIntegrationTest
, but can be overridden with -Dmaven.test.skip
.
*
* @return true
if integration test goals should be executed, false
otherwise.
*/
protected boolean isEnableIntegrationTest() throws MojoFailureException, MojoExecutionException {
if (mavenTestSkip) {
return false;
}
if (mavenSkipTests) {
return false;
}
if ("false".equalsIgnoreCase(enableIntegrationTest)) {
return false;
}
if ("true".equalsIgnoreCase(enableIntegrationTest)) {
return true;
}
if ("auto".equalsIgnoreCase(enableIntegrationTest)) {
if (extractInstrumentationRunnerFromAndroidManifest(androidManifestFile) == null) {
return false;
}
return AndroidTestFinder.containsAndroidTests(new File(project.getBuild().getDirectory(), "android-classes"));
}
throw new MojoFailureException("enableIntegrationTest must be configured as 'true', 'false' or 'auto'.");
}
protected void deployDependencies() throws MojoExecutionException, MojoFailureException {
Set directDependentArtifacts = project.getDependencyArtifacts();
if (directDependentArtifacts != null) {
for (Artifact artifact : directDependentArtifacts) {
String type = artifact.getType();
if (type.equals(APK)) {
getLog().debug("Detected apk dependency " + artifact + ". Will resolve and deploy to device...");
final File targetApkFile = resolveArtifactToFile(artifact);
if (undeployBeforeDeploy) {
getLog().debug("Attempting undeploy of " + targetApkFile + " from device...");
undeployApk(targetApkFile);
}
getLog().debug("Deploying " + targetApkFile + " to device...");
deployApk(targetApkFile);
}
}
}
}
protected void deployBuiltApk() throws MojoExecutionException, MojoFailureException {
// If we're not on a supported packaging with just skip (Issue 112)
// http://code.google.com/p/maven-android-plugin/issues/detail?id=112
if (! SUPPORTED_PACKAGING_TYPES.contains(project.getPackaging())) {
getLog().info("Skipping deployment on " + project.getPackaging());
return;
}
File apkFile = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName()
+ "." + APK);
deployApk(apkFile);
}
}