1 | boolean rebuild = false;↵ | | 1 | boolean rebuild = false;↵
|
|
2 | JarFile genericJar = null;↵ | | 2 | JarFile genericJar = null;↵
|
3 | JarFile wlJar = null;↵ | | 3 | JarFile wasJar = null;↵
|
4 | File newWLJarFile = null;↵ | | 4 | File newwasJarFile = null;↵
|
5 | JarOutputStream newJarStream = null;↵ | | 5 | JarOutputStream newJarStream = null;↵
|
6 | ClassLoader genericLoader = null;↵ | | |
|
|
7 | try {↵ | | 6 | try {↵
|
8 | log("Checking if weblogic Jar needs to be rebuilt for jar " + weblogic↵ | | 7 | log("Checking if websphere Jar needs to be rebuilt for jar "↵
|
9 | JarFile.getName(),↵ | | 8 | + websphereJarFile.getName(),↵
|
10 | Project.MSG_VERBOSE);↵ | | 9 | Project.MSG_VERBOSE);↵
|
11 | // Only go forward if the generic and the weblogic file both exist↵ | | 10 | // Only go forward if the generic and the websphere file both exist↵
|
12 | if (genericJarFile.exists() && genericJarFile.isFile()↵ | | 11 | if (genericJarFile.exists() && genericJarFile.isFile()↵
|
13 | && weblogicJarFile.exists() && weblogicJarFile.isFile()) {↵ | | 12 | && websphereJarFile.exists() && websphereJarFile.isFile()) {↵
|
14 | //open jar files↵ | | 13 | //open jar files↵
|
15 | genericJar = new JarFile(genericJarFile);↵ | | 14 | genericJar = new JarFile(genericJarFile);↵
|
16 | wlJar = new JarFile(weblogicJarFile);↵ | | 15 | wasJar = new JarFile(websphereJarFile);↵
|
|
17 | Hashtable genericEntries = new Hashtable();↵ | | 16 | Hashtable genericEntries = new Hashtable();↵
|
18 | Hashtable wlEntries = new Hashtable();↵ | | 17 | Hashtable wasEntries = new Hashtable();↵
|
19 | Hashtable replaceEntries = new Hashtable();↵ | | 18 | Hashtable replaceEntries = new Hashtable();↵
|
|
20 | //get the list of generic jar entries↵ | | 19 | //get the list of generic jar entries↵
|
21 | for (Enumeration e = genericJar.entries(); e.hasMoreElements();) {↵ | | 20 | for (Enumeration e = genericJar.entries(); e.hasMoreElements();) {↵
|
22 | JarEntry je = (JarEntry) e.nextElement();↵ | | 21 | JarEntry je = (JarEntry) e.nextElement();↵
|
|
23 | genericEntries.put(je.getName().replace('\\', '/'), je);↵ | | 22 | genericEntries.put(je.getName().replace('\\', '/'), je);↵
|
24 | }↵ | | 23 | }↵
|
25 | //get the list of weblogic jar entries↵ | | 24 | //get the list of websphere jar entries↵
|
26 | for (Enumeration e = wlJar.entries(); e.hasMoreElements();) {↵ | | 25 | for (Enumeration e = wasJar.entries(); e.hasMoreElements();) {↵
|
27 | JarEntry je = (JarEntry) e.nextElement();↵ | | 26 | JarEntry je = (JarEntry) e.nextElement();↵
|
|
28 | wlEntries.put(je.getName(), je);↵ | | 27 | wasEntries.put(je.getName(), je);↵
|
29 | }↵ | | 28 | }↵
|
|
30 | //Cycle Through generic and make sure its in weblogic↵ | | 29 | //Cycle Through generic and make sure its in websphere↵
|
31 | genericLoader = getClassLoaderFromJar(genericJarFile);↵ | | 30 | ClassLoader genericLoader = getClassLoaderFromJar(genericJarFile);↵
|
|
32 | for (Enumeration e = genericEntries.keys(); e.hasMoreElements();) {↵ | | 31 | for (Enumeration e = genericEntries.keys(); e.hasMoreElements();) {↵
|
33 | String filepath = (String) e.nextElement();↵ | | 32 | String filepath = (String) e.nextElement();↵
|
|
34 | if (wlEntries.containsKey(filepath)) {↵ | | 33 | if (wasEntries.containsKey(filepath)) {↵
|
35 | // File name/path match↵ | | 34 | // File name/path match↵
|
|
36 | // Check files see if same↵ | | 35 | // Check files see if same↵
|
37 | JarEntry genericEntry = (JarEntry) genericEntries.get(filepath);↵ | | 36 | JarEntry genericEntry = (JarEntry) genericEntries.get(filepath);↵
|
38 | JarEntry wlEntry = (JarEntry) wlEntries.get(filepath);↵ | | 37 | JarEntry wasEntry = (JarEntry) wasEntries.get(filepath);↵
|
|
39 | if ((genericEntry.getCrc() != wlEntry.getCrc())↵ | | 38 | if ((genericEntry.getCrc() != wasEntry.getCrc())↵
|
40 | || (genericEntry.getSize() != wlEntry.getSize())) {↵ | | 39 | || (genericEntry.getSize() != wasEntry.getSize())) {↵
|
|
41 | if (genericEntry.getName().endsWith(".class")) {↵ | | 40 | if (genericEntry.getName().endsWith(".class")) {↵
|
42 | //File are different see if its an object or an interface↵ | | 41 | //File are different see if its an object or an interface↵
|
43 | String classname↵ | | 42 | String classname↵
|
44 | = genericEntry.getName().replace(File.separatorChar, '.');↵ | | 43 | = genericEntry.getName().replace(File.separatorChar, '.');↵
|
|
45 | classname = classname.substring(0, classname.lastIndexOf(".class"));↵ | | 44 | classname = classname.substring(0, classname.lastIndexOf(".class"));↵
|
|
46 | Class genclass = genericLoader.loadClass(classname);↵ | | 45 | Class genclass = genericLoader.loadClass(classname);↵
|
|
47 | if (genclass.isInterface()) {↵ | | 46 | if (genclass.isInterface()) {↵
|
48 | //Interface changed rebuild jar.↵ | | 47 | //Interface changed rebuild jar.↵
|
49 | log("Interface " + genclass.getName()↵ | | 48 | log("Interface " + genclass.getName()↵
|
50 | + " has changed", Project.MSG_VERBOSE);↵ | | 49 | + " has changed", Project.MSG_VERBOSE);↵
|
51 | rebuild = true;↵ | | 50 | rebuild = true;↵
|
52 | break;↵ | | 51 | break;↵
|
53 | } else {↵ | | 52 | } else {↵
|
54 | //Object class Changed update it.↵ | | 53 | //Object class Changed update it.↵
|
55 | replaceEntries.put(filepath, genericEntry);↵ | | 54 | replaceEntries.put(filepath, genericEntry);↵
|
56 | }↵ | | 55 | }↵
|
57 | } else {↵ | | 56 | } else {↵
|
58 | // is it the manifest. If so ignore it↵ | | 57 | // is it the manifest. If so ignore it↵
|
59 | if (!genericEntry.getName().equals("META-INF/MANIFEST.MF")) {↵ | | 58 | if (!genericEntry.getName().equals("META-INF/MANIFEST.MF")) {↵
|
60 | //File other then class changed rebuild↵ | | 59 | //File other then class changed rebuild↵
|
61 | log("Non class file " + genericEntry.getName()↵ | | 60 | log("Non class file " + genericEntry.getName()↵
|
62 | + " has changed", Project.MSG_VERBOSE);↵ | | 61 | + " has changed", Project.MSG_VERBOSE);↵
|
63 | rebuild = true;↵ | | 62 | rebuild = true;↵
|
64 | break;↵ | | 63 | }↵
|
65 | }↵ | | 64 | break;↵
|
66 | }↵ | | 65 | }↵
|
67 | }↵ | | 66 | }↵
|
68 | } else {↵ | | 67 | } else {↵
|
69 | // a file doesnt exist rebuild↵ | | 68 | // a file doesn't exist rebuild↵
|
|
70 | log("File " + filepath + " not present in weblogic jar",↵ | | 69 | log("File " + filepath + " not present in websphere jar",↵
|
71 | Project.MSG_VERBOSE);↵ | | 70 | Project.MSG_VERBOSE);↵
|
72 | rebuild = true;↵ | | 71 | rebuild = true;↵
|
73 | break;↵ | | 72 | break;↵
|
74 | }↵ | | 73 | }↵
|
75 | }↵ | | 74 | }↵
|
|
76 | if (!rebuild) {↵ | | 75 | if (!rebuild) {↵
|
77 | log("No rebuild needed - updating jar", Project.MSG_VERBOSE);↵ | | 76 | log("No rebuild needed - updating jar", Project.MSG_VERBOSE);↵
|
78 | newWLJarFile = new File(weblogicJarFile.getAbsolutePath() + ".temp");↵ | | 77 | newwasJarFile = new File(websphereJarFile.getAbsolutePath() + ".temp");↵
|
79 | if (newWLJarFile.exists()) {↵ | | 78 | if (newwasJarFile.exists()) {↵
|
80 | newWLJarFile.delete();↵ | | 79 | newwasJarFile.delete();↵
|
81 | }↵ | | 80 | }↵
|
|
82 | newJarStream = new JarOutputStream(new FileOutputStream(newWLJarFile));↵ | | 81 | newJarStream = new JarOutputStream(new FileOutputStream(newwasJarFile));↵
|
83 | newJarStream.setLevel(0);↵ | | 82 | newJarStream.setLevel(0);↵
|
|
84 | //Copy files from old weblogic jar↵ | | 83 | //Copy files from old websphere jar↵
|
85 | for (Enumeration e = wlEntries.elements(); e.hasMoreElements();) {↵ | | 84 | for (Enumeration e = wasEntries.elements(); e.hasMoreElements();) {↵
|
86 | byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];↵ | | 85 | byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];↵
|
87 | int bytesRead;↵ | | 86 | int bytesRead;↵
|
88 | InputStream is;↵ | | 87 | InputStream is;↵
|
89 | JarEntry je = (JarEntry) e.nextElement();↵ | | 88 | JarEntry je = (JarEntry) e.nextElement();↵
|
|
90 | if (je.getCompressedSize() == -1↵ | | 89 | if (je.getCompressedSize() == -1↵
|
91 | || je.getCompressedSize() == je.getSize()) {↵ | | 90 | || je.getCompressedSize() == je.getSize()) {↵
|
92 | newJarStream.setLevel(0);↵ | | 91 | newJarStream.setLevel(0);↵
|
93 | } else {↵ | | 92 | } else {↵
|
94 | newJarStream.setLevel(JAR_COMPRESS_LEVEL);↵ | | 93 | newJarStream.setLevel(JAR_COMPRESS_LEVEL);↵
|
95 | }↵ | | 94 | }↵
|
|
96 | // Update with changed Bean class↵ | | 95 | // Update with changed Bean class↵
|
97 | if (replaceEntries.containsKey(je.getName())) {↵ | | 96 | if (replaceEntries.containsKey(je.getName())) {↵
|
98 | log("Updating Bean class from generic Jar "↵ | | 97 | log("Updating Bean class from generic Jar " + je.getName(),↵
|
99 | + je.getName(), Project.MSG_VERBOSE);↵ | | 98 | Project.MSG_VERBOSE);↵
|
100 | // Use the entry from the generic jar↵ | | 99 | // Use the entry from the generic jar↵
|
101 | je = (JarEntry) replaceEntries.get(je.getName());↵ | | 100 | je = (JarEntry) replaceEntries.get(je.getName());↵
|
102 | is = genericJar.getInputStream(je);↵ | | 101 | is = genericJar.getInputStream(je);↵
|
103 | } else {↵ | | 102 | } else {↵
|
104 | //use fle from original weblogic jar↵ | | 103 | //use fle from original websphere jar↵
|
|
105 | is = wlJar.getInputStream(je);↵ | | 104 | is = wasJar.getInputStream(je);↵
|
106 | }↵ | | 105 | }↵
|
107 | newJarStream.putNextEntry(new JarEntry(je.getName()));↵ | | 106 | newJarStream.putNextEntry(new JarEntry(je.getName()));↵
|
|
108 | while ((bytesRead = is.read(buffer)) != -1) {↵ | | 107 | while ((bytesRead = is.read(buffer)) != -1) {↵
|
109 | newJarStream.write(buffer, 0, bytesRead);↵ | | 108 | newJarStream.write(buffer, 0, bytesRead);↵
|
110 | }↵ | | 109 | }↵
|
111 | is.close();↵ | | 110 | is.close();↵
|
112 | }↵ | | 111 | }↵
|
113 | } else {↵ | | 112 | } else {↵
|
114 | log("Weblogic Jar rebuild needed due to changed "↵ | | 113 | log("websphere Jar rebuild needed due to changed "↵
|
115 | + "interface or XML", Project.MSG_VERBOSE);↵ | | 114 | + "interface or XML", Project.MSG_VERBOSE);↵
|
116 | }↵ | | 115 | }↵
|
117 | } else {↵ | | 116 | } else {↵
|
118 | rebuild = true;↵ | | 117 | rebuild = true;↵
|
119 | }↵ | | 118 | }↵
|
120 | } catch (ClassNotFoundException cnfe) {↵ | | 119 | } catch (ClassNotFoundException cnfe) {↵
|
121 | String cnfmsg = "ClassNotFoundException while processing ejb-jar file"↵ | | 120 | String cnfmsg = "ClassNotFoundException while processing ejb-jar file"↵
|
122 | + ". Details: "↵ | | 121 | + ". Details: "↵
|
123 | + cnfe.getMessage();↵ | | 122 | + cnfe.getMessage();↵
|
|
124 | throw new BuildException(cnfmsg, cnfe);↵ | | 123 | throw new BuildException(cnfmsg, cnfe);↵
|
125 | } catch (IOException ioe) {↵ | | 124 | } catch (IOException ioe) {↵
|
126 | String msg = "IOException while processing ejb-jar file "↵ | | 125 | String msg = "IOException while processing ejb-jar file "↵
|
127 | + ". Details: "↵ | | 126 | + ". Details: "↵
|
128 | + ioe.getMessage();↵ | | 127 | + ioe.getMessage();↵
|
|
129 | throw new BuildException(msg, ioe);↵ | | 128 | throw new BuildException(msg, ioe);↵
|
130 | } finally {↵ | | 129 | } finally {↵
|
131 | // need to close files and perhaps rename output↵ | | 130 | // need to close files and perhaps rename output↵
|
132 | if (genericJar != null) {↵ | | 131 | if (genericJar != null) {↵
|
133 | try {↵ | | 132 | try {↵
|
134 | genericJar.close();↵ | | 133 | genericJar.close();↵
|
135 | } catch (IOException closeException) {↵ | | 134 | } catch (IOException closeException) {↵
|
136 | // empty↵ | | 135 | // Ignore↵
|
137 | }↵ | | 136 | }↵
|
138 | }↵ | | 137 | }↵
|
|
139 | if (wlJar != null) {↵ | | 138 | if (wasJar != null) {↵
|
140 | try {↵ | | 139 | try {↵
|
141 | wlJar.close();↵ | | 140 | wasJar.close();↵
|
142 | } catch (IOException closeException) {↵ | | 141 | } catch (IOException closeException) {↵
|
143 | // empty↵ | | 142 | // Ignore↵
|
144 | }↵ | | 143 | }↵
|
145 | }↵ | | 144 | }↵
|
|
146 | if (newJarStream != null) {↵ | | 145 | if (newJarStream != null) {↵
|
147 | try {↵ | | 146 | try {↵
|
148 | newJarStream.close();↵ | | 147 | newJarStream.close();↵
|
149 | } catch (IOException closeException) {↵ | | 148 | } catch (IOException closeException) {↵
|
150 | // empty↵ | | 149 | // Ignore↵
|
151 | }↵ | | 150 | }↵
|
|
152 | try {↵ | | 151 | try {↵
|
153 | FILE_UTILS.rename(newWLJarFile, weblogicJarFile);↵ | | 152 | FILE_UTILS.rename(newwasJarFile, websphereJarFile);↵
|
154 | } catch (IOException renameException) {↵ | | 153 | } catch (IOException renameException) {↵
|
155 | log(renameException.getMessage(), Project.MSG_WARN);↵ | | 154 | log(renameException.getMessage(), Project.MSG_WARN);↵
|
156 | rebuild = true;↵ | | 155 | rebuild = true;↵
|
157 | }↵ | | 156 | }↵
|
158 | }↵ | | 157 | }↵
|
159 | if (genericLoader != null↵ | | |
|
160 | && genericLoader instanceof AntClassLoader) {↵ | | |
|
161 | AntClassLoader loader = (AntClassLoader) genericLoader;↵ | | |
|
162 | loader.cleanup();↵ | | |
|
163 | }↵ | | |
|
164 | }↵ | | 158 | }↵
|
|
165 | return rebuild; | | 159 | return rebuild;
|