Home | History | Annotate | Download | only in maven
      1 /*******************************************************************************
      2  * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors
      3  * All rights reserved. This program and the accompanying materials
      4  * are made available under the terms of the Eclipse Public License v1.0
      5  * which accompanies this distribution, and is available at
      6  * http://www.eclipse.org/legal/epl-v10.html
      7  *
      8  * Contributors:
      9  *    Evgeny Mandrikov - initial API and implementation
     10  *
     11  *******************************************************************************/
     12 package org.jacoco.maven;
     13 
     14 import java.io.File;
     15 import java.io.IOException;
     16 
     17 import org.apache.maven.plugin.MojoExecutionException;
     18 import org.apache.maven.plugin.MojoFailureException;
     19 import org.apache.maven.plugins.annotations.LifecyclePhase;
     20 import org.apache.maven.plugins.annotations.Mojo;
     21 import org.codehaus.plexus.util.FileUtils;
     22 
     23 /**
     24  * Restores original classes as they were before offline instrumentation.
     25  *
     26  * @since 0.6.2
     27  */
     28 @Mojo(name = "restore-instrumented-classes", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, threadSafe = true)
     29 public class RestoreMojo extends AbstractJacocoMojo {
     30 
     31 	@Override
     32 	protected void executeMojo() throws MojoExecutionException,
     33 			MojoFailureException {
     34 		final File originalClassesDir = new File(getProject().getBuild()
     35 				.getDirectory(), "generated-classes/jacoco");
     36 		final File classesDir = new File(getProject().getBuild()
     37 				.getOutputDirectory());
     38 		try {
     39 			FileUtils.copyDirectoryStructure(originalClassesDir, classesDir);
     40 		} catch (final IOException e) {
     41 			throw new MojoFailureException("Unable to restore classes.", e);
     42 		}
     43 	}
     44 
     45 }
     46