Java Code Examples for org.eclipse.emf.common.util.URI#hasTrailingPathSeparator()
The following examples show how to use
org.eclipse.emf.common.util.URI#hasTrailingPathSeparator() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackageJsonValidatorExtension.java From n4js with Eclipse Public License 1.0 | 6 votes |
private boolean isContainedOrEqual(URI uri, URI container) { if (uri.equals(container)) { return true; } if (!container.hasTrailingPathSeparator()) { container = container.appendSegment(""); } URI relative = uri.deresolve(container, true, true, false); if (relative != uri) { if (relative.isEmpty()) { return true; } if ("..".equals(relative.segment(0))) { return false; } return true; } return false; }
Example 2
Source File: SafeURI.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Validate the given URI to be of the correct shape. * * @param given * the URI. * @return the URI if it */ protected URI validate(URI given) throws IllegalArgumentException, NullPointerException { Preconditions.checkNotNull(given); List<String> segments = given.segmentsList(); final int segCountMax = given.hasTrailingPathSeparator() ? segments.size() - 1 : segments.size(); for (int i = 0; i < segCountMax; i++) { String segment = segments.get(i); Preconditions.checkArgument(segment.length() > 0, "'%s'", given); if (OSInfo.isWindows()) { Preconditions.checkArgument(!segment.contains(File.separator)); } } return given; }
Example 3
Source File: SafeURI.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Return true if this URI ends with package.json or package.json.xt * * Does not access the file system for this check. */ public boolean isPackageJsonLocation() { URI raw = toURI(); if (raw.hasTrailingPathSeparator()) { return false; } String filename = raw.lastSegment(); if (IN4JSProject.PACKAGE_JSON.equals(filename) || filename.length() == IN4JSProject.PACKAGE_JSON.length() + 3 && filename.startsWith(IN4JSProject.PACKAGE_JSON) && filename.endsWith(N4JSGlobals.XT_FILE_EXTENSION) && filename.charAt(filename.length() - 3) == '.') { return true; } return false; }
Example 4
Source File: UriUtil.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
/** * A URI is a prefix of another URI if: * <br/> * <ul> * <li>Both have the same scheme</li> * <li>The prefix ends with a trailing separator</li> * <li>The segments of both URIs match up to the prefix's length</li> * </ul> */ public static boolean isPrefixOf(URI prefix, URI uri) { if (prefix.scheme() == null || !prefix.scheme().equals(uri.scheme())) return false; String[] prefixSeg = prefix.segments(); String[] uriSeg = uri.segments(); if (prefixSeg.length == 0 || uriSeg.length == 0) return false; if (!prefix.hasTrailingPathSeparator()) return false; if (uriSeg.length < prefixSeg.length - 1) return false; for (int i = 0; i < prefixSeg.length - 1; i++) if (!uriSeg[i].equals(prefixSeg[i])) return false; return true; }
Example 5
Source File: SafeURI.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Returns a represenation of this URI that has a trailing path delimiter. */ public final U withTrailingPathDelimiter() { URI uri = toURI(); if (uri.hasTrailingPathSeparator()) { @SuppressWarnings("unchecked") U result = (U) this; return result; } return createFrom(uri.appendSegment("")); }
Example 6
Source File: FileSourceFolder.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public URI getPath() { final URI result = URI.createFileURI(name).resolve(parent.getPath()); if (result.hasTrailingPathSeparator()) { return result; } else { return result.appendSegment(""); } }
Example 7
Source File: UriUtil.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public static URI toFolderURI(URI uri) { if (uri.hasTrailingPathSeparator()) { return uri; } else { return uri.appendSegment(""); } }
Example 8
Source File: Repository.java From textuml with Eclipse Public License 1.0 | 5 votes |
/** * Creates a model set. * * @param baseURI * @throws CoreException */ public Repository(URI baseURI, boolean systemPackages) throws CoreException { Assert.isTrue(!baseURI.isRelative(), "Repository base URI must be absolute: " + baseURI); // it seems trailing slash causes cross-references to become relative // URIs preserving parent paths (/common/parent/../sibling/foo.uml // instead of ../sibling/foo.uml) if (baseURI.hasTrailingPathSeparator()) baseURI = baseURI.trimSegments(1); @SuppressWarnings("unused") UMLPackage umlPackage = UMLPackage.eINSTANCE; this.baseURI = baseURI; properties = MDDUtil.loadRepositoryProperties(this.baseURI); init(systemPackages); load(); }
Example 9
Source File: ProjectStateHolder.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * Reads the persisted project state from disk * * @return set of all source URIs with modified contents */ public ResourceChangeSet readProjectState(IProjectConfig projectConfig) { if (persistConfig.isDeleteState(projectConfig)) { deletePersistenceFile(projectConfig); } ResourceChangeSet result = new ResourceChangeSet(); doClear(); PersistedState persistedState = projectStatePersister.readProjectState(projectConfig); if (persistedState != null) { for (HashedFileContent hfc : persistedState.fileHashs.values()) { URI previouslyExistingFile = hfc.getUri(); switch (getSourceChangeKind(hfc, persistedState)) { case UNCHANGED: { uriToHashedFileContents.put(previouslyExistingFile, hfc); break; } case CHANGED: { result.getModified().add(previouslyExistingFile); persistedState.validationIssues.removeAll(previouslyExistingFile); break; } case DELETED: { result.getDeleted().add(previouslyExistingFile); persistedState.validationIssues.removeAll(previouslyExistingFile); break; } } } setIndexState(persistedState.indexState); mergeValidationIssues(persistedState.validationIssues.asMap()); } Set<URI> allIndexedUris = indexState.getResourceDescriptions().getAllURIs(); for (ISourceFolder srcFolder : projectConfig.getSourceFolders()) { List<URI> allSourceFolderUris = srcFolder.getAllResources(fileSystemScanner); for (URI srcFolderUri : allSourceFolderUris) { if (!srcFolderUri.hasTrailingPathSeparator() && !allIndexedUris.contains(srcFolderUri)) { if (resourceServiceProviders.getResourceServiceProvider(srcFolderUri) != null) { result.getModified().add(srcFolderUri); } } } } return result; }