| 1 | |
package com.aurea.maven.plugins.sonic.utils; |
| 2 | |
|
| 3 | |
import java.io.ByteArrayInputStream; |
| 4 | |
import java.io.File; |
| 5 | |
import java.io.IOException; |
| 6 | |
import java.util.ArrayList; |
| 7 | |
import java.util.HashSet; |
| 8 | |
|
| 9 | |
import org.codehaus.plexus.util.xml.XmlStreamReader; |
| 10 | |
import org.codehaus.plexus.util.xml.Xpp3Dom; |
| 11 | |
import org.codehaus.plexus.util.xml.Xpp3DomBuilder; |
| 12 | |
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; |
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | 0 | public class ProjectAnalyzer { |
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
public static File[] getProcessSourceFiles(final String _baseDir) { |
| 31 | |
|
| 32 | 0 | String[] processFileLocations = FileUtilities.getFileList(_baseDir, "**/*.esbp", null); |
| 33 | 0 | File[] processFiles = new File[processFileLocations.length]; |
| 34 | |
|
| 35 | 0 | for (int index = 0; index < processFileLocations.length; index++) { |
| 36 | 0 | processFiles[index] = new File(_baseDir, processFileLocations[index]); |
| 37 | |
} |
| 38 | |
|
| 39 | 0 | return processFiles; |
| 40 | |
} |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
public static HashSet<String> getProcessNames(final String _baseDir) { |
| 50 | |
|
| 51 | 0 | HashSet<String> processNames = new HashSet<String>(); |
| 52 | |
|
| 53 | 0 | for (File processFile : getProcessSourceFiles(_baseDir)) { |
| 54 | 0 | String currProcName = getProcessNameFromFile(processFile); |
| 55 | 0 | processNames.add(currProcName); |
| 56 | |
} |
| 57 | 0 | return processNames; |
| 58 | |
} |
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
public static File[] getServiceConfigSourceFiles(final String _baseDir) { |
| 68 | |
|
| 69 | 0 | String[] serviceConfigFileLocations = FileUtilities.getFileList(_baseDir, "**/*.esbsvc", null); |
| 70 | 0 | File[] serviceConfigFiles = new File[serviceConfigFileLocations.length]; |
| 71 | |
|
| 72 | 0 | for (int index = 0; index < serviceConfigFileLocations.length; index++) { |
| 73 | 0 | serviceConfigFiles[index] = new File(_baseDir, serviceConfigFileLocations[index]); |
| 74 | |
} |
| 75 | |
|
| 76 | 0 | return serviceConfigFiles; |
| 77 | |
} |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
public static File[] getServiceTypeSourceFiles(final String _baseDir) { |
| 87 | |
|
| 88 | 0 | String[] serviceTypeFileLocations = FileUtilities.getFileList(_baseDir, "**/*.esbstyp", null); |
| 89 | 0 | File[] serviceTypeFiles = new File[serviceTypeFileLocations.length]; |
| 90 | |
|
| 91 | 0 | for (int index = 0; index < serviceTypeFileLocations.length; index++) { |
| 92 | 0 | serviceTypeFiles[index] = new File(_baseDir, serviceTypeFileLocations[index]); |
| 93 | |
} |
| 94 | |
|
| 95 | 0 | return serviceTypeFiles; |
| 96 | |
} |
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
public static HashSet<String> getSubProcessesOfProcesses(final File _baseDir) { |
| 105 | |
|
| 106 | 0 | HashSet<String> subProcesses = new HashSet<String>(); |
| 107 | 0 | ArrayList<String> subProcessesReferenced = new ArrayList<String>(); |
| 108 | |
|
| 109 | 0 | for (File processFile : getProcessSourceFiles(_baseDir.getAbsolutePath())) { |
| 110 | 0 | subProcesses.addAll(getSubProcessesOfProcess(processFile)); |
| 111 | 0 | subProcessesReferenced.addAll(getSubProcessesOfProcess(processFile)); |
| 112 | |
} |
| 113 | |
|
| 114 | 0 | return subProcesses; |
| 115 | |
} |
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
public static HashSet<String> getSubProcessesOfProcess(final File _processFile) { |
| 123 | |
|
| 124 | 0 | HashSet<String> hs = new HashSet<String>(); |
| 125 | |
|
| 126 | |
try { |
| 127 | |
|
| 128 | |
|
| 129 | 0 | XmlStreamReader reader = new XmlStreamReader(_processFile); |
| 130 | 0 | Xpp3Dom processDom = Xpp3DomBuilder.build(reader); |
| 131 | 0 | Xpp3Dom itinerary = processDom.getChild("xq:itinerary"); |
| 132 | 0 | Xpp3Dom[] steps = itinerary.getChildren(); |
| 133 | 0 | for (Xpp3Dom currStep : steps) { |
| 134 | 0 | if ("xq:step".equals(currStep.getName()) && "PROCESS".equals(currStep.getAttribute("type"))) { |
| 135 | 0 | hs.add(currStep.getAttribute("endpoint_ref")); |
| 136 | |
} |
| 137 | |
} |
| 138 | 0 | } catch (IOException e) { |
| 139 | 0 | System.out.println("[ERROR] Could not read process source file: " + _processFile); |
| 140 | 0 | e.printStackTrace(); |
| 141 | 0 | } catch (XmlPullParserException e) { |
| 142 | 0 | System.out.println("[ERROR] Could not parse process source file: " + _processFile); |
| 143 | 0 | e.printStackTrace(); |
| 144 | 0 | } |
| 145 | |
|
| 146 | 0 | return hs; |
| 147 | |
} |
| 148 | |
|
| 149 | |
public static HashSet<String> getServiceConfigsOfProcess(final String _processDefinition) { |
| 150 | 0 | HashSet<String> hs = new HashSet<String>(); |
| 151 | |
|
| 152 | |
try { |
| 153 | |
|
| 154 | 0 | XmlStreamReader reader = new XmlStreamReader(new ByteArrayInputStream(_processDefinition.getBytes())); |
| 155 | 0 | Xpp3Dom processDom = Xpp3DomBuilder.build(reader); |
| 156 | 0 | Xpp3Dom itinerary = processDom.getChild("xq:itinerary"); |
| 157 | 0 | Xpp3Dom[] steps = itinerary.getChildren(); |
| 158 | 0 | for (Xpp3Dom currStep : steps) { |
| 159 | 0 | if ("xq:step".equals(currStep.getName()) && "SERVICE".equals(currStep.getAttribute("type"))) { |
| 160 | 0 | hs.add(currStep.getAttribute("endpoint_ref")); |
| 161 | |
} |
| 162 | |
} |
| 163 | 0 | } catch (IOException e) { |
| 164 | 0 | System.out.println("[ERROR] Could not read process"); |
| 165 | 0 | e.printStackTrace(); |
| 166 | 0 | } catch (XmlPullParserException e) { |
| 167 | 0 | System.out.println("[ERROR] Could not parse process"); |
| 168 | 0 | e.printStackTrace(); |
| 169 | 0 | } |
| 170 | |
|
| 171 | 0 | return hs; |
| 172 | |
} |
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
|
| 182 | |
public static String getProcessNameFromFile(final File _processFile) { |
| 183 | |
|
| 184 | 0 | String processName = null; |
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
try { |
| 189 | 0 | XmlStreamReader reader = new XmlStreamReader(_processFile); |
| 190 | 0 | Xpp3Dom processDom = Xpp3DomBuilder.build(reader); |
| 191 | 0 | processName = processDom.getAttribute("name"); |
| 192 | |
|
| 193 | 0 | } catch (IOException e) { |
| 194 | |
|
| 195 | 0 | System.out.println("[ERROR] Could not read process file: " + _processFile.getName()); |
| 196 | 0 | } catch (XmlPullParserException e) { |
| 197 | |
|
| 198 | 0 | System.out.println("[ERROR] Could not parse process file: " + _processFile.getName()); |
| 199 | 0 | } |
| 200 | 0 | return processName; |
| 201 | |
} |
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
public static String getServiceConfigNameFromFile(final File _serviceConfigFile) { |
| 211 | |
|
| 212 | 0 | String serviceName = null; |
| 213 | |
|
| 214 | |
try { |
| 215 | 0 | XmlStreamReader reader = new XmlStreamReader(_serviceConfigFile); |
| 216 | 0 | Xpp3Dom serviceConfigDom = Xpp3DomBuilder.build(reader); |
| 217 | 0 | serviceName = serviceConfigDom.getAttribute("name"); |
| 218 | |
|
| 219 | 0 | } catch (IOException e) { |
| 220 | 0 | System.out.println("[ERROR] Could not read Service Configuration file: " + _serviceConfigFile.getName()); |
| 221 | 0 | } catch (XmlPullParserException e) { |
| 222 | 0 | System.out.println("[ERROR] Could not parse Service Configuration file: " + _serviceConfigFile.getName()); |
| 223 | 0 | } |
| 224 | 0 | return serviceName; |
| 225 | |
} |
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
public static String getServiceConfigEntryRefFromFile(final File _serviceConfigFile) { |
| 235 | |
|
| 236 | 0 | String entryRefName = null; |
| 237 | |
|
| 238 | |
try { |
| 239 | 0 | XmlStreamReader reader = new XmlStreamReader(_serviceConfigFile); |
| 240 | 0 | Xpp3Dom serviceConfigDom = Xpp3DomBuilder.build(reader); |
| 241 | 0 | Xpp3Dom entryRef = serviceConfigDom.getChild("xq:entry_ref"); |
| 242 | 0 | if (entryRef != null) { |
| 243 | 0 | entryRefName = entryRef.getValue(); |
| 244 | |
} |
| 245 | 0 | } catch (IOException e) { |
| 246 | 0 | System.out.println("[ERROR] Could not read Service Configuration file: " + _serviceConfigFile.getName()); |
| 247 | 0 | } catch (XmlPullParserException e) { |
| 248 | 0 | System.out.println("[ERROR] Could not parse Service Configuration file: " + _serviceConfigFile.getName()); |
| 249 | 0 | } |
| 250 | 0 | return entryRefName; |
| 251 | |
} |
| 252 | |
|
| 253 | |
} |