/** * Closes the managed method library. * * @return a method library * @throw <code>LibraryServiceException</code> if an error occurs while performing the operation */ public void closeMethodLibrary() throws LibraryServiceException { if (debug) { String msg = "library=" + library + ", memory on entry=" //$NON-NLS-1$ //$NON-NLS-2$ + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); DebugTrace.print(this, "closeMethodLibrary", msg); // $NON-NLS-1$ } // String libPath = LibraryService.getInstance() // .getCurrentMethodLibraryPath(); File libFile = new File(library.eResource().getURI().toFileString()); String libPath = libFile.getParentFile().getAbsolutePath(); // remove the configuration managers associated with this library LibraryService.getInstance().removeConfigurationManagers(library); removeResourceChangedListeners(); // Clear the temp layout resources. LayoutResources.clear(); Suppression.clearCachedSuppressions(); TngUtil.umaItemProviderAdapterFactory.dispose(); ILibraryResourceSet resourceSet = (ILibraryResourceSet) editingDomain.getResourceSet(); resourceSet.unload(); try { // Close the method library project file. MethodLibraryProject.closeProject(libPath, null); } catch (Exception e) { throw new LibraryServiceException(e); } RefreshJob.getInstance().reset(); // Activates the garbage collector. Runtime.getRuntime().gc(); if (debug) { String msg = "library=" + library + ", memory on exit=" //$NON-NLS-1$ //$NON-NLS-2$ + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); DebugTrace.print(this, "closeMethodLibrary", msg); // $NON-NLS-1$ } }
/** Analyzes the imported library with respect to the base library. */ public void analyze(IProgressMonitor monitor) { try { if (monitor != null) { monitor.setTaskName(ImportResources.ConfigurationImportService_MSG0); } data.getErrorInfo().clear(); // Prepare the library files. String path = data.llData.getParentFolder(); if (path.indexOf(File.separator + LibraryDocument.libraryFile) < 0) { path += File.separator + LibraryDocument.libraryFile; } File importingLibPath = new File(path); boolean isLibraryFile = true; if (!importingLibPath.exists()) { importingLibPath = new File(importingLibPath.getParentFile(), LibraryDocument.exportFile); isLibraryFile = false; } if (!importingLibPath.exists()) { data.getErrorInfo() .addError( NLS.bind( ImportResources.ConfigurationImportService_MSG1, importingLibPath.getParent())); return; } boolean handleVersion = isLibraryFile; if (handleVersion) { upGradeInfo = new ConfigurationImportService.UpgradeInfo( UpgradeCallerInfo.upgradeImportConfig, importingLibPath); if (!handleToolVersion(importingLibPath, upGradeInfo)) { String errMsg = upGradeInfo.getErrorMsg(); if (errMsg == null || errMsg.length() == 0) { errMsg = ImportResources.ImportConfigurationWizard_ERR_Import_configuration; } data.getErrorInfo().addError(NLS.bind(errMsg, importingLibPath.getParent())); return; } if (upGradeInfo.getCopiedLibFile() != null) { importingLibPath = upGradeInfo.getCopiedLibFile(); } } importingLibDoc = new LibraryDocument(importingLibPath); boolean isConfigSpecs = importingLibDoc.isConfigSpecsOnly(); if (isConfigSpecs) { specsMgr = new ConfigSpecsImportManager(); // Scan the library file for configuration information. data.specs = specsMgr.getConfigSpecs(importingLibDoc); } else { if (!isLibraryFile) { data.getErrorInfo() .addError( NLS.bind( ImportResources.ConfigurationImportService_MSG1, importingLibPath.getParent())); return; } data.specs = null; // Open the library and compare the difference. // need to open and close the library to have the project resources initialized properly String libDir = importingLibPath.getParentFile().getAbsolutePath(); String projectName = "Configuration Import Project (" //$NON-NLS-1$ + Integer.toHexString(libDir.hashCode()) + ")"; //$NON-NLS-1$ MethodLibraryProject.openProject(libDir, projectName, monitor); try { MethodLibrary importLibraty = LibraryUtil.loadLibrary(importingLibPath.getAbsolutePath()); MethodLibrary baseLibrary = LibraryService.getInstance().getCurrentMethodLibrary(); handleTypeChanges(baseLibrary, importLibraty); String baseLibDir = null; try { // Not neccessary, but prevent introducing any potential regression due to this // change File bFile = new File(baseLibrary.eResource().getURI().toFileString()).getParentFile(); ; baseLibDir = bFile.getAbsolutePath(); } catch (Throwable e) { } if (libDir.equalsIgnoreCase(baseLibDir)) { data.getErrorInfo() .addError( NLS.bind( ImportResources.ConfigurationImportService_MSG2, importingLibPath.getParent())); return; } fixImportLibrarySystemPackageGUIDs(baseLibrary, importLibraty); diffMgr = new LibraryDiffManager(baseLibrary, importLibraty); diffMgr.buildDiffTree(); if (localDebug) { diffMgr.rootDiffTree.debugDump(); } } catch (RuntimeException e) { // TODO Auto-generated catch block e.printStackTrace(); } MethodLibraryProject.closeProject(libDir, monitor); MethodLibraryProject.deleteProject(libDir, monitor); } } catch (Exception ex) { ex.printStackTrace(); } }