1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. 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,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.plugin.eclipse.writers;
20
21 import java.io.File;
22 import java.util.Arrays;
23 import java.util.Comparator;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.apache.maven.artifact.repository.ArtifactRepository;
28 import org.apache.maven.plugin.eclipse.EclipsePlugin;
29 import org.apache.maven.plugin.eclipse.EclipseSourceDir;
30 import org.apache.maven.plugin.eclipse.WorkspaceConfiguration;
31 import org.apache.maven.plugin.ide.IdeDependency;
32 import org.apache.maven.project.MavenProject;
33
34 /**
35 * @author Fabrizio Giustina
36 * @version $Id: EclipseWriterConfig.java 641616 2008-03-26 22:42:42Z aheritier $
37 */
38 public class EclipseWriterConfig
39 {
40 /**
41 * The maven project.
42 */
43 private MavenProject project;
44
45 /**
46 * The maven project packaging.
47 */
48 private String packaging;
49
50 /**
51 * Eclipse project dir.
52 */
53 private File eclipseProjectDirectory;
54
55 /**
56 * The name of the project in eclipse.
57 */
58 private String eclipseProjectName;
59
60 /**
61 * Base project dir.
62 */
63 private File projectBaseDir;
64
65 /**
66 * List of IDE dependencies.
67 */
68 private IdeDependency[] deps = new IdeDependency[0];
69
70 /**
71 * List of IDE dependencies ordered.
72 */
73 private IdeDependency[] orderedDeps = new IdeDependency[0];
74
75 /**
76 * Source directories.
77 */
78 private EclipseSourceDir[] sourceDirs;
79
80 /**
81 * Local maven repo.
82 */
83 private ArtifactRepository localRepository;
84
85 /**
86 * Build output directory for eclipse.
87 */
88 private File buildOutputDirectory;
89
90 /**
91 * Manifest file.
92 */
93 private File osgiManifestFile;
94
95 /**
96 * PDE mode.
97 */
98 private boolean pde;
99
100 /**
101 * Project natures.
102 */
103 private List projectnatures;
104
105 /**
106 * Project facets.
107 */
108 private Map projectFacets;
109
110 /**
111 * Build commands. List<BuildCommand>
112 */
113 private List buildCommands;
114
115 /**
116 * Classpath containers.
117 */
118 private List classpathContainers;
119
120 /**
121 * Appends the version number to the project name if <tt>true</tt>.
122 *
123 * @deprecated use {@link #projectNameTemplate}
124 */
125 private boolean addVersionToProjectName;
126
127 /**
128 * @see EclipsePlugin#getProjectNameTemplate()
129 */
130 private String projectNameTemplate;
131
132 /**
133 * @see EclipsePlugin#deployName()
134 */
135
136 private String contextName;
137
138 /**
139 * @see EclipsePlugin#wtpapplicationxml()
140 */
141 private boolean wtpapplicationxml;
142
143 /**
144 * @see EclipsePlugin#getWtpversion()
145 */
146 private float wtpVersion;
147
148 private WorkspaceConfiguration workspaceConfiguration;
149
150 public WorkspaceConfiguration getWorkspaceConfiguration()
151 {
152 return workspaceConfiguration;
153 }
154
155 public void setWorkspaceConfiguration( WorkspaceConfiguration workspaceConfiguration )
156 {
157 this.workspaceConfiguration = workspaceConfiguration;
158 }
159
160 /**
161 * Getter for <code>deps</code>.
162 *
163 * @return Returns the deps.
164 */
165 public IdeDependency[] getDeps()
166 {
167 return deps;
168 }
169
170 /**
171 * Setter for <code>deps</code>.
172 *
173 * @param deps The deps to set.
174 */
175 public void setDeps( IdeDependency[] deps )
176 {
177 this.deps = deps;
178 if ( deps != null )
179 {
180 // TODO get the right comparator depending on orderDependencies={name,nearness..};
181 // if none specified it could use a NullComparator to reduce the number of
182 // conditions that have to be checked
183 Comparator depsByArtifactId = new Comparator()
184 {
185 public int compare( Object o1, Object o2 )
186 {
187 int result =
188 ( (IdeDependency) o1 ).getArtifactId().compareToIgnoreCase(
189 ( (IdeDependency) o2 ).getArtifactId() );
190 if ( result != 0 )
191 {
192 return result;
193 }
194 if ( ( (IdeDependency) o1 ).getClassifier() != null &&
195 ( (IdeDependency) o2 ).getClassifier() != null )
196 {
197 result =
198 ( (IdeDependency) o1 ).getClassifier().compareToIgnoreCase(
199 ( (IdeDependency) o2 ).getClassifier() );
200 if ( result != 0 )
201 {
202 return result;
203 }
204 }
205 result = ( (IdeDependency) o1 ).getType().compareToIgnoreCase( ( (IdeDependency) o2 ).getType() );
206 if ( result != 0 )
207 {
208 return result;
209 }
210 result =
211 ( (IdeDependency) o1 ).getGroupId().compareToIgnoreCase( ( (IdeDependency) o2 ).getGroupId() );
212 return result;
213 }
214 };
215
216 orderedDeps = new IdeDependency[deps.length];
217 System.arraycopy( deps, 0, orderedDeps, 0, deps.length );
218 Arrays.sort( orderedDeps, depsByArtifactId );
219 }
220 }
221
222 /**
223 * Getter for <code>eclipseProjectDir</code>.
224 *
225 * @return Returns the eclipseProjectDir.
226 */
227 public File getEclipseProjectDirectory()
228 {
229 return eclipseProjectDirectory;
230 }
231
232 /**
233 * Setter for <code>eclipseProjectDir</code>.
234 *
235 * @param eclipseProjectDir The eclipseProjectDir to set.
236 */
237 public void setEclipseProjectDirectory( File eclipseProjectDir )
238 {
239 eclipseProjectDirectory = eclipseProjectDir;
240 }
241
242 /**
243 * Getter for <code>eclipseProjectName</code>.
244 *
245 * @return Returns the project name used in eclipse.
246 */
247 public String getEclipseProjectName()
248 {
249 return eclipseProjectName;
250 }
251
252 /**
253 * Setter for <code>eclipseProjectName</code>.
254 *
255 * @param eclipseProjectName the project name used in eclipse.
256 */
257 public void setEclipseProjectName( String eclipseProjectName )
258 {
259 this.eclipseProjectName = eclipseProjectName;
260 }
261
262 /**
263 * Getter for <code>project</code>.
264 *
265 * @return Returns the project.
266 */
267 public MavenProject getProject()
268 {
269 return project;
270 }
271
272 /**
273 * Setter for <code>project</code>.
274 *
275 * @param project The project to set.
276 */
277 public void setProject( MavenProject project )
278 {
279 this.project = project;
280 }
281
282 /**
283 * Getter for <code>sourceDirs</code>.
284 *
285 * @return Returns the sourceDirs.
286 */
287 public EclipseSourceDir[] getSourceDirs()
288 {
289 return sourceDirs;
290 }
291
292 /**
293 * Setter for <code>sourceDirs</code>.
294 *
295 * @param sourceDirs The sourceDirs to set.
296 */
297 public void setSourceDirs( EclipseSourceDir[] sourceDirs )
298 {
299 this.sourceDirs = sourceDirs;
300 }
301
302 /**
303 * Getter for <code>buildOutputDirectory</code>.
304 *
305 * @return Returns the buildOutputDirectory.
306 */
307 public File getBuildOutputDirectory()
308 {
309 return buildOutputDirectory;
310 }
311
312 /**
313 * Setter for <code>buildOutputDirectory</code>.
314 *
315 * @param buildOutputDirectory The buildOutputDirectory to set.
316 */
317 public void setBuildOutputDirectory( File buildOutputDirectory )
318 {
319 this.buildOutputDirectory = buildOutputDirectory;
320 }
321
322 /**
323 * Getter for <code>localRepository</code>.
324 *
325 * @return Returns the localRepository.
326 */
327 public ArtifactRepository getLocalRepository()
328 {
329 return localRepository;
330 }
331
332 /**
333 * Setter for <code>localRepository</code>.
334 *
335 * @param localRepository The localRepository to set.
336 */
337 public void setLocalRepository( ArtifactRepository localRepository )
338 {
339 this.localRepository = localRepository;
340 }
341
342 /**
343 * Getter for <code>manifestFile</code>.
344 *
345 * @return Returns the manifestFile.
346 */
347 public File getOSGIManifestFile()
348 {
349 return osgiManifestFile;
350 }
351
352 /**
353 * Setter for <code>manifestFile</code>.
354 *
355 * @param manifestFile The manifestFile to set.
356 */
357 public void setOSGIManifestFile( File manifestFile )
358 {
359 this.osgiManifestFile = manifestFile;
360 }
361
362 /**
363 * Getter for <code>classpathContainers</code>.
364 *
365 * @return Returns the classpathContainers.
366 */
367 public List getClasspathContainers()
368 {
369 return classpathContainers;
370 }
371
372 /**
373 * Setter for <code>classpathContainers</code>.
374 *
375 * @param classpathContainers The classpathContainers to set.
376 */
377 public void setClasspathContainers( List classpathContainers )
378 {
379 this.classpathContainers = classpathContainers;
380 }
381
382 /**
383 * Getter for <code>pde</code>.
384 *
385 * @return Returns the pde.
386 */
387 public boolean isPde()
388 {
389 return pde;
390 }
391
392 /**
393 * Setter for <code>pde</code>.
394 *
395 * @param pde The pde to set.
396 */
397 public void setPde( boolean pde )
398 {
399 this.pde = pde;
400 }
401
402 /**
403 * Getter for <code>buildCommands</code>.
404 *
405 * @return Returns the buildCommands.
406 */
407 public List getBuildCommands()
408 {
409 return buildCommands;
410 }
411
412 /**
413 * Setter for <code>buildCommands</code>.
414 *
415 * @param buildCommands The buildCommands to set.
416 */
417 public void setBuildCommands( List buildCommands )
418 {
419 this.buildCommands = buildCommands;
420 }
421
422 /**
423 * Getter for <code>projectnatures</code>.
424 *
425 * @return Returns the projectnatures.
426 */
427 public List getProjectnatures()
428 {
429 return projectnatures;
430 }
431
432 /**
433 * Setter for <code>projectnatures</code>.
434 *
435 * @param projectnatures The projectnatures to set.
436 */
437 public void setProjectnatures( List projectnatures )
438 {
439 this.projectnatures = projectnatures;
440 }
441
442 /**
443 * Getter for <code>projectFacets</code>.
444 *
445 * @return Returns the projectFacets
446 */
447 public Map getProjectFacets()
448 {
449 return projectFacets;
450 }
451
452 /**
453 * Setter for <code>projectFacets</code>
454 *
455 * @param projectFacets The projectFacets to set.
456 */
457 public void setProjectFacets( Map projectFacets )
458 {
459 this.projectFacets = projectFacets;
460 }
461
462 /**
463 * Getter for <code>projectBaseDir</code>.
464 *
465 * @return Returns the projectBaseDir.
466 */
467 public File getProjectBaseDir()
468 {
469 return projectBaseDir;
470 }
471
472 /**
473 * Setter for <code>projectBaseDir</code>.
474 *
475 * @param projectBaseDir The projectBaseDir to set.
476 */
477 public void setProjectBaseDir( File projectBaseDir )
478 {
479 this.projectBaseDir = projectBaseDir;
480 }
481
482 /**
483 * Getter for <code>addVersionToProjectName</code>.
484 *
485 * @deprecated use {@link #getProjectNameTemplate()}
486 */
487 public boolean isAddVersionToProjectName()
488 {
489 return addVersionToProjectName;
490 }
491
492 /**
493 * Setter for <code>addVersionToProjectName</code>.
494 *
495 * @deprecated use {@link #setProjectNameTemplate(String)}
496 */
497 public void setAddVersionToProjectName( boolean addVersionToProjectName )
498 {
499 this.addVersionToProjectName = addVersionToProjectName;
500 }
501
502 public void setProjectNameTemplate( String projectNameTemplate )
503 {
504 this.projectNameTemplate = projectNameTemplate;
505 }
506
507 public String getProjectNameTemplate()
508 {
509 return projectNameTemplate;
510 }
511
512 public String getContextName()
513 {
514 return contextName;
515 }
516
517 public void setContextName( String deployName )
518 {
519 contextName = deployName;
520 }
521
522 /**
523 * @return the packaging
524 */
525 public String getPackaging()
526 {
527 return packaging;
528 }
529
530 /**
531 * @param packaging the packaging to set
532 */
533 public void setPackaging( String packaging )
534 {
535 this.packaging = packaging;
536 }
537
538 /**
539 * Getter for <code>wtpapplicationxml</code>.
540 *
541 * @return Returns the wtpapplicationxml.
542 */
543 public boolean getWtpapplicationxml()
544 {
545 return wtpapplicationxml;
546 }
547
548 /**
549 * Setter for <code>buildCommands</code>.
550 *
551 * @param buildCommands The buildCommands to set.
552 */
553 public void setWtpapplicationxml( boolean wtpapplicationxml )
554 {
555 this.wtpapplicationxml = wtpapplicationxml;
556 }
557
558 /**
559 * Getter for <code>wtpVersion</code>.
560 *
561 * @return Returns the wtpVersion.
562 */
563 public float getWtpVersion()
564 {
565 return wtpVersion;
566 }
567
568 /**
569 * Setter for <code>wtpVersion</code>.
570 *
571 * @param wtpVersion The wtpVersion to set.
572 */
573 public void setWtpVersion( float wtpVersion )
574 {
575 this.wtpVersion = wtpVersion;
576 }
577
578 /**
579 * @return an ordered list of dependencies
580 */
581 public IdeDependency[] getDepsOrdered()
582 {
583 return orderedDeps;
584 }
585
586 }