public Collection<? extends ServerDescriptor> startServer ( final URI exporterFileUri, final String locationLabel ) throws CoreException { final ResourceSetImpl resourceSet = new ResourceSetImpl (); resourceSet.getResourceFactoryRegistry ().getExtensionToFactoryMap ().put ( "*", new ExporterResourceFactoryImpl () ); final Resource resource = resourceSet.createResource ( exporterFileUri ); try { resource.load ( null ); } catch ( final IOException e ) { throw new CoreException ( StatusHelper.convertStatus ( HivesPlugin.PLUGIN_ID, "Failed to load configuration", e ) ); } final DocumentRoot root = (DocumentRoot)EcoreUtil.getObjectByType ( resource.getContents (), ExporterPackage.Literals.DOCUMENT_ROOT ); if ( root == null ) { throw new CoreException ( new Status ( IStatus.ERROR, HivesPlugin.PLUGIN_ID, "Failed to locate exporter configuration in: " + exporterFileUri ) ); } return startServer ( root, locationLabel ); }
/** * Laods the package and any sub-packages from their serialized form. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void loadPackage() { if (isLoaded) return; isLoaded = true; URL url = getClass().getResource(packageFilename); if (url == null) { throw new RuntimeException("Missing serialized package: " + packageFilename); } URI uri = URI.createURI(url.toString()); Resource resource = new EcoreResourceFactoryImpl().createResource(uri); try { resource.load(null); } catch (IOException exception) { throw new WrappedException(exception); } initializeFromLoadedEPackage(this, (EPackage) resource.getContents().get(0)); createResource(eNS_URI); }
/** * Creates an instance of the resource. * <!-- begin-user-doc --> <!-- end-user-doc --> * @generated */ @Override public Resource createResource(URI uri) { XMLResource result = new MailModuleResourceImpl(uri); result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE); result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE); result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE); result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE); result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE); result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE); return result; }
/** * This is the method called to load a resource into the editing domain's resource set based on the editor's input. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void createModel() { URI resourceURI = EditUIUtil.getURI(getEditorInput(), editingDomain.getResourceSet().getURIConverter()); Exception exception = null; Resource resource = null; try { // Load the resource through the editing domain. // resource = editingDomain.getResourceSet().getResource(resourceURI, true); } catch (Exception e) { exception = e; resource = editingDomain.getResourceSet().getResource(resourceURI, false); } Diagnostic diagnostic = analyzeResourceProblems(resource, exception); if (diagnostic.getSeverity() != Diagnostic.OK) { resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception)); } editingDomain.getResourceSet().eAdapters().add(problemIndicationAdapter); }
private MasterServer loadLastSelection () { final String lastUri = this.dialogSettings.get ( SETTINGS_LAST_SELECTION ); if ( lastUri == null ) { return null; } try { final EObject lastSelection = this.world.eResource ().getResourceSet ().getEObject ( URI.createURI ( lastUri ), true ); if ( lastSelection instanceof MasterServer ) { return (MasterServer)lastSelection; } } catch ( final Exception e ) { } return null; }
/** * Laods the package and any sub-packages from their serialized form. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void loadPackage() { if (isLoaded) return; isLoaded = true; URL url = getClass().getResource(packageFilename); if (url == null) { throw new RuntimeException("Missing serialized package: " + packageFilename); } URI uri = URI.createURI(url.toString()); Resource resource = new EcoreResourceFactoryImpl().createResource(uri); try { resource.load(null); } catch (IOException exception) { throw new WrappedException(exception); } initializeFromLoadedEPackage(this, (EPackage)resource.getContents().get(0)); createResource(eNS_URI); }
@Override public Iterable<IProject> getProjects(java.net.URI rootLocation) { ensureInitialized(); final File rootFolder = new File(rootLocation); final Map<String, IProject> projectsMapping = newTreeMap(); final URI rootUri = URI.createFileURI(rootFolder.getAbsolutePath()); for (Entry<URI, Optional<Pair<ExternalProject, ProjectDescription>>> entry : projectCache.asMap().entrySet()) { final URI projectLocation = entry.getKey(); if (rootUri.equals(projectLocation.trimSegments(1))) { final Pair<ExternalProject, ProjectDescription> pair = entry.getValue().orNull(); if (null != pair && null != pair.getFirst()) { final ExternalProject project = pair.getFirst(); projectsMapping.put(project.getName(), project); } } } return unmodifiableCollection(projectsMapping.values()); }
/***/ public static Set<IReferenceDescription> getIncomingReferences(URI uri) { Set<IReferenceDescription> desc = Sets.newHashSet(); Iterable<IResourceDescription> descriptions = getAllResourceDescriptions(); for (IResourceDescription res : descriptions) { Iterable<IReferenceDescription> descriptions2 = res.getReferenceDescriptions(); for (IReferenceDescription ref : descriptions2) { if (uri.hasFragment()) { if (ref.getTargetEObjectUri().equals(uri)) desc.add(ref); } else { if (ref.getTargetEObjectUri().trimFragment().equals(uri.trimFragment())) desc.add(ref); } } } return desc; }
/** * This is the method called to load a resource into the editing domain's resource set based on the editor's input. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void createModel () { URI resourceURI = EditUIUtil.getURI ( getEditorInput () ); Exception exception = null; Resource resource = null; try { // Load the resource through the editing domain. // resource = editingDomain.getResourceSet ().getResource ( resourceURI, true ); } catch ( Exception e ) { exception = e; resource = editingDomain.getResourceSet ().getResource ( resourceURI, false ); } Diagnostic diagnostic = analyzeResourceProblems ( resource, exception ); if ( diagnostic.getSeverity () != Diagnostic.OK ) { resourceToDiagnosticMap.put ( resource, analyzeResourceProblems ( resource, exception ) ); } editingDomain.getResourceSet ().eAdapters ().add ( problemIndicationAdapter ); }
public T load ( final URI uri, final String contentTypeId ) throws IOException { final ResourceSet rs = new ResourceSetImpl (); final Resource r = rs.createResource ( uri, contentTypeId ); r.load ( null ); for ( final Object o : r.getContents () ) { if ( this.clazz.isAssignableFrom ( o.getClass () ) ) { return this.clazz.cast ( o ); } } throw new IllegalStateException ( String.format ( "Model %s does not contain an object of type %s", uri, this.clazz ) ); }
private IProject generateDesignProject(String occieLocation, String designName, String designProjectName, final IProgressMonitor monitor) throws CoreException, IOException { // Load the ecore file. String ecoreLocation = occieLocation.replace(".occie", ".ecore"); URI ecoreURI = URI.createFileURI(ecoreLocation); // Create a new resource set. ResourceSet resourceSet = new ResourceSetImpl(); // Load the OCCI resource. org.eclipse.emf.ecore.resource.Resource resource = resourceSet.getResource(ecoreURI, true); // Return the first element. EPackage ePackage = (EPackage) resource.getContents().get(0); String extensionScheme = Occi2Ecore.convertEcoreNamespace2OcciScheme(ePackage.getNsURI()); // Register the ePackage to avoid an error when trying to open the generated // .odesign file, EPackage.Registry.INSTANCE.put(ePackage.getNsURI(), ePackage); URI occieURI = URI.createFileURI(occieLocation); /* * Create design project */ IProject project = DesignerGeneratorUtils.genDesignProject(designProjectName, designName, extensionScheme, new ProgressMonitorDialog(shell)); /* * Create design model */ org.eclipse.cmf.occi.core.gen.design.main.Generate generator = new org.eclipse.cmf.occi.core.gen.design.main.Generate( occieURI, project.getFolder("description").getLocation().toFile(), new ArrayList<String>()); generator.doGenerate(BasicMonitor.toMonitor(monitor)); project.refreshLocal(IResource.DEPTH_INFINITE, monitor); return project; }
/** * Creates an instance of the resource. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public Resource createResource ( URI uri ) { XMLResource result = new ChartResourceImpl ( uri ); result.getDefaultSaveOptions ().put ( XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE ); result.getDefaultLoadOptions ().put ( XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE ); result.getDefaultSaveOptions ().put ( XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE ); result.getDefaultLoadOptions ().put ( XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE ); result.getDefaultSaveOptions ().put ( XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE ); result.getDefaultLoadOptions ().put ( XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE ); return result; }
@Override public ProjectDescription getProjectDescription(URI location) { LazyProjectDescriptionHandle handle = projectElementHandles.get(location); if (handle == null) { // check case without trailing path separator if (location.hasTrailingPathSeparator()) { handle = projectElementHandles.get(location.trimSegments(1)); } } if (handle == null) { return null; } ProjectDescription description = handle.resolve(); return description; }
@Override public boolean matches(Issue issue) { URI actualValue = getActualValue.apply(issue); if (actualValue == null) return false; List<String> actualSegments = actualValue.segmentsList(); List<String> expectedSegments = expectedPattern.segmentsList(); switch (mode) { case StartsWith: return Collections.indexOfSubList(actualSegments, expectedSegments) == 0; case EndsWith: return Collections.lastIndexOfSubList(actualSegments, expectedSegments) == actualSegments.size() - expectedSegments.size(); case Equals: return actualSegments.equals(expectedSegments); } throw new IllegalStateException("Unknown URI property matching mode: " + mode); }
/** * Getting an IFile from an EMF Resource * * @param eObject * @return */ public static IFile getIFile(Resource res) { URI uri = res.getURI(); String filePath = uri.toPlatformString(true); IFile ifile = ResourcesPlugin.getWorkspace().getRoot() .getFile(new Path(filePath)); return ifile; }
/** * Creates an instance of the resource. * <!-- begin-user-doc --> <!-- end-user-doc --> * @generated */ @Override public Resource createResource(URI uri) { XMLResource result = new CpsModuleResourceImpl(uri); result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE); result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE); result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE); result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE); result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE); result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE); return result; }
/** * Returns with all external project dependency project ID for a particular non-external, accessible project. */ private Iterable<String> getDirectExternalDependencyIds(final IProject project) { if (null == project || !project.isAccessible()) { return emptyList(); } IN4JSProject n4Project = core.findProject(URI.createPlatformResourceURI(project.getName(), true)).orNull(); if (null == n4Project || !n4Project.exists() || n4Project.isExternal()) { return emptyList(); } return from(n4Project.getAllDirectDependencies()) .filter(IN4JSProject.class) .filter(p -> p.exists() && p.isExternal()) .transform(p -> p.getProjectId()); }
public Collection<URI> initContainedURIs(String handle) { // special handling for searching with project-context if (handle.startsWith(PROJECT_CONTAINER_PREFIX)) { return Collections.emptyList(); } URI uri = URI.createURI(handle.substring(SOURCE_CONTAINER_PREFIX.length())); Optional<? extends IN4JSSourceContainer> containerOpt = core.findN4JSSourceContainer(uri); Collection<URI> uris = new ArrayList<>(); if (containerOpt.isPresent()) { Iterator<URI> iter = containerOpt.get().iterator(); while (iter.hasNext()) { uris.add(iter.next()); } } return uris; }
@Override protected EObject toValidInstanceOrNull(Resource resource, Predicate<URI> targetURIs, EObject value) { EObject result = value; if (result.eIsProxy()) { URI proxyURI = EcoreUtil.getURI(result); if (uriEncoder.isCrossLinkFragment(resource, proxyURI.fragment())) { INode node = uriEncoder.decode(resource, proxyURI.fragment()).getThird(); String string = linkingHelper.getCrossRefNodeAsString(node, true); if (((TargetURIs) targetURIs).getUserData(TargetURIKey.KEY).isMatchingConcreteSyntax(string)) { result = resolveInternalProxy(value, resource); } else { result = null; } } else { result = resolveInternalProxy(value, resource); } } return result; }
private TestTree newTestTree(final String sessionId, final String... testIds) { final List<TestSuite> testSuites = newArrayList(transform(newHashSet(testIds), new Function<String, TestSuite>() { @Override public TestSuite apply(String testId) { final TestSuite suite = new TestSuite("TestSuite_for_Test_" + testId); final TestCase testCase = new TestCase( new ID(testId), "testClassName_" + testId, "origin_" + testId + "name_" + testId + "_0.0.0", "name_" + testId, "displayName_" + testId, URI.createURI("testURI_" + testId)); suite.setTestCases(singletonList(testCase)); return suite; } })); return new TestTree(new ID(sessionId), testSuites); }
@Test public void fragment() throws Exception { waitForWorkspaceChanges(() -> { IFile file = project.getFile("myFile.ext"); file.create(new NullInputStream(0), true, null); }); URI uri = URI.createPlatformResourceURI("/myProject/myFile.ext", true).appendFragment("fragment"); IResource iResource = UriUtils.toIResource(uri); assertTrue(iResource instanceof IFile); assertTrue(iResource.exists()); assertEquals("/myProject/myFile.ext", iResource.getFullPath().toString()); }
private Resource getModel() { URI modelURI = URI.createPlatformResourceURI(_modelLocationText.getText(), true); if(currentModelResource == null || !currentModelResource.getURI().equals(modelURI)){ currentModelResource = PlainK3ExecutionEngine.loadModel(modelURI); } return currentModelResource; }
public static Root createGlueModel(CIMRoot cim, Substandard substandard, COSEMRoot cosem) { Resource cimResource = cim.eResource(); Resource cosemResource = cosem.eResource(); ResourceSet rs = cimResource.getResourceSet(); if (rs != cosemResource.getResourceSet()) { throw new RuntimeException("Different ResourceSets"); } Resource fwdResource = rs.createResource(URI.createURI("fwd.src.xmi")); Root root = GluemodelFactory.eINSTANCE.createRoot(); root.setCim(cim); root.setCosem(cosem); Hashtable<String, MeterAsset> allMeterAssets = getAllMeterAssets(cimResource); root.getAssets().addAll(allMeterAssets.values()); cosem(cosemResource, root, allMeterAssets); if (substandard != null) { root.setSubstandard(substandard); substandard(substandard.eResource(), root, allMeterAssets); } fwdResource.getContents().add(root); return root; }
private void initMocks(File file) { applicationConfiguration = mock(ApplicationConfiguration.class); model = mock(Model.class); resource = mock(Resource.class, RETURNS_DEEP_STUBS); when(resource.getAllContents().next()).thenReturn(model); resourceSet = mock(ResourceSet.class); when(resourceSet.getResource(URI.createFileURI(file.getAbsolutePath()), true)).thenReturn(resource); resourceValidator = mock(IResourceValidator.class); ASTNodeConverter = mock(ASTNodeConverter.class); when(ASTNodeConverter.convert(model)).thenReturn(applicationConfiguration); }
/** * Provides URI for JSX Backend. URI is cached in local map {@link JSXBackendHelper#jsxBackends}. If there is no URI * for given QN, performs lookup via scope of the provided resource. and returned. * */ private URI getOrFindJSXBackend(Resource resource, String qualifiedName) { if (jsxBackends.isEmpty()) { populateBackendsCache(resource); } URI backendURI = jsxBackends.get(qualifiedName); if (backendURI == null) { // Normally we would throw error here, but there are few grey areas with JSX support. // To avoid blocking other teams using JSX, we are a bit defensive and try to keep system running. // With less complicated setups, this will HAPPEN to be correct. backendURI = jsxBackends.get(getAnyBackend()); } return backendURI; }
/** * Initializes the annotations for <b>edu.kit.ipd.sdq.mdsd.mj.classTrace.left</b>. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void createEdu_2Annotations() { String source = "edu.kit.ipd.sdq.mdsd.mj.classTrace.left"; addAnnotation (energyConsumerEClass, source, new String[] { }, new URI[] { URI.createURI(CIMPackage.eNS_URI).appendFragment("//IEC61968/Metering/MeterAsset") }); }
/** * Creates a new archive URI that points to the given archive entry. * * @param archiveFile * the uri to the archive * @param entry * the entry * @return a URI that points to the entry * * @see URI#createHierarchicalURI(String, String, String, String[], String, String) */ public static URI createURI(URI archiveFile, ZipEntry entry) { String entryName = entry.getName(); List<String> segmentList = Strings.split(entryName, '/'); String[] segments = segmentList.toArray(new String[segmentList.size()]); URI result = URI.createHierarchicalURI( "archive", archiveFile.toString() + "!", null, segments, null, null); return result; }
/** * Initializes the annotations for <b>edu.kit.ipd.sdq.mdsd.mj.classTrace.context</b>. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void createEdu_11Annotations() { String source = "edu.kit.ipd.sdq.mdsd.mj.classTrace.context"; addAnnotation (getPositionPoint_XPosition(), source, new String[] { }, new URI[] { URI.createURI(eNS_URI).appendFragment("//PositionPoint") }); addAnnotation (getPositionPoint_YPosition(), source, new String[] { }, new URI[] { URI.createURI(eNS_URI).appendFragment("//PositionPoint") }); addAnnotation (getPositionPoint_ZPosition(), source, new String[] { }, new URI[] { URI.createURI(eNS_URI).appendFragment("//PositionPoint") }); }
/** * generated instances of the tests will use this base implementation */ @Override @Test public void test() throws Exception { if (this.parserN4JS == null) { throw new Error("parser instance is null"); } String code = TestCodeProvider.getContentsFromFileEntry(config.entry, config.resourceName); if (code == null) { throw new Error("test data code instance is null"); } Analyser analyser = createAnalyzer(code); XtextResourceSet resourceSet = resourceSetProvider.get(); URI uri = URI.createURI(config.entry.getName()); // ECMA 6 test suite was changed - "use strict" is synthesized by the test runner // we do the same here if (code.contains("flags: [onlyStrict]")) { // by using the proper file extension uri = uri.trimFileExtension().appendFileExtension("n4js"); } Script script = doParse(code, uri, resourceSet, analyser); if (config.isValidator()) { // validation flag is bogus since it will produce linking issues // thus the negative tests will likely succeed for bogus reasons throw new IllegalStateException(config.entry.getName()); } // try { analyser.analyse(script, config.entry.getName(), code); // } catch (AssertionError e) { // System.out.println(config.entry.getName()); // throw e; // } }
/** * Get the OCCI core extension. */ private Extension getCoreExtension(EObject eobject) { Session session = SessionManager.INSTANCE.getSession(eobject); Resource resource = session.getSessionResource().getResourceSet().getResource( URI.createURI(OcciCoreConstants.OCCI_CORE_URI, true), true); return (Extension) resource.getContents().get(0); }
/** * Processes the contents of the given files. */ protected void processResources(String[] fileNames, Consumer<? super Resource> consumer) { for (String fileName : fileNames) { URI uri = N4Scheme.N4URI.create(fileName); Resource resource = resourceSet.getResource(uri, true); consumer.accept(resource); } }
/** * Creates an instance of the resource. * <!-- begin-user-doc --> <!-- end-user-doc --> * @generated */ @Override public Resource createResource(URI uri) { Resource result = new NullResourceResourceImpl(uri); return result; }
/** * Returns true if the given resourceURI points to a resource that is must be loaded from source into the given * resource set. A resource must be loaded from source if the resource set contains resources, that were loaded from * source and that are in the transitive closure of dependencies of the given resource. * * This is the inverse operation to {@link #canLoadFromDescription(URI, ResourceSet)}. * * @param resourceURI * the URI of the to-be-loaded resource * @param resourceSet * the target resource set * @return true, if the resource must be loaded from source. */ public boolean mustLoadFromSource(URI resourceURI, ResourceSet resourceSet) { // disable this temporarily and go back to old behavior (i.e. can always load from index) // FIXME IDE-2896 re-enable CanLoadFromDescription logic return false; // @formatter:off // // We do already know the resource. Nothing fancy to happen here. // Resource knownResource = resourceSet.getResource(resourceURI, false); // if (knownResource != null) { // return false; // } // // /* // * Iterate all the resources in the resource set and check the instances that have been loaded from source. If // * the to-be-loaded resource has a transitive dependency to any resource, that was loaded from source, we need // * to load this resource from source, too. // */ // Set<URI> sourceURIs = Sets.newHashSet(); // /* // * We load resources concurrently in tests thus we may face a concurrent modification exception here if we // * simply iterate over the resources. Therefore a classical for loop is used here. // */ // List<Resource> listOfResources = resourceSet.getResources(); // for (int i = 0, size = listOfResources.size(); i < size; i++) { // Resource existingResource = listOfResources.get(i); // if (existingResource instanceof N4JSResource) { // N4JSResource casted = (N4JSResource) existingResource; // if (!casted.isLoadedFromDescription()) { // sourceURIs.add(casted.getURI()); // } // } // } // return dependsOnAny(resourceURI, sourceURIs, getIndex(resourceSet), true); // @formatter:on }
private XtextResource getNewResource(String content, URI uri) { IParseResult parseResult = parser.parse(new StringReader(content)); ResourceSet resourceSet2 = resourceSetProvider.get(); XtextResource newXtextResource = resourceProvider.get(); newXtextResource.setURI(uri); resourceSet2.getResources().add(newXtextResource); newXtextResource.setParseResult(parseResult); return newXtextResource; }
private void addReactToBackendsCache(Resource resource) { TModule reactModule = reactHelper.lookUpReactTModule(resource); if (reactModule != null) { URI reactModuleURI = reactModule.eResource().getURI(); jsxBackends.put(ReactHelper.REACT_PROJECT_ID, reactModuleURI); } }