48 * file. All package must also have a package_data.xml file in order to retrieve |
50 * file. All package must also have a package_data.xml file in order to retrieve |
49 * the root and the layer location of the package. |
51 * the root and the layer location of the package. |
50 * |
52 * |
51 * Example: |
53 * Example: |
52 * <pre> |
54 * <pre> |
53 * <hlm:createPackageMapping epocroot="E:\sdk" destFile="E:\sdk\sysdef_root.xml" > |
55 * <hlm:createRootSysdef epocroot="E:\sdk" destFile="E:\sdk\sysdef_root.xml" > |
54 * <fileset dir="E:\sdk" includes="root/**/package_definition.xml"> |
56 * <fileset dir="E:\sdk" includes="root/**/package_definition.xml"> |
55 * </hlm:createPackageMapping> |
57 * </hlm:createRootSysdef> |
56 * </pre> |
58 * </pre> |
57 * |
59 * |
58 * @ant.task name="createRootSysdef" category="Sysdef" |
60 * @ant.task name="createRootSysdef" category="Sysdef" |
59 */ |
61 */ |
60 public class CreateRootSysdefTask extends Task { |
62 public class CreateRootSysdefTask extends Task { |
61 |
63 |
62 private File destFile; |
64 private File destFile; |
63 private List<ResourceCollection> resourceCollections = new ArrayList<ResourceCollection>(); |
65 private List<ResourceCollection> resourceCollections = new ArrayList<ResourceCollection>(); |
64 private Map<String, Map<String, List<String>>> roots = new HashMap<String, Map<String, List<String>>>(); |
66 private Map<String, Map<String, List<Map<String, Object>>>> roots = new HashMap<String, Map<String, List<Map<String, Object>>>>(); |
65 private Map<String, List<String>> layers = new HashMap<String, List<String>>(); |
67 private Map<String, List<String>> layers = new HashMap<String, List<String>>(); |
66 private File epocroot; |
68 private File epocroot; |
67 private boolean failOnError = true; |
69 private boolean failOnError = true; |
68 private boolean checkPackageExists; |
70 private boolean checkPackageExists; |
69 private File template; |
71 private File template; |
|
72 private String idNamespace; |
70 |
73 |
71 /** |
74 /** |
72 * {@inheritDoc} |
75 * {@inheritDoc} |
73 */ |
76 */ |
74 @SuppressWarnings("unchecked") |
77 @SuppressWarnings("unchecked") |
99 File pkgMapFile = new File(pkgDir, CreatePackageMappingTask.PACKAGE_MAP_FILENAME); |
102 File pkgMapFile = new File(pkgDir, CreatePackageMappingTask.PACKAGE_MAP_FILENAME); |
100 try { |
103 try { |
101 if (pkgMapFile.exists()) { |
104 if (pkgMapFile.exists()) { |
102 log("Package map file: " + pkgMapFile); |
105 log("Package map file: " + pkgMapFile); |
103 if (!checkPackageExists) { |
106 if (!checkPackageExists) { |
104 addPackage(pkgMapFile, pkgDir.getName()); |
107 addPackage(pkgDefFile, pkgMapFile, pkgDir.getName()); |
105 } else { |
108 } else { |
106 PackageMap pkgMap = new PackageMap(pkgMapFile); |
109 PackageMap pkgMap = new PackageMap(pkgMapFile); |
107 File destPkg = new File(epocroot, pkgMap.getRoot() + File.separator + |
110 File destPkg = new File(epocroot, pkgMap.getRoot() + File.separator + |
108 pkgMap.getLayer() + File.separator + pkgDir.getName() + File.separator + |
111 pkgMap.getLayer() + File.separator + pkgDir.getName() + File.separator + |
109 CreatePackageMappingTask.PACKAGE_DEFINITION_FILENAME); |
112 CreatePackageMappingTask.PACKAGE_DEFINITION_FILENAME); |
110 if (destPkg.exists()) { |
113 if (destPkg.exists()) { |
111 addPackage(pkgMapFile, pkgDir.getName()); |
114 addPackage(pkgDefFile, pkgMapFile, pkgDir.getName()); |
112 } else { |
115 } else { |
113 log("Could not find " + destPkg.getAbsolutePath() + |
116 log("Could not find " + destPkg.getAbsolutePath() + |
114 " so entry is not added to the root system definition.", Project.MSG_ERR); |
117 " so entry is not added to the root system definition.", Project.MSG_ERR); |
115 } |
118 } |
116 } |
119 } |
117 } else { |
120 } else { |
118 pkgMapFile = new File(pkgDir.getParentFile().getParentFile(), CreatePackageMappingTask.PACKAGE_MAP_FILENAME); |
121 pkgMapFile = new File(pkgDir.getParentFile().getParentFile(), CreatePackageMappingTask.PACKAGE_MAP_FILENAME); |
119 log("Package map file: " + pkgMapFile); |
122 log("Package map file: " + pkgMapFile); |
120 if (pkgMapFile.exists()) { |
123 if (pkgMapFile.exists()) { |
121 if (!checkPackageExists) { |
124 if (!checkPackageExists) { |
122 addPackage(pkgMapFile, pkgDir.getName()); |
125 // slash must be use to generate correct path. |
|
126 addPackage(pkgDefFile, pkgMapFile, pkgMapFile.getParentFile().getName() + "/" + |
|
127 pkgDir.getParentFile().getName() + "/" + pkgDir.getName()); |
123 } else { |
128 } else { |
124 PackageMap pkgMap = new PackageMap(pkgMapFile); |
129 PackageMap pkgMap = new PackageMap(pkgMapFile); |
125 File destPkg = new File(epocroot, pkgMap.getRoot() + File.separator + |
130 File destPkg = new File(epocroot, pkgMap.getRoot() + File.separator + |
126 pkgMap.getLayer() + File.separator + |
131 pkgMap.getLayer() + File.separator + |
127 pkgMapFile.getParentFile().getName() + File.separator + |
132 pkgMapFile.getParentFile().getName() + File.separator + |
128 pkgDir.getParentFile().getName() + File.separator + pkgDir.getName() + |
133 pkgDir.getParentFile().getName() + File.separator + pkgDir.getName() + |
129 File.separator + |
134 File.separator + |
130 CreatePackageMappingTask.PACKAGE_DEFINITION_FILENAME); |
135 CreatePackageMappingTask.PACKAGE_DEFINITION_FILENAME); |
131 if (destPkg.exists()) { |
136 if (destPkg.exists()) { |
132 addPackage(pkgMapFile, pkgDir.getParentFile().getName() + |
137 addPackage(destPkg, pkgMapFile, pkgMapFile.getParentFile().getName() + "/" + |
133 File.separator + pkgDir.getName()); |
138 pkgDir.getParentFile().getName() + "/" + pkgDir.getName()); |
134 } else { |
139 } else { |
135 log("Could not find " + destPkg.getAbsolutePath() + |
140 log("Could not find " + destPkg.getAbsolutePath() + |
136 " so entry is not added to the root system definition.", Project.MSG_ERR); |
141 " so entry is not added to the root system definition.", Project.MSG_ERR); |
137 } |
142 } |
138 } |
143 } |
139 } else { |
144 } else { |
140 log("Could not find: " + pkgMapFile.toString(), Project.MSG_ERR); |
145 log("Could not find package_map.xml file for " + pkgDefFile.toString(), Project.MSG_ERR); |
141 if (shouldFailOnError()) { |
146 if (shouldFailOnError()) { |
142 throw new BuildException("Could not find:" + pkgMapFile.toString()); |
147 throw new BuildException("Could not find package_map.xml file for " + pkgDefFile.toString()); |
143 } |
148 } |
144 } |
149 } |
145 } |
150 } |
146 } catch (PackageMapParsingException e) { |
151 } catch (PackageMapParsingException e) { |
147 log("Invalid " + CreatePackageMappingTask.PACKAGE_MAP_FILENAME |
152 log("Invalid " + CreatePackageMappingTask.PACKAGE_MAP_FILENAME |
148 + " file: " + pkgMapFile.toString() |
153 + " file: " + pkgMapFile.toString() |
149 + "(" + e.getMessage() + ")", Project.MSG_ERR); |
154 + "(" + e.getMessage() + ")", Project.MSG_ERR); |
150 if (shouldFailOnError()) { |
155 if (shouldFailOnError()) { |
151 throw new BuildException(e.getMessage(), e); |
156 throw new BuildException(e.getMessage(), e); |
152 } |
157 } |
|
158 } catch (PackageDefinitionParsingException e) { |
|
159 log("Invalid " + CreatePackageMappingTask.PACKAGE_DEFINITION_FILENAME |
|
160 + "(" + e.getMessage() + ")", Project.MSG_ERR); |
|
161 if (shouldFailOnError()) { |
|
162 throw new BuildException(e.getMessage(), e); |
|
163 } |
153 } |
164 } |
154 |
165 |
155 } |
166 } |
156 } |
167 } |
157 generateRootSysdef(); |
168 generateRootSysdef(); |
158 } |
169 } |
159 |
170 |
160 private void addPackage(File pkgMapFile, String pkgPath) throws |
171 private void addPackage(File pkgDefinition, File pkgMapFile, String pkgPath) throws |
161 PackageMapParsingException { |
172 PackageMapParsingException, PackageDefinitionParsingException { |
|
173 // Some quick validity checking. |
|
174 PackageDefinition pkg = new PackageDefinition(pkgDefinition); |
|
175 if (idNamespace == null && (pkg.getIdNamespace() != null && pkg.getIdNamespace().length() > 0)) { |
|
176 idNamespace = pkg.getIdNamespace(); |
|
177 } else if (idNamespace != null && !idNamespace.equals(pkg.getIdNamespace())) { |
|
178 log("Warning: " + pkgDefinition.toString() + |
|
179 " namespace doesn't match the default one. (" |
|
180 + idNamespace + " != " + pkg.getIdNamespace(), Project.MSG_WARN); |
|
181 } |
|
182 |
|
183 // Adding the package in the structure. |
162 log("Adding: " + pkgMapFile, Project.MSG_DEBUG); |
184 log("Adding: " + pkgMapFile, Project.MSG_DEBUG); |
163 // Adding the package in the structure. |
|
164 PackageMap pkgMap = new PackageMap(pkgMapFile); |
185 PackageMap pkgMap = new PackageMap(pkgMapFile); |
165 if (!roots.containsKey(pkgMap.getRoot())) { |
186 if (!roots.containsKey(pkgMap.getRoot())) { |
166 roots.put(pkgMap.getRoot(), new HashMap<String, List<String>>()); |
187 roots.put(pkgMap.getRoot(), new HashMap<String, List<Map<String, Object>>>()); |
167 } |
188 } |
168 if (!roots.get(pkgMap.getRoot()).containsKey(pkgMap.getLayer())) { |
189 if (!roots.get(pkgMap.getRoot()).containsKey(pkgMap.getLayer())) { |
169 roots.get(pkgMap.getRoot()).put(pkgMap.getLayer(), new ArrayList<String>()); |
190 roots.get(pkgMap.getRoot()).put(pkgMap.getLayer(), new ArrayList<Map<String, Object>>()); |
170 layers.put(pkgMap.getLayer(), new ArrayList<String>()); |
191 layers.put(pkgMap.getLayer(), new ArrayList<String>()); |
171 } |
192 } |
172 roots.get(pkgMap.getRoot()).get(pkgMap.getLayer()).add(pkgPath); |
193 Map<String, Object> data = new HashMap<String, Object>(); |
|
194 data.put("path", pkgPath); |
|
195 data.put("id", pkg.getId()); |
|
196 data.put("namespaces", pkg.getNamespaces()); |
|
197 roots.get(pkgMap.getRoot()).get(pkgMap.getLayer()).add(data); |
173 layers.get(pkgMap.getLayer()).add(pkgPath); |
198 layers.get(pkgMap.getLayer()).add(pkgPath); |
174 } |
199 } |
175 |
200 |
176 /** |
201 /** |
177 * Defines the location of the generated INI file. |
202 * Defines the location of the generated INI file. |