protected Iterable<ModelRoot> loadRoots() { ModuleDescriptor descriptor = getModuleDescriptor(); if (descriptor == null) { return Collections.emptyList(); } List<ModelRoot> result = new ArrayList<ModelRoot>(); for (ModelRootDescriptor modelRoot : descriptor.getModelRootDescriptors()) { try { ModelRootFactory modelRootFactory = PersistenceFacade.getInstance().getModelRootFactory(modelRoot.getType()); if (modelRootFactory == null) { LOG.error( "Unknown model root type: `" + modelRoot.getType() + "'. Requested by: " + this); continue; } ModelRoot root = modelRootFactory.create(); Memento mementoWithFS = new MementoWithFS(modelRoot.getMemento(), myFileSystem); root.load(mementoWithFS); result.add(root); } catch (Exception e) { LOG.error( "Error loading models from root with type: `" + modelRoot.getType() + "'. Requested by: " + this, e); } } return result; }
private void doUpdateModelsSet() { assertCanChange(); for (SModel model : getModels()) { if (model instanceof EditableSModel && ((EditableSModel) model).isChanged()) { LOG.warn( "Trying to reload module " + getModuleName() + " which contains a non-saved model '" + model.getName() + "'. To prevent data loss, MPS will not update models in this module. " + "Please save your work and restart MPS. See MPS-18743 for details."); return; } } Set<ModelRoot> toRemove = new HashSet<ModelRoot>(mySModelRoots); Set<ModelRoot> toUpdate = new HashSet<ModelRoot>(mySModelRoots); Set<ModelRoot> toAttach = new HashSet<ModelRoot>(); for (ModelRoot root : loadRoots()) { try { if (mySModelRoots.contains(root)) { toRemove.remove(root); } else { toAttach.add(root); } } catch (Exception e) { LOG.error( "Error loading models from root `" + root.getPresentation() + "'. Requested by: " + this, e); } } toUpdate.removeAll(toRemove); for (ModelRoot modelRoot : toRemove) { ((ModelRootBase) modelRoot).dispose(); } mySModelRoots.removeAll(toRemove); for (ModelRoot modelRoot : toAttach) { ModelRootBase rootBase = (ModelRootBase) modelRoot; rootBase.setModule(this); mySModelRoots.add(modelRoot); rootBase.attach(); } for (ModelRoot modelRoot : toUpdate) { ((ModelRootBase) modelRoot).update(); } }
public SModelRootEntry(ModelRoot modelRoot) { if (!(modelRoot instanceof SModelRoot)) throw new ClassCastException( "Can't convert " + modelRoot.getClass().getCanonicalName() + " to " + SModelRoot.class.getCanonicalName()); myModelRoot = (SModelRoot) modelRoot; }
@Override protected Iterable<ModelRoot> loadRoots() { Set<ModelRoot> result = new HashSet<ModelRoot>(); for (String stub : myClassPaths) { ModelRoot modelRoot = PersistenceFacade.getInstance() .getModelRootFactory(PersistenceRegistry.JAVA_CLASSES_ROOT) .create(); if (modelRoot instanceof FileBasedModelRoot) { ((FileBasedModelRoot) modelRoot).setContentRoot(stub); ((FileBasedModelRoot) modelRoot).addFile(FileBasedModelRoot.SOURCE_ROOTS, stub); } else { LOG.error( "Unexpected model root type: " + modelRoot.getType() + " but need 'java_classes' model root"); } result.add(modelRoot); } return result; }