/** * Creates and returns a JarWriter for this JAR package. * * @param parent the shell used to display question dialogs, * or <code>null</code> if "false/no/cancel" is the answer * and no dialog should be shown * @return a JarWriter2 * @see JarWriter2 * @throws CoreException if an unexpected exception happens * * @deprecated Use {@link #createJarWriter3(Shell)} instead */ public JarWriter2 createJarWriter(Shell parent) throws CoreException { return new JarWriter2(this, parent); }
/** * Closes the archive and does all required cleanup. * * @throws CoreException to signal any other unusual termination. * This can also be used to return information * in the status object. */ public void close() throws CoreException { if (fJarOutputStream != null) try { fJarOutputStream.close(); registerInWorkspaceIfNeeded(); } catch (IOException ex) { throw JarPackagerUtil.createCoreException(ex.getLocalizedMessage(), ex); } }
/** * Writes the passed resource to the current archive. * * @param resource the file to be written * @param destinationPath the path for the file inside the archive * @throws CoreException to signal any other unusual termination. * This can also be used to return information * in the status object. */ public void write(IFile resource, IPath destinationPath) throws CoreException { try { IPath fileLocation= resource.getLocation(); File file= null; if (fileLocation != null) { file= new File(fileLocation.toOSString()); } if (fJarPackage.areDirectoryEntriesIncluded()) addDirectories(destinationPath, file); addFile(resource, destinationPath, file); } catch (IOException ex) { // Ensure full path is visible String message= null; if (ex.getLocalizedMessage() != null) message= Messages.format(JarPackagerMessages.JarWriter_writeProblemWithMessage, new Object[] {resource.getFullPath(), ex.getLocalizedMessage()}); else message= Messages.format(JarPackagerMessages.JarWriter_writeProblem, resource.getFullPath()); throw JarPackagerUtil.createCoreException(message, ex); } }
fJarPackage= jarPackage; Assert.isTrue(fJarPackage.isValid(), "The JAR package specification is invalid"); //$NON-NLS-1$ if (!canCreateJar(parent)) throw new OperationCanceledException();
calculateCrcAndSize(newEntry, resource, readBuffer);
private void exportResource(IProgressMonitor progressMonitor, IResource resource, int leadingSegmentsToRemove) throws InterruptedException { if (resource instanceof IContainer) { IContainer container= (IContainer)resource; IResource[] children; try { children= container.members(); } catch (CoreException e) { // this should never happen because an #isAccessible check is done before #members is invoked addWarning(Messages.format(JarPackagerMessages.JarFileExportOperation_errorDuringExport, container.getFullPath()), e); return; } for (int i= 0; i < children.length; i++) exportResource(progressMonitor, children[i], leadingSegmentsToRemove); } else if (resource instanceof IFile) { try { IPath destinationPath= resource.getFullPath().removeFirstSegments(leadingSegmentsToRemove); progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, destinationPath.toString())); fJarWriter.write((IFile)resource, destinationPath); } catch (CoreException ex) { Throwable realEx= ex.getStatus().getException(); if (realEx instanceof ZipException && realEx.getMessage() != null && realEx.getMessage().startsWith("duplicate entry:")) //$NON-NLS-1$ addWarning(ex.getMessage(), realEx); else addToStatus(ex); } finally { progressMonitor.worked(1); ModalContext.checkCanceled(progressMonitor); } } }
try { if (fJarWriter != null) fJarWriter.close(); } catch (CoreException ex) { addToStatus(ex);
/** * Writes the passed resource to the current archive. * * @param resource the file to be written * @param destinationPath the path for the file inside the archive * @throws CoreException to signal any other unusual termination. * This can also be used to return information * in the status object. */ public void write(IFile resource, IPath destinationPath) throws CoreException { try { IPath fileLocation= resource.getLocation(); File file= null; if (fileLocation != null) { file= fileLocation.toFile(); } if (fJarPackage.areDirectoryEntriesIncluded()) addDirectories(destinationPath, file); addFile(resource, destinationPath, file); } catch (IOException ex) { // Ensure full path is visible String message= null; if (ex.getLocalizedMessage() != null) message= Messages.format(JarPackagerMessages.JarWriter_writeProblemWithMessage, new Object[] {BasicElementLabels.getPathLabel(resource.getFullPath(), false), ex.getLocalizedMessage()}); else message= Messages.format(JarPackagerMessages.JarWriter_writeProblem, BasicElementLabels.getPathLabel(resource.getFullPath(), false)); throw JarPackagerUtil.createCoreException(message, ex); } }
fJarPackage= jarPackage; Assert.isTrue(fJarPackage.isValid(), "The JAR package specification is invalid"); //$NON-NLS-1$ if (!canCreateJar(parent)) throw new OperationCanceledException();
calculateCrcAndSize(newEntry, resource, readBuffer);
private void exportClassFiles(IProgressMonitor progressMonitor, IPackageFragmentRoot pkgRoot, IResource resource, IJavaProject jProject, IPath destinationPath) { if (fJarPackage.areClassFilesExported() && isJavaFile(resource) && pkgRoot != null) { try { if (!jProject.isOnClasspath(resource)) return; // find corresponding file(s) on classpath and export Iterator iter= filesOnClasspath((IFile)resource, destinationPath, jProject, pkgRoot, progressMonitor); IPath baseDestinationPath= destinationPath.removeLastSegments(1); while (iter.hasNext()) { IFile file= (IFile)iter.next(); if (!resource.isLocal(IResource.DEPTH_ZERO)) file.setLocal(true , IResource.DEPTH_ZERO, progressMonitor); IPath classFilePath= baseDestinationPath.append(file.getName()); progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, classFilePath.toString())); fJarWriter.write(file, classFilePath); } } catch (CoreException ex) { addToStatus(ex); } } }
/** * Writes the passed resource to the current archive. * * @param resource the file to be written * @param destinationPath the path for the file inside the archive * @throws CoreException to signal any other unusual termination. * This can also be used to return information * in the status object. */ public void write(IFile resource, IPath destinationPath) throws CoreException { try { IPath fileLocation= resource.getLocation(); File file= null; if (fileLocation != null) { file= fileLocation.toFile(); } if (fJarPackage.areDirectoryEntriesIncluded()) addDirectories(destinationPath, file); addFile(resource, destinationPath, file); } catch (IOException ex) { // Ensure full path is visible String message= null; if (ex.getLocalizedMessage() != null) message= Messages.format(JarPackagerMessages.JarWriter_writeProblemWithMessage, new Object[] {BasicElementLabels.getPathLabel(resource.getFullPath(), false), ex.getLocalizedMessage()}); else message= Messages.format(JarPackagerMessages.JarWriter_writeProblem, BasicElementLabels.getPathLabel(resource.getFullPath(), false)); throw JarPackagerUtil.createCoreException(message, ex); } }
/** * Creates and returns a JarWriter for this JAR package. * * @param parent the shell used to display question dialogs, * or <code>null</code> if "false/no/cancel" is the answer * and no dialog should be shown * @return a JarWriter2 * @see JarWriter2 * @throws CoreException if an unexpected exception happens * * @deprecated Use {@link #createJarWriter3(Shell)} instead */ @Deprecated public JarWriter2 createJarWriter(Shell parent) throws CoreException { return new JarWriter2(this, parent); }
/** * Closes the archive and does all required cleanup. * * @throws CoreException to signal any other unusual termination. * This can also be used to return information * in the status object. */ public void close() throws CoreException { if (fJarOutputStream != null) try { fJarOutputStream.close(); registerInWorkspaceIfNeeded(); } catch (IOException ex) { throw JarPackagerUtil.createCoreException(ex.getLocalizedMessage(), ex); } }
fJarPackage= jarPackage; Assert.isTrue(fJarPackage.isValid(), "The JAR package specification is invalid"); //$NON-NLS-1$ if (!canCreateJar(parent)) throw new OperationCanceledException();
calculateCrcAndSize(newEntry, resource, readBuffer);
private void exportResource(IProgressMonitor progressMonitor, IPackageFragmentRoot pkgRoot, boolean isInJavaProject, IResource resource, IPath destinationPath, boolean isInOutputFolder) { // Handle case where META-INF/MANIFEST.MF is part of the exported files if (fJarPackage.areClassFilesExported() && destinationPath.toString().equals("META-INF/MANIFEST.MF")) {//$NON-NLS-1$ if (fJarPackage.isManifestGenerated()) addWarning(Messages.format(JarPackagerMessages.JarFileExportOperation_didNotAddManifestToJar, resource.getFullPath()), null); return; } boolean isNonJavaResource= !isInJavaProject || pkgRoot == null; boolean isInClassFolder= false; try { isInClassFolder= pkgRoot != null && !pkgRoot.isArchive() && pkgRoot.getKind() == IPackageFragmentRoot.K_BINARY; } catch (JavaModelException ex) { addWarning(Messages.format(JarPackagerMessages.JarFileExportOperation_cantGetRootKind, resource.getFullPath()), ex); } if ((fJarPackage.areClassFilesExported() && ((isNonJavaResource || (pkgRoot != null && !isJavaFile(resource) && !isClassFile(resource))) || isInClassFolder && isClassFile(resource))) || (fJarPackage.areJavaFilesExported() && (isNonJavaResource || (pkgRoot != null && !isClassFile(resource)) || (isInClassFolder && isClassFile(resource) && !fJarPackage.areClassFilesExported())))) { try { progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, destinationPath.toString())); fJarWriter.write((IFile) resource, destinationPath); } catch (CoreException ex) { Throwable realEx= ex.getStatus().getException(); if (realEx instanceof ZipException && realEx.getMessage() != null && realEx.getMessage().startsWith("duplicate entry:")) //$NON-NLS-1$ addWarning(ex.getMessage(), realEx); else addToStatus(ex); } } }
/** * Creates and returns a JarWriter for this JAR package. * * @param parent the shell used to display question dialogs, * or <code>null</code> if "false/no/cancel" is the answer * and no dialog should be shown * @return a JarWriter2 * @see JarWriter2 * @throws CoreException if an unexpected exception happens * * @deprecated Use {@link #createJarWriter3(Shell)} instead */ @Deprecated public JarWriter2 createJarWriter(Shell parent) throws CoreException { return new JarWriter2(this, parent); }
/** * Closes the archive and does all required cleanup. * * @throws CoreException to signal any other unusual termination. * This can also be used to return information * in the status object. */ public void close() throws CoreException { if (fJarOutputStream != null) try { fJarOutputStream.close(); registerInWorkspaceIfNeeded(); } catch (IOException ex) { throw JarPackagerUtil.createCoreException(ex.getLocalizedMessage(), ex); } }