From 25b415d5740da9f1c3e3394f75a42218d5822d0e Mon Sep 17 00:00:00 2001 From: Pauline DEVILLE Date: Tue, 11 Sep 2018 16:03:11 +0200 Subject: Bug 538928 - [Toolsmiths][ProfileMigrationTool] FileNotFoundException due to bad management of cached files Change-Id: If2819a87eb1d693c93b8535b31ac46daa6aebb1c Signed-off-by: Pauline DEVILLE --- .../META-INF/MANIFEST.MF | 2 +- .../pom.xml | 2 +- .../MigratorProfileApplication.java | 41 +++++++++++++++++----- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration/META-INF/MANIFEST.MF b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration/META-INF/MANIFEST.MF index b3b393a10f7..a5e47869a61 100644 --- a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration/META-INF/MANIFEST.MF +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.papyrus.toolsmiths.profilemigration;singleton:=true -Bundle-Version: 0.7.102.qualifier +Bundle-Version: 0.7.103.qualifier Bundle-ClassPath: . Require-Bundle: org.eclipse.ui, com.google.guava;bundle-version="21.0.0", diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration/pom.xml b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration/pom.xml index 25dc488beba..76a5de42bbd 100644 --- a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration/pom.xml +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration/pom.xml @@ -8,6 +8,6 @@ 0.0.1-SNAPSHOT org.eclipse.papyrus.toolsmiths.profilemigration - 0.7.102-SNAPSHOT + 0.7.103-SNAPSHOT eclipse-plugin diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration/src/org/eclipse/papyrus/toolsmiths/profilemigration/MigratorProfileApplication.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration/src/org/eclipse/papyrus/toolsmiths/profilemigration/MigratorProfileApplication.java index 7924ca0e6b6..c4536f18744 100644 --- a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration/src/org/eclipse/papyrus/toolsmiths/profilemigration/MigratorProfileApplication.java +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration/src/org/eclipse/papyrus/toolsmiths/profilemigration/MigratorProfileApplication.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2017 CEA LIST. + * Copyright (c) 2017, 2018 CEA LIST. * * * All rights reserved. This program and the accompanying materials @@ -11,6 +11,7 @@ * * Contributors: * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 538928 * *****************************************************************************/ package org.eclipse.papyrus.toolsmiths.profilemigration; @@ -18,13 +19,16 @@ package org.eclipse.papyrus.toolsmiths.profilemigration; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import org.eclipse.emf.common.notify.Notifier; import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.common.util.WrappedException; import org.eclipse.emf.compare.Comparison; import org.eclipse.emf.compare.EMFCompare; import org.eclipse.emf.compare.scope.DefaultComparisonScope; @@ -108,7 +112,7 @@ public class MigratorProfileApplication { /** * Reapply the profile on the package_ - * + * * @param package_ * package owning the stereotype application * @param profile @@ -120,11 +124,16 @@ public class MigratorProfileApplication { String path = getFileName(profile, profileAfterResource); if (path != null) { - URI uri = URI.createFileURI(path); - ResourceSet profileBeforeResourceSet = new ResourceSetImpl(); - Resource profileBeforeResource = profileBeforeResourceSet.getResource(uri, true); - - migrateNewAppliedProfile(package_, profile, profileBeforeResource, profileAfterResource); + try { + URI uri = URI.createFileURI(path); + ResourceSet profileBeforeResourceSet = new ResourceSetImpl(); + Resource profileBeforeResource = profileBeforeResourceSet.getResource(uri, true); + migrateNewAppliedProfile(package_, profile, profileBeforeResource, profileAfterResource); + } catch (WrappedException e) { + // File is not found so restart reapply profile with asking the user + removeFilePathFromCached(path); + reapplyProfile(package_, profile); + } } else { MessageDialog message = new MessageDialog(Display.getDefault().getActiveShell(), "Incorect file", null, "The selected path is incorect so the profile will just be reapply.", MessageDialog.INFORMATION, new String[] { "OK" }, 0); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ message.open(); @@ -135,7 +144,7 @@ public class MigratorProfileApplication { /** * Migrate package_ to the new version of profile - * + * * @param package_ * the package to migrate * @param profile @@ -193,7 +202,7 @@ public class MigratorProfileApplication { /** * This method migrate to model to the new version of the profile - * + * * @param model * the profiled model to migrate * @param treeNode @@ -322,4 +331,18 @@ public class MigratorProfileApplication { } return path; } + + /** + * Remove every reference to the given path in the cacheProfileToFile + */ + private void removeFilePathFromCached(String path) { + Iterator> it = cacheProfileToFile.entrySet().iterator(); + while (it.hasNext()) { + Entry entry = it.next(); + if (entry.getValue().equals(path)) { + ProfileMigrationPreferencePage.getCachedFiles().remove(path); + it.remove(); + } + } + } } -- cgit v1.2.3