1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.eclipse.writers.rad;
20
21 import java.io.File;
22 import java.io.IOException;
23
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugin.eclipse.Constants;
27 import org.apache.maven.plugin.eclipse.Messages;
28 import org.apache.maven.plugin.eclipse.writers.AbstractEclipseWriter;
29 import org.apache.maven.plugin.ide.IdeDependency;
30 import org.apache.maven.plugin.ide.IdeUtils;
31 import org.apache.maven.plugin.ide.JeeUtils;
32 import org.apache.maven.plugin.logging.Log;
33 import org.codehaus.plexus.util.FileUtils;
34
35
36
37
38
39
40
41 public class RadLibCopier
42 extends AbstractEclipseWriter
43 {
44
45
46
47
48
49
50 public void write()
51 throws MojoExecutionException
52 {
53 IdeDependency[] deps = config.getDeps();
54
55 String packaging = config.getPackaging();
56 if ( Constants.PROJECT_PACKAGING_EAR.equals( packaging ) )
57 {
58 handleEarLibs( deps );
59 }
60 else if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
61 {
62 handleWarLibs( deps );
63 }
64 }
65
66
67
68
69
70
71
72
73
74
75
76 private void copyArtifact( IdeDependency[] deps, File destDir )
77 throws MojoExecutionException
78 {
79 String[] oldFiles =
80 FileUtils.getFilesFromExtension( destDir.getAbsolutePath(),
81 new String[] { Constants.PROJECT_PACKAGING_JAR } );
82 for (String oldFile : oldFiles) {
83 if (!new File(oldFile).delete()) {
84 log.error(Messages.getString("Rad6LibCopier.cantdeletefile", new Object[]{oldFile}));
85 }
86 }
87 for (IdeDependency dep : deps) {
88 if (!dep.isTestDependency() && !dep.isProvided() && !dep.isReferencedProject()
89 && !dep.isSystemScoped()) {
90 copyFile(dep.getFile(), new File(destDir, dep.getFile().getName()), log);
91 }
92 }
93 }
94
95
96
97
98
99
100
101
102
103 private void copyFile( File artifact, File destFile, Log log )
104 throws MojoExecutionException
105 {
106 try
107 {
108 log.info( "Copying " + artifact.getAbsolutePath() + " to " + destFile );
109 FileUtils.copyFile( artifact, destFile );
110 }
111 catch ( IOException e )
112 {
113 throw new MojoExecutionException( "Error copying artifact from " + artifact + " to " + destFile, e );
114 }
115 }
116
117
118
119
120
121
122
123 private void handleEarLibs( IdeDependency[] deps )
124 throws MojoExecutionException
125 {
126 File targetDir = config.getProject().getBasedir();
127 copyArtifact( deps, targetDir );
128 }
129
130
131
132
133
134
135
136 private void handleWarLibs( IdeDependency[] deps )
137 throws MojoExecutionException
138 {
139 File basedir = config.getProject().getBasedir();
140
141
142 File warSourceDirectory =
143 new File( IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN,
144 "warSourceDirectory",
145 "src/main/webapp" ) );
146 String webContentDir =
147 IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(), warSourceDirectory, false );
148
149 String srcMainWebappWebInfLibDirName =
150 basedir.getAbsolutePath() + File.separatorChar + webContentDir + File.separatorChar + "WEB-INF"
151 + File.separatorChar + "lib";
152
153 File srcMainWebappWebInfLibDir = new File( srcMainWebappWebInfLibDirName );
154 srcMainWebappWebInfLibDir.mkdirs();
155
156 copyArtifact( deps, srcMainWebappWebInfLibDir );
157 }
158
159 }