简体   繁体   English

验证Java类之间方法协定的一致性

[英]Verify consistency of method contracts between classes of java

We have a huge application in our company that was bought with its source code (almost all source code actually) and we have been working adapting it to our needs, fixes etc... The way someone a long time ago decided that it would be a good to compile the project was to have the precompiled jars of the original company and only edit or add the classes we needed in an Override folder that we get from some zip files with the original source code. 我们公司中有一个庞大的应用程序,它是用其源代码(实际上几乎是所有源代码)购买的,并且我们一直在努力使其适应我们的需求,修复等。很久以前,有人认为这将是编译项目的一个好方法是拥有原始公司的预编译jar,然后仅在从Override文件夹中编辑或添加我们需要的类,而Override文件夹是从带有原始源代码的一些zip文件中获得的。 So when we compile we only compile our edited classes, use the original jar in the Classpath and then join our new or edited classes with the original jar to create a new Jar. 因此,当我们编译时,我们仅编译我们已编辑的类,在Classpath中使用原始的jar,然后将新的或已编辑的类与原始jar一起创建一个新的Jar。

The issue seems to be that people are changing method contracts, editing interfaces and adding abstract methods to abstract classes. 问题似乎是人们正在更改方法协定,编辑接口并向抽象类添加抽象方法。 When we compile we don't recompile the complete source code, only ours so the compiler only checks contract consistency of our Overrided source code. 编译时,我们不会重新编译完整的源代码,而不会重新编译完整的源代码,因此编译器仅检查覆盖的源代码的合同一致性。 I have started to notice that thing seem to be breaking because old classes are trying to call a method that doesn't exists any more, or classes that call methods of classes that implement what really is just a partial version of the interface. 我已经开始注意到事情似乎正在崩溃,因为旧的类正在尝试调用不再存在的方法,或者类调用的类的方法实际上实现了接口的部分版本。

I cannot that simply join the original source code with our overrided source code because some classes and java files are autogenerated at build time so i could accidentaly fix something that really isnt broken. 我不能简单地将原始源代码与我们覆盖的源代码连接在一起,因为某些类和Java文件是在生成时自动生成的,因此我可能会意外修复某些确实没有损坏的东西。 (I tried, thats why i know) (我尝试过,这就是为什么我知道)

Is there a way to validate contract consistency between classes of various compiled jars automatically? 有没有一种方法可以自动验证各种已编译jar的类之间的合同一致性? After fixing those inconcesties i will be able merge both source directories together and avoid this issues in the future. 解决这些隐患之后,我将能够将两个源目录合并在一起,并在将来避免此问题。

Why not compile everything? 为什么不编译所有内容? (you do have the source code) That way you will at least get compile errors. (您确实有源代码)这样​​,您至少会得到编译错误。

I assume you don't have any tests to verify things still work. 我假设您没有任何测试可以验证一切是否正常。 Maybe you should start writing those too. 也许您也应该开始写那些。 A good place to start is to test the new code that is written that has broken before. 一个不错的起点是测试之前已被破坏的新代码。 That way you focus on testing the parts that are changing. 这样,您就可以集中精力测试变化中的零件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM