From 896f2754d3720ed7fff10b13df602d5918a48b57 Mon Sep 17 00:00:00 2001 From: Arthur Daussy Date: Wed, 10 Sep 2014 11:06:26 +0200 Subject: [PATCH] [443420] Handle not integrated dynamic profile. This modification force dynamic integrated profile to be loaded. In the previous implementation only the profile registered against the the UML profile extension point were loaded. However it does not handle correctly the case of "fully" dynamic profile. That is to say profiles that are directly referenced from a UML model without being registered in the uml profile registry. Now an approximation will decide whether of not an URI references a profile using the convention ".profile.uml" as file extension. Registered profile that does not use this convention will still be loaded. Bug: 443420 Change-Id: Icde513b9dd52501953194d8875622231f0de99d1 Signed-off-by: Arthur Daussy --- .../META-INF/MANIFEST.MF | 3 +- .../rcp/internal/policy/UMLLoadOnDemandPolicy.java | 68 ++++++++++++++++++---- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/plugins/org.eclipse.emf.compare.uml2.rcp/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.compare.uml2.rcp/META-INF/MANIFEST.MF index 5061acf76..9fd837ca5 100644 --- a/plugins/org.eclipse.emf.compare.uml2.rcp/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.compare.uml2.rcp/META-INF/MANIFEST.MF @@ -11,5 +11,6 @@ Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-Vendor: %providerName Bundle-Localization: plugin -Import-Package: com.google.common.collect;version="[11.0.0,16.0.0)" +Import-Package: com.google.common.base;version="[11.0.0,16.0.0)", + com.google.common.collect;version="[11.0.0,16.0.0)" Export-Package: org.eclipse.emf.compare.uml2.rcp.internal.policy;x-internal:=true diff --git a/plugins/org.eclipse.emf.compare.uml2.rcp/src/org/eclipse/emf/compare/uml2/rcp/internal/policy/UMLLoadOnDemandPolicy.java b/plugins/org.eclipse.emf.compare.uml2.rcp/src/org/eclipse/emf/compare/uml2/rcp/internal/policy/UMLLoadOnDemandPolicy.java index 9ecd2a610..09eac911f 100644 --- a/plugins/org.eclipse.emf.compare.uml2.rcp/src/org/eclipse/emf/compare/uml2/rcp/internal/policy/UMLLoadOnDemandPolicy.java +++ b/plugins/org.eclipse.emf.compare.uml2.rcp/src/org/eclipse/emf/compare/uml2/rcp/internal/policy/UMLLoadOnDemandPolicy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Obeo. + * Copyright (c) 2012, 2014 Obeo. * 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 @@ -10,8 +10,12 @@ *******************************************************************************/ package org.eclipse.emf.compare.uml2.rcp.internal.policy; +import com.google.common.base.Function; +import com.google.common.base.Predicates; +import com.google.common.collect.Collections2; +import com.google.common.collect.Iterables; + import java.util.Collection; -import java.util.Map; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.compare.rcp.policy.ILoadOnDemandPolicy; @@ -20,6 +24,16 @@ import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl; import org.eclipse.uml2.uml.UMLPlugin; /** + * This policy is used to force the loading required resources by a UML model. + *

+ * In this particular case, we want to force the loading of any UML profile model. In order to do it, this + * policy will compare the input URI with the URIs registered as profile in the platform. However it does not + * handle the case of non registered dynamic profile (profile that are not registered against the UML profile + * extension). In order to take into account such profile an approximation has been made. Any URI that as + * thier extension file equal to ".profile.uml" will be considered as referencing a profile model and so will + * be automatically loaded. + *

+ * * @author Mikael Barbero */ public class UMLLoadOnDemandPolicy implements ILoadOnDemandPolicy { @@ -31,15 +45,49 @@ public class UMLLoadOnDemandPolicy implements ILoadOnDemandPolicy { */ public boolean isAuthorizing(URI uri) { URIConverter uriConverter = new ExtensibleURIConverterImpl(); - // Need to normalize the URI in order to resolve URI using path map + // Needs to normalize the URI in order to resolve URI using path map URI normalizedURI = uriConverter.normalize(uri); - Map nsURIToProfileLocationMap = UMLPlugin.getEPackageNsURIToProfileLocationMap(); - Collection profileLocations = nsURIToProfileLocationMap.values(); - for (URI profileLocation : profileLocations) { - URI profileResourceLocation = profileLocation.trimFragment(); - // Need to normalize the URI in order to resolve URI using path map - URI profileResourceNormalizedURI = uriConverter.normalize(profileResourceLocation); - if (profileResourceNormalizedURI.equals(normalizedURI)) { + return isConventionalURIForUMLProfile(normalizedURI) + || isRegisteredUMLProfile(normalizedURI, uriConverter); + } + + /** + * Returns true if the URI is registered in the UML profile registry. + * + * @param normalizedURI + * normalized URI to compare. + * @param uriConverter + * {@link URIConverter} to use for the registered profile URIs. + * @return + */ + private boolean isRegisteredUMLProfile(URI normalizedURI, final URIConverter uriConverter) { + Collection normalizedURIs = Collections2.transform(UMLPlugin + .getEPackageNsURIToProfileLocationMap().values(), new Function() { + + public URI apply(URI t) { + return uriConverter.normalize(t).trimFragment(); + } + }); + return Iterables.tryFind(normalizedURIs, Predicates.equalTo(normalizedURI.trimFragment())) + .isPresent(); + } + + /** + * Tries to guess if the input URI is pointing a profile URI. Any URI which as a file extension equals to + * ".profile.uml" will be considered as a profile URI. + * + * @param normalizedURI + * input URI to test. + * @return true if the input URI is considered as a profile URI, false + * otherwise. + */ + private boolean isConventionalURIForUMLProfile(URI normalizedURI) { + URI noFragmentURI = normalizedURI.trimFragment(); + String firstFileExtension = noFragmentURI.fileExtension(); + if ("uml".equals(firstFileExtension)) { //$NON-NLS-1$ + URI withoutFirstFileExtension = noFragmentURI.trimFileExtension(); + String secondFileExtension = withoutFirstFileExtension.fileExtension(); + if ("profile".equals(secondFileExtension)) { //$NON-NLS-1$ return true; } } -- 2.11.4.GIT