/** * This will search throughout the resourceSet(s) containing the loaded modules for modules going * by name <code>moduleName</code>. * * @param moduleName Name of the module we seek. * @return The Set of all modules loaded within the generation ResourceSet going by the name * <code>moduleName</code>. */ private Set<URI> searchResourceSetForMatches(String moduleName) { final Set<URI> candidates = new CompactLinkedHashSet<URI>(); final List<ResourceSet> resourceSets = new ArrayList<ResourceSet>(); for (Module module : parentEnvironment.getCurrentModules()) { if (module != null && module.eResource() != null) { final ResourceSet resourceSet = module.eResource().getResourceSet(); if (!resourceSets.contains(resourceSet)) { resourceSets.add(resourceSet); } } } for (ResourceSet resourceSet : resourceSets) { for (Resource resource : resourceSet.getResources()) { if (IAcceleoConstants.EMTL_FILE_EXTENSION.equals(resource.getURI().fileExtension())) { String candidateName = resource.getURI().lastSegment(); candidateName = candidateName.substring(0, candidateName.lastIndexOf('.')); if (moduleName.equals(candidateName)) { candidates.add(resource.getURI()); } } } } return candidates; }
/** * This will be called if the parent {@link URIConverter} didn't know how to convert the given * URI. * * @param uri The uri we are to normalize. * @return The normalized form of <code>uri</code>. */ private URI dynamicNormalize(URI uri) { URI normalized = getURIMap().get(uri); if (normalized == null && EMFPlugin.IS_ECLIPSE_RUNNING) { BundleURLConverter conv = new BundleURLConverter(uri.toString()); if (conv.resolveBundle() != null) { normalized = URI.createURI(conv.resolveAsPlatformPlugin()); } } if (normalized == null && (!IAcceleoConstants.EMTL_FILE_EXTENSION.equals(uri.fileExtension()) || !"file".equals(uri.scheme()))) { // $NON-NLS-1$ normalized = super.normalize(uri); } if (normalized != null) { getURIMap().put(uri, normalized); return normalized; } String moduleName = uri.lastSegment(); moduleName = moduleName.substring(0, moduleName.lastIndexOf('.')); Set<URI> candidateURIs = new CompactLinkedHashSet<URI>(); // Search matching module in the current generation context Set<Module> candidateModules = searchCurrentModuleForCandidateMatches(moduleName); for (Module candidateModule : candidateModules) { if (candidateModule.eResource() != null) { candidateURIs.add(candidateModule.eResource().getURI()); } } // If there were no matching module, search in their ResourceSet(s) if (candidateURIs.size() == 0) { candidateURIs.addAll(searchResourceSetForMatches(moduleName)); } if (candidateURIs.size() == 1) { normalized = candidateURIs.iterator().next(); } else if (candidateURIs.size() > 0) { normalized = findBestMatchFor(uri, candidateURIs); } // There is a chance that our match should itself be normalized if ((normalized == null || "file".equals(normalized.scheme())) // $NON-NLS-1$ && EMFPlugin.IS_ECLIPSE_RUNNING) { BundleURLConverter conv = new BundleURLConverter(uri.toString()); if (conv.resolveBundle() != null) { normalized = URI.createURI(conv.resolveAsPlatformPlugin()); } else { String uriToString = uri.toString(); if (uriToString.indexOf('#') > 0) { uriToString = uriToString.substring(0, uriToString.indexOf('#')); } String resolvedPath = AcceleoWorkspaceUtil.resolveInBundles(uriToString); if (resolvedPath != null) { normalized = URI.createURI(resolvedPath); } } } if (normalized == null) { normalized = super.normalize(uri); } if (!uri.equals(normalized)) { getURIMap().put(uri, normalized); } return normalized; }