use of com.google.copybara.exception.CannotResolveLabel in project copybara by google.
the class MapConfigFileTest method testResolveFailure.
@Test
public void testResolveFailure() throws CannotResolveLabel {
ImmutableMap<String, byte[]> map = ImmutableMap.of("/foo", "foo".getBytes(UTF_8));
ConfigFile fooConfig = new MapConfigFile(ImmutableMap.copyOf(map), "/foo");
CannotResolveLabel thrown = assertThrows(CannotResolveLabel.class, () -> fooConfig.resolve("bar"));
assertThat(thrown).hasMessageThat().contains("Cannot resolve '/bar': does not exist.");
}
use of com.google.copybara.exception.CannotResolveLabel in project copybara by google.
the class PathBasedConfigFileTest method testResolveFailure.
@Test
public void testResolveFailure() throws IOException, CannotResolveLabel {
ConfigFile fooConfig = new PathBasedConfigFile(Files.write(fs.getPath("/foo"), "foo".getBytes(UTF_8)), /*rootPath=*/
null, /*identifierPrefix=*/
null);
CannotResolveLabel thrown = assertThrows(CannotResolveLabel.class, () -> fooConfig.resolve("bar"));
assertThat(thrown).hasMessageThat().contains("Cannot find 'bar'. '/bar' does not exist.");
}
use of com.google.copybara.exception.CannotResolveLabel in project copybara by google.
the class PathBasedConfigFileTest method testAbsoluteResolveFailsIfNoRoot.
@Test
public void testAbsoluteResolveFailsIfNoRoot() throws IOException, CannotResolveLabel {
ConfigFile fooConfig = new PathBasedConfigFile(Files.write(fs.getPath("/foo"), "foo".getBytes(UTF_8)), /*rootPath=*/
null, /*identifierPrefix=*/
null);
CannotResolveLabel thrown = assertThrows(CannotResolveLabel.class, () -> fooConfig.resolve("//bar"));
assertThat(thrown).hasMessageThat().contains("Absolute paths are not allowed because the root config path" + " couldn't be automatically detected");
}
use of com.google.copybara.exception.CannotResolveLabel in project copybara by google.
the class ConfigFile method isAbsolute.
/**
* Check if the path is absolute and validates that the path is normalized
* @throws CannotResolveLabel if the path is not normalized
*/
static boolean isAbsolute(String path) throws CannotResolveLabel {
boolean isAbsolute = path.startsWith("//");
// Remove '//' for absolute paths
String withoutPrefix = isAbsolute ? path.substring(2) : path;
try {
FileUtil.checkNormalizedRelative(withoutPrefix);
return isAbsolute;
} catch (IllegalArgumentException e) {
throw new CannotResolveLabel(String.format("Invalid path '%s': %s", withoutPrefix, e.getMessage()));
}
}
use of com.google.copybara.exception.CannotResolveLabel in project copybara by google.
the class QuiltTransformation method copyPatchConfigsToTmpDir.
private ImmutableList<Path> copyPatchConfigsToTmpDir() throws IOException {
ImmutableList.Builder<Path> builder = ImmutableList.builder();
Path patchDir = options.getGeneralOptions().getDirFactory().newTempDir("inputpatches");
for (ConfigFile patch : patchConfigs) {
// Uses String instead of Path for baseName, because patchDir's FileSystem may not match
// the default FileSystem from Paths.get().
String baseName = Paths.get(patch.path()).getFileName().toString();
Path patchFile = patchDir.resolve(baseName);
builder.add(patchFile);
try {
Files.write(patchFile, patch.readContentBytes());
} catch (CannotResolveLabel e) {
throw new IOException("Error reading input patch", e);
}
}
return builder.build();
}
Aggregations