/*package*/ Solution createNewSolution(final IFile solutionDescriptorFile) { MPSProject mpsProject = myThis.getProject(); // Prepare files File dir = new File(solutionDescriptorFile.getAbsolutePath()).getParentFile(); if (!(dir.exists())) { dir.mkdirs(); } String solutionFileName = solutionDescriptorFile.getName(); String solutionName = solutionFileName.substring(0, solutionFileName.length() - 4); // Create // RE-2448 ModelRoot modelRoot = new ModelRoot(); modelRoot.setPrefix(""); modelRoot.setPath(solutionDescriptorFile.getParent().getAbsolutePath()); final Solution solution = Solution.createStubSolution(solutionName, solutionDescriptorFile, mpsProject, modelRoot); SolutionDescriptor solutionDescriptor = solution.getModuleDescriptor(); solutionDescriptor.setCompileInMPS(myThis.getCompileInMPS()); // Add SWC file to the classpath ModelRoot stubModelEntry = new ModelRoot(); stubModelEntry.setPath(myThis.getSourcesPath()); stubModelEntry.setManager(LanguageID.AS_MANAGER); solutionDescriptor.getStubModelEntries().add(stubModelEntry); // Add languages refs solutionDescriptor .getUsedLanguages() .add(ModuleReference.fromString(Languages.ACTION_SCRIPT_INTERNAL)); solutionDescriptor .getUsedLanguages() .add(ModuleReference.fromString(Languages.ACTION_SCRIPT_LOGGING)); solutionDescriptor .getUsedLanguages() .add(ModuleReference.fromString(Languages.ACTION_SCRIPT_ASSETS)); // Add playerglobal reference Dependency playerGlobalDependency = new Dependency(); playerGlobalDependency.setModuleRef(ModuleReference.fromString(PLAYERGLOBAL_SWC)); solutionDescriptor.getDependencies().add(playerGlobalDependency); // Save the solution descriptor ModelAccess.instance() .writeFilesInEDT( new Runnable() { public void run() { solution.save(); } }); mpsProject.addProjectModule(solution); return solution; }
public ASNewLibraryFromSourcesDialogContentPane() { this.myThis = this; ASNewLibraryFromSourcesDialogContentPane component = this; component.setLayout(new GridLayout(4, 1)); component.add(this.createComponent0()); component.add(this.createComponent1()); component.add(this.createComponent2()); component.add(this.createComponent3()); this.myEvents.initialize(); myThis.setSourcesPath(""); myThis.myPath0.setName("Path"); myThis.myPath0.setMode(TreeFileChooser.MODE_DIRECTORIES); }
protected boolean checkLibraryName(String libraryName) { if (MPSModuleRepository.getInstance().getModuleByUID(libraryName) != null) { myThis.getDialog().setErrorText("Duplicate library name: " + libraryName); return false; } return true; }
/*package*/ void createNewLib( final String descriptorPath, final List<SModelDescriptor> modelDescriptors) { ModelAccess.instance() .runWriteActionWithProgressSynchronously( new Progressive() { public void run(ProgressIndicator indicator) { indicator.setIndeterminate(true); myThis.setResult( myThis.createNewSolution( FileSystem.getInstance().getFileByPath(descriptorPath))); // RE-912 for (final SModelDescriptor sModelDescriptor : myResult.getOwnModelDescriptors()) { if (sModelDescriptor instanceof BaseStubModelDescriptor) { BaseStubModelDescriptor stubModelDescriptor = (BaseStubModelDescriptor) sModelDescriptor; // RF-616 if (stubModelDescriptor.getLoadingState() == ModelLoadingState.NOT_LOADED) { ModelRootManager asStubManager = LanguageID.AS_MANAGER; IModelRootManager modelRootManager = null; try { modelRootManager = BaseStubModelRootManager.create( asStubManager.getModuleId(), asStubManager.getClassName()); } catch (ManagerNotFoundException e) { throw new RuntimeException( "Can't locate the AS sources stub model root manager " + asStubManager); } stubModelDescriptor.setModelRootManager(modelRootManager); } modelDescriptors.add(sModelDescriptor); } } } }, "Creating", false, myThis.getProject().getProject()); }
/*package*/ void onCancel() { myThis.getDialog().dispose(); }
/*package*/ void onOk() { if (myThis.getSourcesPath().length() == 0) { myThis.getDialog().setErrorText("Enter the sources path"); return; } File sourcesDir = new File(myThis.getSourcesPath()); if (!(sourcesDir.exists())) { myThis.getDialog().setErrorText("Specified sources dir doesn't exist"); return; } String moduleName = myThis.myModuleNameField.getText(); // RE-3532 if (!SolutionUtils.isValidModuleName(moduleName)) { myThis.getDialog().setErrorText("Invalid module name"); return; } if (moduleName.isEmpty()) { myThis.getDialog().setErrorText("Enter the module name"); return; } final String libraryName = moduleName; if (!checkLibraryName(libraryName)) { return; } String projectPath = FileUtil.getCanonicalPath(myThis.getProject().getProjectFile().getParentFile()); String solutionDirPath = projectPath + File.separator + "modules" + File.separator + libraryName; String message = NewModuleCheckUtil.checkModuleDirectory( new File(solutionDirPath), MPSExtentions.DOT_SOLUTION, "Module"); if (message != null) { myThis.getDialog().setErrorText(message); return; } final String descriptorPath = solutionDirPath + File.separator + libraryName + MPSExtentions.DOT_SOLUTION; myThis.getDialog().dispose(); SolutionUtils.refreshModuleFiles(descriptorPath); final List<SModelDescriptor> modelDescriptors = new ArrayList<SModelDescriptor>(); execute(descriptorPath, modelDescriptors); // RE-3181 ModelAccess.instance() .runWriteActionInCommand( new Runnable() { @Override public void run() { try { SWCStubsRegistry.setAvoidIndexing(true); SModelOperations.validateLanguagesAndImportsNew(modelDescriptors, myResult); } finally { SWCStubsRegistry.setAvoidIndexing(false); StubSolutionUtils.invalidateStubSolutionCaches(myResult); } } }, getProject().getProject()); }