All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jayway.maven.plugins.android.phase08preparepackage.EmmaMojo Maven / Gradle / Ivy

There is a newer version: 4.0.0-rc.2
Show newest version
/*
 * Copyright (C) 2009 Jayway AB Copyright (C) 2007-2008 JVending Masa 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.phase08preparepackage;

import com.jayway.maven.plugins.android.AbstractAndroidMojo;
import com.jayway.maven.plugins.android.configuration.Emma;
import com.vladium.emma.instr.InstrProcessor;
import com.vladium.emma.instr.InstrProcessor.OutMode;

import java.io.File;
import java.util.ArrayList;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

/**
 * After compiled Java classes use emma tool
 * @author [email protected]
 * @goal emma
 * @phase prepare-package
 * @requiresDependencyResolution compile
 */
public class EmmaMojo extends AbstractAndroidMojo {

    private static final String EMMA_FOLDER_NAME = "emma";
    private static final String CLASSES_FOLDER_NAME = "classes";
    private static final String COVERAGE_METADATA_NAME = "coverage.em";
    /**
     * Configuration for the emma command execution. It can be configured in the plugin configuration like so
     * 
     * 
     * <emma>
     *   <enable>true|false</enable>
     *   <classFolders>${project}/target/classes</classFolders>
     *   <outputMetaFile>${project}/target/emma/coverage.em</outputMetaFile>
     * </emma>
     * 
* * or via properties emma.* or command line parameters android.emma.* * @parameter */ private Emma emma; /** * Decides whether to enable or not enable emma. * @parameter expression="${android.emma.enable}" default-value="false" */ private boolean emmaEnable; /** * Configure directory where compiled classes are. * @parameter expression="${android.emma.classFolders}" default-value="${project.build.directory}/classes/" */ private String emmaClassFolders; /** * Decides whether to enable or not enable emma. * @parameter expression="${android.emma.outputMetaFile}" default-value="${project.build.directory}/emma/coverage.es" */ private File emmaOutputMetaFile; private boolean parsedEnable; private String[] parsedEmmaClassFolders; private String parsedOutputMetadataFile; public void execute() throws MojoExecutionException, MojoFailureException { getLog().debug("Emma start working. Before parse configuration"); parseConfiguration(); if (parsedEnable) { getLog().info("Emma OVERWRITE compiled class is on for this project !!! please don't use this project on production"); getLog().debug("configuration: Class Folders - this file will be modificated by emma " + parsedEmmaClassFolders); getLog().debug("configuration: parsedOutputMetadataFile " + parsedOutputMetadataFile); InstrProcessor processor = InstrProcessor.create(); processor.setInstrPath(parsedEmmaClassFolders, true); processor.setInstrOutDir(parsedEmmaClassFolders[0]); //always to first define folder processor.setMetaOutFile(parsedOutputMetadataFile); processor.setOutMode(OutMode.OUT_MODE_OVERWRITE); processor.setMetaOutMerge(Boolean.TRUE); processor.run(); } getLog().debug("Emma OVERWRITE is OFF for this project (" + project.getArtifactId() + ") taeget/classes files are safe"); } private void parseConfiguration() throws MojoExecutionException { if (emma != null) { if (emma.isEnable() == null) { parsedEnable = emmaEnable; } else { parsedEnable = emma.isEnable(); } if (emma.getClassFolders() != null) { parsedEmmaClassFolders = getAllCompiledDirectory(); } else { parsedEmmaClassFolders = getDefaultCompiledFolders(); } if (emma.getOutputMetaFile() != null) { parsedOutputMetadataFile = emma.getOutputMetaFile(); }else{ parsedOutputMetadataFile = getDefaultMetaDataFile(); } } else { parsedEnable = emmaEnable; parsedEmmaClassFolders = new String[]{emmaClassFolders}; parsedOutputMetadataFile = emmaOutputMetaFile.getAbsolutePath(); } } private String getDefaultMetaDataFile() { File outputFolder = new File(project.getBuild().getDirectory() + File.separator + EMMA_FOLDER_NAME + File.separator + COVERAGE_METADATA_NAME); return outputFolder.getAbsolutePath(); } private String[] getDefaultCompiledFolders() { File sourceJavaFolder = new File(project.getBuild().getDirectory() + File.separator + CLASSES_FOLDER_NAME + File.separator); return new String[]{sourceJavaFolder.getAbsolutePath()}; } private String[] getAllCompiledDirectory() throws MojoExecutionException { String classFoldersTemp = emma.getClassFolders(); String[] classFolders; if (classFoldersTemp==null){ return new String[]{emmaClassFolders}; }else{ classFolders = classFoldersTemp.split(","); } ArrayList classFoldersArray = new ArrayList(); for (String folder : classFolders) { File directory = new File(folder); if (directory.exists() && directory.isDirectory()) { classFoldersArray.add(directory.getAbsolutePath()); } } return classFoldersArray.toArray(new String[0]); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy