lemminx icon indicating copy to clipboard operation
lemminx copied to clipboard

Add AbstractClasspathResourceResolver

Open rzgry opened this issue 5 years ago • 5 comments

Adds an abstract class to make it easier to deploy and resolve a classpath resource. Ie. XSD schema @angelozerr mentioned this could be useful

Can be used like this:

package io.openliberty.lemminx.liberty;

import io.openliberty.lemminx.liberty.util.LibertyUtils;
import org.eclipse.lemminx.uriresolver.CacheResourcesManager.ResourceToDeploy;

public class LibertyXSDURIResolver extends AbstractClasspathResourceResolver {

  private static final String XSD_RESOURCE_URL = "https://github.com/OpenLiberty/liberty-language-server/master/lemminx-liberty/src/main/resources/schema/server.xsd";
  private static final String XSD_CLASSPATH_LOCATION = "/schema/server.xsd";

  private static final ResourceToDeploy serverXSDResource = new ResourceToDeploy(XSD_RESOURCE_URL, XSD_CLASSPATH_LOCATION);


  @Override
  ResourceToDeploy resourceToResolve(String baseLocation, String publicId, String systemId) {
    if (LibertyUtils.isServerXMLFile(baseLocation)) {
      return serverXSDResource;
    }

    return null;
  }
}


Signed-off-by: Ryan Zegray [email protected]

rzgry avatar Aug 27 '20 18:08 rzgry

unit tests would be nice ;-)

fbricon avatar Aug 28 '20 17:08 fbricon

@rzgry it should be nice if XSLURIResolverExtension will extend your AbstractClasspathResourceResolver . I'm not sure that it works since XSLURIResolverExtension manage several XSD and choose it according the version attribute.

angelozerr avatar Aug 28 '20 17:08 angelozerr

I can take a look at adapting the AbstractClasspathResourceResolver to support managing multiple XSDs.

rzgry avatar Aug 28 '20 17:08 rzgry

@angelozerr Updated to instead have an abstract method public abstract ResourceToDeploy resourceToResolve(String baseLocation, String publicId, String systemId); Where you return the resource you want to resolve/deploy given the parameters. And updated the implementation of XSLURIResolverExtension.

rzgry avatar Aug 28 '20 18:08 rzgry

As a consumer, I'd rather not have to extend 1 class to provide a schema to LemMinX. I would hope for this basic use-case to be something more built-in directly in LemMinX API (see suggestions in #1007). One way to achieve that would be to provide a concrete ClasspathResourceResolver(URI schemaUri, String classpathResource) which we'd just have to instantiate with eg new ClasspathResourceResolver(URI.create("http://maven.apache.org/maven-v4_0_0.xsd"), "/xsd/maven-v4_0_0.xsd"). Could this PR help towards that goal?

mickaelistria avatar Mar 28 '21 04:03 mickaelistria