when importing a class, which depends on a class which is not imported, the JavaPackage of that dependency class is not fully populated (with annotations, etc). This should be possible via DependencyResolutionProcess
This is because the full package-info class information (which includes things like package-level annotations) is only scanned if it is part of the list of paths passed to the the classfile importer. The DependencyResolutionProcess is what allows information about related classes on the classpath to be scanned, but since no classes directly reference the package-info class, it will not get scanned in this way.
to be more concrete, a rule like this is not possible to write currently:
return ArchRuleDefinition.priority(Priority.MEDIUM)
.noClasses().that(resideOutsideOfPackage(packageName + ".."))
.should()
.dependOnClassesThat(isInternalClassInPackage(packageName))
.allowEmptyShould(true)
.because("Internal APIs are not stable");
}
static DescribedPredicate<JavaClass> isInternalClassInPackage(String packageName) {
return resideInAPackage(packageName + "..")
.and(doNot(resideInAPackageThat(is(annotatedWith("com.netflix.annotations.Exported")))));
}
which is basically saying "no classes should access any classes outside of its package, unless that class is in a package annotated with the @Exported annotation. It works if all the classes are in the same classpath being imported with ClassFileImporter. but if the @Exported package is from another library, this will not work, because the package-info.class is never scanned via dependencies
when importing a class, which depends on a class which is not imported, the JavaPackage of that dependency class is not fully populated (with annotations, etc). This should be possible via DependencyResolutionProcess
This is because the full package-info class information (which includes things like package-level annotations) is only scanned if it is part of the list of paths passed to the the classfile importer. The DependencyResolutionProcess is what allows information about related classes on the classpath to be scanned, but since no classes directly reference the package-info class, it will not get scanned in this way.
to be more concrete, a rule like this is not possible to write currently:
which is basically saying "no classes should access any classes outside of its package, unless that class is in a package annotated with the
@Exportedannotation. It works if all the classes are in the same classpath being imported withClassFileImporter. but if the@Exportedpackage is from another library, this will not work, because the package-info.class is never scanned via dependencies