VOOZH about

URL: https://www.javacodegeeks.com/2017/12/x-mas-musings-many-paths-one-path-spec.html

⇱ X-Mas Musings – Too Many Paths. One Path Spec? - Java Code Geeks


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.

Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

👁 Photo of Ted Vinke
Ted Vinke
December 22nd, 2017Last Updated: December 20th, 2017
0 83 1 minute read

Ted Vinke

Ted is a Java software engineer with a passion for Web development and JVM languages and works for First8, a Java Web development company in the Netherlands.
Subscribe

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Back to top button
Close
wpDiscuz