简体   繁体   English

如何阻止使用google guava库中的beta类?

[英]How do I prevent use of beta classes from google guava library?

We have been using Google collections in the production for several months. 我们几个月来一直在制作中使用Google收藏。 We would like to start using guava for additional functions. 我们想开始使用番石榴来增加其他功能。 However, I'm afraid to bring guava into our product stack b/c some developers may start to use 'beta' classes. 但是,我害怕将番石榴带入我们的产品堆栈b / c一些开发人员可能会开始使用'beta'类。

We have various unit-tests in our code but at this point, I prefer not to include 'beta' class b/c it is subject to change in the future. 我们的代码中有各种单元测试,但在这一点上,我不希望包含'beta'类b / c,它将来会发生变化。

Is there any easy way to do detect if the project includes any 'beta' guava classes? 如果项目包含任何'beta'番石榴类,有没有简单的方法来检测?

Overstock.com最近发布了一个Findbugs插件,用于标记@Beta类,方法或字段的使用。

在单元测试中,在使用任何beta类(或任何不受欢迎的类)时设置一个方面来记录和/或失败。

Apparently Google Guava has an @Beta annotation which indicates which classes or methods you don't want to use. 显然,Google Guava有一个@Beta注释,表明你不想使用哪些类或方法。

Unfortunalty this annotation is @Retention(value=CLASS) which I've never used but since it's supposed to be kept in .class files it might mean that it will still be availiable to Class.getDeclaredAnnotations() . 不幸的是,这个注释是@Retention(value=CLASS) ,我从来没有使用过,但因为它应该保存在.class文件中,这可能意味着它仍然可用于Class.getDeclaredAnnotations() If it's not you will have to use CGLIB or similar bytecode level library to find it. 如果不是,您将不得不使用CGLIB或类似的字节码级别库来查找它。

Given that you might want to instrument your CI application or add a checking classloader to your app to detect usage of beta API 鉴于您可能希望检测CI应用程序或向应用程序添加检查类加载器以检测beta API的使用情况

If you're using eclipse, access rules are one option. 如果您正在使用eclipse,则访问规则是一种选择。 You'd get a compile-time error whenever you are importing or otherwise using a restricted class. 无论何时导入或使用受限类,都会出现编译时错误。

I was thinking you could probably use reflection for that if you had a list of beta classes, which you can using Gili's link. 如果你有一个beta类列表,你可以使用Gili的链接,我认为你可以使用反射。 Then it gets pretty easy - just see this answer: 然后它变得非常简单 - 只需看看这个答案:

Can you find all classes in a package using reflection? 你能用反射找到包中的所有类吗?

I'd probably just put that in a unit test and have the unit test fail if it sees a class you don't like. 我可能只是把它放在单元测试中,如果它看到你不喜欢的课程,那么单元测试会失败。

这是一个Guava的Beta类列表。在使用guava类之前,你必须告诉其他开发人员检查这个链接。

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

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