当前位置: 首页>>代码示例>>Java>>正文


Java URI.relativize方法代码示例

本文整理汇总了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));
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-testing-clients,代码行数:29,代码来源:AbstractSlingClient.java

示例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();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:8,代码来源:PublishArtifactToFileBuildOutcomeTransformer.java

示例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()]);
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:NbMavenProjectImpl.java

示例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();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:AbstractSvnTestCase.java

示例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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:Test.java

示例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"));
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:63,代码来源:JsHint.java

示例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();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:7,代码来源:ManifestUtil.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:5,代码来源:BookmarkUtils.java


注:本文中的java.net.URI.relativize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。