1 | package npanday.plugin.aspx; |
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.lang.StackTraceElement; |
23 | import java.io.File; |
24 | import java.io.IOException; |
25 | import java.util.Set; |
26 | import java.util.ArrayList; |
27 | |
28 | import org.apache.maven.artifact.Artifact; |
29 | import org.apache.maven.plugin.AbstractMojo; |
30 | import org.apache.maven.plugin.MojoExecutionException; |
31 | import org.apache.maven.plugin.MojoFailureException; |
32 | import org.apache.maven.project.MavenProject; |
33 | import org.codehaus.plexus.util.FileUtils; |
34 | import npanday.PathUtil; |
35 | |
36 | |
37 | /** |
38 | * Maven Mojo for copying ASPx project dependencies to sourceDirectory\Bin folder |
39 | * |
40 | * @goal copy-dependency |
41 | * @phase process-sources |
42 | * @description Maven Mojo for copying ASPx project dependencies to sourceDirectory\Bin folder |
43 | */ |
44 | public class AspxBinDependencyResolver |
45 | extends AbstractMojo { |
46 | /** |
47 | * The dependencies. |
48 | * |
49 | * @parameter expression="${project.dependencyArtifacts}" |
50 | * @required |
51 | */ |
52 | private Set<Artifact> dependencies; |
53 | |
54 | /** |
55 | * The bin directory. |
56 | * |
57 | * @parameter default-value="${project.build.sourceDirectory}/Bin" |
58 | * @required |
59 | */ |
60 | private File binDir; |
61 | |
62 | public void execute() |
63 | throws MojoExecutionException, MojoFailureException { |
64 | for (Artifact dependency : dependencies) { |
65 | try { |
66 | String filename = dependency.getArtifactId() + "." + dependency.getArtifactHandler().getExtension(); |
67 | File targetFile = new File(binDir, filename); |
68 | |
69 | if (!targetFile.exists()) { |
70 | getLog().debug("NPANDAY-000-0001: copy dependency: typeof:" + dependency.getClass()); |
71 | getLog().debug("NPANDAY-000-0001: copy dependency: " + dependency); |
72 | getLog().debug("NPANDAY-000-0002: copying " + dependency.getFile().getAbsolutePath() + " to " + targetFile); |
73 | File sourceFile = PathUtil.getGACFile4Artifact(dependency); |
74 | |
75 | FileUtils.copyFile(sourceFile, targetFile); |
76 | |
77 | } |
78 | } |
79 | catch (IOException ioe) { |
80 | throw new MojoExecutionException("NPANDAY-000-00002: Error copying dependency " + dependency, ioe); |
81 | |
82 | } |
83 | } |
84 | } |
85 | |
86 | public void setBinDir(File binDir) { |
87 | this.binDir = binDir; |
88 | } |
89 | |
90 | public void setDependencies(Set<Artifact> dependencies) { |
91 | this.dependencies = dependencies; |
92 | } |
93 | } |