1 package org.apache.tomcat.maven.common.run;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.io.FileUtils;
23 import org.apache.maven.artifact.Artifact;
24 import org.apache.maven.artifact.DependencyResolutionRequiredException;
25 import org.apache.maven.plugin.logging.Log;
26 import org.apache.maven.project.MavenProject;
27 import org.codehaus.plexus.archiver.ArchiverException;
28 import org.codehaus.plexus.archiver.UnArchiver;
29 import org.codehaus.plexus.archiver.manager.ArchiverManager;
30 import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
31 import org.codehaus.plexus.component.annotations.Component;
32 import org.codehaus.plexus.component.annotations.Requirement;
33 import org.codehaus.plexus.util.StringUtils;
34
35 import java.io.File;
36 import java.io.FilenameFilter;
37 import java.io.IOException;
38 import java.util.ArrayList;
39 import java.util.Collection;
40 import java.util.LinkedHashSet;
41 import java.util.List;
42 import java.util.Set;
43
44
45
46
47
48 @Component (role = ClassLoaderEntriesCalculator.class)
49 public class DefaultClassLoaderEntriesCalculator
50 implements ClassLoaderEntriesCalculator
51 {
52
53 @Requirement
54 private ArchiverManager archiverManager;
55
56
57 public ClassLoaderEntriesCalculatorResult calculateClassPathEntries( ClassLoaderEntriesCalculatorRequest request )
58 throws TomcatRunException
59 {
60 Set<String> classLoaderEntries = new LinkedHashSet<String>();
61
62 List<String> fileInClassLoaderEntries = new ArrayList<String>();
63
64 List<File> tmpDirectories = new ArrayList<File>();
65
66
67 try
68 {
69 @SuppressWarnings ("unchecked") List<String> classPathElements = request.isUseTestClassPath()
70 ? request.getMavenProject().getTestClasspathElements()
71 : request.getMavenProject().getRuntimeClasspathElements();
72 if ( classPathElements != null )
73 {
74 for ( String classPathElement : classPathElements )
75 {
76 File classPathElementFile = new File( classPathElement );
77 if ( classPathElementFile.isDirectory() )
78 {
79 request.getLog().debug(
80 "adding classPathElementFile " + classPathElementFile.toURI().toString() );
81 classLoaderEntries.add( classPathElementFile.toURI().toString() );
82 }
83 }
84 }
85 }
86 catch ( DependencyResolutionRequiredException e )
87 {
88 throw new TomcatRunException( e.getMessage(), e );
89 }
90
91
92
93 File tmpExtractDatas =
94 new File( request.getMavenProject().getBuild().getDirectory(), "apache-tomcat-maven-plugin" );
95
96 if ( tmpExtractDatas.exists() )
97 {
98 deleteDirectory( tmpExtractDatas, request.getLog() );
99 }
100 tmpExtractDatas.mkdirs();
101
102
103 if ( request.getDependencies() != null )
104 {
105 for ( Artifact artifact : request.getDependencies() )
106 {
107 String scope = artifact.getScope();
108
109
110 if ( !Artifact.SCOPE_PROVIDED.equals( scope ) && ( !Artifact.SCOPE_TEST.equals( scope )
111 || request.isUseTestClassPath() ) )
112 {
113 request.getLog().debug(
114 "add dependency to webapploader " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
115 + artifact.getVersion() + ":" + artifact.getScope() );
116
117
118 if ( !isInProjectReferences( artifact, request.getMavenProject() ) || artifact.getFile().isFile() )
119 {
120 String fileName = artifact.getFile().getName();
121 if ( !fileInClassLoaderEntries.contains( fileName ) )
122 {
123 classLoaderEntries.add( artifact.getFile().toURI().toString() );
124 fileInClassLoaderEntries.add( fileName );
125 }
126 }
127 else
128 {
129 request.getLog().debug(
130 "skip adding artifact " + artifact.getArtifactId() + " as it's in reactors" );
131
132 }
133 }
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234