1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.maven.plugin.buildmetadata;
17
18 import java.io.File;
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.apache.maven.model.Build;
23 import org.apache.maven.project.MavenProject;
24
25
26
27
28
29
30
31 final class PropertyOutputFileMapper
32 {
33
34
35
36
37
38
39
40
41
42 private final MavenProject project;
43
44
45
46
47 private List<FileMapping> propertyOutputFileMapping;
48
49
50
51
52
53 PropertyOutputFileMapper(final MavenProject project,
54 final List<FileMapping> propertyOutputFileMapping)
55 {
56 this.project = project;
57 this.propertyOutputFileMapping = propertyOutputFileMapping;
58 }
59
60
61
62
63
64
65
66
67
68
69
70 List<FileMapping> initPropertyOutputFileMapping()
71 {
72 if (propertyOutputFileMapping == null)
73 {
74 propertyOutputFileMapping = new ArrayList<FileMapping>(10);
75 final Build build = project.getBuild();
76 final String classesDir = build.getOutputDirectory();
77 final File jarFile = new File(classesDir, "META-INF/build.properties");
78 final File targetDir = new File(build.getDirectory());
79 final String finalName = build.getFinalName();
80 final File deploymentUnitFile =
81 new File(targetDir, finalName + "/META-INF/build.properties");
82
83 propertyOutputFileMapping.add(new FileMapping("pom", new File(targetDir,
84 "build.properties")));
85 propertyOutputFileMapping.add(new FileMapping("war", deploymentUnitFile));
86 propertyOutputFileMapping.add(new FileMapping("ear", deploymentUnitFile));
87 propertyOutputFileMapping.add(new FileMapping("sar", deploymentUnitFile));
88 propertyOutputFileMapping.add(new FileMapping("rar", deploymentUnitFile));
89 propertyOutputFileMapping.add(new FileMapping("par", deploymentUnitFile));
90 propertyOutputFileMapping.add(new FileMapping("jar", jarFile));
91 propertyOutputFileMapping.add(new FileMapping("ejb", jarFile));
92 propertyOutputFileMapping.add(new FileMapping("maven-plugin", jarFile));
93 propertyOutputFileMapping
94 .add(new FileMapping("maven-archetype", jarFile));
95 propertyOutputFileMapping.add(new FileMapping("eclipse-plugin", new File(targetDir,
96 "build.properties")));
97 propertyOutputFileMapping.add(new FileMapping("eclipse-feature", new File(targetDir,
98 "build.properties")));
99 propertyOutputFileMapping.add(new FileMapping("eclipse-repository", new File(targetDir,
100 "build.properties")));
101 propertyOutputFileMapping.add(new FileMapping("eclipse-update-site", new File(targetDir,
102 "build.properties")));
103 propertyOutputFileMapping.add(new FileMapping("targetplatform", new File(targetDir,
104 "build.properties")));
105 return propertyOutputFileMapping;
106
107 }
108
109 return propertyOutputFileMapping;
110 }
111
112
113
114
115
116
117 File getPropertiesOutputFile(final boolean activatePropertyOutputFileMapping,
118 final File propertiesOutputFile)
119 {
120 if (activatePropertyOutputFileMapping)
121 {
122 final String packaging = project.getPackaging();
123 for (final FileMapping mapping : propertyOutputFileMapping)
124 {
125 if (packaging.equals(mapping.getPackaging()))
126 {
127 return mapping.getOutputFile();
128 }
129 }
130 }
131
132 return propertiesOutputFile;
133 }
134
135
136
137 }