Revision 041aac8a
Added by Andreas Kohlbecker about 8 years ago
src/main/java/eu/etaxonomy/cdm/server/Bootloader.java | ||
---|---|---|
47 | 47 |
import org.apache.commons.cli.HelpFormatter; |
48 | 48 |
import org.apache.commons.cli.ParseException; |
49 | 49 |
import org.apache.commons.io.FileUtils; |
50 |
import org.apache.commons.io.FilenameUtils; |
|
50 | 51 |
import org.apache.log4j.Logger; |
51 | 52 |
import org.apache.log4j.PatternLayout; |
52 | 53 |
import org.apache.log4j.RollingFileAppender; |
... | ... | |
229 | 230 |
logger.info("Success! Using war file from " + resource.toString()); |
230 | 231 |
} else { |
231 | 232 |
logger.error("Also could not find the " + warFileName + " in maven project, try excuting 'mvn install'"); |
232 |
System.exit(-1); |
|
233 | 233 |
} |
234 | 234 |
} |
235 | 235 |
} |
236 | 236 |
|
237 |
|
|
237 | 238 |
if (resource == null) { |
238 | 239 |
// no way finding the war file :-( |
239 | 240 |
System.exit(1); |
240 | 241 |
} |
241 | 242 |
|
242 | 243 |
|
243 |
File warFile = new File(TMP_PATH, warName + "-" + WAR_POSTFIX); |
|
244 |
logger.info("Extracting " + warFileName + " to " + warFile + " ..."); |
|
245 |
|
|
246 |
writeStreamTo(resource.openStream(), new FileOutputStream(warFile), 8 * KB); |
|
244 |
File extractedWarFile = new File(TMP_PATH, warName + "-" + WAR_POSTFIX); |
|
245 |
logger.info("Extracting " + resource + " to " + extractedWarFile + " ..."); |
|
247 | 246 |
|
248 |
logger.info("Extracted " + warFileName);
|
|
247 |
writeStreamTo(resource.openStream(), new FileOutputStream(extractedWarFile), 8 * KB);
|
|
249 | 248 |
|
250 |
if(unpack) { |
|
249 |
if(!unpack) { |
|
250 |
// return the war file |
|
251 |
return extractedWarFile; |
|
252 |
} else { |
|
253 |
// unpack the archive |
|
254 |
File explodedWebApp = null; |
|
251 | 255 |
try { |
252 |
logger.info("Unpacking " + warFileName);
|
|
253 |
warFile = unzip(warFile, warName);
|
|
256 |
logger.info("Unpacking " + extractedWarFile);
|
|
257 |
explodedWebApp = unzip(extractedWarFile);
|
|
254 | 258 |
|
255 | 259 |
// get the 'Bundle-Version' and 'Bnd-LastModified' properties of the |
256 | 260 |
// manifest file in the cdmlib services jar |
257 |
if(warFile != null && warFile.isDirectory()) {
|
|
261 |
if(explodedWebApp != null && explodedWebApp.isDirectory()) {
|
|
258 | 262 |
// generate the webapp lib dir path |
259 |
String warLibDirAbsolutePath = warFile.getAbsolutePath() +
|
|
263 |
String warLibDirAbsolutePath = explodedWebApp.getAbsolutePath() +
|
|
260 | 264 |
File.separator + |
261 | 265 |
"WEB-INF" + |
262 | 266 |
File.separator + |
... | ... | |
293 | 297 |
} |
294 | 298 |
} |
295 | 299 |
} catch (IOException e) { |
296 |
logger.error("extractWar() - Unziping of war file " + warFile + " failed. Will return the war file itself instead of the extracted folder.", e);
|
|
300 |
logger.error("extractWar() - Unziping of war file " + explodedWebApp + " failed. Will return the war file itself instead of the extracted folder.", e);
|
|
297 | 301 |
} |
302 |
return explodedWebApp; |
|
298 | 303 |
} |
299 |
|
|
300 |
return warFile; |
|
301 | 304 |
} |
302 | 305 |
|
303 | 306 |
|
... | ... | |
313 | 316 |
* @return |
314 | 317 |
* @throws IOException |
315 | 318 |
*/ |
316 |
private File unzip(File extractWar, String warName) throws IOException {
|
|
319 |
private File unzip(File extractWar) throws IOException { |
|
317 | 320 |
UnzipUtility unzip = new UnzipUtility(); |
318 | 321 |
|
319 |
File destDirectory = new File(TMP_PATH + File.separator + warName); |
|
322 |
String targetFolderName = FilenameUtils.getBaseName(extractWar.getName()); |
|
323 |
File destDirectory = new File(TMP_PATH + File.separator + targetFolderName); |
|
320 | 324 |
unzip.unzip(extractWar, destDirectory); |
321 | 325 |
return destDirectory; |
322 | 326 |
} |
Also available in: Unified diff
uncluttering war extration code