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; }
public TempModule(Set<ModelRootDescriptor> modelRoots) { SModuleId id = ModuleId.regular(); SModuleReference reference = new ModuleReference("TempModule" + id, id); setModuleReference(reference); myDescriptor = new ModuleDescriptor(); myDescriptor.getModelRootDescriptors().addAll(modelRoots); setModuleDescriptor(myDescriptor, false); }
private void processExcludes( @NotNull IFile descriptorFile, ModuleDescriptor descriptor, Set<IFile> excludes) { if (descriptor == null || descriptorFile.isReadOnly()) { return; } for (String p : descriptor.getSourcePaths()) { excludes.add(FileSystem.getInstance().getFileByPath(p)); } IFile genPath = ProjectPathUtil.getGeneratorOutputPath(descriptorFile.getParent(), descriptor); if (genPath != null) { excludes.add(genPath); if (!descriptorFile.isReadOnly()) { FileSystem.getInstance().getFileByPath(FileGenerationUtil.getCachesPath(genPath.getPath())); } } IFile testsGenPath = ProjectPathUtil.getGeneratorTestsOutputPath(descriptorFile, descriptor); if (testsGenPath != null) { excludes.add(testsGenPath); if (!descriptorFile.isReadOnly()) { FileSystem.getInstance() .getFileByPath(FileGenerationUtil.getCachesPath(testsGenPath.getPath())); } } for (ModelRootDescriptor rootDescriptor : descriptor.getModelRootDescriptors()) { ModelRoot root = rootDescriptor.getRoot(); if (root == null || root.getManager() != null && root.getManager() != LanguageID.JAVA_MANAGER) { continue; } excludes.add(FileSystem.getInstance().getFileByPath(root.getPath())); } IFile classesGen = ProjectPathUtil.getClassesGenFolder(descriptorFile.getParent(), false); if (classesGen != null) { excludes.add(classesGen); } // todo: specify what kind of descriptor can be input for this method if (descriptor instanceof LanguageDescriptor) { IFile generatorClassesGen = ProjectPathUtil.getClassesGenFolder(descriptorFile.getParent(), true); if (generatorClassesGen != null) { excludes.add(generatorClassesGen); } } for (String entry : descriptor.getAdditionalJavaStubPaths()) { excludes.add(FileSystem.getInstance().getFileByPath(entry)); } }
// 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)); } } }