Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to write to PathURLConnection #161

Open
jsnps opened this issue Jun 29, 2021 · 2 comments
Open

Allow to write to PathURLConnection #161

jsnps opened this issue Jun 29, 2021 · 2 comments
Assignees
Labels
P3 type=enhancement Make an existing feature better

Comments

@jsnps
Copy link

jsnps commented Jun 29, 2021

Hey,

we ran into some issues in our unit tests, where EMF is trying to write to some URL in the jimfs filesystem.

The stack is the following:

PathURLConnection.getOutputStream() line: 130  =>  "protocol doesn't support output"
URIHandlerImpl.createOutputStream(URI, Map<?,?>) line: 154   
ExtensibleURIConverterImpl.createOutputStream(URI, Map<?,?>) line: 349   
PlatformResourceURIHandlerImpl.createOutputStream(URI, Map<?,?>) line: 498   
ExtensibleURIConverterImpl.createOutputStream(URI, Map<?,?>) line: 349   
ModelResourceImpl(ResourceImpl).save(Map<?,?>) line: 1041

To make EMF aware of jimfs, we register the top-level URI of a jimfs path into the ecore 'platform resource map' (essentially a map from Eclipse IProject -> URI) in the test setup:

EcorePlugin.getPlatformResourceMap().put("VdkWithVHub", URI.createURI(top.toUri().toString()));

It would be good, if the PathURLConnection could also implement the write protocol.

A trivial implementation fixed the issue for us: pull request

We would kindly ask to review the change and make suggestions if you see any violations of the protocol.

also see: #13 Obtaining a URL from a jimfs path

Thanks
Janik

@netdpb netdpb added P3 type=enhancement Make an existing feature better labels Jun 30, 2021
@cgdecker
Copy link
Member

I've just tested the behavior of the default file system (on my Mac, at least) and URLConnections created for its files do not support writing. I'm disinclined to have Jimfs support things that, if you switched to a real file system, would not work.

@jsnps
Copy link
Author

jsnps commented Jul 2, 2021

I see that the generic file path url connection does indeed not support output and I’ve found some (old) enhancement requests for this to be enabled.

There are some file-oriented url connections that do support getoutputstream: for example org.jboss.net.protocol.file.FileURLConnection (FileURLConnection (JBoss/Common API))

Essentially, having jimfs not support this feature means that any infrastructure that uses URIs to interact with jimfs cannot write to the filesystem, hence making jimfs of limited use in those contexts
(such as the emf platform uri extension mechanism).

If this is not an option for the jimfs API, then we either need to move away from jimfs as a testing aid or find some other way of allowing (emf) resources to be written ‘out’ in a unittest context.

Maybe you would be open to conditionally enable this getoutputstream capability, based on a java property or something?

This way, unittesting uses could still work with an additional action and the ‘normal’ behavior stays in line with standard path url connection behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 type=enhancement Make an existing feature better
Projects
None yet
Development

No branches or pull requests

3 participants