Search in sources :

Example 1 with ArchiveMemberSourcePath

use of com.facebook.buck.rules.ArchiveMemberSourcePath in project buck by facebook.

the class DefaultClassUsageFileReader method loadFromFile.

public static ImmutableList<SourcePath> loadFromFile(SourcePathResolver pathResolver, ProjectFilesystem projectFilesystem, Path classUsageFilePath, ImmutableSortedSet<BuildRule> deps) {
    final ImmutableMap<Path, SourcePath> jarAbsolutePathToAbiJarSourcePath = buildJarToAbiJarMap(pathResolver, deps);
    final ImmutableList.Builder<SourcePath> builder = ImmutableList.builder();
    try {
        final ImmutableSet<Map.Entry<String, ImmutableList<String>>> classUsageEntries = loadClassUsageMap(classUsageFilePath).entrySet();
        for (Map.Entry<String, ImmutableList<String>> jarUsedClassesEntry : classUsageEntries) {
            Path jarAbsolutePath = projectFilesystem.resolve(Paths.get(jarUsedClassesEntry.getKey()));
            SourcePath abiJarSourcePath = jarAbsolutePathToAbiJarSourcePath.get(jarAbsolutePath);
            if (abiJarSourcePath == null) {
                // it came from the build environment (JDK, Android SDK, etc.)
                continue;
            }
            ImmutableList<String> classAbsolutePaths = jarUsedClassesEntry.getValue();
            for (String classAbsolutePath : classAbsolutePaths) {
                builder.add(new ArchiveMemberSourcePath(abiJarSourcePath, Paths.get(classAbsolutePath)));
            }
        }
    } catch (IOException e) {
        throw new HumanReadableException(e, "Failed to load class usage files from %s:\n%s", classUsageFilePath, e.getLocalizedMessage());
    }
    return builder.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) IOException(java.io.IOException) SourcePath(com.facebook.buck.rules.SourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) HumanReadableException(com.facebook.buck.util.HumanReadableException) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 2 with ArchiveMemberSourcePath

use of com.facebook.buck.rules.ArchiveMemberSourcePath in project buck by facebook.

the class DependencyFileRuleKeyFactoryTest method testKeysWhenInputArchiveMemberChanges.

@Test
public void testKeysWhenInputArchiveMemberChanges() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRuleResolver ruleResolver = newRuleResolver();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    SourcePath archivePath = new PathSourcePath(filesystem, Paths.get("archive"));
    SourcePath usedSourcePath = new ArchiveMemberSourcePath(archivePath, Paths.get("used"));
    SourcePath unusedSourcePath = new ArchiveMemberSourcePath(archivePath, Paths.get("unused"));
    SourcePath noncoveredSourcePath = new ArchiveMemberSourcePath(archivePath, Paths.get("nc"));
    SourcePath interestingSourcePath = new ArchiveMemberSourcePath(archivePath, Paths.get("META-INF"));
    testKeysWhenInputContentsChanges(ruleFinder, pathResolver, usedSourcePath, unusedSourcePath, noncoveredSourcePath, interestingSourcePath, Paths.get(pathResolver.getAbsoluteArchiveMemberPath(usedSourcePath).toString()), Paths.get(pathResolver.getAbsoluteArchiveMemberPath(unusedSourcePath).toString()), Paths.get(pathResolver.getAbsoluteArchiveMemberPath(noncoveredSourcePath).toString()), Paths.get(pathResolver.getAbsoluteArchiveMemberPath(interestingSourcePath).toString()), DependencyFileEntry.fromSourcePath(usedSourcePath, pathResolver));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 3 with ArchiveMemberSourcePath

use of com.facebook.buck.rules.ArchiveMemberSourcePath in project buck by facebook.

the class AbstractDependencyFileEntry method fromSourcePath.

public static DependencyFileEntry fromSourcePath(SourcePath sourcePath, SourcePathResolver resolver) {
    final DependencyFileEntry.Builder builder = DependencyFileEntry.builder();
    if (sourcePath instanceof ArchiveMemberSourcePath) {
        ArchiveMemberSourcePath archiveMemberSourcePath = (ArchiveMemberSourcePath) sourcePath;
        ArchiveMemberPath relativeArchiveMemberPath = resolver.getRelativeArchiveMemberPath(archiveMemberSourcePath);
        builder.setPathToFile(relativeArchiveMemberPath.getArchivePath());
        builder.setPathWithinArchive(relativeArchiveMemberPath.getMemberPath());
    } else {
        builder.setPathToFile(resolver.getRelativePath(sourcePath));
    }
    return builder.build();
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath)

Aggregations

ArchiveMemberSourcePath (com.facebook.buck.rules.ArchiveMemberSourcePath)3 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)2 SourcePath (com.facebook.buck.rules.SourcePath)2 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)1 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)1 PathSourcePath (com.facebook.buck.rules.PathSourcePath)1 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)1 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)1 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Map (java.util.Map)1 Test (org.junit.Test)1