Search in sources :

Example 1 with ProjectActionList

use of net.sourceforge.usbdm.packageParser.ProjectActionList in project usbdm-eclipse-plugins by podonoghue.

the class ProcessProjectActions method process.

public static void process(final Wizard wizard, final IProject projectHandle, final Device device, final ProjectActionList actionList, final Map<String, String> variableMap, final IProgressMonitor monitor) throws Exception {
    // System.err.println("ProcessProjectActions.process("+device.getName()+") =============================================");
    if (actionList == null) {
        return;
    }
    final ApplyOptions applyOptions = new ApplyOptions(projectHandle);
    class MyVisitor implements ProjectActionList.Visitor {

        @Override
        public Result applyTo(ProjectAction action, Value result, IProgressMonitor monitor) {
            // System.err.println("ProjectCustomAction: "+action.toString());
            try {
                if (action instanceof FileAction) {
                    new AddTargetFiles().process(projectHandle, variableMap, (FileAction) action, monitor);
                } else if (action instanceof DeleteResourceAction) {
                    new DeleteResource().process(projectHandle, variableMap, (DeleteResourceAction) action, monitor);
                } else if (action instanceof CreateFolderAction) {
                    ProjectUtilities.createFolder(projectHandle, variableMap, (CreateFolderAction) action, monitor);
                } else if (action instanceof ProjectOption) {
                    applyOptions.process(variableMap, (ProjectOption) action, monitor);
                } else if (action instanceof ExcludeAction) {
                    ProjectUtilities.excludeItem(projectHandle, (ExcludeAction) action, monitor);
                } else if (action instanceof ProjectActionList) {
                    ProjectActionList projectActionList = (ProjectActionList) action;
                    return new Result(projectActionList.appliesTo(device, variableMap) ? Status.CONTINUE : Status.PRUNE);
                } else if (action instanceof ProjectCustomAction) {
                    ProjectCustomAction customAction = (ProjectCustomAction) action;
                    Class<?> actionClass = Class.forName(customAction.getclassName());
                    Object clsInstance = actionClass.newInstance();
                    if (!(clsInstance instanceof CustomAction)) {
                        throw new Exception("Custom action does not implement required interface");
                    }
                    ((CustomAction) clsInstance).action(projectHandle, variableMap, monitor, customAction.getValue());
                } else if (action instanceof ProjectConstant) {
                // Ignore as already added to paramMap
                } else if (action instanceof WizardGroup) {
                // Ignore as already added to paramMap
                } else if (action instanceof ProjectVariable) {
                // Ignore as already added to paramMap
                } else if (action instanceof WizardPageInformation) {
                // Ignore as only applicable to wizard dialogues
                } else {
                    throw new Exception("Unexpected action class: " + action.getClass());
                }
            } catch (Exception e) {
                // e.printStackTrace();
                StringBuffer sb = new StringBuffer();
                sb.append("Unable to process Action " + action.toString() + "\n");
                sb.append("Action id = " + action.getId() + "\n");
                sb.append("Action owned by = " + action.getOwnerId() + "\n");
                sb.append(e.getMessage());
                return new Result(new Exception(sb.toString()));
            }
            return new Result(Status.CONTINUE);
        }
    }
    ;
    MyVisitor visitor = new MyVisitor();
    Result res = actionList.visit(visitor, null, monitor);
    if (res.getStatus() == Status.EXCEPTION) {
        throw res.getException();
    }
}
Also used : AddTargetFiles(net.sourceforge.usbdm.cdt.utilties.AddTargetFiles) Result(net.sourceforge.usbdm.packageParser.ProjectActionList.Visitor.Result) WizardPageInformation(net.sourceforge.usbdm.packageParser.WizardPageInformation) ProjectAction(net.sourceforge.usbdm.packageParser.ProjectAction) CreateFolderAction(net.sourceforge.usbdm.packageParser.CreateFolderAction) ProjectCustomAction(net.sourceforge.usbdm.packageParser.ProjectCustomAction) ProjectVariable(net.sourceforge.usbdm.packageParser.ProjectVariable) ProjectConstant(net.sourceforge.usbdm.packageParser.ProjectConstant) WizardGroup(net.sourceforge.usbdm.packageParser.WizardGroup) DeleteResourceAction(net.sourceforge.usbdm.packageParser.DeleteResourceAction) ProjectCustomAction(net.sourceforge.usbdm.packageParser.ProjectCustomAction) ApplyOptions(net.sourceforge.usbdm.cdt.utilties.ApplyOptions) DeleteResource(net.sourceforge.usbdm.cdt.utilties.DeleteResource) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Value(net.sourceforge.usbdm.packageParser.ProjectActionList.Value) ProjectOption(net.sourceforge.usbdm.packageParser.ProjectOption) ExcludeAction(net.sourceforge.usbdm.packageParser.ExcludeAction) ProjectActionList(net.sourceforge.usbdm.packageParser.ProjectActionList) FileAction(net.sourceforge.usbdm.packageParser.FileAction)

Example 2 with ProjectActionList

use of net.sourceforge.usbdm.packageParser.ProjectActionList in project usbdm-eclipse-plugins by podonoghue.

the class ParseMenuXML method parseControlItem.

/**
 * Parse element: <ul>
 *   <li> &lt;fragment&gt; referencing only elements below
 *   <li> &lt;validate&gt;
 *   <li> &lt;template&gt;
 *   <li> &lt;projectActionList&gt;
 *</ul>
 *
 * Items found are recorded
 *
 * @param  menuElement  Menu element to parse
 *
 * @throws Exception
 */
private void parseControlItem(Element element) throws Exception {
    String tagName = element.getTagName();
    if (tagName == "fragment") {
        for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) {
            if (node.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }
            parseControlItem((Element) node);
        }
    } else if (tagName == "validate") {
        fValidators.add(parseValidate(element));
    } else if (tagName == "template") {
        /**
         * namespace:
         *    class - Template is available in
         */
        String name = element.getAttribute("name");
        String namespace = element.getAttribute("namespace");
        if (namespace.isEmpty()) {
            throw new Exception("Template is missing namespace, name='" + name + "'");
        }
        if (!name.isEmpty() && !namespace.equals("all")) {
            throw new Exception("Named templates must have 'all' namespace, name='" + name + "'");
        }
        int dimension = getIntAttribute(element, "dim");
        addTemplate(name, namespace, dimension, element.getTextContent().replaceAll("^\n\\s*", "").replaceAll("(\\\\n|\\n)\\s*", "\n").replaceAll("\\\\t", "   "));
    // System.err.println(fTemplate.toString().substring(0, 40)+"\n");
    } else if (tagName == "projectActionList") {
        ProjectActionList pal = PackageParser.parseRestrictedProjectActionList(element, RESOURCE_PATH);
        pal.visit(new Visitor() {

            @Override
            public Result applyTo(ProjectAction action, Value result, IProgressMonitor monitor) {
                if (action instanceof ProjectConstant) {
                    ProjectConstant constant = (ProjectConstant) action;
                    Variable var = new StringVariable(constant.getId(), constant.getId());
                    var.setValue(constant.getValue());
                    System.err.println("Adding " + var);
                    fProvider.addVariable(var);
                }
                return Visitor.CONTINUE;
            }
        }, null);
        fProjectActionList.addProjectAction(pal);
    } else {
        throw new Exception("Unexpected field in parseControlItem(), value = \'" + tagName + "\'");
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) PinListVariable(net.sourceforge.usbdm.deviceEditor.information.PinListVariable) DoubleVariable(net.sourceforge.usbdm.deviceEditor.information.DoubleVariable) ChoiceVariable(net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable) IrqVariable(net.sourceforge.usbdm.deviceEditor.information.IrqVariable) StringVariable(net.sourceforge.usbdm.deviceEditor.information.StringVariable) IndexedCategoryVariable(net.sourceforge.usbdm.deviceEditor.information.IndexedCategoryVariable) Variable(net.sourceforge.usbdm.deviceEditor.information.Variable) BitmaskVariable(net.sourceforge.usbdm.deviceEditor.information.BitmaskVariable) LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) NumericListVariable(net.sourceforge.usbdm.deviceEditor.information.NumericListVariable) Visitor(net.sourceforge.usbdm.packageParser.ProjectActionList.Visitor) ProjectAction(net.sourceforge.usbdm.packageParser.ProjectAction) ProjectConstant(net.sourceforge.usbdm.packageParser.ProjectConstant) Node(org.w3c.dom.Node) Value(net.sourceforge.usbdm.packageParser.ProjectActionList.Value) ProjectActionList(net.sourceforge.usbdm.packageParser.ProjectActionList) StringVariable(net.sourceforge.usbdm.deviceEditor.information.StringVariable) UsbdmException(net.sourceforge.usbdm.jni.UsbdmException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with ProjectActionList

use of net.sourceforge.usbdm.packageParser.ProjectActionList in project usbdm-eclipse-plugins by podonoghue.

the class UsbdmNewProjectWizard method updateMapConstants.

/**
 * Visits the nodes of the projectActionList and add constants found
 *
 * @param paramMap            Map to add constants to
 * @param projectActionList   Action list to visit
 */
void updateMapConstants(final Map<String, String> paramMap, ProjectActionList projectActionList) {
    Visitor visitor = new Visitor() {

        @Override
        public Result applyTo(ProjectAction action, Value result, IProgressMonitor monitor) {
            try {
                if (action instanceof ProjectActionList) {
                    ProjectActionList projectActionList = (ProjectActionList) action;
                    return projectActionList.appliesTo(fUsbdmProjectParametersPage_2.getDevice(), paramMap) ? CONTINUE : PRUNE;
                } else if (action instanceof ProjectConstant) {
                    ProjectConstant projectConstant = (ProjectConstant) action;
                    // System.err.println(String.format("updateMapConstants(): Found constant %s => %s",  projectConstant.getId(), projectConstant.getValue()));
                    String value = paramMap.get(projectConstant.getId());
                    if (value != null) {
                        if (projectConstant.isWeak()) {
                            // Ignore - assume constant is a default that has been overwritten
                            return CONTINUE;
                        }
                        if (!projectConstant.doOverwrite() && !value.equals(projectConstant.getValue())) {
                            return new Result(new Exception("paramMap already contains constant " + projectConstant.getId()));
                        }
                    }
                    paramMap.put(projectConstant.getId(), projectConstant.getValue());
                }
                return CONTINUE;
            } catch (Exception e) {
                return new Result(e);
            }
        }
    };
    // Visit all enabled actions and collect constants
    Result result = fProjectActionList.visit(visitor, null);
    if (result.getStatus() == Status.EXCEPTION) {
        result.getException().printStackTrace();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Visitor(net.sourceforge.usbdm.packageParser.ProjectActionList.Visitor) ProjectAction(net.sourceforge.usbdm.packageParser.ProjectAction) ProjectConstant(net.sourceforge.usbdm.packageParser.ProjectConstant) Value(net.sourceforge.usbdm.packageParser.ProjectActionList.Value) ProjectActionList(net.sourceforge.usbdm.packageParser.ProjectActionList) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Result(net.sourceforge.usbdm.packageParser.ProjectActionList.Visitor.Result)

Example 4 with ProjectActionList

use of net.sourceforge.usbdm.packageParser.ProjectActionList in project usbdm-eclipse-plugins by podonoghue.

the class KSDKLibraryImportWizard method run.

@Override
public void run(IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException {
    System.err.println("KSDKLibraryImportWizard.run()");
    SubMonitor monitor = SubMonitor.convert(progressMonitor);
    monitor.beginTask("Importing KDS Library", 100);
    Map<String, String> paramMap = new HashMap<String, String>();
    try {
        kdsLibraryImportWizardPage.getPageData(paramMap);
        Device device = getDevice(paramMap.get(UsbdmConstants.TARGET_DEVICE_KEY));
        if (device == null) {
            throw new Exception("Failed to obtain device description for " + paramMap.get(UsbdmConstants.TARGET_DEVICE_KEY));
        }
        // Add device options
        ProjectActionList deviceActionList = device.getProjectActionList(paramMap);
        // UsbdmOptionsPanel.getPageData(paramMap, deviceActionLists);
        listParamMap("KSDKLibraryImportWizard.run() - paramMap =================================", paramMap);
        // Create project
        System.err.println("KSDKLibraryImportWizard.run() - Creating project");
        IProject project = new CDTProjectManager().createUSBDMProject(paramMap, monitor.newChild(30));
        // Apply default device project options
        System.err.println("KSDKLibraryImportWizard.run() - Applying deviceActionLists");
        ProcessProjectActions.process(this, project, device, deviceActionList, paramMap, monitor.newChild(30));
        // Apply Library options
        System.err.println("KSDKLibraryImportWizard.run() - Getting libraryActionList");
        ProjectActionList libraryActionList = kdsLibraryImportWizardPage.getProjectActionList();
        System.err.println("KSDKLibraryImportWizard.run() - Applying libraryActionList");
        ProcessProjectActions.process(this, project, device, libraryActionList, paramMap, monitor.newChild(30));
        updateConfigurations(project, monitor.newChild(10));
    } catch (Exception e) {
        e.printStackTrace();
        throw new InvocationTargetException(e);
    } finally {
        monitor.done();
    }
}
Also used : HashMap(java.util.HashMap) Device(net.sourceforge.usbdm.deviceDatabase.Device) SubMonitor(org.eclipse.core.runtime.SubMonitor) CDTProjectManager(net.sourceforge.usbdm.cdt.ui.newProjectWizard.CDTProjectManager) ProjectActionList(net.sourceforge.usbdm.packageParser.ProjectActionList) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with ProjectActionList

use of net.sourceforge.usbdm.packageParser.ProjectActionList in project usbdm-eclipse-plugins by podonoghue.

the class UsbdmDynamicOptionPage_N method main.

// @Override
// public boolean canFlipToNextPage() {
// return isPageComplete();
// }
/**
 * Test main
 *
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Packages Available");
    shell.setLayout(new FillLayout());
    Composite composite = new Composite(shell, SWT.NONE);
    composite.setLayout(new FillLayout());
    String deviceName = "FRDM_K22F";
    // String deviceName = "FRDM_KL27Z";
    // String deviceName = "MKL27Z64M4";
    Map<String, String> paramMap = new HashMap<String, String>();
    paramMap.put("linkerFlashSize", "0x100");
    paramMap.put("linkerRamSize", "0x100");
    paramMap.put("outputType", "xxxxxProjectType.exe");
    paramMap.put("targetDevice", deviceName);
    // UsbdmDynamicOptionPage_N page = new UsbdmDynamicOptionPage_N(deviceName, paramMap, "usbdm-project-options-page");
    // UsbdmDynamicOptionPage_N page = new UsbdmDynamicOptionPage_N(deviceName, paramMap, "kinetis-CPP-abstraction-options-page");
    WizardPageInformation wizardPageInfo = new WizardPageInformation("kinetis-sdk-options-page", "Kinetis", "Kinetis description");
    DeviceDatabase deviceDatabase = new DeviceDatabase(TargetType.T_ARM);
    Device device = deviceDatabase.getDevice(deviceName);
    ProjectActionList projectActionList = device.getProjectActionList(paramMap);
    UsbdmDynamicOptionPage_N page = new UsbdmDynamicOptionPage_N(device, projectActionList, wizardPageInfo);
    page.createControl(composite);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    page.getPageData(paramMap);
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Composite(org.eclipse.swt.widgets.Composite) HashMap(java.util.HashMap) DeviceDatabase(net.sourceforge.usbdm.deviceDatabase.DeviceDatabase) Device(net.sourceforge.usbdm.deviceDatabase.Device) ProjectActionList(net.sourceforge.usbdm.packageParser.ProjectActionList) FillLayout(org.eclipse.swt.layout.FillLayout) Display(org.eclipse.swt.widgets.Display) WizardPageInformation(net.sourceforge.usbdm.packageParser.WizardPageInformation)

Aggregations

ProjectActionList (net.sourceforge.usbdm.packageParser.ProjectActionList)8 ProjectAction (net.sourceforge.usbdm.packageParser.ProjectAction)6 Value (net.sourceforge.usbdm.packageParser.ProjectActionList.Value)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 ProjectConstant (net.sourceforge.usbdm.packageParser.ProjectConstant)5 Visitor (net.sourceforge.usbdm.packageParser.ProjectActionList.Visitor)4 Result (net.sourceforge.usbdm.packageParser.ProjectActionList.Visitor.Result)4 ProjectVariable (net.sourceforge.usbdm.packageParser.ProjectVariable)4 WizardPageInformation (net.sourceforge.usbdm.packageParser.WizardPageInformation)4 HashMap (java.util.HashMap)3 WizardGroup (net.sourceforge.usbdm.packageParser.WizardGroup)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 AddTargetFiles (net.sourceforge.usbdm.cdt.utilties.AddTargetFiles)2 ApplyOptions (net.sourceforge.usbdm.cdt.utilties.ApplyOptions)2 DeleteResource (net.sourceforge.usbdm.cdt.utilties.DeleteResource)2 Device (net.sourceforge.usbdm.deviceDatabase.Device)2 CreateFolderAction (net.sourceforge.usbdm.packageParser.CreateFolderAction)2 DeleteResourceAction (net.sourceforge.usbdm.packageParser.DeleteResourceAction)2 ExcludeAction (net.sourceforge.usbdm.packageParser.ExcludeAction)2 FileAction (net.sourceforge.usbdm.packageParser.FileAction)2