1 package org.apache.maven.plugins.jar; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.io.File; 23 import org.apache.maven.plugin.MojoExecutionException; 24 import org.apache.maven.plugins.annotations.LifecyclePhase; 25 import org.apache.maven.plugins.annotations.Mojo; 26 import org.apache.maven.plugins.annotations.Parameter; 27 import org.apache.maven.plugins.annotations.ResolutionScope; 28 29 /** 30 * Build a JAR of the test classes for the current project. 31 * 32 * @author <a href="evenisse@apache.org">Emmanuel Venisse</a> 33 * @version $Id: TestJarMojo.java 1740869 2016-04-25 18:08:04Z khmarbaise $ 34 */ 35 // CHECKSTYLE_OFF: LineLength 36 @Mojo( name = "test-jar", defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true, threadSafe = true, requiresDependencyResolution = ResolutionScope.TEST ) 37 // CHECKSTYLE_ON: LineLength 38 public class TestJarMojo 39 extends AbstractJarMojo 40 { 41 42 /** 43 * Set this to <code>true</code> to bypass test-jar generation. Its use is <b>NOT RECOMMENDED</b>, but quite 44 * convenient on occasion. 45 */ 46 @Parameter( property = "maven.test.skip" ) 47 private boolean skip; 48 49 /** 50 * Directory containing the test classes and resource files that should be packaged into the JAR. 51 */ 52 @Parameter( defaultValue = "${project.build.testOutputDirectory}", required = true ) 53 private File testClassesDirectory; 54 55 /** 56 * Classifier to used for {@code test-jar}. 57 */ 58 @Parameter( defaultValue = "tests" ) 59 private String classifier; 60 61 /** 62 * {@inheritDoc} 63 */ 64 protected String getClassifier() 65 { 66 return classifier; 67 } 68 69 /** 70 * {@inheritDoc} 71 */ 72 protected String getType() 73 { 74 return "test-jar"; 75 } 76 77 /** 78 * {@inheritDoc} 79 */ 80 protected File getClassesDirectory() 81 { 82 return testClassesDirectory; 83 } 84 85 /** 86 * {@inheritDoc} 87 */ 88 public void execute() 89 throws MojoExecutionException 90 { 91 if ( skip ) 92 { 93 getLog().info( "Skipping packaging of the test-jar" ); 94 } 95 else 96 { 97 super.execute(); 98 } 99 } 100 }