Add AbstractClasspathResourceResolver
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]
unit tests would be nice ;-)
@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.
I can take a look at adapting the AbstractClasspathResourceResolver to support managing multiple XSDs.
@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.
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?