X-Mas Musings – Too Many Paths. One Path Spec?
December is for many people a period of reflection or thought. So I decided to reflect upon last year’s things and thoughts — each day until Christmas. This is day 15.
Within a typical (Java) project there a lots of places where some kind of “path” needs to be specified.
Gradle
For starters, in any build configuration quite a few paths to directories or files need to be described.
sonarqube {
properties {
property 'sonar.sources', 'src'
property 'sonar.exclusions', '**/*.spec.js'
property 'sonar.tests', 'src'
property 'sonar.test.inclusions', '**/*.spec.js'
}
}
task test(type: YarnTask, dependsOn: 'yarn') {
description = 'Run the client tests'
inputs.files(fileTree('config'))
inputs.files(fileTree('src'))
inputs.file('package.json')
outputs.dir('build')
args = ['run', 'unit']
}
war {
dependsOn asciidoctor
from ("${asciidoctor.outputDir}/html5") {
into 'static/docs'
}
}UrlMappings Grails
Mappings of urls to the appropriate controller and action on the server-side.
"/"(controller: "dashboard") "500"(view: "/error") "/api/v1/person/$id"( controller: "person", action: "details")
Spring Security
Securing urls with permissions.
http
.authorizeRequests()
.antMatchers("/assets/**").permitAll()
.antMatchers("/admin").hasRole("ADMIN")
.anyRequest().authenticated()Vue routing
Mappings of paths. Same project, but for the JavaScript client.
routes: [
{ path: '/', redirect: '/dashboard' },
{ path: '/staff/person/:id?', component: Person },
{ path: '*', redirect: '/notfound' }
]Spring REST Docs
Describing the path of JSON fields to generate documentation for API requests and responses.
given(this.spec)
.accept("application/json")
.filter(document("user", responseFields(
fieldWithPath("name").description("The user's name"),
fieldWithPath("email.primary").description("The primary email address"),
fieldWithPath("roles[]").description("List of roles"),
fieldWithPath("subscription[].type.*.name").description("Any subscription type"))))
.when().get("/user/5")
.then().assertThat().statusCode(is(200));And more…
That’s just in one project!
I sometimes even forget what the right syntax is �� Some docs clearly state they’re using Ant-style path patterns (**/*.?) or just use a home-grown system ([].*).
I think it’s time for a standardized “Path specification” — where all paths can be described in a uniform way and are treated equally! ��
Does your own project contains other surprising, path examples? I’d love to hear about them in the comments section.
| Published on Java Code Geeks with permission by Ted Vinke, partner at our JCG program. See the original article here: X-Mas Musings #15 – Too Many Paths. One Path Spec? Opinions expressed by Java Code Geeks contributors are their own. |



