Save This Page
Home » maven-launchpad-plugin-2.0.6-source-release » org.apache.sling.maven.projectsupport » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements. See the NOTICE file distributed with this
    4    * work for additional information regarding copyright ownership. The ASF
    5    * licenses this file to You under the Apache License, Version 2.0 (the
    6    * "License"); you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   13    * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   14    * License for the specific language governing permissions and limitations under
   15    * the License.
   16    */
   17   package org.apache.sling.maven.projectsupport;
   18   
   19   import java.io.File;
   20   
   21   import org.apache.maven.artifact.handler.ArtifactHandler;
   22   import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
   23   import org.apache.maven.plugin.MojoExecutionException;
   24   import org.apache.maven.plugin.MojoFailureException;
   25   
   26   /**
   27    * Initialize a Sling integration test webapp by extracting bundles into the
   28    * correct locations, including the current artifact.
   29    *
   30    * @goal prepare-test-webapp
   31    * @requiresDependencyResolution test
   32    * @phase package
   33    */
   34   public class PrepareTestWebAppMojo extends PreparePackageMojo {
   35   
   36       /**
   37        * The project's build directory (i.e. target).
   38        *
   39        * @parameter expression="${project.build.directory}"
   40        * @readonly
   41        */
   42       private File buildDirectory;
   43   
   44       /**
   45        * The start level for the current artifact.
   46        *
   47        * @parameter default-value="16"
   48        */
   49       private int startLevel;
   50   
   51       /**
   52        * The output directory for bundles.
   53        *
   54        * @parameter default-value="${project.build.directory}/launchpad-bundles"
   55        */
   56       private File outputDirectory;
   57   
   58       /**
   59        * @component
   60        */
   61       private ArtifactHandlerManager artifactHandlerManager;
   62   
   63       public void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
   64           super.executeWithArtifacts();
   65           copy(getPrimaryArtifact(), startLevel, getOutputDirectory());
   66       }
   67   
   68       @Override
   69       protected File getOutputDirectory() {
   70           return outputDirectory;
   71       }
   72   
   73   
   74       @Override
   75       protected void unpackBaseArtifact() throws MojoExecutionException {
   76           // No-op. This is JAR-specific.
   77       }
   78   
   79       private File getPrimaryArtifact() throws MojoExecutionException {
   80           ArtifactHandler handler = artifactHandlerManager.getArtifactHandler(project.getPackaging());
   81   
   82           String artifactName = project.getBuild().getFinalName() + "." + handler.getExtension();
   83   
   84           File file = new File(buildDirectory, artifactName);
   85           if (!file.exists()) {
   86               throw new MojoExecutionException("Project's primary artifact (" + file.getPath() + ") doesn't exist.");
   87           }
   88           return file;
   89       }
   90   
   91   }

Save This Page
Home » maven-launchpad-plugin-2.0.6-source-release » org.apache.sling.maven.projectsupport » [javadoc | source]