### Eclipse Workspace Patch 1.0 #P org.eclipse.jst.j2ee Index: archiveops/org/eclipse/jst/j2ee/internal/archive/operations/AppClientComponentExportOperation.java =================================================================== RCS file: /cvsroot/webtools/jeetools/plugins/org.eclipse.jst.j2ee/archiveops/org/eclipse/jst/j2ee/internal/archive/operations/AppClientComponentExportOperation.java,v retrieving revision 1.7 diff -u -r1.7 AppClientComponentExportOperation.java --- archiveops/org/eclipse/jst/j2ee/internal/archive/operations/AppClientComponentExportOperation.java 7 Jun 2007 19:28:15 -0000 1.7 +++ archiveops/org/eclipse/jst/j2ee/internal/archive/operations/AppClientComponentExportOperation.java 23 Feb 2009 08:51:31 -0000 @@ -10,56 +10,47 @@ *******************************************************************************/ package org.eclipse.jst.j2ee.internal.archive.operations; -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.jst.j2ee.commonarchivecore.internal.CommonarchiveFactory; -import org.eclipse.jst.j2ee.commonarchivecore.internal.CommonarchivePackage; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.SaveFailureException; -import org.eclipse.jst.j2ee.internal.J2EEConstants; -import org.eclipse.jst.j2ee.internal.archive.JavaEEArchiveUtilities; -import org.eclipse.jst.jee.archive.IArchive; -import org.eclipse.jst.jee.util.internal.JavaEEQuickPeek; import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -public class AppClientComponentExportOperation extends J2EEArtifactExportOperation { +public class AppClientComponentExportOperation extends J2EEModuleExportOperation { public AppClientComponentExportOperation(IDataModel model) { super(model); } - public void export() throws SaveFailureException, CoreException, InvocationTargetException, InterruptedException { - IProgressMonitor subMonitor = new SubProgressMonitor(progressMonitor, EXPORT_WORK); - IArchive archiveFromComponent = null; - try { - archiveFromComponent = JavaEEArchiveUtilities.INSTANCE.openArchive(getComponent()); - JavaEEQuickPeek quickPeek = JavaEEArchiveUtilities.INSTANCE.getJavaEEQuickPeek(archiveFromComponent); - if (quickPeek.getJavaEEVersion() == J2EEConstants.JEE_5_0_ID) { - saveArchive(archiveFromComponent, getDestinationPath().toOSString(), subMonitor); - } else { - CommonarchiveFactory caf = ((CommonarchivePackage) EPackage.Registry.INSTANCE.getEPackage(CommonarchivePackage.eNS_URI)).getCommonarchiveFactory(); - AppClientComponentLoadStrategyImpl ls = new AppClientComponentLoadStrategyImpl(getComponent()); - ls.setExportSource(isExportSource()); - setModuleFile(caf.openApplicationClientFile(ls, getDestinationPath().toOSString())); - ls.setProgressMonitor(subMonitor); - getModuleFile().saveAsNoReopen(getDestinationPath().toOSString()); - } - } catch (SaveFailureException ex) { - throw ex; - } catch (Exception e) { - throw new SaveFailureException(AppClientArchiveOpsResourceHandler.ARCHIVE_OPERATION_OpeningArchive, e); - } finally { - if (archiveFromComponent != null) - JavaEEArchiveUtilities.INSTANCE.closeArchive(archiveFromComponent); - subMonitor.done(); - } - } +// public void export() throws SaveFailureException, CoreException, InvocationTargetException, InterruptedException { +// IProgressMonitor subMonitor = new SubProgressMonitor(progressMonitor, EXPORT_WORK); +// IArchive archiveFromComponent = null; +// try { +// archiveFromComponent = JavaEEArchiveUtilities.INSTANCE.openArchive(getComponent()); +// JavaEEQuickPeek quickPeek = JavaEEArchiveUtilities.INSTANCE.getJavaEEQuickPeek(archiveFromComponent); +// if (quickPeek.getJavaEEVersion() == J2EEConstants.JEE_5_0_ID) { +// saveArchive(archiveFromComponent, getDestinationPath().toOSString(), subMonitor); +// } else { +// CommonarchiveFactory caf = ((CommonarchivePackage) EPackage.Registry.INSTANCE.getEPackage(CommonarchivePackage.eNS_URI)).getCommonarchiveFactory(); +// AppClientComponentLoadStrategyImpl ls = new AppClientComponentLoadStrategyImpl(getComponent()); +// ls.setExportSource(isExportSource()); +// setModuleFile(caf.openApplicationClientFile(ls, getDestinationPath().toOSString())); +// ls.setProgressMonitor(subMonitor); +// getModuleFile().saveAsNoReopen(getDestinationPath().toOSString()); +// } +// } catch (SaveFailureException ex) { +// throw ex; +// } catch (Exception e) { +// throw new SaveFailureException(AppClientArchiveOpsResourceHandler.ARCHIVE_OPERATION_OpeningArchive, e); +// } finally { +// if (archiveFromComponent != null) +// JavaEEArchiveUtilities.INSTANCE.closeArchive(archiveFromComponent); +// subMonitor.done(); +// } +// } protected String archiveString() { return AppClientArchiveOpsResourceHandler.Application_Client_File_UI_; } + protected String getModuleTypeID() { + return "jst.appclient"; + } + } Index: archiveops/org/eclipse/jst/j2ee/internal/archive/operations/EARComponentExportOperation.java =================================================================== RCS file: /cvsroot/webtools/jeetools/plugins/org.eclipse.jst.j2ee/archiveops/org/eclipse/jst/j2ee/internal/archive/operations/EARComponentExportOperation.java,v retrieving revision 1.11 diff -u -r1.11 EARComponentExportOperation.java --- archiveops/org/eclipse/jst/j2ee/internal/archive/operations/EARComponentExportOperation.java 4 Sep 2008 05:51:09 -0000 1.11 +++ archiveops/org/eclipse/jst/j2ee/internal/archive/operations/EARComponentExportOperation.java 23 Feb 2009 08:51:31 -0000 @@ -10,67 +10,57 @@ *******************************************************************************/ package org.eclipse.jst.j2ee.internal.archive.operations; -import java.lang.reflect.InvocationTargetException; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jst.j2ee.commonarchivecore.internal.EARFile; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.SaveFailureException; -import org.eclipse.jst.j2ee.componentcore.EnterpriseArtifactEdit; -import org.eclipse.jst.j2ee.internal.J2EEVersionConstants; -import org.eclipse.jst.j2ee.internal.archive.JavaEEArchiveUtilities; -import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; -import org.eclipse.jst.jee.archive.IArchive; -import org.eclipse.wst.common.componentcore.internal.util.ComponentUtilities; import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; import org.eclipse.wst.common.componentcore.resources.IVirtualReference; import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -public class EARComponentExportOperation extends J2EEArtifactExportOperation { +public class EARComponentExportOperation extends J2EEModuleExportOperation { public EARComponentExportOperation(IDataModel model) { super(model); } - protected void export() throws SaveFailureException, CoreException, InvocationTargetException, InterruptedException { - IProgressMonitor subMonitor = new SubProgressMonitor(progressMonitor, EXPORT_WORK); - IArchive archiveFromComponent = null; - try { - //[Bug 244049] need to use ProjectFacet version to determine how to export the EAR - String versionStr = J2EEProjectUtilities.getJ2EEProjectVersion(getComponent().getProject()); - if (versionStr.equals(J2EEVersionConstants.VERSION_5_0_TEXT)) { - archiveFromComponent = JavaEEArchiveUtilities.INSTANCE.openArchive(getComponent()); - saveArchive(archiveFromComponent, getDestinationPath().toOSString(), subMonitor); - } else { - EnterpriseArtifactEdit artifactEdit = null; - try { - artifactEdit = (EnterpriseArtifactEdit) ComponentUtilities.getArtifactEditForRead(getComponent()); - EARFile archive = (EARFile) artifactEdit.asArchive(isExportSource()); - String destination = getDestinationPath().toOSString(); - archive.setURI(destination); - setModuleFile(archive); - ComponentLoadStrategyImpl ls = (ComponentLoadStrategyImpl) archive.getLoadStrategy(); - ls.setProgressMonitor(subMonitor); - archive.saveAsNoReopen(destination); - } catch (SaveFailureException ex) { - throw ex; - } catch (Exception e) { - throw new SaveFailureException(AppClientArchiveOpsResourceHandler.ARCHIVE_OPERATION_OpeningArchive, e); - } finally { - if (null != artifactEdit) { - artifactEdit.dispose(); - } - } - } - } catch (Exception e) { - throw new SaveFailureException(AppClientArchiveOpsResourceHandler.ARCHIVE_OPERATION_OpeningArchive, e); - } finally { - if (archiveFromComponent != null) - JavaEEArchiveUtilities.INSTANCE.closeArchive(archiveFromComponent); - subMonitor.done(); - } - } +// protected void export() throws SaveFailureException, CoreException, InvocationTargetException, InterruptedException { +// IProgressMonitor subMonitor = new SubProgressMonitor(progressMonitor, EXPORT_WORK); +// IArchive archiveFromComponent = null; +// try { +// //[Bug 244049] need to use ProjectFacet version to determine how to export the EAR +// String versionStr = J2EEProjectUtilities.getJ2EEProjectVersion(getComponent().getProject()); +// if (versionStr.equals(J2EEVersionConstants.VERSION_5_0_TEXT)) { +// archiveFromComponent = JavaEEArchiveUtilities.INSTANCE.openArchive(getComponent()); +// saveArchive(archiveFromComponent, getDestinationPath().toOSString(), subMonitor); +// } else { +// EnterpriseArtifactEdit artifactEdit = null; +// try { +// artifactEdit = (EnterpriseArtifactEdit) ComponentUtilities.getArtifactEditForRead(getComponent()); +// EARFile archive = (EARFile) artifactEdit.asArchive(isExportSource()); +// String destination = getDestinationPath().toOSString(); +// archive.setURI(destination); +// setModuleFile(archive); +// ComponentLoadStrategyImpl ls = (ComponentLoadStrategyImpl) archive.getLoadStrategy(); +// ls.setProgressMonitor(subMonitor); +// archive.saveAsNoReopen(destination); +// } catch (SaveFailureException ex) { +// throw ex; +// } catch (Exception e) { +// throw new SaveFailureException(AppClientArchiveOpsResourceHandler.ARCHIVE_OPERATION_OpeningArchive, e); +// } finally { +// if (null != artifactEdit) { +// artifactEdit.dispose(); +// } +// } +// } +// } catch (Exception e) { +// throw new SaveFailureException(AppClientArchiveOpsResourceHandler.ARCHIVE_OPERATION_OpeningArchive, e); +// } finally { +// if (archiveFromComponent != null) +// JavaEEArchiveUtilities.INSTANCE.closeArchive(archiveFromComponent); +// subMonitor.done(); +// } +// } protected void runNecessaryBuilders(IVirtualComponent component, IProgressMonitor monitor) throws CoreException { try { @@ -90,4 +80,8 @@ return "EAR"; } + protected String getModuleTypeID() { + return "jst.ear"; + } + } Index: archiveops/org/eclipse/jst/j2ee/internal/archive/operations/J2EEModuleExportOperation.java =================================================================== RCS file: archiveops/org/eclipse/jst/j2ee/internal/archive/operations/J2EEModuleExportOperation.java diff -N archiveops/org/eclipse/jst/j2ee/internal/archive/operations/J2EEModuleExportOperation.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ archiveops/org/eclipse/jst/j2ee/internal/archive/operations/J2EEModuleExportOperation.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,420 @@ +/******************************************************************************* + * Copyright (c) 2003, 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jst.j2ee.internal.archive.operations; + +import static org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties.ARCHIVE_DESTINATION; +import static org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties.COMPONENT; +import static org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties.EXPORT_SOURCE_FILES; +import static org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties.OPTIMIZE_FOR_SPECIFIC_RUNTIME; +import static org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties.RUNTIME_SPECIFIC_PARTICIPANTS; +import static org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties.RUN_BUILD; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.lang.reflect.InvocationTargetException; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.ICommand; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceRuleFactory; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.core.runtime.jobs.MultiRule; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.SaveFailureException; +import org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties.IArchiveExportParticipantData; +import org.eclipse.jst.j2ee.internal.plugin.LibCopyBuilder; +import org.eclipse.jst.j2ee.internal.project.ProjectSupportResourceHandler; +import org.eclipse.jst.jee.archive.ArchiveSaveFailureException; +import org.eclipse.jst.jee.archive.internal.ArchiveUtil; +import org.eclipse.jst.server.core.IEnterpriseApplication; +import org.eclipse.jst.server.core.IJ2EEModule; +import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; +import org.eclipse.wst.common.componentcore.resources.IVirtualReference; +import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation; +import org.eclipse.wst.common.frameworks.datamodel.IDataModel; +import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; +import org.eclipse.wst.server.core.IModule; +import org.eclipse.wst.server.core.ServerUtil; +import org.eclipse.wst.server.core.model.IModuleFile; +import org.eclipse.wst.server.core.model.IModuleFolder; +import org.eclipse.wst.server.core.model.IModuleResource; +import org.eclipse.wst.server.core.model.ModuleDelegate; + +public abstract class J2EEModuleExportOperation extends AbstractDataModelOperation { + + protected IProgressMonitor progressMonitor; + private IVirtualComponent component; + private IModule module; + private IPath destinationPath; + private boolean exportSource = false; + + public J2EEModuleExportOperation() { + super(); + } + + public J2EEModuleExportOperation(IDataModel model) { + super(model); + } + + protected final int REFRESH_WORK = 100; + protected final int JAVA_BUILDER_WORK = 100; + protected final int LIB_BUILDER_WORK = 100; + protected final int EXPORT_WORK = 1000; + protected final int CLOSE_WORK = 10; + protected final int SINGLE_PARTICIPANT_WORK = 200; + + protected int computeTotalWork() { + int totalWork = REFRESH_WORK; + if (model.getBooleanProperty(RUN_BUILD)) { + totalWork += JAVA_BUILDER_WORK + LIB_BUILDER_WORK; + } + totalWork += EXPORT_WORK + CLOSE_WORK; + + final IDataModel dm = getDataModel(); + + if( dm.getProperty( OPTIMIZE_FOR_SPECIFIC_RUNTIME ) == Boolean.TRUE ) + { + final List extensions + = (List) dm.getProperty( RUNTIME_SPECIFIC_PARTICIPANTS ); + + totalWork += extensions.size() * SINGLE_PARTICIPANT_WORK; + } + + return totalWork; + } + + public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { + setComponent((IVirtualComponent) model.getProperty(COMPONENT)); + setDestinationPath(new Path(model.getStringProperty(ARCHIVE_DESTINATION))); + setExportSource(model.getBooleanProperty(EXPORT_SOURCE_FILES)); + + try + { + monitor.beginTask(ProjectSupportResourceHandler.getString(ProjectSupportResourceHandler.Exporting_archive, new Object [] { getDestinationPath().lastSegment() }), computeTotalWork()); + setProgressMonitor(monitor); + + try { + // defect 240999 + component.getProject().refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, REFRESH_WORK)); + if (model.getBooleanProperty(RUN_BUILD)) { + runNecessaryBuilders(component, new SubProgressMonitor(monitor, JAVA_BUILDER_WORK + LIB_BUILDER_WORK)); + } + export(); + } catch (Exception e) { + monitor.worked(CLOSE_WORK); + throw new ExecutionException(EJBArchiveOpsResourceHandler.Error_exporting__UI_ + archiveString(), e); + } + + final IDataModel dm = getDataModel(); + + if( dm.getProperty( OPTIMIZE_FOR_SPECIFIC_RUNTIME ) == Boolean.TRUE ) + { + for( IArchiveExportParticipantData extData + : (List) dm.getProperty( RUNTIME_SPECIFIC_PARTICIPANTS ) ) + { + final IDataModelOperation op + = extData.getParticipant().createOperation( extData.getDataModel() ); + + op.execute( null, null ); + monitor.worked( SINGLE_PARTICIPANT_WORK ); + } + } + } + finally + { + monitor.done(); + } + + return OK_STATUS; + } + + protected abstract String archiveString(); + + protected void setProgressMonitor(IProgressMonitor newProgressMonitor) { + progressMonitor = newProgressMonitor; + } + + protected IProgressMonitor getProgressMonitor() { + return progressMonitor; + } + + private void setComponent(IVirtualComponent newComponent) { + component = newComponent; + setModule(); + } + + protected IVirtualComponent getComponent() { + if (component == null) + component = (IVirtualComponent) model.getProperty(COMPONENT); + return component; + } + + protected IPath getDestinationPath() { + return destinationPath; + } + + protected void setDestinationPath(IPath newDestinationPath) { + destinationPath = newDestinationPath; + } + + protected boolean isExportSource() { + return exportSource; + } + + protected void setExportSource(boolean newExportSource) { + exportSource = newExportSource; + } + + protected void setModule() { + String moduleType = getModuleTypeID(); + if( component != null && component.getProject() != null && moduleType != null) { + IModule[] modules = ServerUtil.getModules(component.getProject()); + for( int i = 0; i < modules.length; i++ ) { + if( modules[i].getModuleType().getId().equals(moduleType)) { + module = modules[i]; + return; + } + } + } + module = null; + Object o = module; + } + + protected abstract String getModuleTypeID(); + + + /* Return null to skip this child */ + protected /* abstract */ String getChildURI(IModule parent, IModule child) { + IEnterpriseApplication app = (IEnterpriseApplication)parent.loadAdapter(IEnterpriseApplication.class, new NullProgressMonitor()); + if( app != null ) { + return app.getURI(child); + } + return null; + } + + protected void runNecessaryBuilders(IVirtualComponent component, IProgressMonitor monitor) throws CoreException { + try{ + monitor.beginTask(null, JAVA_BUILDER_WORK + LIB_BUILDER_WORK); + if(!component.isBinary()){ + IProject project = component.getProject(); + IProjectDescription description = project.getDescription(); + ICommand javaBuilder = getJavaCommand(description); + if (javaBuilder != null) { + project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, JavaCore.BUILDER_ID, javaBuilder.getArguments(), new SubProgressMonitor(monitor, JAVA_BUILDER_WORK)); + } + ICommand libCopyBuilder = getLibCopyBuilder(description); + if (null != libCopyBuilder) { + project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, LibCopyBuilder.BUILDER_ID, libCopyBuilder.getArguments(), new SubProgressMonitor(monitor, LIB_BUILDER_WORK)); + } + } + } finally { + monitor.done(); + } + } + + /** + * Find the specific Java command amongst the build spec of a given description + */ + protected ICommand getJavaCommand(IProjectDescription description) throws CoreException { + if (description == null) { + return null; + } + + ICommand[] commands = description.getBuildSpec(); + for (int i = 0; i < commands.length; ++i) { + if (commands[i].getBuilderName().equals(JavaCore.BUILDER_ID)) { + return commands[i]; + } + } + return null; + } + + protected ICommand getLibCopyBuilder(IProjectDescription description) throws CoreException { + if (description == null) { + return null; + } + + ICommand[] commands = description.getBuildSpec(); + for (int i = 0; i < commands.length; ++i) { + if (commands[i].getBuilderName().equals(LibCopyBuilder.BUILDER_ID)) { + return commands[i]; + } + } + return null; + + } + + public ISchedulingRule getSchedulingRule() { + Set projs = gatherDependentProjects(getComponent(), new HashSet()); + ISchedulingRule combinedRule = null; + IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory(); + for (Iterator iter = projs.iterator(); iter.hasNext();) { + IProject proj = (IProject) iter.next(); + ISchedulingRule rule = ruleFactory.createRule(proj); + combinedRule = MultiRule.combine(rule, combinedRule); + } + combinedRule = MultiRule.combine(ruleFactory.buildRule(), combinedRule); + + return combinedRule; + } + + private Set gatherDependentProjects(IVirtualComponent comp, Set projs) { + if (!projs.contains(comp.getProject())) { + projs.add(comp.getProject()); + IVirtualReference[] refs = comp.getReferences(); + for (int i = 0; i < refs.length; i++) { + IVirtualReference refComp = refs[i]; + projs.addAll(gatherDependentProjects(refComp.getReferencedComponent(), projs)); + } + } + return projs; + } + + + + protected void export() throws SaveFailureException, CoreException, InvocationTargetException, InterruptedException { + if( module == null ) + throw new SaveFailureException(); // TODO add some real message + try { + File dest = getDestinationPath().toFile(); + File parent = dest.getParentFile(); + + /* Prepare the streams */ + if (dest.exists() && dest.isDirectory()) { + throw new IOException("The specified file: " + dest.getAbsolutePath() + " exists and is a directory"); + } + if (parent != null) + parent.mkdirs(); + java.io.OutputStream out = new java.io.FileOutputStream(dest); + ZipStreamModuleSaveAdapterImpl saver = new ZipStreamModuleSaveAdapterImpl(out); + + ModuleDelegate moduleDelegate = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class, new NullProgressMonitor()); + addResources(saver, moduleDelegate.members()); + addChildren(saver, module, moduleDelegate.getChildModules()); + saver.finish(); + } catch( Exception e ) { + throw new SaveFailureException(); + } + } + + protected void addChildren(ZipStreamModuleSaveAdapterImpl saver, IModule parent, IModule[] children ) throws IOException, ArchiveSaveFailureException, CoreException { + if( children != null ) { + for( int i = 0; i < children.length; i++ ) { + String path = getChildURI(parent, children[i]); + ModuleDelegate childDelegate = (ModuleDelegate)children[i]. + loadAdapter(ModuleDelegate.class, new NullProgressMonitor()); + IJ2EEModule tempMod = (IJ2EEModule)children[i].loadAdapter(IJ2EEModule.class, new NullProgressMonitor()); + boolean isBinary = tempMod.isBinary(); + if( path != null ) { + ZipStreamModuleSaveAdapterImpl childSaver = saver.createNestedSaveAdapter(path); + addResources(childSaver, childDelegate.members()); + addChildren(childSaver, children[i], childDelegate.getChildModules()); + childSaver.finish(); + } + } + } + } + + protected void addResources(ZipStreamModuleSaveAdapterImpl saver, IModuleResource[] resources) throws ArchiveSaveFailureException { + for( int i = 0; i < resources.length; i++ ) { + if( resources[i] instanceof IModuleFile ) { + saver.save(resources[i]); + } else if( resources[i] instanceof IModuleFolder ) { + addResources(saver, ((IModuleFolder)resources[i]).members()); + } + } + } + + + public static class ZipStreamModuleSaveAdapterImpl { + protected OutputStream destinationStream; + /** Used internally */ + protected ZipOutputStream zipOutputStream; + + public ZipStreamModuleSaveAdapterImpl(OutputStream out) { + destinationStream = out; + zipOutputStream = new ZipOutputStream(out); + } + + public void close() throws IOException { + getDestinationStream().close(); + } + + protected ZipStreamModuleSaveAdapterImpl createNestedSaveAdapter(String entry) throws IOException { + ZipEntry nest = new ZipEntry(entry); + getZipOutputStream().putNextEntry(nest); + return new ZipStreamModuleSaveAdapterImpl(getZipOutputStream()); + } + + public void finish() throws IOException { + getZipOutputStream().finish(); + //If this is not nested, close the stream to free up the resource + //otherwise, don't close it because the parent may not be done + if (!(getDestinationStream() instanceof ZipOutputStream)) + getDestinationStream().close(); + } + + public java.io.OutputStream getDestinationStream() { + return destinationStream; + } + + protected java.util.zip.ZipOutputStream getZipOutputStream() { + return zipOutputStream; + } + + protected void save(IModuleResource resource) throws ArchiveSaveFailureException { + if( resource instanceof IModuleFile ) { + File f = (File)((IModuleFile)resource).getAdapter(File.class); + if( f == null ) { + IFile ifile = (IFile)((IModuleFile)resource).getAdapter(IFile.class); + if( ifile != null ) + f = ifile.getLocation().toFile(); + } + saveFile(f, resource.getModuleRelativePath().append(resource.getName())); + } + } + + protected void saveFile(File f, IPath entryPath) throws ArchiveSaveFailureException{ + try { + ZipEntry entry = new ZipEntry(entryPath.toString()); + if (f.lastModified() > 0) + entry.setTime(f.lastModified()); + getZipOutputStream().putNextEntry(entry); + ArchiveUtil.copy(new FileInputStream(f), getZipOutputStream()); + getZipOutputStream().closeEntry(); + } catch (IOException e) { + throw new ArchiveSaveFailureException(e); + } + } + } + +} #P org.eclipse.jst.j2ee.jca Index: jcaedit/org/eclipse/jst/j2ee/internal/jca/archive/operations/ConnectorComponentExportOperation.java =================================================================== RCS file: /cvsroot/webtools/jeetools/plugins/org.eclipse.jst.j2ee.jca/jcaedit/org/eclipse/jst/j2ee/internal/jca/archive/operations/ConnectorComponentExportOperation.java,v retrieving revision 1.6 diff -u -r1.6 ConnectorComponentExportOperation.java --- jcaedit/org/eclipse/jst/j2ee/internal/jca/archive/operations/ConnectorComponentExportOperation.java 7 Jun 2007 19:30:21 -0000 1.6 +++ jcaedit/org/eclipse/jst/j2ee/internal/jca/archive/operations/ConnectorComponentExportOperation.java 23 Feb 2009 08:51:33 -0000 @@ -10,20 +10,10 @@ *******************************************************************************/ package org.eclipse.jst.j2ee.internal.jca.archive.operations; -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.jst.j2ee.commonarchivecore.internal.CommonarchiveFactory; -import org.eclipse.jst.j2ee.commonarchivecore.internal.CommonarchivePackage; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.SaveFailureException; -import org.eclipse.jst.j2ee.internal.archive.operations.AppClientArchiveOpsResourceHandler; -import org.eclipse.jst.j2ee.internal.archive.operations.J2EEArtifactExportOperation; +import org.eclipse.jst.j2ee.internal.archive.operations.J2EEModuleExportOperation; import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -public class ConnectorComponentExportOperation extends J2EEArtifactExportOperation { +public class ConnectorComponentExportOperation extends J2EEModuleExportOperation { public ConnectorComponentExportOperation() { super(); @@ -33,26 +23,30 @@ super(model); } - protected void export() throws SaveFailureException, CoreException, InvocationTargetException, InterruptedException { - IProgressMonitor subMonitor = new SubProgressMonitor(progressMonitor, EXPORT_WORK); - try { - CommonarchiveFactory caf = ((CommonarchivePackage) EPackage.Registry.INSTANCE.getEPackage(CommonarchivePackage.eNS_URI)).getCommonarchiveFactory(); - ConnectorComponentLoadStrategyImpl ls = new ConnectorComponentLoadStrategyImpl(getComponent()); - ls.setExportSource(isExportSource()); - setModuleFile(caf.openRARFile(ls, getDestinationPath().toOSString())); - ls.setProgressMonitor(subMonitor); - getModuleFile().saveAsNoReopen(getDestinationPath().toOSString()); - } catch (SaveFailureException ex) { - throw ex; - } catch (Exception e) { - throw new SaveFailureException(AppClientArchiveOpsResourceHandler.ARCHIVE_OPERATION_OpeningArchive, e); - } finally { - subMonitor.done(); - } - } +// protected void export() throws SaveFailureException, CoreException, InvocationTargetException, InterruptedException { +// IProgressMonitor subMonitor = new SubProgressMonitor(progressMonitor, EXPORT_WORK); +// try { +// CommonarchiveFactory caf = ((CommonarchivePackage) EPackage.Registry.INSTANCE.getEPackage(CommonarchivePackage.eNS_URI)).getCommonarchiveFactory(); +// ConnectorComponentLoadStrategyImpl ls = new ConnectorComponentLoadStrategyImpl(getComponent()); +// ls.setExportSource(isExportSource()); +// setModuleFile(caf.openRARFile(ls, getDestinationPath().toOSString())); +// ls.setProgressMonitor(subMonitor); +// getModuleFile().saveAsNoReopen(getDestinationPath().toOSString()); +// } catch (SaveFailureException ex) { +// throw ex; +// } catch (Exception e) { +// throw new SaveFailureException(AppClientArchiveOpsResourceHandler.ARCHIVE_OPERATION_OpeningArchive, e); +// } finally { +// subMonitor.done(); +// } +// } protected String archiveString() { //TODO fill in string return ""; //$NON-NLS-1$ } + + protected String getModuleTypeID() { + return "jst.connector"; + } } #P org.eclipse.jst.j2ee.web Index: webproject/org/eclipse/jst/j2ee/internal/web/archive/operations/WebComponentExportOperation.java =================================================================== RCS file: /cvsroot/webtools/jeetools/plugins/org.eclipse.jst.j2ee.web/webproject/org/eclipse/jst/j2ee/internal/web/archive/operations/WebComponentExportOperation.java,v retrieving revision 1.8 diff -u -r1.8 WebComponentExportOperation.java --- webproject/org/eclipse/jst/j2ee/internal/web/archive/operations/WebComponentExportOperation.java 7 Jun 2007 19:31:31 -0000 1.8 +++ webproject/org/eclipse/jst/j2ee/internal/web/archive/operations/WebComponentExportOperation.java 23 Feb 2009 08:51:35 -0000 @@ -10,24 +10,10 @@ *******************************************************************************/ package org.eclipse.jst.j2ee.internal.web.archive.operations; -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.jst.j2ee.commonarchivecore.internal.CommonarchiveFactory; -import org.eclipse.jst.j2ee.commonarchivecore.internal.CommonarchivePackage; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.SaveFailureException; -import org.eclipse.jst.j2ee.internal.J2EEConstants; -import org.eclipse.jst.j2ee.internal.archive.JavaEEArchiveUtilities; -import org.eclipse.jst.j2ee.internal.archive.operations.AppClientArchiveOpsResourceHandler; -import org.eclipse.jst.j2ee.internal.archive.operations.J2EEArtifactExportOperation; -import org.eclipse.jst.jee.archive.IArchive; -import org.eclipse.jst.jee.util.internal.JavaEEQuickPeek; +import org.eclipse.jst.j2ee.internal.archive.operations.J2EEModuleExportOperation; import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -public class WebComponentExportOperation extends J2EEArtifactExportOperation { +public class WebComponentExportOperation extends J2EEModuleExportOperation { public WebComponentExportOperation() { super(); @@ -37,37 +23,41 @@ super(model); } - protected void export() throws SaveFailureException, CoreException, InvocationTargetException, InterruptedException { - IProgressMonitor subMonitor = new SubProgressMonitor(progressMonitor, EXPORT_WORK); - IArchive archiveFromComponent = null; - try { - archiveFromComponent = JavaEEArchiveUtilities.INSTANCE.openArchive(getComponent()); - JavaEEQuickPeek quickPeek = JavaEEArchiveUtilities.INSTANCE.getJavaEEQuickPeek(archiveFromComponent); - if (quickPeek.getJavaEEVersion() == J2EEConstants.JEE_5_0_ID) { - saveArchive(archiveFromComponent, getDestinationPath().toOSString(), subMonitor); - } else { - CommonarchiveFactory caf = ((CommonarchivePackage) EPackage.Registry.INSTANCE.getEPackage(CommonarchivePackage.eNS_URI)).getCommonarchiveFactory(); - WebComponentLoadStrategyImpl ls = new WebComponentLoadStrategyImpl(getComponent()); - ls.setExportSource(isExportSource()); - setModuleFile(caf.openWARFile(ls, getDestinationPath().toOSString())); - ls.setProgressMonitor(subMonitor); - getModuleFile().saveAsNoReopen(getDestinationPath().toOSString()); - } - - } catch (SaveFailureException ex) { - throw ex; - } catch (Exception e) { - throw new SaveFailureException(AppClientArchiveOpsResourceHandler.ARCHIVE_OPERATION_OpeningArchive, e); - } finally { - if (archiveFromComponent != null) - JavaEEArchiveUtilities.INSTANCE.closeArchive(archiveFromComponent); - - subMonitor.done(); - } - } +// protected void export() throws SaveFailureException, CoreException, InvocationTargetException, InterruptedException { +// IProgressMonitor subMonitor = new SubProgressMonitor(progressMonitor, EXPORT_WORK); +// IArchive archiveFromComponent = null; +// try { +// archiveFromComponent = JavaEEArchiveUtilities.INSTANCE.openArchive(getComponent()); +// JavaEEQuickPeek quickPeek = JavaEEArchiveUtilities.INSTANCE.getJavaEEQuickPeek(archiveFromComponent); +// if (quickPeek.getJavaEEVersion() == J2EEConstants.JEE_5_0_ID) { +// saveArchive(archiveFromComponent, getDestinationPath().toOSString(), subMonitor); +// } else { +// CommonarchiveFactory caf = ((CommonarchivePackage) EPackage.Registry.INSTANCE.getEPackage(CommonarchivePackage.eNS_URI)).getCommonarchiveFactory(); +// WebComponentLoadStrategyImpl ls = new WebComponentLoadStrategyImpl(getComponent()); +// ls.setExportSource(isExportSource()); +// setModuleFile(caf.openWARFile(ls, getDestinationPath().toOSString())); +// ls.setProgressMonitor(subMonitor); +// getModuleFile().saveAsNoReopen(getDestinationPath().toOSString()); +// } +// +// } catch (SaveFailureException ex) { +// throw ex; +// } catch (Exception e) { +// throw new SaveFailureException(AppClientArchiveOpsResourceHandler.ARCHIVE_OPERATION_OpeningArchive, e); +// } finally { +// if (archiveFromComponent != null) +// JavaEEArchiveUtilities.INSTANCE.closeArchive(archiveFromComponent); +// +// subMonitor.done(); +// } +// } protected String archiveString() { return "War File"; } + protected String getModuleTypeID() { + return "jst.web"; + } + } #P org.eclipse.jst.j2ee.ejb Index: ejbarchive/org/eclipse/jst/j2ee/internal/ejb/archiveoperations/EJBComponentExportOperation.java =================================================================== RCS file: /cvsroot/webtools/ejbtools/plugins/org.eclipse.jst.j2ee.ejb/ejbarchive/org/eclipse/jst/j2ee/internal/ejb/archiveoperations/EJBComponentExportOperation.java,v retrieving revision 1.7 diff -u -r1.7 EJBComponentExportOperation.java --- ejbarchive/org/eclipse/jst/j2ee/internal/ejb/archiveoperations/EJBComponentExportOperation.java 7 Jun 2007 19:32:25 -0000 1.7 +++ ejbarchive/org/eclipse/jst/j2ee/internal/ejb/archiveoperations/EJBComponentExportOperation.java 23 Feb 2009 08:51:37 -0000 @@ -10,24 +10,10 @@ *******************************************************************************/ package org.eclipse.jst.j2ee.internal.ejb.archiveoperations; -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.jst.j2ee.commonarchivecore.internal.CommonarchiveFactory; -import org.eclipse.jst.j2ee.commonarchivecore.internal.CommonarchivePackage; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.SaveFailureException; -import org.eclipse.jst.j2ee.internal.J2EEConstants; -import org.eclipse.jst.j2ee.internal.archive.JavaEEArchiveUtilities; -import org.eclipse.jst.j2ee.internal.archive.operations.ComponentLoadStrategyImpl; -import org.eclipse.jst.j2ee.internal.archive.operations.J2EEArtifactExportOperation; -import org.eclipse.jst.jee.archive.IArchive; -import org.eclipse.jst.jee.util.internal.JavaEEQuickPeek; +import org.eclipse.jst.j2ee.internal.archive.operations.J2EEModuleExportOperation; import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -public class EJBComponentExportOperation extends J2EEArtifactExportOperation { +public class EJBComponentExportOperation extends J2EEModuleExportOperation { public EJBComponentExportOperation() { super(); @@ -37,45 +23,49 @@ super(model); } - protected void export() throws SaveFailureException, CoreException, InvocationTargetException, InterruptedException { - IProgressMonitor subMonitor = new SubProgressMonitor(progressMonitor, EXPORT_WORK); - IArchive archiveFromComponent = null; - try { - archiveFromComponent = JavaEEArchiveUtilities.INSTANCE.openArchive(getComponent()); - JavaEEQuickPeek quickPeek = JavaEEArchiveUtilities.INSTANCE.getJavaEEQuickPeek(archiveFromComponent); - if (quickPeek.getJavaEEVersion() == J2EEConstants.JEE_5_0_ID) { - saveArchive(archiveFromComponent, getDestinationPath().toOSString(), subMonitor); - } else { - createModuleFile(); - ((ComponentLoadStrategyImpl) (getModuleFile().getLoadStrategy())).setProgressMonitor(subMonitor); - getModuleFile().saveAsNoReopen(getDestinationPath().toOSString()); - } - - } catch (SaveFailureException ex) { - throw ex; - } catch (Exception e) { - throw new SaveFailureException(EJBArchiveOpsResourceHandler.ARCHIVE_OPERATION_OpeningArchive, e); - } finally { - if (archiveFromComponent != null) - JavaEEArchiveUtilities.INSTANCE.closeArchive(archiveFromComponent); - subMonitor.done(); - } - } +// protected void export() throws SaveFailureException, CoreException, InvocationTargetException, InterruptedException { +// IProgressMonitor subMonitor = new SubProgressMonitor(progressMonitor, EXPORT_WORK); +// IArchive archiveFromComponent = null; +// try { +// archiveFromComponent = JavaEEArchiveUtilities.INSTANCE.openArchive(getComponent()); +// JavaEEQuickPeek quickPeek = JavaEEArchiveUtilities.INSTANCE.getJavaEEQuickPeek(archiveFromComponent); +// if (quickPeek.getJavaEEVersion() == J2EEConstants.JEE_5_0_ID) { +// saveArchive(archiveFromComponent, getDestinationPath().toOSString(), subMonitor); +// } else { +// createModuleFile(); +// ((ComponentLoadStrategyImpl) (getModuleFile().getLoadStrategy())).setProgressMonitor(subMonitor); +// getModuleFile().saveAsNoReopen(getDestinationPath().toOSString()); +// } +// +// } catch (SaveFailureException ex) { +// throw ex; +// } catch (Exception e) { +// throw new SaveFailureException(EJBArchiveOpsResourceHandler.ARCHIVE_OPERATION_OpeningArchive, e); +// } finally { +// if (archiveFromComponent != null) +// JavaEEArchiveUtilities.INSTANCE.closeArchive(archiveFromComponent); +// subMonitor.done(); +// } +// } protected String archiveString() { return EJBArchiveOpsResourceHandler.EJB_Jar_File_UI_; } - public void createModuleFile() throws SaveFailureException { - try { - CommonarchiveFactory caf = ((CommonarchivePackage) EPackage.Registry.INSTANCE.getEPackage(CommonarchivePackage.eNS_URI)).getCommonarchiveFactory(); - EJBComponentLoadStrategyImpl ls = new EJBComponentLoadStrategyImpl(getComponent()); - ls.setExportSource(isExportSource()); - setModuleFile(caf.openEJBJarFile(ls, getDestinationPath().toOSString())); - } catch (Exception e) { - throw new SaveFailureException(EJBArchiveOpsResourceHandler.ARCHIVE_OPERATION_OpeningArchive, e); - } - + protected String getModuleTypeID() { + return "jst.ejb"; } +// public void createModuleFile() throws SaveFailureException { +// try { +// CommonarchiveFactory caf = ((CommonarchivePackage) EPackage.Registry.INSTANCE.getEPackage(CommonarchivePackage.eNS_URI)).getCommonarchiveFactory(); +// EJBComponentLoadStrategyImpl ls = new EJBComponentLoadStrategyImpl(getComponent()); +// ls.setExportSource(isExportSource()); +// setModuleFile(caf.openEJBJarFile(ls, getDestinationPath().toOSString())); +// } catch (Exception e) { +// throw new SaveFailureException(EJBArchiveOpsResourceHandler.ARCHIVE_OPERATION_OpeningArchive, e); +// } +// +// } + }