View Javadoc

1   /*
2    * #%L
3    * Native ARchive plugin for Maven
4    * %%
5    * Copyright (C) 2002 - 2014 NAR Maven Plugin developers.
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * 
11   * http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package com.github.maven_nar;
21  
22  import java.io.File;
23  import java.util.List;
24  
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.plugin.MojoExecutionException;
27  import org.apache.maven.plugin.MojoFailureException;
28  import org.apache.maven.plugins.annotations.LifecyclePhase;
29  import org.apache.maven.plugins.annotations.Mojo;
30  import org.apache.maven.plugins.annotations.Parameter;
31  import org.apache.maven.plugins.annotations.ResolutionScope;
32  import org.apache.maven.shared.artifact.filter.collection.ScopeFilter;
33  
34  /**
35   * Unpacks NAR files needed for tests compilation and execution. Unpacking
36   * happens in the project target folder, and
37   * also sets flags on binaries and corrects static libraries.
38   *
39   * @author Mark Donszelmann
40   */
41  @Mojo(name = "nar-test-unpack", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES, requiresProject = true,
42    requiresDependencyResolution = ResolutionScope.TEST)
43  public class NarTestUnpackMojo extends AbstractDependencyMojo {
44  
45    /**
46     * List of tests to create
47     */
48    @Parameter
49    private List tests;
50    
51    /**
52     * List the dependencies needed for tests compilations and executions.
53     */
54    @Override
55    protected ScopeFilter getArtifactScopeFilter() {
56      return new ScopeFilter( Artifact.SCOPE_TEST, null );
57    }
58  
59    @Override
60    protected File getUnpackDirectory() {
61      return getTestUnpackDirectory() == null ? super.getUnpackDirectory() : getTestUnpackDirectory();
62    }
63  
64    @Override
65    public final void narExecute() throws MojoExecutionException, MojoFailureException {
66      final List<AttachedNarArtifact> attachedNarArtifacts = getAttachedNarArtifacts(tests);
67      unpackAttachedNars(attachedNarArtifacts);
68    }
69  }