Construct a file path given URI and version of a spec.

@param fsSpecStoreDirPath The directory path for specs.
@param uri Uri as the identifier of JobSpec
@return
422057
protected Path getPathForURI(Path fsSpecStoreDirPath, URI uri, String version) {
    return PathUtils.addExtension(PathUtils.mergePaths(fsSpecStoreDirPath, new Path(uri)), version);
  }
844175
private static String getAnalysisJobName(final URI uri) {
        final String filename = uri.getPath();
        final int lastIndexOfSlash = filename.lastIndexOf("/");
        final int lastIndexOfFileExtension = filename.lastIndexOf(".analysis.xml");
        return filename.substring(lastIndexOfSlash + 1, lastIndexOfFileExtension);
    }
580748
public static Path sourcePathFromParityPath(Path parityPath, FileSystem fs) 
        throws IOException {
    String parityPathStr = parityPath.toUri().getPath();
    for (Codec codec : Codec.getCodecs()) {
      String prefix = codec.getParityPrefix();
      if (parityPathStr.startsWith(prefix)) {
        // Remove the prefix to get the source file.
        String src = parityPathStr.replaceFirst(prefix, Path.SEPARATOR);
        Path srcPath = new Path(src);
        if (fs.exists(srcPath)) {
          return srcPath;
        }
      }
    }
    return null;
  }
1192044
public synchronized SiteNode findClosestParent(URI uri) {
    	if (uri == null) {
    		return null;
    	}
        SiteNode lastParent = null;
        SiteNode parent = getRoot();
        String folder = "";
        
        try {
        	String host = getHostName(uri);
        	
            // no host yet
            parent = findChild(parent, host);
            if (parent == null) {
                return null;
        	}
            lastParent = parent;
            
            List<String> path = model.getSession().getTreePath(uri);
            for (int i=0; i < path.size(); i++) {
            	folder = path.get(i);
                if (folder != null && !folder.equals("")) {
                    if (i == path.size()-1) {
                        lastParent = parent;
                    } else {
                        parent = findChild(parent, folder);
                        if (parent == null) {
                            break;
                        }
                        lastParent = parent;
                    }
                }
            }
        } catch (URIException e) {
            log.error(e.getMessage(), e);
        }
        
        return lastParent;
    }
735306
public URI asDirectoryURI() throws URISyntaxException {
        final String pathName = getPathName(false);
        return new URI(VFSUtils.VFS_PROTOCOL, "", parent == null ? pathName : pathName + "/", null);
    }
83
public static String resolveUriPrefix(URI serverURI)
      throws URISyntaxException {
    if (RESTLI_SCHEMES.contains(serverURI.getScheme())) {
      return new URI(serverURI.getScheme(), serverURI.getAuthority(), null, null, null).toString() + "/";
    }

    throw new RuntimeException("Unrecognized scheme for URI " + serverURI);
  }
1142909
protected function pathFromUri(FileUriInterface $uri)
    {
        $path = $uri->getPath();
        if (null === $path) {
            $path = '';
        }

        return $path;
    }
1267018
private PathEntry getPathEntry(UriEntry uri)
    {
        PathEntry  pathEntry = new PathEntry( ContextRouter.MAP_PATH_TYPE, "default");
        
        
        int length = uri.getLength();
        // like /a or /
        if ( length < 2) return pathEntry;
    

        String requestUri = uri.getRequestUri();
        
        String last_str = uri.get( length - 1 );
        if ( last_str.equals("*") || last_str.equals("") ) {
//            StringBuffer buffer = new StringBuffer();
//            buffer.append('/');
//            
//            for(int i = 0; i < length - 1; i++)
//            {
//                buffer.append(uri.get(i) + "/");
//            }
            
//            position of  last / charactor
            int lastPosition = requestUri.lastIndexOf('/');

            pathEntry.type = ContextRouter.MATCH_PATH_TYPE;
            pathEntry.key  = requestUri.substring(0, lastPosition + 1);
            
            // @TODO maybe we should get parameters to pathEntry
        } else {
            pathEntry.key  = requestUri;
        }
        
        return pathEntry;
    }
695301
public static Builder from(URI swaggerUri) {
        Validate.notNull(swaggerUri, "swaggerUri must not be null");
        String scheme = swaggerUri.getScheme();
        if (scheme != null && swaggerUri.getScheme().startsWith("http")) {
            try {
                return from(swaggerUri.toURL());
            } catch (MalformedURLException e) {
                throw new RuntimeException("Failed to convert URI to URL", e);
            }
        } else if (scheme != null && swaggerUri.getScheme().startsWith("file")) {
            return from(Paths.get(swaggerUri));
        } else {
            return from(URIUtils.convertUriWithoutSchemeToFileScheme(swaggerUri));
        }
    }
399047
public static String getModulePathForRelativeURI( String uri )
    {
        if ( uri == null ) return null;
        assert uri.length() > 0;
        assert uri.charAt( 0 ) == '/' : uri;

        // Strip off the actual page name (e.g., some_page.jsp)
        int slash = uri.lastIndexOf( '/' );
        uri = uri.substring( 0, slash );

        return uri;
    }
331478
protected String getSitePath(String uri) {

        if (m_internal) {
            String siteRoot = getSiteRoot();
            if (siteRoot != null) {
                return uri.substring(siteRoot.length());
            } else {
                return uri;
            }
        }
        return null;
    }
118280
@Override
    public Path getPath(final URI uri) {

        // Precondition checks
        if (uri == null) {
            throw new IllegalArgumentException("URI must be specified");
        }

        // ID exists? We're referencing a previously-opened archive?
        final String id = uri.getHost();
        ShrinkWrapFileSystem fs = null;
        if (id != null && id.length() > 0) {
            fs = this.createdFileSystems.get(id);
        }

        // Check that the file system exists
        if (fs == null) {
            throw new FileSystemNotFoundException("Could not find a previously-created filesystem with URI: "
                + uri.toString());
        }
        // Check FS is open
        if (!fs.isOpen()) {
            throw new FileSystemNotFoundException("File System for URI: " + uri.toString()
                + " is closed; create a new one to re-mount.");
        }

        final String pathComponent = uri.getPath();
        final ArchivePath archivePath = ArchivePaths.create(pathComponent);
        final Path path = new ShrinkWrapPath(archivePath, fs);

        // Return
        return path;
    }
1154878
private Path createPath(PathUri uri) {

    PathProvider provider = getProvider(uri);
    if (provider == null) {
      if (uri.getSchemePrefix() == null) {
        return Paths.get(uri.getPath());
      } else {
        try {
          return Paths.get(new URI(uri.getUri()));
        } catch (URISyntaxException e) {
          throw new ResourceUriUndefinedException(e, uri.getUri());
        }
      }
    }
    return provider.createResource(uri);
  }
184304
@SuppressWarnings({"PMD.NPathComplexity"})
	/*package*/ URI buildUri(final String rawUrl, final String branch, final String lastKnownCommit) throws URISyntaxException {
		URIBuilder builder = new URIBuilder();
		
		/*
		 * Examples:
		 * 
		 * ssh://git@company.com/project/repository.git
		 * https://username@company.com/scm/project/repository.git
		 * ssh://git@company.com/~username/repository.git
		 * https://username@company.com/scm/~username/repository.git
		 * 
		 */
		
		String repoUrlRaw = rawUrl;
		String repoUrlProcessed = repoUrlRaw;
		
		if (repoUrlProcessed.endsWith(".git")) {
			repoUrlProcessed = repoUrlProcessed.substring(0, repoUrlProcessed.lastIndexOf(".git"));
		}
		
		URI uri = URI.create(repoUrlProcessed.replaceAll(" ", "%20"));
		
		String host = uri.getHost();
		String scheme = "ssh".equalsIgnoreCase(uri.getScheme())? "https" : uri.getScheme();
		int port = uri.getPort();
		String path = uri.getPath();
		if ((path.startsWith("scm/") || path.startsWith("/scm")) && path.length() > 4) {
			path = path.substring(4);
		}
		if (path.length() > 0 && path.charAt(0) == '/') {
			path = path.substring(1, path.length());
		}
		
		String[] splitPath = path.split("/");
		String projectKey = "";
		String repositorySlug = "";
		
		if (splitPath.length > 1) {
			projectKey = splitPath[0];
			repositorySlug = path.substring(path.indexOf('/') + 1, path.length());
		} else {
			// Shouldn't get to this case
			projectKey = "";
			repositorySlug = path;
		}
		
		String apiPath = settings.getApi() != null? settings.getApi() : "";
		
		if (apiPath.endsWith("/")) {
			apiPath = settings.getApi().substring(0, settings.getApi().length() - 1);
		}
		
		builder.setScheme(scheme);
		builder.setHost(host);
		if (port != -1) {
			builder.setPort(port);
		}
		
		builder.setPath(apiPath + "/projects/" + projectKey + "/repos/" + repositorySlug + "/commits");
		if (branch == null || branch.length() == 0) {
			builder.addParameter("until", "master");
		} else {
			builder.addParameter("until", branch.replaceAll(" ", "%20"));
		}
		
		if (lastKnownCommit != null && lastKnownCommit.length() > 0) {
			builder.addParameter("since", lastKnownCommit);
		}
		
		if (settings.getPageSize() > 0) {
			builder.addParameter("limit", String.valueOf(settings.getPageSize()));
		}
		
		return builder.build();
	}
294913
public Iterator<URI> getSpecURIs() throws SpecSerDeException{
    try {
      return specStore.getSpecURIs();
    } catch (IOException ioe) {
      throw new SpecSerDeException("Cannot retrieve Specs' URI from Spec Store", specStore.getSpecStoreURI().get(), ioe);
    }
  }
19938
@Override
  public synchronized JobSpec getJobSpec(URI uri)
      throws JobSpecNotFoundException {
    try {
      Path targetJobSpecFullPath = getPathForURI(this.jobConfDirPath, uri);
      return this.converter.apply(loader.loadPullFile(targetJobSpecFullPath, this.sysConfig, shouldLoadGlobalConf()));
    } catch (FileNotFoundException e) {
      throw new JobSpecNotFoundException(uri);
    } catch (IOException e) {
      throw new RuntimeException("IO exception thrown on loading single job configuration file:" + e.getMessage());
    }
  }
1115393
private RemoteIterator<LocatedFileStatus> versionBasedListPathWithLocation(
      final String src) throws IOException {
    if (namenodeVersion >= ClientProtocol.BULK_BLOCK_LOCATIONS_VERSION) {
      return iteratorListing(src);
    } else {
      return arrayListing(src);
    }
  }