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 691404 2008-09-02 21:57:19Z 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 float ajdtVersion;
149
150 private WorkspaceConfiguration workspaceConfiguration;
151
152 public WorkspaceConfiguration getWorkspaceConfiguration()
153 {
154 return workspaceConfiguration;
155 }
156
157 public void setWorkspaceConfiguration( WorkspaceConfiguration workspaceConfiguration )
158 {
159 this.workspaceConfiguration = workspaceConfiguration;
160 }
161
162 /**
163 * Getter for <code>deps</code>.
164 *
165 * @return Returns the deps.
166 */
167 public IdeDependency[] getDeps()
168 {
169 return deps;
170 }
171
172 /**
173 * Setter for <code>deps</code>.
174 *
175 * @param deps The deps to set.
176 */
177 public void setDeps( IdeDependency[] deps )
178 {
179 this.deps = deps;
180 if ( deps != null )
181 {
182 // TODO get the right comparator depending on orderDependencies={name,nearness..};
183 // if none specified it could use a NullComparator to reduce the number of
184 // conditions that have to be checked
185 Comparator depsByArtifactId = new Comparator()
186 {
187 public int compare( Object o1, Object o2 )
188 {
189 int result =
190 ( (IdeDependency) o1 ).getArtifactId().compareToIgnoreCase(
191 ( (IdeDependency) o2 ).getArtifactId() );
192 if ( result != 0 )
193 {
194 return result;
195 }
196 if ( ( (IdeDependency) o1 ).getClassifier() != null
197 && ( (IdeDependency) o2 ).getClassifier() != null )
198 {
199 result =
200 ( (IdeDependency) o1 ).getClassifier().compareToIgnoreCase(
201 ( (IdeDependency) o2 ).getClassifier() );
202 if ( result != 0 )
203 {
204 return result;
205 }
206 }
207 result = ( (IdeDependency) o1 ).getType().compareToIgnoreCase( ( (IdeDependency) o2 ).getType() );
208 if ( result != 0 )
209 {
210 return result;
211 }
212 result =
213 ( (IdeDependency) o1 ).getGroupId().compareToIgnoreCase( ( (IdeDependency) o2 ).getGroupId() );
214 return result;
215 }
216 };
217
218 orderedDeps = new IdeDependency[deps.length];
219 System.arraycopy( deps, 0, orderedDeps, 0, deps.length );
220 Arrays.sort( orderedDeps, depsByArtifactId );
221 }
222 }
223
224 /**
225 * Getter for <code>eclipseProjectDir</code>.
226 *
227 * @return Returns the eclipseProjectDir.
228 */
229 public File getEclipseProjectDirectory()
230 {
231 return eclipseProjectDirectory;
232 }
233
234 /**
235 * Setter for <code>eclipseProjectDir</code>.
236 *
237 * @param eclipseProjectDir The eclipseProjectDir to set.
238 */
239 public void setEclipseProjectDirectory( File eclipseProjectDir )
240 {
241 eclipseProjectDirectory = eclipseProjectDir;
242 }
243
244 /**
245 * Getter for <code>eclipseProjectName</code>.
246 *
247 * @return Returns the project name used in eclipse.
248 */
249 public String getEclipseProjectName()
250 {
251 return eclipseProjectName;
252 }
253
254 /**
255 * Setter for <code>eclipseProjectName</code>.
256 *
257 * @param eclipseProjectName the project name used in eclipse.
258 */
259 public void setEclipseProjectName( String eclipseProjectName )
260 {
261 this.eclipseProjectName = eclipseProjectName;
262 }
263
264 /**
265 * Getter for <code>project</code>.
266 *
267 * @return Returns the project.
268 */
269 public MavenProject getProject()
270 {
271 return project;
272 }
273
274 /**
275 * Setter for <code>project</code>.
276 *
277 * @param project The project to set.
278 */
279 public void setProject( MavenProject project )
280 {
281 this.project = project;
282 }
283
284 /**
285 * Getter for <code>sourceDirs</code>.
286 *
287 * @return Returns the sourceDirs.
288 */
289 public EclipseSourceDir[] getSourceDirs()
290 {
291 return sourceDirs;
292 }
293
294 /**
295 * Setter for <code>sourceDirs</code>.
296 *
297 * @param sourceDirs The sourceDirs to set.
298 */
299 public void setSourceDirs( EclipseSourceDir[] sourceDirs )
300 {
301 this.sourceDirs = sourceDirs;
302 }
303
304 /**
305 * Getter for <code>buildOutputDirectory</code>.
306 *
307 * @return Returns the buildOutputDirectory.
308 */
309 public File getBuildOutputDirectory()
310 {
311 return buildOutputDirectory;
312 }
313
314 /**
315 * Setter for <code>buildOutputDirectory</code>.
316 *
317 * @param buildOutputDirectory The buildOutputDirectory to set.
318 */
319 public void setBuildOutputDirectory( File buildOutputDirectory )
320 {
321 this.buildOutputDirectory = buildOutputDirectory;
322 }
323
324 /**
325 * Getter for <code>localRepository</code>.
326 *
327 * @return Returns the localRepository.
328 */
329 public ArtifactRepository getLocalRepository()
330 {
331 return localRepository;
332 }
333
334 /**
335 * Setter for <code>localRepository</code>.
336 *
337 * @param localRepository The localRepository to set.
338 */
339 public void setLocalRepository( ArtifactRepository localRepository )
340 {
341 this.localRepository = localRepository;
342 }
343
344 /**
345 * Getter for <code>manifestFile</code>.
346 *
347 * @return Returns the manifestFile.
348 */
349 public File getOSGIManifestFile()
350 {
351 return osgiManifestFile;
352 }
353
354 /**
355 * Setter for <code>manifestFile</code>.
356 *
357 * @param manifestFile The manifestFile to set.
358 */
359 public void setOSGIManifestFile( File manifestFile )
360 {
361 this.osgiManifestFile = manifestFile;
362 }
363
364 /**
365 * Getter for <code>classpathContainers</code>.
366 *
367 * @return Returns the classpathContainers.
368 */
369 public List getClasspathContainers()
370 {
371 return classpathContainers;
372 }
373
374 /**
375 * Setter for <code>classpathContainers</code>.
376 *
377 * @param classpathContainers The classpathContainers to set.
378 */
379 public void setClasspathContainers( List classpathContainers )
380 {
381 this.classpathContainers = classpathContainers;
382 }
383
384 /**
385 * Getter for <code>pde</code>.
386 *
387 * @return Returns the pde.
388 */
389 public boolean isPde()
390 {
391 return pde;
392 }
393
394 /**
395 * Setter for <code>pde</code>.
396 *
397 * @param pde The pde to set.
398 */
399 public void setPde( boolean pde )
400 {
401 this.pde = pde;
402 }
403
404 /**
405 * Getter for <code>buildCommands</code>.
406 *
407 * @return Returns the buildCommands.
408 */
409 public List getBuildCommands()
410 {
411 return buildCommands;
412 }
413
414 /**
415 * Setter for <code>buildCommands</code>.
416 *
417 * @param buildCommands The buildCommands to set.
418 */
419 public void setBuildCommands( List buildCommands )
420 {
421 this.buildCommands = buildCommands;
422 }
423
424 /**
425 * Getter for <code>projectnatures</code>.
426 *
427 * @return Returns the projectnatures.
428 */
429 public List getProjectnatures()
430 {
431 return projectnatures;
432 }
433
434 /**
435 * Setter for <code>projectnatures</code>.
436 *
437 * @param projectnatures The projectnatures to set.
438 */
439 public void setProjectnatures( List projectnatures )
440 {
441 this.projectnatures = projectnatures;
442 }
443
444 /**
445 * Getter for <code>projectFacets</code>.
446 *
447 * @return Returns the projectFacets
448 */
449 public Map getProjectFacets()
450 {
451 return projectFacets;
452 }
453
454 /**
455 * Setter for <code>projectFacets</code>
456 *
457 * @param projectFacets The projectFacets to set.
458 */
459 public void setProjectFacets( Map projectFacets )
460 {
461 this.projectFacets = projectFacets;
462 }
463
464 /**
465 * Getter for <code>projectBaseDir</code>.
466 *
467 * @return Returns the projectBaseDir.
468 */
469 public File getProjectBaseDir()
470 {
471 return projectBaseDir;
472 }
473
474 /**
475 * Setter for <code>projectBaseDir</code>.
476 *
477 * @param projectBaseDir The projectBaseDir to set.
478 */
479 public void setProjectBaseDir( File projectBaseDir )
480 {
481 this.projectBaseDir = projectBaseDir;
482 }
483
484 /**
485 * Getter for <code>addVersionToProjectName</code>.
486 *
487 * @deprecated use {@link #getProjectNameTemplate()}
488 */
489 public boolean isAddVersionToProjectName()
490 {
491 return addVersionToProjectName;
492 }
493
494 /**
495 * Setter for <code>addVersionToProjectName</code>.
496 *
497 * @deprecated use {@link #setProjectNameTemplate(String)}
498 */
499 public void setAddVersionToProjectName( boolean addVersionToProjectName )
500 {
501 this.addVersionToProjectName = addVersionToProjectName;
502 }
503
504 public void setProjectNameTemplate( String projectNameTemplate )
505 {
506 this.projectNameTemplate = projectNameTemplate;
507 }
508
509 public String getProjectNameTemplate()
510 {
511 return projectNameTemplate;
512 }
513
514 public String getContextName()
515 {
516 return contextName;
517 }
518
519 public void setContextName( String deployName )
520 {
521 contextName = deployName;
522 }
523
524 /**
525 * @return the packaging
526 */
527 public String getPackaging()
528 {
529 return packaging;
530 }
531
532 /**
533 * @param packaging the packaging to set
534 */
535 public void setPackaging( String packaging )
536 {
537 this.packaging = packaging;
538 }
539
540 /**
541 * Getter for <code>wtpapplicationxml</code>.
542 *
543 * @return Returns the wtpapplicationxml.
544 */
545 public boolean getWtpapplicationxml()
546 {
547 return wtpapplicationxml;
548 }
549
550 /**
551 * Setter for <code>buildCommands</code>.
552 *
553 * @param buildCommands The buildCommands to set.
554 */
555 public void setWtpapplicationxml( boolean wtpapplicationxml )
556 {
557 this.wtpapplicationxml = wtpapplicationxml;
558 }
559
560 /**
561 * Getter for <code>wtpVersion</code>.
562 *
563 * @return Returns the wtpVersion.
564 */
565 public float getWtpVersion()
566 {
567 return wtpVersion;
568 }
569
570 /**
571 * Setter for <code>wtpVersion</code>.
572 *
573 * @param wtpVersion The wtpVersion to set.
574 */
575 public void setWtpVersion( float wtpVersion )
576 {
577 this.wtpVersion = wtpVersion;
578 }
579
580 /**
581 * @return an ordered list of dependencies
582 */
583 public IdeDependency[] getDepsOrdered()
584 {
585 return orderedDeps;
586 }
587
588 /**
589 * Returns the ajdtVersion.
590 *
591 * @return the ajdtVersion.
592 */
593 public float getAjdtVersion()
594 {
595 return ajdtVersion;
596 }
597
598 /**
599 * Sets the ajdtVersion.
600 *
601 * @param ajdtVersion the ajdtVersion.
602 */
603 public void setAjdtVersion( float ajdtVersion )
604 {
605 this.ajdtVersion = ajdtVersion;
606 }
607
608 }