本文整理汇总了Java中java.net.URI.relativize方法的典型用法代码示例。如果您正苦于以下问题:Java URI.relativize方法的具体用法?Java URI.relativize怎么用?Java URI.relativize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.URI
的用法示例。
在下文中一共展示了URI.relativize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPath
import java.net.URI; //导入方法依赖的package包/类
/**
* <p>Transforms an external {@code url} into a sling path, by subtracting the {@code server url} (incl. contextPath).
* The returned path will not contain the context path, so it can be used with {@link #getUrl(String)}</p>
*
* <p>The url can be absolute (incl. hostname) or relative to root (starts with "/").</p>
*
* <p>If the server url is not a prefix of the given url, it returns the given url</p>
*
* <p>If the url is just a path, it returns the path (with leading slash if not already present)</p>
*
* @param url full url
* @return sling path
*/
public URI getPath(URI url) {
// special case for urls that are server urls, but without trailing slash
if (url.relativize(getUrl()).equals(URI.create(""))) {
return slash;
}
URI contextPath = URI.create(getUrl().getPath());
URI relativeUrl = contextPath.relativize(slash.resolve(url));
if (relativeUrl.relativize(contextPath).equals(URI.create(""))) {
return slash;
}
return slash.resolve(getUrl().relativize(relativeUrl));
}
示例2: getId
import java.net.URI; //导入方法依赖的package包/类
private String getId(PublishArtifact artifact, Project project) {
// Assume that each artifact points to a unique file, and use the relative path from the project as the id
URI artifactUri = artifact.getFile().toURI();
URI projectDirUri = project.getProjectDir().toURI();
URI relativeUri = projectDirUri.relativize(artifactUri);
return relativeUri.getPath();
}
示例3: getResources
import java.net.URI; //导入方法依赖的package包/类
public URI[] getResources(boolean test) {
List<URI> toRet = new ArrayList<URI>();
URI projectroot = getProjectDirectory().toURI();
Set<URI> sourceRoots = null;
List<Resource> res = test ? getOriginalMavenProject().getTestResources() : getOriginalMavenProject().getResources();
LBL : for (Resource elem : res) {
String dir = elem.getDirectory();
if (dir == null) {
continue; // #191742
}
URI uri = FileUtilities.getDirURI(getProjectDirectory(), dir);
if (elem.getTargetPath() != null || !elem.getExcludes().isEmpty() || !elem.getIncludes().isEmpty()) {
URI rel = projectroot.relativize(uri);
if (rel.isAbsolute()) { //outside of project directory
continue;// #195928, #231517
}
if (sourceRoots == null) {
sourceRoots = new HashSet<URI>();
sourceRoots.addAll(Arrays.asList(getSourceRoots(true)));
sourceRoots.addAll(Arrays.asList(getSourceRoots(false)));
//should we also consider generated sources? most like not necessary
}
for (URI sr : sourceRoots) {
if (!uri.relativize(sr).isAbsolute()) {
continue LBL;// #195928, #231517
}
}
//hope for the best now
}
// if (new File(uri).exists()) {
toRet.add(uri);
// }
}
return toRet.toArray(new URI[toRet.size()]);
}
示例4: getPathRelativeToWC
import java.net.URI; //导入方法依赖的package包/类
protected String getPathRelativeToWC(File file) {
URI wcURI = getWC().toURI();
URI fileURI = file.toURI();
URI relativePathURI = wcURI.relativize(fileURI);
if (relativePathURI == fileURI) {
throw new IllegalArgumentException(
"The given file is not in the working directory.");
}
return relativePathURI.getPath();
}
示例5: rtvz
import java.net.URI; //导入方法依赖的package包/类
Test rtvz(URI base) {
if (!parsed())
return this;
this.base = base;
op = "rtvz";
uri = base.relativize(uri);
checked = 0;
failed = 0;
return this;
}
示例6: doJsHint
import java.net.URI; //导入方法依赖的package包/类
@TaskAction
public void doJsHint() {
RhinoWorkerHandleFactory handleFactory = new DefaultRhinoWorkerHandleFactory(getWorkerProcessBuilderFactory());
LogLevel logLevel = getProject().getGradle().getStartParameter().getLogLevel();
JsHintProtocol worker = handleFactory.create(getRhinoClasspath(), JsHintProtocol.class, JsHintWorker.class, logLevel, getProject().getProjectDir());
JsHintSpec spec = new JsHintSpec();
spec.setSource(getSource().getFiles()); // flatten because we need to serialize
spec.setEncoding(getEncoding());
spec.setJsHint(getJsHint().getSingleFile());
JsHintResult result = worker.process(spec);
setDidWork(true);
// TODO - this is all terribly lame. We need some proper reporting here (which means implementing Reporting).
Logger logger = getLogger();
boolean anyErrors = false;
Map<String, Map<?, ?>> reportData = new LinkedHashMap<String, Map<?, ?>>(result.getResults().size());
for (Map.Entry<File, Map<String, Object>> fileEntry: result.getResults().entrySet()) {
File file = fileEntry.getKey();
Map<String, Object> data = fileEntry.getValue();
reportData.put(file.getAbsolutePath(), data);
if (data.containsKey("errors")) {
anyErrors = true;
URI projectDirUri = getProject().getProjectDir().toURI();
@SuppressWarnings("unchecked") Map<String, Object> errors = (Map<String, Object>) data.get("errors");
if (!errors.isEmpty()) {
URI relativePath = projectDirUri.relativize(file.toURI());
logger.warn("JsHint errors for file: {}", relativePath.getPath());
for (Map.Entry<String, Object> errorEntry : errors.entrySet()) {
@SuppressWarnings("unchecked") Map<String, Object> error = (Map<String, Object>) errorEntry.getValue();
int line = Float.valueOf(error.get("line").toString()).intValue();
int character = Float.valueOf(error.get("character").toString()).intValue();
String reason = error.get("reason").toString();
logger.warn(" {}:{} > {}", new Object[] {line, character, reason});
}
}
}
}
File jsonReportFile = getJsonReport();
if (jsonReportFile != null) {
try {
FileWriter reportWriter = new FileWriter(jsonReportFile);
new GsonBuilder().setPrettyPrinting().create().toJson(reportData, reportWriter);
reportWriter.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
if (anyErrors) {
throw new TaskExecutionException(this, new GradleException("JsHint detected errors"));
}
}
示例7: constructRelativeClasspathUri
import java.net.URI; //导入方法依赖的package包/类
private static String constructRelativeClasspathUri(File jarFile, File file) {
URI jarFileUri = jarFile.getParentFile().toURI();
URI fileUri = file.toURI();
URI relativeUri = jarFileUri.relativize(fileUri);
return relativeUri.getRawPath();
}
示例8: getRelativeURI
import java.net.URI; //导入方法依赖的package包/类
public static URI getRelativeURI(ProjectBookmarks projectBookmarks, URI fileURI) {
URI projectURI = projectBookmarks.getProjectURI();
return (projectURI != null) ? projectURI.relativize(fileURI) : fileURI;
}