Search in sources :

Example 1 with CannotResolveLabel

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.");
}
Also used : CannotResolveLabel(com.google.copybara.exception.CannotResolveLabel) Test(org.junit.Test)

Example 2 with CannotResolveLabel

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.");
}
Also used : CannotResolveLabel(com.google.copybara.exception.CannotResolveLabel) Test(org.junit.Test)

Example 3 with CannotResolveLabel

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");
}
Also used : CannotResolveLabel(com.google.copybara.exception.CannotResolveLabel) Test(org.junit.Test)

Example 4 with CannotResolveLabel

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()));
    }
}
Also used : CannotResolveLabel(com.google.copybara.exception.CannotResolveLabel)

Example 5 with CannotResolveLabel

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();
}
Also used : Path(java.nio.file.Path) CannotResolveLabel(com.google.copybara.exception.CannotResolveLabel) ConfigFile(com.google.copybara.config.ConfigFile) ImmutableList(com.google.common.collect.ImmutableList) IOException(java.io.IOException)

Aggregations

CannotResolveLabel (com.google.copybara.exception.CannotResolveLabel)5 Test (org.junit.Test)3 ImmutableList (com.google.common.collect.ImmutableList)1 ConfigFile (com.google.copybara.config.ConfigFile)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1