@Override public List<String> getErrors() { List<String> errors = new ArrayList<String>(); Throwable loadException = myModule.getModuleDescriptor().getLoadException(); if (loadException != null) { errors.add("Couldn't load module: " + loadException.getMessage()); return errors; } ModuleDescriptor descriptor = myModule.getModuleDescriptor(); // null? for (Dependency dep : descriptor.getDependencies()) { SModuleReference moduleRef = dep.getModuleRef(); if (MPSModuleRepository.getInstance().getModule(moduleRef) == null) { errors.add("Can't find dependency: " + moduleRef.getModuleName()); } } for (SModuleReference reference : descriptor.getUsedLanguages()) { if (ModuleRepositoryFacade.getInstance().getModule(reference, Language.class) == null) { errors.add("Can't find used language: " + reference.getModuleName()); } } for (SModuleReference reference : descriptor.getUsedDevkits()) { if (MPSModuleRepository.getInstance().getModule(reference) == null) { errors.add("Can't find used devkit: " + reference.getModuleName()); } } if (descriptor.getSourcePaths() != null && !myModule.isPackaged()) { for (String sourcePath : descriptor.getSourcePaths()) { IFile file = FileSystem.getInstance().getFileByPath(sourcePath); if (file == null || !file.exists()) { errors.add("Can't find source path: " + sourcePath); } } } if (descriptor.getAdditionalJavaStubPaths() != null) { for (String path : descriptor.getAdditionalJavaStubPaths()) { IFile file = FileSystem.getInstance().getFileByPath(path); if (file == null || !file.exists()) { if (new File(path).exists()) { errors.add("Idea VFS is not up-to-date. Can't find library: " + path); } else { errors.add("Can't find library: " + path); } } } } // todo: =( if (!(myModule instanceof Generator)) { errors.addAll(validateDependenciesOnGenerators()); } return errors; }
private <T> void readModuleDescriptorsFromFolder( IFile file, Set<IFile> excludes, List<T> result, boolean refreshFiles, DescriptorReader<T> reader) { if (!needProcess(file, excludes)) return; if (refreshFiles) { FileSystem.getInstance().refresh(file); } // if this is a jar dir, we need to go to modules sub dir or check for META-INF/module.xml // if this is just good old plain directory, we check every file in it if (file.getPath().endsWith(JAR + JAR_SEPARATOR)) { IFile moduleXml = file.getDescendant(META_INF).getDescendant(MODULE_XML); if (moduleXml.exists() && !moduleXml.isDirectory()) { ModuleDescriptor moduleDescriptor = loadModuleDescriptor(moduleXml); if (moduleDescriptor != null) { T descriptor = reader.read(new ModuleHandle(moduleXml, moduleDescriptor)); if (descriptor != null) { result.add(descriptor); } } } else { IFile dirInJar = file.getDescendant(MODULES_DIR); if (dirInJar.exists() && dirInJar.isDirectory()) { readModuleDescriptorsFromFolder(dirInJar, excludes, result, refreshFiles, reader); } } } else { // first, we read from files // this way all modules roots, sources/classes folders are in excludes and we do not even go // into them List<IFile> children = file.getChildren(); ArrayList<IFile> folders = new ArrayList<IFile>(); for (IFile child : children) { if (!child.isDirectory()) { readModuleDescriptorsFromFile(child, excludes, result, refreshFiles, reader); } else { folders.add(child); } } // now read from folders for (IFile child : folders) { readModuleDescriptorsFromFolder(child, excludes, result, refreshFiles, reader); } } }
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); } }
@Nullable public static IFile getRealDescriptorFile( String filePath, DeploymentDescriptor deploymentDescriptor) { if (deploymentDescriptor.getSourcesJar() != null) { IFile moduleJar = FileSystem.getInstance() .getFileByPath( filePath.substring(0, filePath.length() - SLASH_META_INF_MODULE_XML.length())); IFile sourcesJar = moduleJar.getParent().getDescendant(deploymentDescriptor.getSourcesJar()); if (sourcesJar.exists() && deploymentDescriptor.getDescriptorFile() != null) { return FileSystem.getInstance() .getFileByPath( sourcesJar.getPath() + "!/module/" + deploymentDescriptor.getDescriptorFile()); } } return null; }
public static StructureModificationLog load(IFile modelFile) { IFile refactoringsFile = getRefactoringsFile(modelFile); if (!refactoringsFile.exists()) return null; try { HistoryReaderHandler handler = new HistoryReaderHandler(); JDOMUtil.createSAXParser().parse(JDOMUtil.loadSource(refactoringsFile), handler); return handler.getResult(); } catch (SAXParseException e) { LOG.warning(refactoringsFile.getPath() + " line " + e.getLineNumber()); } catch (IOException e) { LOG.error(e); } catch (SAXException e) { LOG.error(e); } catch (ParserConfigurationException e) { LOG.error(e); } return null; }
@Override public void scheduleUpdateForWrittenFiles(Iterable<IFile> writtenFiles) { final List<IFile> newFiles = new ArrayList<IFile>(); final List<IFile> updatedFiles = new ArrayList<IFile>(); for (IFile file : writtenFiles) { if (file.exists()) { updatedFiles.add(file); } else { newFiles.add(file); } } ApplicationManager.getApplication() .invokeLater( new IdeaWriteAction( new Runnable() { @Override public void run() { // Recreate files using VFS for (IFile file : newFiles) { OutputStream out = null; try { // No need to close InputStream: it will be closed by loadFromStream() byte[] content = StreamUtil.loadFromStream(new FileInputStream(file.getPath())); out = file.openOutputStream(); out.write(content); } catch (IOException e) { LOG.error(null, e); } finally { FileUtil.closeFileSafe(out); } } // Refresh added files for (IFile file : updatedFiles) { FileSystem.getInstance().refresh(file); } } })); }
public ProcessHandler createProcess(SNode file) throws ExecutionException { if ((myGccLocation_String == null || myGccLocation_String.length() == 0) || !(new File(myGccLocation_String).exists())) { throw new ExecutionException("Could not find gcc by path " + myGccLocation_String); } IFile sourceFile = Gcc_Command.getSourceFile(file); if (!((sourceFile.exists()))) { throw new ExecutionException( "Source file " + sourceFile + " does not exist. Can't compile it."); } final IFile executableFile = Gcc_Command.getExecutableFile(file); ThreadUtils.runInUIThreadAndWait( new Runnable() { public void run() { ModelAccess.instance() .requireWrite( new Runnable() { public void run() { executableFile.getParent().mkdirs(); } }); } }); // -xc -- specifies source language (c) // -g -- save debug information return new Exec_Command() .setWorkingDirectory_File(new File(sourceFile.getParent().getAbsolutePath())) .setProgramParameters_String( "-xc" + " " + "-g" + " " + Gcc_Command.protect(sourceFile.getAbsolutePath()) + " " + "-o " + Gcc_Command.protect(executableFile.getAbsolutePath())) .createProcess(new File(myGccLocation_String)); }
// 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)); } } }
private void update(boolean force) { final Wrappers._boolean _force = new Wrappers._boolean(force); myQueue.assertSoftlyIsCommandThread(); if (!(myDifference.isEnabled())) { return; } IFile modelFile = myModelDescriptor.getSource().getFile(); if (!(modelFile.exists())) { return; } VirtualFile modelVFile = VirtualFileUtils.getVirtualFile(modelFile); if (modelVFile == null || ProjectLevelVcsManager.getInstance(myProject).getVcsFor(modelVFile) == null) { return; } FileStatus status = FileStatusManager.getInstance(myProject).getStatus(modelVFile); if (ConflictsUtil.isModelOrModuleConflicting(myModelDescriptor, myProject)) { status = FileStatus.MERGED_WITH_CONFLICTS; } if (myDifference.getChangeSet() != null) { ModelAccess.instance() .runReadAction( new Runnable() { public void run() { if (myDifference.getChangeSet().getNewModel() != myModelDescriptor.getSModel()) { _force.value = true; } } }); } if (myStatusOnLastUpdate == status && !(_force.value)) { return; } myDifference.removeChangeSet(); myStatusOnLastUpdate = status; if (FileStatus.NOT_CHANGED == status && !(_force.value)) { return; } final Wrappers._T<SModel> baseVersionModel = new Wrappers._T<SModel>(null); if (BaseVersionUtil.isAddedFileStatus(status) || ConflictsUtil.isModelOrModuleConflicting(myModelDescriptor, myProject)) { baseVersionModel.value = new jetbrains.mps.smodel.SModel(myModelDescriptor.getSModelReference()); } else { String content = BaseVersionUtil.getBaseVersionContent(modelVFile, myProject); if (content == null && status != FileStatus.NOT_CHANGED) { LOG.error("Base version content is null while file status is " + status); } if (content == null) { return; } try { baseVersionModel.value = ModelPersistence.readModel(content, false); } catch (ModelReadException e) { LOG.warning("", e); return; } } ModelAccess.instance() .runReadAction( new Runnable() { public void run() { synchronized (ChangesTracking.this) { if (!(myDisposed)) { ChangeSet changeSet = ChangeSetBuilder.buildChangeSet( baseVersionModel.value, myModelDescriptor.getSModel(), true); myDifference.setChangeSet((ChangeSetImpl) changeSet); buildCaches(); } } } }); }
@Override public boolean touch(String name, boolean isCache) { IFile file = fileForContent(name, isCache); mySavedFiles.add(file); return file.exists(); }