Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF file URI#isPrefix()
EMF file URI#isPrefix() [message #1772582] Tue, 12 September 2017 15:55 Go to next message
Akos Kitta is currently offline Akos KittaFriend
Messages: 25
Registered: November 2015
Junior Member
Hi there,

What would be the preferred way to preserve the #isPrefix property on a file URI if that references an actual existing directory?

I naively thought that is done auto-magically when creating the EMF URI from the absolute path of a directory. But that is not the case.

Can someone please clarify, what is the preferred way to initialize the URI correctly? Is that the client's responsibility to suffix the URI with a trailing slash if the #isPrefix needs to be preserved?

Here are my stupid tests to represent the issue I am talking:

import java.io.File;

import org.eclipse.emf.common.util.URI;
import org.junit.Assert;
import org.junit.Test;

public class EmfURI_IsPrefix {

  @Test
  public void test_01() {
    File dir = new File(System.getProperty("java.io.tmpdir"));
    Assert.assertTrue(dir.exists());
    Assert.assertTrue(dir.isDirectory());
    URI uri = URI.createFileURI(dir.getAbsolutePath());
    Assert.assertTrue(uri.isPrefix()); // Error
  }

  @Test
  public void test_02() {
    File dir = new File(System.getProperty("java.io.tmpdir"));
    Assert.assertTrue(dir.exists());
    Assert.assertTrue(dir.isDirectory());
    URI uri = URI.createFileURI(dir.getAbsolutePath() + "/");
    Assert.assertTrue(uri.isPrefix());
  }

}


Thanks for the help!
Re: EMF file URI#isPrefix() [message #1774288 is a reply to message #1772582] Thu, 12 October 2017 13:38 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 29648
Registered: July 2009
Senior Member
Sorry I wasn't seeing posts because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=525901

Creating a URI is a syntactic operation; no IO is involved. If you want a URI that ends in / when the File is a directory/folder you have to add that "/" your self.
Previous Topic:How to use external classes in an ecore model
Next Topic:Repair broken inter-resource references
Goto Forum:
  


Current Time: Tue Nov 13 07:39:55 GMT 2018

Powered by FUDForum. Page generated in 0.01754 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top