1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.maven.plugin.buildmetadata.common;
17
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.Collections;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Properties;
25 import java.util.Set;
26
27 import org.codehaus.plexus.util.StringUtils;
28
29
30
31
32
33
34
35 public final class Constant
36 {
37
38
39
40
41
42
43
44
45
46
47
48
49 public static final String SECTION_BUILD_SCM = "build.scm";
50
51
52
53
54
55
56
57 public static final String SECTION_ARTIFACT = "build.artifact";
58
59
60
61
62
63
64
65 public static final String SECTION_BUILD_DATE = "build.timeAndDate";
66
67
68
69
70
71
72
73 public static final String SECTION_BUILD_RUNTIME = "build.runtime";
74
75
76
77
78
79
80
81 public static final String SECTION_BUILD_JAVA = "build.java";
82
83
84
85
86
87
88
89 public static final String SECTION_BUILD_MAVEN = "build.maven";
90
91
92
93
94
95
96
97 public static final String SECTION_BUILD_MISC = "build.misc";
98
99
100
101
102
103
104
105 public static final String SECTION_PROJECT = "project";
106
107
108
109
110
111
112
113
114
115 public static final String PROP_NAME_SCM_URL = "build.scmRevision.url";
116
117
118
119
120
121
122
123
124 public static final String PROP_NAME_SCM_REVISION_ID = "build.scmRevision.id";
125
126
127
128
129
130
131
132
133 public static final String PROP_NAME_SCM_REVISION_DATE =
134 "build.scmRevision.date";
135
136
137
138
139
140
141
142
143 public static final String PROP_NAME_SCM_LOCALLY_MODIFIED =
144 "build.scmLocallyModified";
145
146
147
148
149
150
151
152
153 public static final String PROP_NAME_SCM_LOCALLY_MODIFIED_FILES =
154 "build.scmLocallyModified.files";
155
156
157
158
159
160
161
162 public static final String PROP_NAME_BUILD_DATE = "build.date";
163
164
165
166
167
168
169
170 public static final String PROP_NAME_BUILD_TIMESTAMP =
171 "build.timestamp.millis";
172
173
174
175
176
177
178
179
180 public static final String PROP_NAME_BUILD_DATE_PATTERN =
181 "build.date.pattern";
182
183
184
185
186
187
188
189
190 public static final String PROP_NAME_GROUP_ID = "build.groupId";
191
192
193
194
195
196
197
198
199 public static final String PROP_NAME_ARTIFACT_ID = "build.artifactId";
200
201
202
203
204
205
206
207
208 public static final String PROP_NAME_VERSION = "build.version";
209
210
211
212
213
214
215
216
217
218 public static final String PROP_NAME_FULL_VERSION = "build.version.full";
219
220
221
222
223
224
225
226 public static final String PROP_NAME_BUILD_YEAR = "build.year";
227
228
229
230
231
232
233
234
235
236
237
238 public static final String PROP_NAME_BUILD_DURATION = "build.duration";
239
240
241
242
243
244
245
246
247
248
249 public static final String PROP_NAME_COPYRIGHT_YEAR = "build.copyright.year";
250
251
252
253
254
255
256
257 public static final String DEFAULT_DATE_PATTERN = "dd.MM.yyyy";
258
259
260
261
262
263
264
265
266
267 public static final String PROP_NAME_BUILD_USER = "build.user";
268
269
270
271
272
273
274
275
276 public static final String PROP_NAME_HOSTNAME = "build.host.name";
277
278
279
280
281
282
283
284
285 public static final String PROP_NAME_OS_NAME = "build.os.name";
286
287
288
289
290
291
292
293
294 public static final String PROP_NAME_OS_ARCH = "build.os.arch";
295
296
297
298
299
300
301
302
303 public static final String PROP_NAME_OS_VERSION = "build.os.version";
304
305
306
307
308
309
310
311
312 public static final String PROP_NAME_JAVA_RUNTIME_NAME =
313 "build.java.runtime.name";
314
315
316
317
318
319
320
321
322 public static final String PROP_NAME_JAVA_RUNTIME_VERSION =
323 "build.java.runtime.version";
324
325
326
327
328
329
330
331
332 public static final String PROP_NAME_JAVA_VENDOR = "build.java.vendor";
333
334
335
336
337
338
339
340
341 public static final String PROP_NAME_JAVA_VM = "build.java.vm";
342
343
344
345
346
347
348
349
350 public static final String PROP_NAME_JAVA_COMPILER = "build.java.compiler";
351
352
353
354
355
356
357
358
359 public static final String PROP_NAME_MAVEN_VERSION = "build.maven.version";
360
361
362
363
364
365
366
367
368 public static final String PROP_NAME_MAVEN_GOALS =
369 "build.maven.execution.goals";
370
371
372
373
374
375
376
377 public static final String PROP_NAME_MAVEN_CMDLINE =
378 "build.maven.execution.cmdline";
379
380
381
382
383
384
385
386 public static final String PROP_NAME_MAVEN_OPTS =
387 "build.maven.execution.opts";
388
389
390
391
392
393
394
395 public static final String PROP_NAME_JAVA_OPTS =
396 "build.maven.execution.java.opts";
397
398
399
400
401
402
403
404
405 public static final String PROP_NAME_MAVEN_IS_EXECUTION_ROOT =
406 "build.maven.execution.isRoot";
407
408
409
410
411
412
413
414 public static final String PROP_NAME_MAVEN_EXECUTION_PROJECT =
415 "build.maven.execution.project";
416
417
418
419
420
421
422
423
424 public static final String PROP_NAME_MAVEN_FILTERS =
425 "build.maven.execution.filters";
426
427
428
429
430
431
432
433
434 public static final String MAVEN_EXECUTION_PROPERTIES_PREFIX =
435 "execution.property";
436
437
438
439
440
441
442
443
444 public static final String PROP_NAME_MAVEN_ACTIVE_PROFILES =
445 "build.maven.execution.profiles.active";
446
447
448
449
450
451
452
453 public static final String MAVEN_ACTIVE_PROFILE_PREFIX =
454 "build.maven.execution.profile.active";
455
456
457
458
459
460
461
462 public static final String PROP_NAME_PROJECT_HOMEPAGE =
463 "project.page.home.url";
464
465
466
467
468
469
470
471
472 public static final String PROP_NAME_PROJECT_OPS = "project.page.ops.url";
473
474
475
476
477
478
479
480 public static final String PROP_NAME_PROJECT_CATEGORY = "project.category";
481
482
483
484
485
486
487
488
489 public static final String PROP_NAME_PROJECT_SUBCATEGORY =
490 "project.subcategory";
491
492
493
494
495
496
497
498
499 public static final String PROP_NAME_PROJECT_TAGS = "project.tags";
500
501
502
503
504
505
506 public static final List<Section> REPORT_PROPERTIES;
507
508
509
510
511
512
513 public static final Set<String> STANDARD_PROPERTIES;
514
515
516
517
518
519 static
520 {
521 final List<Section> sections = new ArrayList<Section>();
522 final Section scm =
523 new Section(SECTION_BUILD_SCM, PROP_NAME_SCM_REVISION_ID,
524 PROP_NAME_SCM_REVISION_DATE, PROP_NAME_SCM_URL,
525 PROP_NAME_SCM_LOCALLY_MODIFIED_FILES);
526 sections.add(scm);
527
528 final Section artifact =
529 new Section(SECTION_ARTIFACT, PROP_NAME_GROUP_ID,
530 PROP_NAME_ARTIFACT_ID, PROP_NAME_VERSION, PROP_NAME_FULL_VERSION);
531 sections.add(artifact);
532
533 final Section dateAndVersion =
534 new Section(SECTION_BUILD_DATE, PROP_NAME_BUILD_DATE,
535 PROP_NAME_BUILD_TIMESTAMP, PROP_NAME_BUILD_YEAR,
536 PROP_NAME_COPYRIGHT_YEAR, DEFAULT_DATE_PATTERN);
537 sections.add(dateAndVersion);
538
539 final Section buildRuntime =
540 new Section(SECTION_BUILD_RUNTIME, PROP_NAME_HOSTNAME,
541 PROP_NAME_OS_NAME, PROP_NAME_OS_ARCH, PROP_NAME_OS_VERSION,
542 PROP_NAME_BUILD_USER);
543 sections.add(buildRuntime);
544
545 final Section buildJava =
546 new Section(SECTION_BUILD_JAVA, PROP_NAME_JAVA_VENDOR,
547 PROP_NAME_JAVA_RUNTIME_NAME, PROP_NAME_JAVA_RUNTIME_VERSION,
548 PROP_NAME_JAVA_VM, PROP_NAME_JAVA_COMPILER, PROP_NAME_JAVA_OPTS);
549 sections.add(buildJava);
550
551 final Section buildMaven =
552 new Section(SECTION_BUILD_MAVEN, PROP_NAME_MAVEN_VERSION,
553 PROP_NAME_MAVEN_CMDLINE, PROP_NAME_MAVEN_GOALS,
554 PROP_NAME_MAVEN_OPTS, PROP_NAME_MAVEN_EXECUTION_PROJECT,
555 PROP_NAME_MAVEN_ACTIVE_PROFILES);
556 sections.add(buildMaven);
557
558 final Section project =
559 new Section(SECTION_PROJECT, PROP_NAME_PROJECT_HOMEPAGE,
560 PROP_NAME_PROJECT_OPS, PROP_NAME_PROJECT_CATEGORY,
561 PROP_NAME_PROJECT_SUBCATEGORY, PROP_NAME_PROJECT_TAGS);
562 sections.add(project);
563
564 final Set<String> properties =
565 new HashSet<String>(Arrays.asList(new String[]
566 { PROP_NAME_SCM_REVISION_ID, PROP_NAME_SCM_REVISION_DATE,
567 PROP_NAME_SCM_URL, PROP_NAME_SCM_LOCALLY_MODIFIED_FILES,
568 PROP_NAME_BUILD_DATE, PROP_NAME_BUILD_TIMESTAMP, PROP_NAME_BUILD_YEAR,
569 PROP_NAME_COPYRIGHT_YEAR, DEFAULT_DATE_PATTERN, PROP_NAME_GROUP_ID,
570 PROP_NAME_ARTIFACT_ID, PROP_NAME_VERSION, PROP_NAME_FULL_VERSION,
571 PROP_NAME_HOSTNAME, PROP_NAME_OS_NAME, PROP_NAME_OS_ARCH,
572 PROP_NAME_OS_VERSION, PROP_NAME_BUILD_USER, PROP_NAME_JAVA_VENDOR,
573 PROP_NAME_JAVA_RUNTIME_NAME, PROP_NAME_JAVA_RUNTIME_VERSION,
574 PROP_NAME_JAVA_VM, PROP_NAME_JAVA_COMPILER, PROP_NAME_JAVA_OPTS,
575 PROP_NAME_MAVEN_VERSION, PROP_NAME_MAVEN_CMDLINE,
576 PROP_NAME_MAVEN_GOALS, PROP_NAME_MAVEN_OPTS,
577 PROP_NAME_MAVEN_EXECUTION_PROJECT, PROP_NAME_MAVEN_ACTIVE_PROFILES,
578 PROP_NAME_PROJECT_HOMEPAGE, PROP_NAME_PROJECT_OPS }));
579
580 STANDARD_PROPERTIES = Collections.unmodifiableSet(properties);
581 REPORT_PROPERTIES = Collections.unmodifiableList(sections);
582 }
583
584
585
586
587
588
589 private Constant()
590 {
591 }
592
593
594
595
596
597
598 public static final class Section
599 {
600
601
602
603 private final String titleKey;
604
605
606
607
608 private final List<String> properties;
609
610
611
612
613
614
615
616
617 private Section(final String titleKey, final String... properties)
618 {
619 this.titleKey = titleKey;
620 this.properties = Arrays.asList(properties);
621 }
622
623
624
625
626
627
628 public String getTitleKey()
629 {
630 return titleKey;
631 }
632
633
634
635
636
637
638 public List<String> getProperties()
639 {
640 return properties;
641 }
642 }
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660 public static boolean isIntendedForMiscSection(final String name)
661 {
662 return !name.startsWith(MAVEN_ACTIVE_PROFILE_PREFIX);
663 }
664
665
666
667
668
669
670
671
672
673
674 public static Properties calcNonStandardProperties(
675 final Properties buildMetaDataProperties,
676 final List<Property> userProperties)
677 {
678 final SortedProperties nonStandardProperties = new SortedProperties();
679 final Set<String> selectedProperties =
680 createSelectedPropertiesExcludeMiscSection(userProperties);
681
682 for (final Map.Entry<Object, Object> entry : buildMetaDataProperties
683 .entrySet())
684 {
685 final String key = String.valueOf(entry.getKey());
686 if (!Constant.STANDARD_PROPERTIES.contains(key)
687 && !selectedProperties.contains(key))
688 {
689 nonStandardProperties.put(key, entry.getValue());
690 }
691 }
692 return nonStandardProperties;
693 }
694
695 private static Set<String> createSelectedPropertiesExcludeMiscSection(
696 final List<Property> userProperties)
697 {
698 final Set<String> selectedProperties = new HashSet<String>();
699
700 if (userProperties != null)
701 {
702 for (final Property property : userProperties)
703 {
704 if (isNotTargetedForMiscSection(property.getSection()))
705 {
706 selectedProperties.add(property.getName());
707 }
708 }
709 }
710 return selectedProperties;
711 }
712
713 private static boolean isNotTargetedForMiscSection(final String section)
714 {
715 return SECTION_BUILD_SCM.equals(section)
716 || SECTION_BUILD_DATE.equals(section)
717 || SECTION_BUILD_RUNTIME.equals(section)
718 || SECTION_BUILD_JAVA.equals(section)
719 || SECTION_BUILD_MAVEN.equals(section);
720 }
721
722
723
724
725
726
727
728
729 public static String prettify(final String string)
730 {
731 final String trimmed = string.trim();
732 final int end = trimmed.length() - 1;
733 if (trimmed.charAt(0) == '[' && trimmed.charAt(end) == ']')
734 {
735 return trimmed.substring(1, end);
736 }
737 return trimmed;
738 }
739
740
741
742
743
744
745
746
747 public static String prettifyFilesValue(final Object value)
748 {
749 if (value == null)
750 {
751 return null;
752 }
753
754 String string = String.valueOf(value);
755 if (StringUtils.isNotBlank(string))
756 {
757 string = string.replace(']', ' ');
758 string = string.replace('[', ',');
759 if (string.indexOf(0) == ',')
760 {
761 return string.substring(1);
762 }
763 }
764
765 return string;
766 }
767
768
769 }