How do I create a concrete instance of FileReference?


(Jeremy Jarrell) #1

I’m manually adding javadoc elements to a few entries of a classpath file generated by the eclipseClasspath task.

I’ve can easily locate the proper library that I need to add the doc element too, but the javadocPath property of the Library class is of type FileReference, which is an interface.

I can’t find any example of classes that implement the FileReference interface in the platform, what is proper way to set this property?

eclipse {
 classpath {
  file {
   whenMerged { classpath ->
       for (entry in classpath.entries)
        if (entry.path.endsWith('gwt-dispatch-1.2.0.jar'))
      entry.javadocPath = ?
   }
  }
 }
}

(Peter Niederwieser) #2

I’m not aware of a good solution. In the past I’ve used the XML hook to work around this. I’ve created GRADLE-2853 for this.


(Jeremy Jarrell) #3

Thanks, Peter.


(Jeremy Jarrell) #4

As a work around, I’ve discovered that you can create an instance of FileReference on the fly if you’re willing to use the FileReferenceFactory from the internal namespace.

I’m assuming that the FileReferenceFactory isn’t part of the public API, but it’s working in a pinch.

import org.gradle.plugins.ide.eclipse.model.internal.FileReferenceFactory
  eclipse {
 classpath {
  file {
   whenMerged { classpath ->
          for (entry in classpath.entries) {
       if (entry instanceof Library) {
      if (entry.path.endsWith('gwt-dispatch-1.2.0.jar')) {
        entry.javadocPath = new FileReferenceFactory().fromJarURI('file:/resource/listhub/docs/lib/gwt-dispatch-1.2.0-javadoc.jar!/')
      }
     }
                                }
                           }
                     }
             }
  }