当前位置: 首页 > news >正文

做本地网站赚钱新闻今天的最新新闻

做本地网站赚钱,新闻今天的最新新闻,网站显示内容不显示不出来,哈尔滨品牌网站建设文章目录 openpnp - src - 配置文件载入过程的初步分析概述笔记自己编译用的git版本报错截图问题1 - 怎么在调试状态下, 定位到抛异常的第一现场?结合单步调试找到的现场, 来分析报错的原因openpnp配置文件读取的流程END openpnp - src - 配置文件载入过程的初步分析 概述 从…

文章目录

    • openpnp - src - 配置文件载入过程的初步分析
    • 概述
    • 笔记
    • 自己编译用的git版本
    • 报错截图
    • 问题1 - 怎么在调试状态下, 定位到抛异常的第一现场?
    • 结合单步调试找到的现场, 来分析报错的原因
    • openpnp配置文件读取的流程
    • END

openpnp - src - 配置文件载入过程的初步分析

概述

从openpnp - dev - 2022_0801那天最后的代码, 编译除了一份可执行程序给自己用.
用官方打包的发布版 dev - 2022_0801运行, 居然读取我自己版本的配置文件失败.
将自己打包的那份dev-2022_0801, 再将版本退一个版本, 也会读取配置文件失败. 估计官方打包没用dev-2022_0801那天的最后版本.

通过git版本比对, 结合报错信息, 大概知道是新版本有个类, 添加了一个新属性, 导致旧版本读取不了新版本增加的属性时, 因为没有那个旧类没有那个新增加的属性, 导致抛出异常.

作为新手, 想弄清为啥读取配置文件报错, 错在哪里. 顺便看一下openpnp序列化配置文件的过程. 多一些了解, 总是没错的…

笔记

自己编译用的git版本

在这里插入图片描述
不太理解为啥官方打包的版本是2022/8/1下午的时间, 但是却没采用2022/8/1那天最新的实现. 而且提交时间只差了3分钟, 还是同一个人提交的, 迷惑…

编译openpnp工程的过程已经做了笔记(openpnp - 软件调试环境搭建).

报错截图

先用官方版本的dev-2022/8/1的发布包标定的设备.

后来发现openpnp有点bug, 修正了, 此时正常用, 但是配置文件被新版本(比官方版本晚3分钟的git版本, 修正后, 重新编译)改了, machine.xml中的视觉方案类中多了一个类属性.

偶然用官方发布的dev-2022_0801实验, 才发现报错如下:
在这里插入图片描述
根据报错提示, 可以知道 machine.xml中有个属性 settle-test-move-mm 在类org.openpnp.machine.referene.solutions.VisionSolutions中没有, 导致了抛异常报错.

看到这个报错后, 有2个想法:

  • 具体报错点在哪里? (等以后出现版本和配置文件不匹配时, 可以迅速定位到发生异常的类, 还可以知道报错前, 哪里是抛异常的第一现场?)
  • openpnp配置文件有4个xml, 这些配置文件读取的流程大致是从哪里到哪里?

用了一天, 将上面2个问题搞定了. 心里舒坦多了.

问题1 - 怎么在调试状态下, 定位到抛异常的第一现场?

我是第一次调试这个问题, 不断的下条件断点. 最后可以2步就到达报错现场. 如果不设置条件断点, 那基本就是不可调试的.

在这里插入图片描述
在这里插入图片描述
F8步过loadMachine(file), 如果没有其他条件断点, 就会直接进入437行的抛异常实现, 就会看到报错对话框.
F7步入loadMachine(file), 先F8, 如果哪步会导致进入437行报错断点, 再F7那个函数. 结合条件断点, 就能定位到抛异常的第一现场.
然后 CTRL + ALT + 向左的箭头, 就可以回到最后一次F8的代码实现. 然后停掉程序, 看看是不是第一现场, F7, F8, 直到找到第一现场.

当断住后, 如果不是我们要的调试代码, 按F9, 让程序继续跑, 命中我们后续的断点继续调试. 如果确定断点没用了, 就在一个断点上右击, 进入断点编辑器, 禁止掉不用的断点(不用删除, 可能找调试痕迹还有用).

在这里插入图片描述
这里就是找到的抛异常的第一现场.
2个条件断点都一样, 如下:

((null != name) && (19 == name.length()) && (0x73 == name.value[0]))

这个条件断点, 是找name == “visual-solutions”, 为了简单, 值判断了name的长度和第一个字符, 已经可以正确断住了. 如果只判断一个字符值不好使, 那就再挑一个字符值, 看情况, 条件写的越少越好.

在IDEA中下字符串的条件断点的方法已经做了笔记(java - IDEA IDE - 设置字符串断点).

因为报错的第一现场是在第三方jar包中, 只读的无法添加调试代码, 所以下条件断点能捕获到调试点就行.

结合单步调试找到的现场, 来分析报错的原因

第一现场的代码如下:

   private void readAttribute(InputNode node, Object source, Section section, LabelMap map) throws Exception {String name = node.getName(); // 取节点名称String path = section.getAttribute(name); // 取属性的path// map这里是类实际的属性值的集合// path是xml中指定的这个类的属性名称Label label = map.getLabel(path); // 拿属性的path去取属性的值if(label == null) {// 这里是没取到属性的值, 也就是旧版本openpnp读取新版本配置文件, 因为具体的类没有这个属性, 自然无法将xml中规定的类属性设置到类的到属性成员中.// 这里就是抛异常的第一现场Position line = node.getPosition(); // 报错的行数, 这里取的值不准, 没有参考价值. 文件是应该包含该属性的类, 行数(line)根本不对. 不怪IDEA, 因为这个属性就不存在, 用属性的代码行数自然也不对.Class expect = context.getType(type, source); // 好像是发生错误的类名称// 如果map是要求严格匹配(类的属性和xml中必须严格对应), 缓存也是要求严格匹配的, 就抛出异常报错.if(map.isStrict(context) && revision.isEqual()) {   // 然后就进入这里, 抛异常, 异常的内容就在报错框中被我们看到           throw new AttributeException("Attribute '%s' does not have a match in %s at %s", path, expect, line);}            } else {readInstance(node, source, label);}         }

openpnp配置文件读取的流程

只看用户空间的代码(主干函数), 进了第三方库的实现就不看了.

从main函数开始
D:\my_openpnp\openpnp_github\src\main\java\org\openpnp\Main.java

    public static void main(String[] args) {monkeyPatchBeansBinding();for (String s : args) {if (s.equals("--version")) {System.out.println(getVersion());System.exit(0);}}// http://developer.apple.com/library/mac/#documentation/Java/Conceptual/Java14Development/07-NativePlatformIntegration/NativePlatformIntegration.html#//apple_ref/doc/uid/TP40001909-212952-TPXREF134System.setProperty("apple.laf.useScreenMenuBar", "true");try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}catch (Exception e) {throw new Error(e);}File configurationDirectory = new File(System.getProperty("user.home"));configurationDirectory = new File(configurationDirectory, ".openpnp2");if (System.getProperty("configDir") != null) {configurationDirectory = new File(System.getProperty("configDir"));}configurationDirectory.mkdirs();configureLogging(configurationDirectory);Configuration.initialize(configurationDirectory);final Configuration configuration = Configuration.get();Locale.setDefault(Configuration.get().getLocale());ThemeInfo theme = configuration.getThemeInfo();new ThemeSettingsPanel().setTheme(theme, configuration.getFontSize(), configuration.isAlternateRows());ThemeDialog.getInstance().setOldTheme(theme);EventQueue.invokeLater(new Runnable() {public void run() {try {MainFrame frame = new MainFrame(configuration); // 进入MainFrame实现读配置frame.setVisible(true);Logger.info(String.format("Bienvenue, Bienvenido, Willkommen, Hello, Namaskar, Welkom, Bonjour to OpenPnP version %s.", Main.getVersion()));configuration.getScripting().on("Startup", null);}catch (Exception e) {e.printStackTrace();}}});}
}

D:\my_openpnp\openpnp_github\src\main\java\org\openpnp\gui\MainFrame.java

public MainFrame(Configuration configuration) {
// 巨大的一个函数, 只看相关实现
// ...registerBoardImporters();addComponentListener(componentListener);boolean configurationLoaded = false;while (!configurationLoaded) {try {configuration.load(); // 这里载入配置文件(4个.xml), 如果配置文件过不去, 就会抛一场.scriptFileWatcher = new ScriptFileWatcher(configuration.getScripting());scriptFileWatcher.setMenu(mnScripts);if (Configuration.get().getMachine().getProperty("Welcome2_0_Dialog_Shown") == null) {Welcome2_0Dialog dialog = new Welcome2_0Dialog(this);dialog.setSize(750, 550);dialog.setLocationRelativeTo(null);dialog.setModal(true);dialog.setVisible(true);Configuration.get().getMachine().setProperty("Welcome2_0_Dialog_Shown", true);}configurationLoaded = true;    }catch (Exception e) {// 这里就是用户看到报错提示框的地方e.printStackTrace();if (!MessageBoxes.errorBoxWithRetry(this, "Configuration Load Error", //$NON-NLS-1$"There was a problem loading the configuration. The reason was:<br/><br/>" //$NON-NLS-1$+ e.getMessage() + "<br/><br/>" //$NON-NLS-1$+ "Please check your configuration files and try again. They are located at: " //$NON-NLS-1$+ configuration.getConfigurationDirectory().getAbsolutePath()+ "<br/><br/>" //$NON-NLS-1$+ "If you would like to start with a fresh configuration, just delete the entire directory at the location above.<br/><br/>" //$NON-NLS-1$+ "Retry loading (else openpnp will exit) ?")) { //$NON-NLS-1$System.exit(1);}}}splitWindows();}
}

D:\my_openpnp\openpnp_github\src\main\java\org\openpnp\model\Configuration.java

	// 用户空间读取配置的函数// .xml和具体的类是对应的, 就是序列化xml文件到类的属性public synchronized void load() throws Exception {boolean forceSave = false;boolean overrideUserConfig = Boolean.getBoolean("overrideUserConfig");// 1. 读取packages.xml到具体类的属性try {File file = new File(configurationDirectory, "packages.xml");if (overrideUserConfig || !file.exists()) {Logger.info("No packages.xml found in configuration directory, loading defaults.");file = File.createTempFile("packages", "xml");FileUtils.copyURLToFile(ClassLoader.getSystemResource("config/packages.xml"), file);forceSave = true;}loadPackages(file);}catch (Exception e) {String message = e.getMessage();if (e.getCause() != null && e.getCause().getMessage() != null) {message = e.getCause().getMessage();}throw new Exception("Error while reading packages.xml (" + message + ")", e);}// 2. 读取parts.xml到具体类的属性try {File file = new File(configurationDirectory, "parts.xml");if (overrideUserConfig || !file.exists()) {Logger.info("No parts.xml found in configuration directory, loading defaults.");file = File.createTempFile("parts", "xml");FileUtils.copyURLToFile(ClassLoader.getSystemResource("config/parts.xml"), file);forceSave = true;}loadParts(file);}catch (Exception e) {String message = e.getMessage();if (e.getCause() != null && e.getCause().getMessage() != null) {message = e.getCause().getMessage();}throw new Exception("Error while reading parts.xml (" + message + ")", e);}// 3. 读取vision-settings.xml到具体类的属性try {File file = new File(configurationDirectory, "vision-settings.xml");if (overrideUserConfig || !file.exists()) {Logger.info("No vision-settings.xml found in configuration directory, loading defaults.");file = File.createTempFile("visionSettings", "xml");FileUtils.copyURLToFile(ClassLoader.getSystemResource("config/vision-settings.xml"), file);forceSave = true;}loadVisionSettings(file);}catch (Exception e) {String message = e.getMessage();if (e.getCause() != null && e.getCause().getMessage() != null) {message = e.getCause().getMessage();}throw new Exception("Error while reading vision-settings.xml (" + message + ")", e);}// 4. 读取machine.xml到具体类的属性// 这次调试, 就能看到是在读取machine.xml配置文件时, 抛异常.try {File file = new File(configurationDirectory, "machine.xml");if (overrideUserConfig || !file.exists()) {Logger.info("No machine.xml found in configuration directory, loading defaults.");file = File.createTempFile("machine", "xml");FileUtils.copyURLToFile(ClassLoader.getSystemResource("config/machine.xml"), file);forceSave = true;}loadMachine(file); // 这里具体都配置文件}catch (Exception e) {String message = e.getMessage();if (e.getCause() != null && e.getCause().getMessage() != null) {message = e.getCause().getMessage();}throw new Exception("Error while reading machine.xml (" + message + ")", e);}loaded = true;// Tell all listeners the configuration is loaded. Use a snapshot of the list in order to tolerate new// listener additions that may happen through object migration.for (ConfigurationListener listener : new ArrayList<>(listeners)) {listener.configurationLoaded(this);}if (forceSave) {Logger.info("Defaults were loaded. Saving to configuration directory.");configurationDirectory.mkdirs();save();}for (ConfigurationListener listener : listeners) {listener.configurationComplete(this);}}// 下面是保存配置文件的函数public synchronized void save() throws Exception {LocalDateTime now = LocalDateTime.now();
    private void loadMachine(File file) throws Exception {Serializer serializer = createSerializer();// serializer.read 已经离开用户代码, 去了第三方库中.// 如果不是调试代码, 就不用去看了.MachineConfigurationHolder holder = serializer.read(MachineConfigurationHolder.class, file);machine = holder.machine;}

END

http://www.hkea.cn/news/754886/

相关文章:

  • 泰安诚信的网站建设b站推广入口2023年
  • 高校网站建设资料库东莞seo推广公司
  • 电子印章手机在线制作软件四川seo整站优化费用
  • 个人风采网站制作外贸网站平台哪个好
  • 沈阳企业建站谷歌推广和seo
  • .la域名做的网站如何快速推广app
  • 广州优化网站建设怎么用手机制作网站
  • 做微网站的第三方学网络营销
  • 湖南做网站的公司有哪些搜索引擎是什么
  • flash网站管理系统seo优化排名易下拉用法
  • 永年网站建设友链互换平台推荐
  • 企业网站的设计公司网络广告营销的典型案例
  • 高校思政主题网站建设的意义关键词歌词任然
  • 哪里做网站比较快2345网址导航下载桌面
  • 广州建设委员会官方网站凡科建站下载
  • 全球做网站的公司排名百度一下你就知道官网
  • 小企业网站价格免费发链接的网站
  • 买了空间和域名 怎么做网站哪家公司网站做得好
  • 网站备案是否关闭衡阳网站建设公司
  • 遂昌建设局网站个人怎么做网站
  • 软件开发和网站建设网络营销的未来6个发展趋势
  • 做网站一年多少钱免费seo网站推广
  • 智通人才网东莞最新招聘信息官网seo是如何做优化的
  • 个人做跨境电商网站百度地图导航手机版免费下载
  • 阿里云注册网站之后怎么做网站百度联盟是什么
  • 动画制作视频河南网站排名优化
  • 网站关键词怎么做排名掌门一对一辅导官网
  • 现在什么网站做推广比较好网页设计需要学什么
  • 个人购物网站 怎么建网络营销包括
  • 有没有做鸭的网站工作室招聘广州网站优化工具