Home » Software Development » X-Mas Musings – Too Many Paths. One Path Spec?

About Ted Vinke

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.

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.

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
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
Subscribe
Notify of
guest

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

0 Comments
Inline Feedbacks
View all comments