Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (C) 2000-2026 Vaadin Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.base;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.router.Route;

/**
* A package-private route view used to verify that
* {@link com.vaadin.browserless.internal.Routes#autoDiscoverViews}
* discovers non-public views.
*/
@Tag("div")
@Route("package-private")
class PackagePrivateView extends Component {
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ import com.vaadin.browserless.viewscan.byannotatedclass.ViewPackagesTestView
import kotlin.test.expect


val packagePrivateViewClass: Class<out Component> = Class.forName("com.example.base.PackagePrivateView").asSubclass(Component::class.java)
val allViews: Set<Class<out Component>> = setOf<Class<out Component>>(
HelloWorldView::class.java, WelcomeView::class.java,
ParametrizedView::class.java, ChildView::class.java, NavigationPostponeView::class.java,
ViewPackagesTestView::class.java, SignalsView::class.java)
ViewPackagesTestView::class.java, SignalsView::class.java, packagePrivateViewClass)
val allErrorRoutes: Set<Class<out HasErrorParameter<*>>> = setOf(ErrorView::class.java, MockRouteNotFoundError::class.java, MockInternalSeverError::class.java)

@DynaTestDsl
Expand All @@ -53,6 +54,13 @@ fun DynaNodeGroup.routesTestBatch() {
expect(allErrorRoutes) { routes.errorRoutes.toSet() }
}

test("package-private views are discovered") {
val routes: Routes = Routes().autoDiscoverViews(*packagesToScan)
expect(true, "PackagePrivateView should be discovered") {
routes.routes.any { it.name == "com.example.base.PackagePrivateView" }
}
}

test("calling autoDiscoverViews() multiple times won't fail") {
expect(allViews) { Routes().autoDiscoverViews(*packagesToScan).routes }
expect(allViews) { Routes().autoDiscoverViews(*packagesToScan).routes }
Expand Down Expand Up @@ -106,7 +114,7 @@ fun DynaNodeGroup.routesTestBatch() {

test("merge routes") {
val routes1 = Routes(mutableSetOf(HelloWorldView::class.java, WelcomeView::class.java,
ViewPackagesTestView::class.java, SignalsView::class.java),
ViewPackagesTestView::class.java, SignalsView::class.java, packagePrivateViewClass),
mutableSetOf(ErrorView::class.java))
val routes2 = Routes(mutableSetOf(ParametrizedView::class.java, ChildView::class.java, NavigationPostponeView::class.java),
mutableSetOf(MockRouteNotFoundError::class.java, MockInternalSeverError::class.java))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ data class Routes(
fun autoDiscoverViews(vararg packageNames: String? = arrayOf()): Routes = apply {
val classGraph: ClassGraph = ClassGraph().enableClassInfo()
.enableAnnotationInfo()
.ignoreClassVisibility()
.acceptPackages(*(packageNames.map { it ?: "" }.toTypedArray()))
classGraph.scan().use { scanResult: ScanResult ->
scanResult.getClassesWithAnnotation(Route::class.java.name).mapTo(routes) { info: ClassInfo ->
Expand Down
Loading