/******************************************************************************* * Copyright (c) 2012, 2015 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 * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Obeo - initial API and implementation *******************************************************************************/ package org.eclipse.emf.compare.diagram.papyrus.tests; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; import org.eclipse.emf.common.EMFPlugin; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.compare.tests.framework.AbstractInputData; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.gmf.runtime.emf.core.resources.GMFResourceFactory; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.uml2.uml.UMLPackage; import org.eclipse.uml2.uml.internal.resource.UMLResourceFactoryImpl; @SuppressWarnings("restriction") public class DiagramInputData extends AbstractInputData { /** Store the set of the resource sets of the input data. */ private Set<ResourceSet> sets = new LinkedHashSet<ResourceSet>(); public DiagramInputData() { } public Set<ResourceSet> getSets() { return sets; } @Override protected Resource loadFromClassLoader(String string) throws IOException { final URL fileURL = getClass().getResource(string); final InputStream str = fileURL.openStream(); final URI uri = URI.createURI(fileURL.toString()); ResourceSet resourceSet = new ResourceSetImpl(); getSets().add(resourceSet); if (!EMFPlugin.IS_RESOURCES_BUNDLE_AVAILABLE) { resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("uml", new UMLResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("notation", new GMFResourceFactory()); EPackage.Registry.INSTANCE.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE); EPackage.Registry.INSTANCE.put(NotationPackage.eNS_URI, NotationPackage.eINSTANCE); // EPackage.Registry.INSTANCE.put(StylePackage.eNS_URI, // NotationPackage.eINSTANCE); } Resource resource = resourceSet.createResource(uri); resource.load(str, Collections.emptyMap()); str.close(); EcoreUtil.resolveAll(resourceSet); return resource; } }