/** * Handles the conversion for a node. * * @param node the test case * @throws StopConversionException */ private void handleNode(INodePO node) throws StopConversionException { if (progressMonitor.isCanceled()) { throw new StopConversionException(true); } progressMonitor.worked(1); NodeInfo info = uuidToNodeInfoMap.get(node.getGuid()); File file = new File(info.getFqFileName()); if (node instanceof ICategoryPO) { file.mkdirs(); for (INodePO child : node.getUnmodifiableNodeList()) { handleNode(child); } } else { try { file.getParentFile().mkdirs(); file.createNewFile(); NodeGenerator gen = new NodeGenerator(); try { String content = gen.generate(info); writeContentToFile(file, content); } catch (MinorConversionException e) { Plugin.getDefault() .writeLineToConsole( NLS.bind(Messages.InvalidNode, new String[] {node.getName(), e.getMessage()}), true); file.delete(); } } catch (IOException e) { ErrorHandlingUtil.createMessageDialog( new JBException(e.getMessage(), e, MessageIDs.E_FILE_NO_PERMISSION)); throw new StopConversionException(); } } }
/** * Maps a node's UUID to the name of its corresponding class to generate * * @param node the node * @param basePath the base path * @throws StopConversionException */ private void determineClassNamesForNode(INodePO node, String basePath) throws StopConversionException { workUnits++; if (node instanceof ICategoryPO) { ICategoryPO category = (ICategoryPO) node; String path = StringConstants.EMPTY; try { path = basePath + StringConstants.SLASH + Utils.translateToPackageName(category); } catch (InvalidNodeNameException e) { displayErrorForInvalidName(category); throw new StopConversionException(); } for (NodeInfo nodeInfo : uuidToNodeInfoMap.values()) { if (nodeInfo.getFqFileName().equals(path)) { displayErrorForDuplicate(node); throw new StopConversionException(); } } NodeInfo nodeInfo = new NodeInfo(path, node, genPackage, defaultToolkit); uuidToNodeInfoMap.put(node.getGuid(), nodeInfo); for (INodePO child : node.getUnmodifiableNodeList()) { determineClassNamesForNode(child, path); } } else { String className = StringConstants.EMPTY; try { className = Utils.determineClassName(node); } catch (InvalidNodeNameException e) { displayErrorForInvalidName(node); throw new StopConversionException(); } String fileName = basePath + StringConstants.SLASH + className + ".java"; // $NON-NLS-1$ for (NodeInfo nodeInfo : uuidToNodeInfoMap.values()) { if (nodeInfo.getFqFileName().equals(fileName)) { Plugin.getDefault() .writeErrorLineToConsole( "Duplicate filename error:" + fileName, true); // $NON-NLS-1$ } } NodeInfo nodeInfo = new NodeInfo(fileName, node, genPackage, defaultToolkit); uuidToNodeInfoMap.put(node.getGuid(), nodeInfo); } }
/** {@inheritDoc} */ public void run(IProgressMonitor monitor) { progressMonitor = monitor; IProjectPO project = GeneralStorage.getInstance().getProject(); progressMonitor.setTaskName(Messages.PreparingConvertProjectTaskName); String basePath = genPath + StringConstants.SLASH + genPackage.replace(StringConstants.DOT, StringConstants.SLASH); uuidToNodeInfoMap = new HashMap<String, NodeInfo>(); NodeInfo.setUuidToNodeInfoMap(uuidToNodeInfoMap); projects = new HashSet<IProjectPO>(); workUnits = 0; if (project != null) { defaultToolkit = determineDefaultToolkit(project); addProjectsToConvert(project); try { for (IProjectPO p : projects) { determineClassNamesForProject(p, basePath); } progressMonitor.beginTask(Messages.PreparingConvertProjectTaskName, workUnits); for (IProjectPO p : projects) { progressMonitor.setTaskName(NLS.bind(Messages.ConvertProjectTaskName, p.getName())); handleProject(p, basePath); } } catch (StopConversionException e) { progressMonitor.setCanceled(true); if (!e.wasManuallyTriggered()) { ErrorHandlingUtil.createMessageDialog( new JBException(e.getMessage(), e, MessageIDs.E_CONVERSION_ABORTED_ERROR)); } return; } } progressMonitor.done(); }