[378507] NPE when exporting an EAR if one of the modules is out of synch
diff --git a/plugins/org.eclipse.jst.j2ee/archiveops/org/eclipse/jst/j2ee/internal/archive/operations/ComponentExportOperation.java b/plugins/org.eclipse.jst.j2ee/archiveops/org/eclipse/jst/j2ee/internal/archive/operations/ComponentExportOperation.java index 757e97c..c0f9778 100644 --- a/plugins/org.eclipse.jst.j2ee/archiveops/org/eclipse/jst/j2ee/internal/archive/operations/ComponentExportOperation.java +++ b/plugins/org.eclipse.jst.j2ee/archiveops/org/eclipse/jst/j2ee/internal/archive/operations/ComponentExportOperation.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 IBM Corporation and others. + * Copyright (c) 2010, 2012 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 @@ -49,6 +49,8 @@ import org.eclipse.jdt.core.JavaCore; import org.eclipse.jst.j2ee.commonarchivecore.internal.CommonArchiveResourceHandler; import org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties.IArchiveExportParticipantData; +import org.eclipse.jst.j2ee.internal.archive.operations.FlatComponentArchiver.UnderlyingFileNotFoundException; +import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; import org.eclipse.jst.j2ee.internal.project.ProjectSupportResourceHandler; import org.eclipse.jst.jee.archive.ArchiveSaveFailureException; import org.eclipse.jst.jee.archive.internal.ArchiveUtil; @@ -133,7 +135,20 @@ } export(); } catch (Exception e) { - throw new ExecutionException(EJBArchiveOpsResourceHandler.Error_exporting__UI_ + getDestinationPath(), e); + if (e.getCause() != null && e.getCause().getCause() instanceof UnderlyingFileNotFoundException){ + // Try to refresh the child modules and do the archive operation again + J2EEPlugin.logWarning("Refreshing referenced projects before trying to export again the project " + component.getDeployedName()); //$NON-NLS-1$ + try{ + refreshChildModules(component); + export(); + } + catch (Exception exceptionWhileRetry){ + throw new ExecutionException(EJBArchiveOpsResourceHandler.Error_exporting__UI_ + getDestinationPath(), exceptionWhileRetry); + } + } + else{ + throw new ExecutionException(EJBArchiveOpsResourceHandler.Error_exporting__UI_ + getDestinationPath(), e); + } } final IDataModel dm = getDataModel(); @@ -330,4 +345,19 @@ return projs; } + private void refreshProject(IVirtualComponent refComp) throws CoreException { + if (!component.isBinary()) { + IProject project = refComp.getProject(); + project.refreshLocal(IResource.DEPTH_INFINITE,null); + } + } + + private void refreshChildModules(IVirtualComponent component) throws CoreException { + IVirtualReference[] refs = component.getReferences(); + for (int i = 0; i < refs.length; i++) { + IVirtualComponent refComp = refs[i].getReferencedComponent(); + refreshProject(refComp); + } + } + }
diff --git a/plugins/org.eclipse.jst.j2ee/archiveops/org/eclipse/jst/j2ee/internal/archive/operations/FlatComponentArchiver.java b/plugins/org.eclipse.jst.j2ee/archiveops/org/eclipse/jst/j2ee/internal/archive/operations/FlatComponentArchiver.java index cf4fff1..2f46714 100644 --- a/plugins/org.eclipse.jst.j2ee/archiveops/org/eclipse/jst/j2ee/internal/archive/operations/FlatComponentArchiver.java +++ b/plugins/org.eclipse.jst.j2ee/archiveops/org/eclipse/jst/j2ee/internal/archive/operations/FlatComponentArchiver.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 IBM Corporation and others. + * Copyright (c) 2010, 2012 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 @@ -55,6 +55,15 @@ public IFlatVirtualComponent saveComponent(IVirtualComponent component, ZipOutputStream zipOutputStream, List<IPath> zipEntries) throws ArchiveException; public boolean createManifest(); } + + public static class UnderlyingFileNotFoundException extends ArchiveSaveFailureException { + private static final long serialVersionUID = 1; + + public UnderlyingFileNotFoundException(String message) { + super(message); + } + + } public FlatComponentArchiver(IVirtualComponent aComponent, OutputStream out, List<IFlattenParticipant> fParticipants) { participants = fParticipants; @@ -238,7 +247,17 @@ getZipOutputStream().putNextEntry(entry); if (!isFolder) { - ArchiveUtil.copy((InputStream) f.getAdapter(InputStream.class), getZipOutputStream()); + InputStream is = (InputStream) f.getAdapter(InputStream.class); + if (is == null){ + File file = (File) f.getAdapter(File.class); + String msg = null; + if (file!= null) + msg = "Cannot find the file " + file.getAbsolutePath() + " in the file system. Make sure the file exists and try the operation again"; //$NON-NLS-1$ //$NON-NLS-2$ + else + msg = "Cannot find the file " + f.getModuleRelativePath().append(f.getName()) + " in the file system. Make sure the file exists and try the operation again"; //$NON-NLS-1$ //$NON-NLS-2$ + throw new UnderlyingFileNotFoundException(msg); + } + ArchiveUtil.copy(is, getZipOutputStream()); } getZipOutputStream().closeEntry(); } catch (IOException e) {