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 | 0 | public class RadLibCopier |
42 | |
extends AbstractEclipseWriter |
43 | |
{ |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
public void write() |
51 | |
throws MojoExecutionException |
52 | |
{ |
53 | 0 | IdeDependency[] deps = config.getDepsOrdered(); |
54 | |
|
55 | 0 | String packaging = config.getPackaging(); |
56 | 0 | if ( Constants.PROJECT_PACKAGING_EAR.equals( packaging ) ) |
57 | |
{ |
58 | 0 | handleEarLibs( deps ); |
59 | |
} |
60 | 0 | else if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) ) |
61 | |
{ |
62 | 0 | handleWarLibs( deps ); |
63 | |
} |
64 | 0 | } |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
private void copyArtifact( IdeDependency[] deps, File destDir ) |
77 | |
throws MojoExecutionException |
78 | |
{ |
79 | 0 | String[] oldFiles = |
80 | |
FileUtils.getFilesFromExtension( destDir.getAbsolutePath(), |
81 | |
new String[] { Constants.PROJECT_PACKAGING_JAR } ); |
82 | 0 | for ( int index = 0; index < oldFiles.length; index++ ) |
83 | |
{ |
84 | 0 | if ( !new File( oldFiles[index] ).delete() ) |
85 | |
{ |
86 | 0 | log.error( Messages.getString( "Rad6LibCopier.cantdeletefile", new Object[] { oldFiles[index] } ) ); |
87 | |
} |
88 | |
} |
89 | 0 | for ( int index = 0; index < deps.length; index++ ) |
90 | |
{ |
91 | 0 | if ( !deps[index].isTestDependency() && !deps[index].isProvided() && !deps[index].isReferencedProject() |
92 | |
&& !deps[index].isSystemScoped() ) |
93 | |
{ |
94 | 0 | copyFile( deps[index].getFile(), new File( destDir, deps[index].getFile().getName() ), log ); |
95 | |
} |
96 | |
} |
97 | 0 | } |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
private void copyFile( File artifact, File destFile, Log log ) |
108 | |
throws MojoExecutionException |
109 | |
{ |
110 | |
try |
111 | |
{ |
112 | 0 | log.info( "Copying " + artifact.getAbsolutePath() + " to " + destFile ); |
113 | 0 | FileUtils.copyFile( artifact, destFile ); |
114 | |
} |
115 | 0 | catch ( IOException e ) |
116 | |
{ |
117 | 0 | throw new MojoExecutionException( "Error copying artifact from " + artifact + " to " + destFile, e ); |
118 | 0 | } |
119 | 0 | } |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
private void handleEarLibs( IdeDependency[] deps ) |
128 | |
throws MojoExecutionException |
129 | |
{ |
130 | 0 | File targetDir = config.getProject().getBasedir(); |
131 | 0 | copyArtifact( deps, targetDir ); |
132 | 0 | } |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
private void handleWarLibs( IdeDependency[] deps ) |
141 | |
throws MojoExecutionException |
142 | |
{ |
143 | 0 | File basedir = config.getProject().getBasedir(); |
144 | |
|
145 | |
|
146 | 0 | File warSourceDirectory = |
147 | |
new File( IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN, |
148 | |
"warSourceDirectory", |
149 | |
"src/main/webapp" ) ); |
150 | 0 | String webContentDir = |
151 | |
IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(), warSourceDirectory, false ); |
152 | |
|
153 | 0 | String srcMainWebappWebInfLibDirName = |
154 | |
basedir.getAbsolutePath() + File.separatorChar + webContentDir + File.separatorChar + "WEB-INF" |
155 | |
+ File.separatorChar + "lib"; |
156 | |
|
157 | 0 | File srcMainWebappWebInfLibDir = new File( srcMainWebappWebInfLibDirName ); |
158 | 0 | srcMainWebappWebInfLibDir.mkdirs(); |
159 | |
|
160 | 0 | copyArtifact( deps, srcMainWebappWebInfLibDir ); |
161 | 0 | } |
162 | |
|
163 | |
} |