/** * Convert path from sources module descriptor for using on distribution /classes && /classes_gen * converts to bundle home path * * @param originalPath Original path from sources module descriptor * @return Converted path, null if path meaningless on packaged module */ @Nullable private String convertPath( String originalPath, IFile bundleHome, IFile sourcesDescriptorFile, ModuleDescriptor descriptor) { MacroHelper macroHelper = MacrosFactory.forModuleFile(sourcesDescriptorFile); String canonicalPath = FileUtil.getCanonicalPath(originalPath).toLowerCase(); // /classes && /classes_gen hack String suffix = descriptor.getCompileInMPS() ? CLASSES_GEN : CLASSES; if (canonicalPath.endsWith(suffix)) { // MacrosFactory based on original descriptor file because we use original descriptor file for // ModuleDescriptor reading, so all paths expanded to original descriptor file String classes = macroHelper.expandPath("${module}/" + suffix); if (FileUtil.getCanonicalPath(classes).equalsIgnoreCase(canonicalPath)) { return bundleHome.getPath(); } } else if (FileUtil.getCanonicalPath(bundleHome.getPath()).equalsIgnoreCase(canonicalPath)) { return bundleHome.getPath(); } // ${mps_home}/lib String mpsHomeLibPath = FileUtil.getCanonicalPath(PathManager.getHomePath() + File.separator + "lib").toLowerCase(); if (canonicalPath.startsWith(mpsHomeLibPath)) { return canonicalPath; } // we used to keep originalPath if it has a macro not known to MPS here. // However, the check has been deprecated in 2012 and thus removed. I'm not 100% sure what // 'meaningless' in the contract of the method means. Of course, unknown macros make no sense // for us // and thus null is legitimate answer, OTOH, custom macros might have a lot of meaning to // someone else. // // ignore paths starts from ${module}/${project} etc return null; }
@Override protected void customizeCellRenderer( JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) { setPaintFocusBorder(false); setFocusBorderAroundIcon(true); setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); if (value != null) { String path = FileUtil.getCanonicalPath((String) value); if (!(new File(path)).exists()) { append(path, SimpleTextAttributes.ERROR_ATTRIBUTES); } else { append(path); } } }
/*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()); }