| 1 | |
package com.aurea.maven.plugins.sonic.utils; |
| 2 | |
|
| 3 | |
import java.io.ByteArrayInputStream; |
| 4 | |
import java.io.File; |
| 5 | |
import java.util.ArrayList; |
| 6 | |
import java.util.List; |
| 7 | |
|
| 8 | |
import com.aurea.maven.plugins.sonic.sdm.container.IServiceType; |
| 9 | |
import com.aurea.maven.plugins.sonic.sdm.container.impl.DefaultServiceType; |
| 10 | |
import com.progress.sonic.utilities.esb.admin.XarAnalyzer; |
| 11 | |
import com.sonicsw.deploy.IArtifact; |
| 12 | |
import com.sonicsw.deploy.artifact.ESBArtifact; |
| 13 | |
import com.sonicsw.deploy.artifact.SonicFSArtifact; |
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
public class DependencyAnalyzer { |
| 22 | |
|
| 23 | |
|
| 24 | 0 | private String baseDir = null; |
| 25 | 0 | private List<String> serviceJarFiles = null; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | 0 | private List<String> serviceCtJarFiles = null; |
| 31 | 0 | private List<String> packagedJarFiles = null; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | 0 | public DependencyAnalyzer(final String _baseDir) { |
| 41 | |
|
| 42 | 0 | baseDir = _baseDir; |
| 43 | 0 | } |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
public final String[] getDependencyJars() { |
| 52 | |
|
| 53 | 0 | return FileUtilities.getFileList(getJarDependencyDir(), "**/*.jar", null); |
| 54 | |
} |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
public final List<String> getServiceJarFiles() { |
| 64 | |
|
| 65 | |
|
| 66 | 0 | if (serviceJarFiles == null) { |
| 67 | 0 | serviceJarFiles = new ArrayList<String>(); |
| 68 | 0 | serviceCtJarFiles = new ArrayList<String>(); |
| 69 | |
|
| 70 | |
|
| 71 | 0 | for (String xarFile : FileUtilities.getFileList(getXarDependencyDir(), "**/*.xar", null)) { |
| 72 | |
try { |
| 73 | 0 | XarAnalyzer analyzer = new XarAnalyzer(new File(getXarDependencyDir() + "/" + xarFile)); |
| 74 | |
|
| 75 | 0 | for (IArtifact sTypeArtifact : analyzer.getArtifacts(ESBArtifact.SERVICE_TYPE)) { |
| 76 | 0 | IServiceType sType = new DefaultServiceType(); |
| 77 | 0 | byte[] bytes = analyzer.getContent(sTypeArtifact); |
| 78 | |
|
| 79 | 0 | String temp = new String(bytes); |
| 80 | 0 | temp = temp.replace("<xq:selfFirst/>", "<xq:selfFirst>false</xq:selfFirst>"); |
| 81 | 0 | sType.load(new ByteArrayInputStream(temp.getBytes())); |
| 82 | |
|
| 83 | 0 | serviceJarFiles.addAll(sType.getInstanceClasspath()); |
| 84 | 0 | serviceJarFiles.addAll(sType.getTypeClasspath()); |
| 85 | 0 | serviceJarFiles.addAll(sType.getContainerClasspath()); |
| 86 | 0 | serviceCtJarFiles.addAll(sType.getContainerClasspath()); |
| 87 | 0 | } |
| 88 | 0 | } catch (Exception e) { |
| 89 | 0 | e.printStackTrace(); |
| 90 | 0 | } |
| 91 | |
} |
| 92 | |
} |
| 93 | 0 | return serviceJarFiles; |
| 94 | |
} |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
public final List<String> getServiceCtJarFiles() { |
| 102 | |
|
| 103 | 0 | if (serviceCtJarFiles == null) { |
| 104 | 0 | getServiceJarFiles(); |
| 105 | |
} |
| 106 | |
|
| 107 | 0 | return serviceCtJarFiles; |
| 108 | |
} |
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
public final List<String> getUnpackagedJarFiles() { |
| 117 | |
|
| 118 | 0 | List<String> result = new ArrayList<String>(); |
| 119 | |
|
| 120 | |
|
| 121 | 0 | for (String jarFile : getDependencyJars()) { |
| 122 | 0 | String toCompare = "/SonicFS/ESBResources/" + jarFile.replaceAll("\\\\", "/"); |
| 123 | |
|
| 124 | 0 | if (!getPackagedJarFiles().contains(toCompare)) { |
| 125 | 0 | result.add(jarFile); |
| 126 | |
} |
| 127 | |
} |
| 128 | |
|
| 129 | 0 | return result; |
| 130 | |
} |
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
public final List<String> getPackagedJarFiles() { |
| 140 | |
|
| 141 | 0 | if (packagedJarFiles == null) { |
| 142 | 0 | packagedJarFiles = new ArrayList<String>(); |
| 143 | 0 | for (String xarFile : FileUtilities.getFileList(getXarDependencyDir(), "**/*.xar", null)) { |
| 144 | 0 | XarAnalyzer analyzer = new XarAnalyzer(new File(getXarDependencyDir() + "/" + xarFile)); |
| 145 | |
try { |
| 146 | 0 | for (IArtifact jarFile : analyzer.getArtifacts(new SonicFSArtifact("ESBResources/"))) { |
| 147 | 0 | packagedJarFiles.add(jarFile.getArchivePath()); |
| 148 | 0 | } |
| 149 | 0 | } catch (Exception e) { |
| 150 | 0 | e.printStackTrace(); |
| 151 | 0 | } |
| 152 | |
} |
| 153 | |
} |
| 154 | 0 | return packagedJarFiles; |
| 155 | |
} |
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
public final List<String> additionalContainerClassPath(final String _cpPattern, |
| 174 | |
final List<String> _existingClasspath, final boolean _ignoreServiceTypeDeps) { |
| 175 | |
|
| 176 | 0 | List<String> result = new ArrayList<String>(); |
| 177 | 0 | if (_existingClasspath != null) { |
| 178 | 0 | result.addAll(_existingClasspath); |
| 179 | |
} |
| 180 | |
|
| 181 | 0 | for (String jarFile : getDependencyJars()) { |
| 182 | 0 | String jarURL = "sonicfs:///ESBResources/" + jarFile.replaceAll("\\\\", "/"); |
| 183 | 0 | if (!(_ignoreServiceTypeDeps && getServiceJarFiles().contains(jarURL)) && !result.contains(jarURL)) { |
| 184 | 0 | if (jarFile.matches(_cpPattern)) { |
| 185 | 0 | result.add(jarURL); |
| 186 | |
} |
| 187 | |
} |
| 188 | |
} |
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | 0 | if (!_ignoreServiceTypeDeps) { |
| 195 | 0 | for (String jarURL : getServiceCtJarFiles()) { |
| 196 | 0 | String jarFile = jarURL.substring(jarURL.lastIndexOf('/') + 1); |
| 197 | 0 | if (jarFile.matches(_cpPattern) && !result.contains(jarURL)) { |
| 198 | 0 | result.add(jarURL); |
| 199 | |
} |
| 200 | 0 | } |
| 201 | |
} |
| 202 | |
|
| 203 | 0 | return result; |
| 204 | |
} |
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
public final String getXarDependencyDir() { |
| 212 | |
|
| 213 | 0 | return baseDir + "/xar"; |
| 214 | |
} |
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
public final String getJarDependencyDir() { |
| 222 | |
|
| 223 | 0 | return baseDir + "/jar"; |
| 224 | |
} |
| 225 | |
} |