use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class ArtifactCacheHandler method handleGet.
private int handleGet(Request baseRequest, HttpServletResponse response) throws IOException {
if (!artifactCache.isPresent()) {
response.getWriter().write("Serving local cache is disabled for this instance.");
return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
}
String path = baseRequest.getUri().getPath();
String[] pathElements = path.split("/");
if (pathElements.length != 4 || !pathElements[2].equals("key")) {
response.getWriter().write("Incorrect url format.");
return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
}
RuleKey ruleKey = new RuleKey(pathElements[3]);
Path temp = null;
try {
projectFilesystem.mkdirs(projectFilesystem.getBuckPaths().getScratchDir());
temp = projectFilesystem.createTempFile(projectFilesystem.getBuckPaths().getScratchDir(), "outgoing_rulekey", ".tmp");
CacheResult fetchResult = artifactCache.get().fetch(ruleKey, LazyPath.ofInstance(temp));
if (!fetchResult.getType().isSuccess()) {
return HttpServletResponse.SC_NOT_FOUND;
}
final Path tempFinal = temp;
HttpArtifactCacheBinaryProtocol.FetchResponse fetchResponse = new HttpArtifactCacheBinaryProtocol.FetchResponse(ImmutableSet.of(ruleKey), fetchResult.getMetadata(), new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return projectFilesystem.newFileInputStream(tempFinal);
}
});
fetchResponse.write(response.getOutputStream());
response.setContentLengthLong(fetchResponse.getContentLength());
return HttpServletResponse.SC_OK;
} finally {
if (temp != null) {
projectFilesystem.deleteFileAtPathIfExists(temp);
}
}
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class AaptPackageResourcesTest method testThatChangingAndroidManifestChangesRuleKey.
@Test
public void testThatChangingAndroidManifestChangesRuleKey() {
// Generate a rule key for the defaults.
AaptConstructorArgs args = new AaptConstructorArgs();
args.manifest = createPathSourcePath("AndroidManifest.xml", "same_content");
RuleKey previousRuleKey = calculateRuleKey(args);
args.manifest = createPathSourcePath("other/AndroidManifest.xml", "same_content");
previousRuleKey = assertKeyChanged(previousRuleKey, args);
args.manifest = createPathSourcePath("other/AndroidManifest.xml", "different_content");
previousRuleKey = assertKeyChanged(previousRuleKey, args);
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class AaptPackageResourcesTest method testThatChangingResourceDirectoryOrderChangesRulekey.
@Test
public void testThatChangingResourceDirectoryOrderChangesRulekey() {
// Generate a rule key for the defaults.
AaptConstructorArgs args = new AaptConstructorArgs();
RuleKey previousRuleKey = calculateRuleKey(args);
args.hasAndroidResourceDeps = ImmutableList.of(resource1, resource2);
args.filteredResourcesProvider = new IdentityResourcesProvider(ImmutableList.of(Paths.get("res1"), Paths.get("res2")));
previousRuleKey = assertKeyChanged(previousRuleKey, args);
args.hasAndroidResourceDeps = ImmutableList.of(resource1, resource2);
args.filteredResourcesProvider = new IdentityResourcesProvider(ImmutableList.of(Paths.get("res2"), Paths.get("res1")));
// TODO(cjhopman): AaptPackageResources' rulekey doesn't properly reflect changes in the
// ordering of resource-only dependencies.
// previousRuleKey = assertKeyChanged(previousRuleKey, args);
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class AaptPackageResourcesTest method testThatChangingResourcesChangesRuleKey.
@Test
public void testThatChangingResourcesChangesRuleKey() {
// Generate a rule key for the defaults.
AaptConstructorArgs args = new AaptConstructorArgs();
RuleKey previousRuleKey = calculateRuleKey(args);
args.hasAndroidResourceDeps = ImmutableList.of(resource1);
previousRuleKey = assertKeyChanged(previousRuleKey, args);
createPathSourcePath("res1", "different_value");
previousRuleKey = assertKeyChanged(previousRuleKey, args);
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class AaptPackageResourcesTest method testThatChangingManifestEntriesChangesRuleKey.
@Test
public void testThatChangingManifestEntriesChangesRuleKey() {
// Generate a rule key for the defaults.
AaptConstructorArgs args = new AaptConstructorArgs();
args.manifestEntries = ManifestEntries.builder().setDebugMode(false).build();
RuleKey previousRuleKey = calculateRuleKey(args);
args.manifestEntries = ManifestEntries.builder().setDebugMode(true).build();
previousRuleKey = assertKeyChanged(previousRuleKey, args);
}
Aggregations