@Override public void attach(@NotNull SRepository repository) { super.attach(repository); if (myDescriptorFile != null) { myFileSystem.addListener(this); } initFacetsAndModels(); }
public void rename(@NotNull String newName) { SModuleReference oldRef = getModuleReference(); renameModels(getModuleName(), newName, true); save(); // see MPS-18743, need to save before setting descriptor ModuleDescriptor descriptor = getModuleDescriptor(); if (myDescriptorFile != null) { // fixme AP: this looks awful -- I agree; the right way is to have IFile something immutable // fixme or just work in <code>WatchedRoots</code> by IFile (not by String) and listen for // rename myFileSystem.removeListener(this); myDescriptorFile.rename(newName + "." + FileUtil.getExtension(myDescriptorFile.getName())); myFileSystem.addListener(this); } if (descriptor != null) { descriptor.setNamespace(newName); setModuleDescriptor(descriptor); } fireModuleRenamed(oldRef); }
@Override public void dispose() { assertCanChange(); LOG.trace("Disposing the module " + this); myFileSystem.removeListener(this); for (ModuleFacetBase f : myFacets) { f.dispose(); } myFacets.clear(); for (ModelRoot m : mySModelRoots) { ((ModelRootBase) m).dispose(); } mySModelRoots.clear(); super.dispose(); }
// 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)); } } }