@Override public void writeArchive(ZipFile zipFile, IProgressMonitor progressMonitor) { Enumeration<? extends ZipEntry> jarEntriesEnum= zipFile.entries(); File zipFile1 = new File(zipFile.getName()); try { String zipFileCanonical = zipFile1.getCanonicalPath(); while (jarEntriesEnum.hasMoreElements()) { ZipEntry zipEntry= jarEntriesEnum.nextElement(); if (!zipEntry.isDirectory()) { String entryName= zipEntry.getName(); File zipEntryFile = new File(zipFile1, entryName); String zipEntryCanonical = zipEntryFile.getCanonicalPath(); if (zipEntryCanonical.startsWith(zipFileCanonical + File.separator)) { addFile(entryName, zipEntry, zipFile); } else { addWarning("Invalid path" + entryName, null); //$NON-NLS-1$ } } progressMonitor.worked(1); if (progressMonitor.isCanceled()) throw new OperationCanceledException(); } } catch (IOException e) { addWarning("ZipFile error" + zipFile.getName(), null); //$NON-NLS-1$ e.printStackTrace(); } }
private void addFile(String destinationPath, ZipEntry jarEntry, ZipFile zipFile) { // Handle META-INF/MANIFEST.MF if (destinationPath.equalsIgnoreCase("META-INF/MANIFEST.MF") //$NON-NLS-1$ || (isRemoveSigners() && destinationPath.startsWith("META-INF/") && destinationPath.endsWith(".SF"))) { //$NON-NLS-1$//$NON-NLS-2$ return; } try { getJarWriter().addZipEntry(jarEntry, zipFile, destinationPath); } catch (IOException ex) { if (ex instanceof ZipException && ex.getMessage() != null && ex.getMessage().startsWith("duplicate entry:")) {//$NON-NLS-1$ // ignore duplicates in META-INF (*.SF, *.RSA) if (!destinationPath.startsWith("META-INF/")) { //$NON-NLS-1$ addWarning(ex.getMessage(), ex); } } else addWarning(Messages.format(FatJarPackagerMessages.FatJarBuilder_error_readingArchiveFile, new Object[] { BasicElementLabels.getResourceName(zipFile.getName()), ex.getLocalizedMessage() }), ex); } } }
private void addFile(String destinationPath, ZipEntry jarEntry, ZipFile zipFile) { // Handle META-INF/MANIFEST.MF if (destinationPath.equalsIgnoreCase("META-INF/MANIFEST.MF") //$NON-NLS-1$ || (isRemoveSigners() && destinationPath.startsWith("META-INF/") && destinationPath.endsWith(".SF"))) { //$NON-NLS-1$//$NON-NLS-2$ return; } try { getJarWriter().addZipEntry(jarEntry, zipFile, destinationPath); } catch (IOException ex) { if (ex instanceof ZipException && ex.getMessage() != null && ex.getMessage().startsWith("duplicate entry:")) {//$NON-NLS-1$ // ignore duplicates in META-INF (*.SF, *.RSA) if (!destinationPath.startsWith("META-INF/")) { //$NON-NLS-1$ addWarning(ex.getMessage(), ex); } } else addWarning(Messages.format(FatJarPackagerMessages.FatJarBuilder_error_readingArchiveFile, new Object[] { BasicElementLabels.getResourceName(zipFile.getName()), ex.getLocalizedMessage() }), ex); } } }