protected void readModules(FileMPSProject.ProjectDescriptor projDesc) { myErrors = null; // load solutions Set<ModuleReference> existingModules = getModuleReferences(); for (Path modulePath : projDesc.getModules()) { String path = modulePath.getPath(); IFile descriptorFile = FileSystem.getInstance().getFileByPath(path); if (descriptorFile.exists()) { ModuleDescriptor descriptor = ModulesMiner.getInstance().loadModuleDescriptor(descriptorFile); if (descriptor != null) { ModulesMiner.ModuleHandle moduleHandle = new ModulesMiner.ModuleHandle(descriptorFile, descriptor); IModule m = ModuleRepositoryFacade.createModule(moduleHandle, this); ModuleReference moduleReference = m.getModuleReference(); if (!(existingModules.remove(moduleReference))) { super.addModule(moduleReference); } } else { error("Can't load module from " + descriptorFile.getPath() + " Unknown file type."); } } else { error("Can't load module from " + descriptorFile.getPath() + " File doesn't exist."); } } for (ModuleReference ref : existingModules) { super.removeModule(ref); } }
private Iterable<SModule> loadModule(String modulePath) { final List<ModulesMiner.ModuleHandle> collectModules = ModulesMiner.getInstance() .collectModules(FileSystem.getInstance().getFileByPath(modulePath), false); if (collectModules.isEmpty()) { return ListSequence.fromList(new ArrayList<SModule>()); } return ModelAccess.instance() .runWriteAction( new Computable<List<SModule>>() { public List<SModule> compute() { List<SModule> modules = new ArrayList<SModule>(); BaseMPSModuleOwner owner = new BaseMPSModuleOwner() {}; for (ModulesMiner.ModuleHandle moduleHandle : collectModules) { SModule module = ModuleRepositoryFacade.createModule(moduleHandle, owner); if (module != null) { modules.add(module); } } CleanupManager.getInstance().cleanup(); ClassLoaderManager.getInstance().reloadAll(new EmptyProgressMonitor()); return modules; } }); }
@Override public void update(ProgressMonitor monitor, FileSystemEvent event) { boolean changed = false; for (IFile f : event.getChanged()) { if (ModulesMiner.getInstance().isModuleFile(f)) { changed = true; } } for (IFile f : event.getCreated()) { if (ModulesMiner.getInstance().isModuleFile(f)) { changed = true; } } if (changed) { update(false); } }
void update(boolean refreshFiles) { ModelAccess.assertLegalWrite(); List<ModuleHandle> moduleHandles = Collections.unmodifiableList(ModulesMiner.getInstance().collectModules(file, refreshFiles)); myHandles.set(moduleHandles); List<SModule> loaded = new ArrayList<SModule>(); for (ModuleHandle moduleHandle : moduleHandles) { SModule module = ModuleRepositoryFacade.createModule(moduleHandle, this); if (module != null) { loaded.add(module); } } for (SModule module : loaded) { ((AbstractModule) module).onModuleLoad(); } }
// FIXME: MPS-19756 // TODO: get rid of this code - generate the deployment descriptor during build process protected void updatePackagedDescriptor() { // things to do: // 1) load/prepare stub libraries (getAdditionalJavaStubPaths) from sources descriptor // 2) load/prepare stub model roots from sources descriptor // 3) load libraries from deployment descriptor (/classes_gen ?) // possible cases: // 1) without deployment descriptor (nothing to do; todo: ?) // 2) with deployment descriptor, without sources (to do: 3) // 3) with deployment descriptor, with sources (to do: 1,2,3) if (!isPackaged()) { return; } ModuleDescriptor descriptor = getModuleDescriptor(); if (descriptor == null) { return; } DeploymentDescriptor deplDescriptor = descriptor.getDeploymentDescriptor(); if (deplDescriptor == null) { return; } final IFile bundleHomeFile = getDescriptorFile().getBundleHome(); if (bundleHomeFile == null) { return; } IFile bundleParent = bundleHomeFile.getParent(); if (bundleParent == null || !bundleParent.exists()) { return; } IFile sourcesDescriptorFile = ModulesMiner.getSourceDescriptorFile(getDescriptorFile(), deplDescriptor); if (sourcesDescriptorFile == null) { // todo: for now it's impossible assert descriptor instanceof DeploymentDescriptor; } else { assert !(descriptor instanceof DeploymentDescriptor); } // 1 && 2 if (sourcesDescriptorFile != null) { // stub libraries // todo: looks like module.xml contains info about model libs // ignore stub libraries from source module descriptor, use libs from DeploymentDescriptor descriptor.getAdditionalJavaStubPaths().clear(); // stub model roots List<ModelRootDescriptor> toRemove = new ArrayList<ModelRootDescriptor>(); List<ModelRootDescriptor> toAdd = new ArrayList<ModelRootDescriptor>(); for (ModelRootDescriptor rootDescriptor : descriptor.getModelRootDescriptors()) { String rootDescriptorType = rootDescriptor.getType(); if (rootDescriptorType.equals(PersistenceRegistry.JAVA_CLASSES_ROOT)) { // trying to load old format from deployment descriptor String pathElement = rootDescriptor.getMemento().get("path"); boolean update = false; Memento newMemento = new MementoImpl(); if (pathElement != null) { // See JavaSourceStubModelRoot & JavaClassStubsModelRoot load methods need to replace // with super String convertedPath = convertPath(pathElement, bundleHomeFile, sourcesDescriptorFile, descriptor); if (convertedPath != null) { newMemento.put("path", convertedPath); update = true; } } else { // trying to load new format : replacing paths like **.jar!/module -> String contentPath = rootDescriptor.getMemento().get(FileBasedModelRoot.CONTENT_PATH); List<String> paths = new LinkedList<String>(); for (Memento sourceRoot : rootDescriptor.getMemento().getChildren(FileBasedModelRoot.SOURCE_ROOTS)) { paths.add(contentPath + File.separator + sourceRoot.get("location")); } newMemento.put(FileBasedModelRoot.CONTENT_PATH, bundleParent.getPath()); Memento newMementoChild = newMemento.createChild(FileBasedModelRoot.SOURCE_ROOTS); for (String path : paths) { String convertedPath = convertPath(path, bundleHomeFile, sourcesDescriptorFile, descriptor); if (convertedPath != null) { newMementoChild.put( "location", convertedPath.replace(newMemento.get(FileBasedModelRoot.CONTENT_PATH), "")); update = true; } } } if (update) { toAdd.add(new ModelRootDescriptor(rootDescriptorType, newMemento)); } toRemove.add(rootDescriptor); } } descriptor.getModelRootDescriptors().removeAll(toRemove); descriptor.getModelRootDescriptors().addAll(toAdd); } // 3 for (String jarFile : deplDescriptor.getLibraries()) { IFile jar = jarFile.startsWith("/") ? myFileSystem.getFile(PathManager.getHomePath() + jarFile) : bundleParent.getDescendant(jarFile); if (jar.exists()) { String path = jar.getPath(); descriptor.getAdditionalJavaStubPaths().add(path); descriptor.getModelRootDescriptors().add(ModelRootDescriptor.getJavaStubsModelRoot(jar)); } } }