use of net.sourceforge.usbdm.jni.UsbdmException in project usbdm-eclipse-plugins by podonoghue.
the class DevicePeripheralsProviderInterface method getProvider.
/**
* Get provider from ID
*
* @param providerId
* @return
* @throws Exception
*/
public IPeripheralDescriptionProvider getProvider(final String providerId) throws UsbdmException {
// System.err.println("IPeripheralDescriptionProvider.getProvider() looking for providerId = " + providerId);
IExtensionRegistry registry = Platform.getExtensionRegistry();
if (registry == null) {
throw new UsbdmException("DevicePeripheralsProviderInterface.getProvider() failed to get registry ");
}
IConfigurationElement[] config = registry.getConfigurationElementsFor(PeripheralDescriptionProvider_ID);
// Get provider
final ArrayList<IPeripheralDescriptionProvider> peripheralDescriptionProvider = new ArrayList<IPeripheralDescriptionProvider>();
IApplyTo listProviderNames = new IApplyTo(config) {
@Override
public void run(IPeripheralDescriptionProvider provider) {
if (provider.getId().equals(providerId)) {
peripheralDescriptionProvider.add(provider);
}
}
};
listProviderNames.foreach();
if (peripheralDescriptionProvider.size() > 0) {
return peripheralDescriptionProvider.get(0);
}
throw new UsbdmException("DevicePeripheralsProviderInterface.getProvider() failed to get provider for " + providerId);
}
use of net.sourceforge.usbdm.jni.UsbdmException in project usbdm-eclipse-plugins by podonoghue.
the class Peripheral method writeHeaderFileDmaInformation.
/**
* Write header file miscellaneous information
*
* @param writer
* @throws UsbdmException
*/
void writeHeaderFileDmaInformation(PrintWriter writer) throws UsbdmException {
final Pattern peripheralPattern = Pattern.compile("DMAMUX(\\d+)");
final Matcher peripheralMatcher = peripheralPattern.matcher(getName());
if (!peripheralMatcher.matches()) {
return;
}
boolean doneBraces = false;
// System.err.println("writeHeaderFileDmaInformation() - creating enum for "+ this);
HashSet<String> usedEnums = null;
String instance = peripheralMatcher.group(1);
for (Cluster cluster : getRegisters()) {
if (cluster instanceof Register) {
Register register = (Register) cluster;
final Pattern registerPattern = Pattern.compile("CHCFG_?(LOW|HIGH)?.*");
final Matcher registerMatcher = registerPattern.matcher(register.getName());
for (Field field : register.getFields()) {
if (registerMatcher.matches()) {
// System.err.println("writeHeaderFileDmaInformation() - matched "+register);
String description = "";
String modifier = "";
String offset = "";
if (registerMatcher.group(1) != null) {
if (registerMatcher.group(1).equals("LOW")) {
description = " - low channels 0-15";
modifier = "Low";
} else if (registerMatcher.group(1).equals("HIGH")) {
description = " - high channels 16-31";
modifier = "High";
offset = "0x800|";
}
}
if (field.getName().equals("SOURCE")) {
for (Enumeration e : field.getEnumerations()) {
if (e.getName().startsWith("Reserved")) {
continue;
}
String identifier = "Dma" + instance + "Slot" + modifier + "_" + e.getName();
if (!Utiltity.isCIdentifier(identifier)) {
throw new UsbdmException("Invalid name for C identifier in DMAMUX names \'" + identifier + "\'");
}
if (!doneBraces) {
usedEnums = new HashSet<String>();
writer.print(String.format(DMA_ENUM_OPENING, description));
doneBraces = true;
}
if (usedEnums.contains(identifier)) {
continue;
// throw new UsbdmException("Repeated enum value for DMA slot" + identifier);
}
usedEnums.add(identifier);
writer.print(String.format(DMA_FORMAT, identifier, offset + e.getValue(), e.getDescription() + description));
}
}
}
}
}
}
if (doneBraces) {
writer.print(String.format(DMA_ENUM_CLOSING));
doneBraces = false;
}
}
use of net.sourceforge.usbdm.jni.UsbdmException in project usbdm-eclipse-plugins by podonoghue.
the class ExampleList method parseExampleList.
/**
* Parse exampleList
*
* @param exampleListElement <exampleList> element
*
* @return list of project elements
*
* @throws UsbdmException
*/
private ArrayList<ProjectInformation> parseExampleList(Element exampleListElement) throws UsbdmException {
ArrayList<ProjectInformation> projectList = new ArrayList<ProjectInformation>();
for (Node node = exampleListElement.getFirstChild(); node != null; node = node.getNextSibling()) {
// element node for <example>
if (node.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Element element = (Element) node;
if (element.getTagName() != "example") {
throw new UsbdmException("parseExampleList(" + node.getNodeName() + ") - not example element");
}
String description = element.getAttribute("description");
String longDescription = element.getTextContent().trim();
IPath path = new Path(exampleFolderPath + "/" + element.getAttribute("path"));
String buildTool = element.getAttribute("buildTool");
// File file = path.toFile();
// if (!file.isFile() || !file.canRead()) {
// throw new UsbdmException("Failed to find Example Project file: " + path.toString());
// }
String family = element.getAttribute("family");
ProjectInformation projectInfo = new ProjectInformation(description, longDescription, path, family, buildTool);
projectList.add(projectInfo);
parseVariables(projectInfo, element);
}
return projectList;
}
use of net.sourceforge.usbdm.jni.UsbdmException in project usbdm-eclipse-plugins by podonoghue.
the class ExampleList method parseXmlFile.
/**
* @param iPath path to example list XML file
*
* @throws UsbdmException
*/
void parseXmlFile(IPath iPath) throws UsbdmException {
// Get the factory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
// Using factory get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();
// Parse using builder to get DOM representation of the XML file
dom = db.parse(iPath.toFile());
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
throw new UsbdmException(pce.getMessage());
} catch (SAXException se) {
se.printStackTrace();
throw new UsbdmException(se.getMessage());
} catch (IOException ioe) {
ioe.printStackTrace();
throw new UsbdmException(ioe.getMessage());
}
}
use of net.sourceforge.usbdm.jni.UsbdmException in project usbdm-eclipse-plugins by podonoghue.
the class UsbdmExampleProjectsWizard method performFinish.
@Override
public boolean performFinish() {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
ZipFile zipFile = null;
String internalProjectDirectoryName = null;
if (!usbdmSelectProjectWizardPage.validate()) {
return false;
}
// Unzip example into workspace
try {
usbdmSelectProjectWizardPage.saveSetting();
ProjectInformation projectInformation = usbdmSelectProjectWizardPage.getProjectInformation();
zipFile = new ZipFile(projectInformation.getPath().toFile());
ArrayList<Attribute> attributes = projectInformation.getAttributes();
attributes.add(new Attribute("projectName", projectInformation.getDescription()));
addCommonAttributes(attributes);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
if (!entries.hasMoreElements()) {
throw new UsbdmException("Example Zip file is empty");
}
IPath workspaceRootPath = workspace.getRoot().getLocation();
IPath projectPath = null;
// Do pass through zip file creating directories & files
entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
// System.err.println("performFinish() entry = " + entry.getName());
IPath internalPath = new Path(entry.getName());
if (internalPath.segmentCount() < 1) {
throw new UsbdmException("Example project has invalid structure, \'" + entry.toString() + "\' is missing project directory)");
}
if (internalProjectDirectoryName == null) {
// Haven't got project directory yet - determine from root of first entry
internalProjectDirectoryName = internalPath.segment(0);
projectPath = workspaceRootPath.append(internalProjectDirectoryName);
// System.err.println("performFinish() Project Path: " + projectPath.toString());
File directory = projectPath.toFile();
if (directory.exists()) {
// Project directory should not already exist
throw new UsbdmException("Project Directory already exists (" + internalProjectDirectoryName + ")");
}
// System.err.println("performFinish() Creating project directory: " + directory.toString());
directory.mkdir();
}
if (!internalProjectDirectoryName.equals(internalPath.segment(0))) {
// Entry is not a child of project directory
throw new UsbdmException("Example project has invalid structure, \'" + entry.toString() + "\' is outside project directory)");
}
if ((internalPath.segmentCount() == 1) && !entry.isDirectory()) {
// Only 1 segment => must be project directory
throw new UsbdmException("Example project has invalid structure, \'" + entry.toString() + "\' is outside project directory)");
}
IPath filePath = workspaceRootPath.append(internalPath);
// Create each directory in path (excluding last segment which may be a file or directory)
File directory = filePath.uptoSegment(filePath.segmentCount() - 1).toFile();
if (!directory.exists()) {
// System.err.println("performFinish() Creating directories in path: " + directory.toString());
directory.mkdirs();
}
if (entry.isDirectory()) {
// Make the directory
directory = filePath.toFile();
if (!directory.exists()) {
// System.err.println("performFinish() Creating directory: " + filePath.toString());
directory.mkdir();
}
} else {
// System.err.println("performFinish() Creating file: " + filePath.toString());
String fileExtension = filePath.getFileExtension();
String[] textFiles = { "project", "cproject", "h", "hpp", "c", "cpp", "s", "asm", "ld", "launch", "mk", "rc", "d" };
boolean doConversion = false;
if ((fileExtension != null) && (fileExtension.length() > 0)) {
for (String textExtension : textFiles) {
if (fileExtension.equalsIgnoreCase(textExtension)) {
doConversion = true;
break;
}
}
} else {
String filename = filePath.lastSegment();
String[] specialFiles = { "makefile", "timestamp" };
if ((filename != null) && (filename.length() > 0)) {
for (String specialFile : specialFiles) {
if (filename.equalsIgnoreCase(specialFile)) {
doConversion = true;
break;
}
}
}
}
if (doConversion) {
// System.err.println("performFinish() Converting file: " + filePath.toString());
convertTextStream(zipFile.getInputStream(entry), new FileOutputStream(filePath.toFile()), attributes);
} else {
// System.err.println("performFinish() Copying file: " + filePath.toString());
copyBinaryStream(zipFile.getInputStream(entry), new FileOutputStream(filePath.toFile()));
}
}
}
;
if (projectPath == null) {
throw new UsbdmException("No project Folder found");
}
IProjectDescription description = workspace.loadProjectDescription(projectPath.append(".project"));
IProject newProject = workspace.getRoot().getProject(description.getName());
newProject.create(description, null);
newProject.open(null);
String additionalProjectNature = null;
if ((usbdmSelectProjectWizardPage.getBuildToolsId().equals(UsbdmSharedConstants.CODESOURCERY_ARM_BUILD_ID)) || (usbdmSelectProjectWizardPage.getBuildToolsId().equals(UsbdmSharedConstants.ARMLTD_ARM_BUILD_ID))) {
additionalProjectNature = "net.sourceforge.usbdm.cdt.tools.ArmProjectNature";
} else if (usbdmSelectProjectWizardPage.getBuildToolsId().equals(UsbdmSharedConstants.CODESOURCERY_COLDFIRE_BUILD_ID)) {
additionalProjectNature = "net.sourceforge.usbdm.cdt.tools.ColdfireProjectNature";
}
if (additionalProjectNature != null) {
IProjectDescription projectDescription = newProject.getDescription();
String[] currentIds = projectDescription.getNatureIds();
String[] newIds = new String[currentIds.length + 1];
int index;
for (index = 0; index < currentIds.length; index++) {
newIds[index] = currentIds[index];
// System.err.println("AddNature.process() Copying nature : " + newIds[index]);
}
newIds[index] = additionalProjectNature;
// System.err.println("AddNature.process() Adding nature : " + newIds[index]);
projectDescription.setNatureIds(newIds);
newProject.setDescription(projectDescription, null);
ManagedBuildManager.saveBuildInfo(newProject, true);
}
} catch (Exception e) {
e.printStackTrace();
MessageBox errBox = new MessageBox(getShell(), SWT.ERROR);
errBox.setText("Error Creating Project");
errBox.setMessage("Reason:\n\n " + e.getMessage());
errBox.open();
} finally {
if (zipFile != null) {
try {
zipFile.close();
} catch (IOException e) {
}
}
}
return true;
}
Aggregations