View Javadoc

1   /*
2    * DaCapo Benchmark Maven Plugin
3    * Copyright (C) 2010 Technische Universität Darmstadt
4    * info@scalabench.org
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.scalabench.plugins.dacapo;
19  
20  import java.io.File;
21  import java.io.IOException;
22  
23  import org.apache.maven.artifact.Artifact;
24  import org.apache.maven.plugin.MojoExecutionException;
25  import org.apache.maven.plugin.MojoFailureException;
26  import org.codehaus.plexus.util.FileUtils;
27  
28  /**
29   * Package the benchmark's required libraries.
30   * 
31   * @since 0.1.0
32   * 
33   * @threadSafe
34   * @goal package-libraries
35   * @phase prepare-package
36   * @requiresDependencyResolution compile
37   */
38  public class PackageLibrariesMojo extends AbstractDacapoBenchmarkMojo {
39      
40      /**
41       * The library output directory.
42       * 
43       * @required
44       * @readonly
45       * @parameter expression="${project.build.outputDirectory}/jar"
46       */
47      private File libraryOutputDirectory;
48      
49      @Override
50      public void execute() throws MojoExecutionException, MojoFailureException {
51          for (final Artifact library : getLibraries())
52              packageLibrary(library);
53      }
54      
55      private void packageLibrary(Artifact artifact) throws MojoExecutionException {
56          final File source = artifact.getFile();
57          final File destination = new File(libraryOutputDirectory, artifact.getFile().getName());
58          logInfo("Copying library from %s to %s", source, destination);
59          copyFile(source, destination);
60      }
61      
62      private void copyFile(File source, File destination) throws MojoExecutionException {
63          try {
64              FileUtils.copyFile(source, destination);
65          } catch (IOException e) {
66              throw new MojoExecutionException("Error copying from " + source + " to " + destination, e);
67          }
68      }
69  }