]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.repo/src/org/argeo/slc/repo/maven/ConvertPoms_01_03.java
Merge remote-tracking branch 'origin/unstable' into testing
[gpl/argeo-slc.git] / org.argeo.slc.repo / src / org / argeo / slc / repo / maven / ConvertPoms_01_03.java
1 package org.argeo.slc.repo.maven;
2
3 import java.io.File;
4 import java.util.HashMap;
5
6 import javax.xml.parsers.DocumentBuilder;
7 import javax.xml.parsers.DocumentBuilderFactory;
8 import javax.xml.transform.Result;
9 import javax.xml.transform.Source;
10 import javax.xml.transform.Transformer;
11 import javax.xml.transform.TransformerFactory;
12 import javax.xml.transform.dom.DOMSource;
13 import javax.xml.transform.stream.StreamResult;
14
15 import org.w3c.dom.Document;
16 import org.w3c.dom.Element;
17 import org.w3c.dom.Node;
18 import org.w3c.dom.NodeList;
19
20 /** Recursively migrate all the POMs to Argeo Distribution v1.3 */
21 public class ConvertPoms_01_03 implements Runnable {
22 final String SPRING_SOURCE_PREFIX = "com.springsource";
23
24 private HashMap<String, String> artifactMapping = new HashMap<String, String>();
25
26 private File rootDir;
27
28 public ConvertPoms_01_03(String rootDirPath) {
29 this(new File(rootDirPath));
30 }
31
32 public ConvertPoms_01_03(File rootDir) {
33 this.rootDir = rootDir;
34
35 artifactMapping.put("org.argeo.dep.jacob", "com.jacob");
36 artifactMapping.put("org.argeo.dep.jacob.win32.x86",
37 "com.jacob.win32.x86");
38 artifactMapping.put("org.argeo.dep.osgi.activemq",
39 "org.apache.activemq");
40 artifactMapping.put("org.argeo.dep.osgi.activemq.optional",
41 "org.apache.activemq.optional");
42 artifactMapping.put("org.argeo.dep.osgi.activemq.xmpp",
43 "org.apache.activemq.xmpp");
44 artifactMapping.put("org.argeo.dep.osgi.aether", "org.eclipse.aether");
45 artifactMapping.put("org.argeo.dep.osgi.boilerpipe",
46 "de.l3s.boilerpipe");
47 artifactMapping.put("org.argeo.dep.osgi.commons.cli",
48 "org.apache.commons.cli");
49 artifactMapping.put("org.argeo.dep.osgi.commons.exec",
50 "org.apache.commons.exec");
51 artifactMapping.put("org.argeo.dep.osgi.directory.shared.asn.codec",
52 "org.apache.directory.shared.asn.codec");
53 artifactMapping.put("org.argeo.dep.osgi.drewnoakes.metadata_extractor",
54 "com.drewnoakes.metadata_extractor");
55 artifactMapping.put("org.argeo.dep.osgi.geoapi", "org.opengis");
56 artifactMapping.put("org.argeo.dep.osgi.geotools", "org.geotools");
57 artifactMapping.put("org.argeo.dep.osgi.google.collections",
58 "com.google.collections");
59 artifactMapping.put("org.argeo.dep.osgi.hibernatespatial",
60 "org.hibernatespatial");
61 artifactMapping.put("org.argeo.dep.osgi.jackrabbit",
62 "org.apache.jackrabbit");
63 artifactMapping.put("org.argeo.dep.osgi.jai.imageio",
64 "com.sun.media.jai.imageio");
65 artifactMapping.put("org.argeo.dep.osgi.java3d", "javax.vecmath");
66 artifactMapping.put("org.argeo.dep.osgi.jcr", "javax.jcr");
67 artifactMapping.put("org.argeo.dep.osgi.jsr275", "javax.measure");
68 artifactMapping.put("org.argeo.dep.osgi.jts", "com.vividsolutions.jts");
69 artifactMapping.put("org.argeo.dep.osgi.mina.filter.ssl",
70 "org.apache.mina.filter.ssl");
71 artifactMapping.put("org.argeo.dep.osgi.modeshape", "org.modeshape");
72 artifactMapping.put("org.argeo.dep.osgi.netcdf",
73 "edu.ucar.unidata.netcdf");
74 artifactMapping.put("org.argeo.dep.osgi.pdfbox", "org.apache.pdfbox");
75 artifactMapping.put("org.argeo.dep.osgi.poi", "org.apache.poi");
76 artifactMapping.put("org.argeo.dep.osgi.postgis.jdbc",
77 "org.postgis.jdbc");
78 artifactMapping.put("org.argeo.dep.osgi.springframework.ldap",
79 "org.springframework.ldap");
80 artifactMapping.put("org.argeo.dep.osgi.tagsoup",
81 "org.ccil.cowan.tagsoup");
82 artifactMapping.put("org.argeo.dep.osgi.tika", "org.apache.tika");
83 }
84
85 public void run() {
86 traverse(rootDir);
87 }
88
89 protected void traverse(File dir) {
90 for (File file : dir.listFiles()) {
91 String fileName = file.getName();
92 if (file.isDirectory() && !skipDirName(fileName)) {
93 traverse(file);
94 } else if (fileName.equals("pom.xml")) {
95 processPom(file);
96 }
97 }
98 }
99
100 protected Boolean skipDirName(String fileName) {
101 return fileName.equals(".svn") || fileName.equals("target")
102 || fileName.equals("META-INF") || fileName.equals("src");
103 }
104
105 protected void processPom(File pomFile) {
106 try {
107 Boolean wasChanged = false;
108 DocumentBuilderFactory dbFactory = DocumentBuilderFactory
109 .newInstance();
110 DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
111 Document doc = dBuilder.parse(pomFile);
112 doc.getDocumentElement().normalize();
113
114 Element dependenciesElement = null;
115 NodeList rootChildren = doc.getDocumentElement().getChildNodes();
116 for (int temp = 0; temp < rootChildren.getLength(); temp++) {
117 Node n = rootChildren.item(temp);
118 if (n.getNodeName().equals("dependencies"))
119 dependenciesElement = (Element) n;
120 }
121
122 if (dependenciesElement != null) {
123 stdOut("\n## " + pomFile);
124 NodeList dependencyElements = dependenciesElement
125 .getElementsByTagName("dependency");
126
127 for (int temp = 0; temp < dependencyElements.getLength(); temp++) {
128 Element eElement = (Element) dependencyElements.item(temp);
129 String groupId = getTagValue(eElement, "groupId");
130 String artifactId = getTagValue(eElement, "artifactId");
131 // stdOut(groupId + ":" + artifactId);
132
133 String newGroupId = null;
134 String newArtifactId = null;
135 if (groupId.startsWith("org.argeo.dep")) {
136 newGroupId = "org.argeo.tp";
137 } else if (!(groupId.startsWith("org.argeo")
138 || groupId.startsWith("com.capco")
139 || groupId.startsWith("com.agfa") || groupId
140 .startsWith("org.ibboost"))) {
141 newGroupId = "org.argeo.tp";
142 }
143
144 if (artifactMapping.containsKey(artifactId)) {
145 newArtifactId = artifactMapping.get(artifactId);
146 } else if (artifactId.startsWith(SPRING_SOURCE_PREFIX)
147 && !artifactId.equals(SPRING_SOURCE_PREFIX
148 + ".json")) {
149 newArtifactId = artifactId
150 .substring(SPRING_SOURCE_PREFIX.length() + 1);
151 }
152
153 // modify
154 if (newGroupId != null || newArtifactId != null) {
155 if (newGroupId == null)
156 newGroupId = groupId;
157 if (newArtifactId == null)
158 newArtifactId = artifactId;
159 stdOut(groupId + ":" + artifactId + " => " + newGroupId
160 + ":" + newArtifactId);
161 setTagValue(eElement, "groupId", newGroupId);
162 setTagValue(eElement, "artifactId", newArtifactId);
163 wasChanged = true;
164 }
165 }
166 }
167
168 if (wasChanged) {
169 // pomFile.renameTo(new File(pomFile.getParentFile(),
170 // "pom-old.xml"));
171 // save in place
172 Source source = new DOMSource(doc);
173 Result result = new StreamResult(pomFile);
174 Transformer xformer = TransformerFactory.newInstance()
175 .newTransformer();
176 xformer.transform(source, result);
177 }
178 } catch (Exception e) {
179 throw new RuntimeException("Cannot process " + pomFile, e);
180 }
181
182 }
183
184 private String getTagValue(Element eElement, String sTag) {
185 NodeList nList = eElement.getElementsByTagName(sTag);
186 if (nList.getLength() > 0) {
187 NodeList nlList = nList.item(0).getChildNodes();
188 Node nValue = (Node) nlList.item(0);
189 return nValue.getNodeValue();
190 } else
191 return null;
192 }
193
194 private void setTagValue(Element eElement, String sTag, String value) {
195 NodeList nList = eElement.getElementsByTagName(sTag);
196 if (nList.getLength() > 0) {
197 NodeList nlList = nList.item(0).getChildNodes();
198 Node nValue = (Node) nlList.item(0);
199 nValue.setNodeValue(value);
200 }
201 }
202
203 public static void stdOut(Object obj) {
204 System.out.println(obj);
205 }
206
207 public static void main(String argv[]) {
208 new ConvertPoms_01_03(argv[0]).run();
209 }
210
211 }