本文整理了Java中org.uberfire.java.nio.file.Path.relativize()
方法的一些代码示例,展示了Path.relativize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Path.relativize()
方法的具体详情如下:
包路径:org.uberfire.java.nio.file.Path
类名称:Path
方法名:relativize
暂无
代码示例来源:origin: kiegroup/appformer
@Override
public FileVisitResult preVisitDirectory(final org.uberfire.java.nio.file.Path src,
final BasicFileAttributes attrs) {
final org.uberfire.java.nio.file.Path tgt = target.resolve(source.relativize(src));
try {
Files.copy(src,
tgt,
StandardCopyOption.REPLACE_EXISTING);
// } catch (FileAlreadyExistsException x) {
} catch (Exception x) {
x.printStackTrace();
//Swallow
}
return FileVisitResult.CONTINUE;
}
代码示例来源:origin: org.uberfire/uberfire-project-backend
private String getPackagePathSuffix(final org.uberfire.java.nio.file.Path nioModuleRootPath,
final org.uberfire.java.nio.file.Path nioPackagePath) {
final org.uberfire.java.nio.file.Path nioMainSrcPath = nioModuleRootPath.resolve(MAIN_SRC_PATH);
final org.uberfire.java.nio.file.Path nioTestSrcPath = nioModuleRootPath.resolve(TEST_SRC_PATH);
final org.uberfire.java.nio.file.Path nioMainResourcesPath = nioModuleRootPath.resolve(MAIN_RESOURCES_PATH);
final org.uberfire.java.nio.file.Path nioTestResourcesPath = nioModuleRootPath.resolve(TEST_RESOURCES_PATH);
String packageName = null;
org.uberfire.java.nio.file.Path packagePath = null;
if (nioPackagePath.startsWith(nioMainSrcPath)) {
packagePath = nioMainSrcPath.relativize(nioPackagePath);
packageName = packagePath.toString();
} else if (nioPackagePath.startsWith(nioTestSrcPath)) {
packagePath = nioTestSrcPath.relativize(nioPackagePath);
packageName = packagePath.toString();
} else if (nioPackagePath.startsWith(nioMainResourcesPath)) {
packagePath = nioMainResourcesPath.relativize(nioPackagePath);
packageName = packagePath.toString();
} else if (nioPackagePath.startsWith(nioTestResourcesPath)) {
packagePath = nioTestResourcesPath.relativize(nioPackagePath);
packageName = packagePath.toString();
}
return packageName;
}
代码示例来源:origin: org.guvnor/guvnor-project-backend
private String getPackagePathSuffix(final org.uberfire.java.nio.file.Path nioProjectRootPath,
final org.uberfire.java.nio.file.Path nioPackagePath) {
final org.uberfire.java.nio.file.Path nioMainSrcPath = nioProjectRootPath.resolve(MAIN_SRC_PATH);
final org.uberfire.java.nio.file.Path nioTestSrcPath = nioProjectRootPath.resolve(TEST_SRC_PATH);
final org.uberfire.java.nio.file.Path nioMainResourcesPath = nioProjectRootPath.resolve(MAIN_RESOURCES_PATH);
final org.uberfire.java.nio.file.Path nioTestResourcesPath = nioProjectRootPath.resolve(TEST_RESOURCES_PATH);
String packageName = null;
org.uberfire.java.nio.file.Path packagePath = null;
if (nioPackagePath.startsWith(nioMainSrcPath)) {
packagePath = nioMainSrcPath.relativize(nioPackagePath);
packageName = packagePath.toString();
} else if (nioPackagePath.startsWith(nioTestSrcPath)) {
packagePath = nioTestSrcPath.relativize(nioPackagePath);
packageName = packagePath.toString();
} else if (nioPackagePath.startsWith(nioMainResourcesPath)) {
packagePath = nioMainResourcesPath.relativize(nioPackagePath);
packageName = packagePath.toString();
} else if (nioPackagePath.startsWith(nioTestResourcesPath)) {
packagePath = nioTestResourcesPath.relativize(nioPackagePath);
packageName = packagePath.toString();
}
return packageName;
}
代码示例来源:origin: kiegroup/appformer
private String getPackagePathSuffix(final org.uberfire.java.nio.file.Path nioModuleRootPath,
final org.uberfire.java.nio.file.Path nioPackagePath) {
final org.uberfire.java.nio.file.Path nioMainSrcPath = nioModuleRootPath.resolve(MAIN_SRC_PATH);
final org.uberfire.java.nio.file.Path nioTestSrcPath = nioModuleRootPath.resolve(TEST_SRC_PATH);
final org.uberfire.java.nio.file.Path nioMainResourcesPath = nioModuleRootPath.resolve(MAIN_RESOURCES_PATH);
final org.uberfire.java.nio.file.Path nioTestResourcesPath = nioModuleRootPath.resolve(TEST_RESOURCES_PATH);
String packageName = null;
org.uberfire.java.nio.file.Path packagePath = null;
if (nioPackagePath.startsWith(nioMainSrcPath)) {
packagePath = nioMainSrcPath.relativize(nioPackagePath);
packageName = packagePath.toString();
} else if (nioPackagePath.startsWith(nioTestSrcPath)) {
packagePath = nioTestSrcPath.relativize(nioPackagePath);
packageName = packagePath.toString();
} else if (nioPackagePath.startsWith(nioMainResourcesPath)) {
packagePath = nioMainResourcesPath.relativize(nioPackagePath);
packageName = packagePath.toString();
} else if (nioPackagePath.startsWith(nioTestResourcesPath)) {
packagePath = nioTestResourcesPath.relativize(nioPackagePath);
packageName = packagePath.toString();
}
return packageName;
}
代码示例来源:origin: kiegroup/drools-wb
private List<String> loadWorkItemImages(final Path resourcePath) {
final Path projectRoot = moduleService.resolveModule(resourcePath).getRootPath();
final org.uberfire.java.nio.file.Path nioProjectPath = Paths.convert(projectRoot);
final org.uberfire.java.nio.file.Path nioResourceParent = Paths.convert(resourcePath).getParent();
final Collection<org.uberfire.java.nio.file.Path> imagePaths = fileDiscoveryService.discoverFiles(nioProjectPath,
imageFilter,
true);
final List<String> images = new ArrayList<String>();
for (org.uberfire.java.nio.file.Path imagePath : imagePaths) {
final org.uberfire.java.nio.file.Path relativePath = nioResourceParent.relativize(imagePath);
images.add(relativePath.toString());
}
return images;
}
代码示例来源:origin: org.drools/drools-wb-workitems-editor-backend
private List<String> loadWorkItemImages(final Path resourcePath) {
final Path projectRoot = moduleService.resolveModule(resourcePath).getRootPath();
final org.uberfire.java.nio.file.Path nioProjectPath = Paths.convert(projectRoot);
final org.uberfire.java.nio.file.Path nioResourceParent = Paths.convert(resourcePath).getParent();
final Collection<org.uberfire.java.nio.file.Path> imagePaths = fileDiscoveryService.discoverFiles(nioProjectPath,
imageFilter,
true);
final List<String> images = new ArrayList<String>();
for (org.uberfire.java.nio.file.Path imagePath : imagePaths) {
final org.uberfire.java.nio.file.Path relativePath = nioResourceParent.relativize(imagePath);
images.add(relativePath.toString());
}
return images;
}
代码示例来源:origin: kiegroup/appformer
@Test
public void relativize() {
final Path path = GeneralPathImpl.create(fs,
"/path/to/file.txt",
false);
assertThatThrownBy(() -> path.relativize(null))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Parameter named 'otherx' should be not null!");
}
代码示例来源:origin: kiegroup/appformer
/**
* Substring the second path from the first. This can be used to for example to substring the repository prefix from a Path.
* @param wholePath What we want to substring from the first Path
* @param prefixToRemove The Path we want to substring
* @return The result. For example the File URI from the Repository root or from a submodule root.
* @throws IllegalStateException When the the prefix is longer than the URI where it is removed from.
*/
public static String removePrefix(final Path wholePath,
final Path prefixToRemove) {
PortablePreconditions.checkNotNull("prefixToRemove", prefixToRemove);
PortablePreconditions.checkNotNull("wholePath", wholePath);
if (prefixToRemove.toURI().length() > wholePath.toURI().length()) {
throw new IllegalArgumentException("Prefix is longer than the URI where it is being removed from.");
}
final org.uberfire.java.nio.file.Path nioWholePath = convert(wholePath);
final org.uberfire.java.nio.file.Path nioPrefixToRemove = convert(prefixToRemove);
if (!nioWholePath.startsWith(nioPrefixToRemove)) {
throw new IllegalArgumentException("The beginning of the whole Path " + nioWholePath + " does not match the prefix path " + nioPrefixToRemove + ".");
}
return nioPrefixToRemove.relativize(nioWholePath).toString();
}
代码示例来源:origin: org.kie.workbench.screens/kie-wb-common-data-modeller-backend
/**
* Given a path within a module calculates the expected class name for the given class.
*/
public String calculateClassName(final Module module,
final org.uberfire.backend.vfs.Path path) {
PortablePreconditions.checkNotNull("module", module);
if (path == null) {
return null;
}
final Package defaultPackage = moduleService.resolveDefaultPackage(module);
if (defaultPackage == null) {
return null;
}
final Path mainSrcNioPath = Paths.convert(defaultPackage.getPackageMainSrcPath());
final Path testSrcNioPath = Paths.convert(defaultPackage.getPackageTestSrcPath());
final Path nioPath = Paths.convert(path);
Path relativePath = null;
if (mainSrcNioPath != null && nioPath.startsWith(mainSrcNioPath)) {
relativePath = mainSrcNioPath.relativize(nioPath);
} else if (testSrcNioPath != null && nioPath.startsWith(testSrcNioPath)) {
relativePath = testSrcNioPath.relativize(nioPath);
}
if (relativePath != null) {
String className = relativePath.toString().replace("/", ".");
return className.substring(0, className.lastIndexOf(".java"));
}
return null;
}
代码示例来源:origin: kiegroup/appformer
@Test
public void testRelativizeWindowsIllegal3() {
final FileSystemProvider fsprovider = mock(FileSystemProvider.class);
when(fsprovider.isDefault()).thenReturn(true);
when(fsprovider.getScheme()).thenReturn("file");
when(fs.provider()).thenReturn(fsprovider);
when(fs.getSeparator()).thenReturn("\\");
final Path path = create(fs,
"",
false);
final Path other = create(fs,
"c:\\path\\to",
false);
assertThatThrownBy(() -> path.relativize(other))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Could not relativize path 'otherx', 'isAbsolute()' for 'this' and 'otherx' should be equal.");
}
代码示例来源:origin: kiegroup/appformer
@Test
public void testRelativizeIlegal1() {
final FileSystemProvider fsprovider = mock(FileSystemProvider.class);
when(fsprovider.isDefault()).thenReturn(true);
when(fsprovider.getScheme()).thenReturn("file");
when(fs.provider()).thenReturn(fsprovider);
when(fs.getSeparator()).thenReturn("/");
final Path path = create(fs,
"/path/to",
false);
final Path other = create(fs,
"some/place",
false);
assertThatThrownBy(() -> path.relativize(other))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Could not relativize path 'otherx', 'isAbsolute()' for 'this' and 'otherx' should be equal.");
}
代码示例来源:origin: kiegroup/appformer
@Test
public void testRelativizeWindowsIllegal1() {
final FileSystemProvider fsprovider = mock(FileSystemProvider.class);
when(fsprovider.isDefault()).thenReturn(true);
when(fsprovider.getScheme()).thenReturn("file");
when(fs.provider()).thenReturn(fsprovider);
when(fs.getSeparator()).thenReturn("\\");
final Path path = create(fs,
"c:\\path\\to",
false);
final Path other = create(fs,
"some\\place",
false);
assertThatThrownBy(() -> path.relativize(other))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Could not relativize path 'otherx', 'isAbsolute()' for 'this' and 'otherx' should be equal.");
}
代码示例来源:origin: kiegroup/appformer
@Test
public void testRelativizeWindowsIllegal2() {
final FileSystemProvider fsprovider = mock(FileSystemProvider.class);
when(fsprovider.isDefault()).thenReturn(true);
when(fsprovider.getScheme()).thenReturn("file");
when(fs.provider()).thenReturn(fsprovider);
when(fs.getSeparator()).thenReturn("\\");
final Path path = create(fs,
"some\\place",
false);
final Path other = create(fs,
"c:\\path\\to",
false);
assertThatThrownBy(() -> path.relativize(other))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Could not relativize path 'otherx', 'isAbsolute()' for 'this' and 'otherx' should be equal.");
}
代码示例来源:origin: kiegroup/appformer
@Test
public void testRelativizeIlegal2() {
final FileSystemProvider fsprovider = mock(FileSystemProvider.class);
when(fsprovider.isDefault()).thenReturn(true);
when(fsprovider.getScheme()).thenReturn("file");
when(fs.provider()).thenReturn(fsprovider);
when(fs.getSeparator()).thenReturn("/");
final Path path = create(fs,
"some/place",
false);
final Path other = create(fs,
"/path/to",
false);
assertThatThrownBy(() -> path.relativize(other))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Could not relativize path 'otherx', 'isAbsolute()' for 'this' and 'otherx' should be equal.");
}
代码示例来源:origin: kiegroup/appformer
@Test
public void testRelativizeIlegal3() {
final FileSystemProvider fsprovider = mock(FileSystemProvider.class);
when(fsprovider.isDefault()).thenReturn(true);
when(fsprovider.getScheme()).thenReturn("file");
when(fs.provider()).thenReturn(fsprovider);
when(fs.getSeparator()).thenReturn("/");
final Path path = create(fs,
"",
false);
final Path other = create(fs,
"/path/to",
false);
assertThatThrownBy(() -> path.relativize(other))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Could not relativize path 'otherx', 'isAbsolute()' for 'this' and 'otherx' should be equal.");
}
代码示例来源:origin: kiegroup/appformer
@Test
public void testRelativizeWindowsIllegal4() {
final FileSystemProvider fsprovider = mock(FileSystemProvider.class);
when(fsprovider.isDefault()).thenReturn(true);
when(fsprovider.getScheme()).thenReturn("file");
when(fs.provider()).thenReturn(fsprovider);
when(fs.getSeparator()).thenReturn("\\");
final Path path = create(fs,
"d:\\path\\to",
false);
final Path other = create(fs,
"c:\\path\\to",
false);
assertThatThrownBy(() -> path.relativize(other))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Could not relativize path 'otherx', 'getRoot()' for 'this' and 'otherx' should be equal.");
}
代码示例来源:origin: kiegroup/appformer
@Test
public void testRelativizeWindowsIllegal5() {
final FileSystemProvider fsprovider = mock(FileSystemProvider.class);
when(fsprovider.isDefault()).thenReturn(true);
when(fsprovider.getScheme()).thenReturn("file");
when(fs.provider()).thenReturn(fsprovider);
when(fs.getSeparator()).thenReturn("\\");
final Path path = create(fs,
"/d:/path/to",
false);
final Path other = create(fs,
"c:\\path\\to",
false);
assertThatThrownBy(() -> path.relativize(other))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Could not relativize path 'otherx', 'getRoot()' for 'this' and 'otherx' should be equal.");
}
代码示例来源:origin: org.uberfire/vfs-api
public static Path createDirectories(final Path dir, final FileAttribute<?>... attrs)
throws UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException {
checkNotNull("dir", dir);
final Path absoluteDir = dir.toAbsolutePath();
if (!notExists(absoluteDir)) {
throw new FileAlreadyExistsException(absoluteDir.toString());
}
Path parent = absoluteDir.getParent();
while (parent != null) {
try {
providerOf(parent).checkAccess(parent);
break;
} catch (NoSuchFileException x) {
}
parent = parent.getParent();
}
if (parent == null) {
throw new IOException("Root directory does not exist");
}
// create directories
Path child = parent;
for (final Path name : parent.relativize(dir)) {
child = child.resolve(name);
providerOf(child).createDirectory(child, attrs);
}
return dir;
}
代码示例来源:origin: org.uberfire/uberfire-nio2-api
public static Path createDirectories(final Path dir,
final FileAttribute<?>... attrs)
throws UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException {
checkNotNull("dir",
dir);
final Path absoluteDir = dir.toAbsolutePath();
if (!notExists(absoluteDir)) {
throw new FileAlreadyExistsException(absoluteDir.toString());
}
Path parent = absoluteDir.getParent();
while (parent != null) {
try {
providerOf(parent).checkAccess(parent);
break;
} catch (NoSuchFileException x) {
}
parent = parent.getParent();
}
if (parent == null) {
throw new IOException("Root directory does not exist");
}
// create directories
Path child = parent;
for (final Path name : parent.relativize(dir)) {
child = child.resolve(name);
providerOf(child).createDirectory(child,
attrs);
}
return dir;
}
代码示例来源:origin: kiegroup/appformer
public static Path createDirectories(final Path dir,
final FileAttribute<?>... attrs)
throws UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException {
checkNotNull("dir",
dir);
final Path absoluteDir = dir.toAbsolutePath();
if (!notExists(absoluteDir)) {
throw new FileAlreadyExistsException(absoluteDir.toString());
}
Path parent = absoluteDir.getParent();
while (parent != null) {
try {
providerOf(parent).checkAccess(parent);
break;
} catch (NoSuchFileException x) {
}
parent = parent.getParent();
}
if (parent == null) {
throw new IOException("Root directory does not exist");
}
// create directories
Path child = parent;
for (final Path name : parent.relativize(dir)) {
child = child.resolve(name);
providerOf(child).createDirectory(child,
attrs);
}
return dir;
}
内容来源于网络,如有侵权,请联系作者删除!