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   import java.io.IOException;
   21   
   22   import org.apache.maven.artifact.Artifact;
   23   import org.apache.maven.plugin.MojoExecutionException;
   24   import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle;
   25   import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList;
   26   import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel;
   27   import org.codehaus.plexus.util.FileUtils;
   28   
   29   /**
   30    * This class contains the Launchpad-framework specific utility methods.
   31    *
   32    */
   33   public abstract class AbstractLaunchpadFrameworkMojo extends AbstractBundleListMojo {
   34   
   35       /**
   36        * The name of the directory within the output directory into which the base
   37        * JAR should be installed.
   38        *
   39        * @parameter default-value="resources"
   40        */
   41       protected String baseDestination;
   42   
   43       /**
   44        * The directory which contains the start-level bundle directories.
   45        *
   46        * @parameter default-value="bundles"
   47        */
   48       protected String bundlesDirectory;
   49   
   50       protected void copyBundles(BundleList bundles, File outputDirectory) throws MojoExecutionException {
   51           for (StartLevel startLevel : bundles.getStartLevels()) {
   52               for (Bundle bundle : startLevel.getBundles()) {
   53                   copy(new ArtifactDefinition(bundle, startLevel.getLevel()), outputDirectory);
   54               }
   55           }
   56       }
   57   
   58       protected void copy(ArtifactDefinition additionalBundle, File outputDirectory) throws MojoExecutionException {
   59           Artifact artifact = getArtifact(additionalBundle);
   60           copy(artifact.getFile(), additionalBundle.getStartLevel(), outputDirectory);
   61       }
   62   
   63       protected void copy(File file, int startLevel, File outputDirectory) throws MojoExecutionException {
   64           File destination = new File(outputDirectory, String.format("%s/%s/%s/%s", baseDestination, bundlesDirectory,
   65                   startLevel, file.getName()));
   66           if (shouldCopy(file, destination)) {
   67               getLog().info(String.format("Copying bundle from %s to %s", file.getPath(), destination.getPath()));
   68               try {
   69                   FileUtils.copyFile(file, destination);
   70               } catch (IOException e) {
   71                   throw new MojoExecutionException("Unable to copy bundle from " + file.getPath(), e);
   72               }
   73           }
   74       }
   75   
   76   }

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