コード例 #1
0
ファイル: ProjectWorkspace.java プロジェクト: kkartikeya/buck
  /**
   * This will copy the template directory, renaming files named {@code BUCK.test} to {@code BUCK}
   * in the process. Files whose names end in {@code .expected} will not be copied.
   */
  public void setUp() throws IOException {
    DefaultKnownBuildRuleTypes.resetInstance();

    MoreFiles.copyRecursively(templatePath, destPath, BUILD_FILE_RENAME);

    // If there's a local.properties in the host project but not in the destination, make a copy.
    Path localProperties = FileSystems.getDefault().getPath("local.properties");
    Path destLocalProperties = destPath.resolve(localProperties.getFileName());

    if (localProperties.toFile().exists() && !destLocalProperties.toFile().exists()) {
      java.nio.file.Files.copy(localProperties, destLocalProperties);
    }

    if (Platform.detect() == Platform.WINDOWS) {
      // Hack for symlinks on Windows.
      SimpleFileVisitor<Path> copyDirVisitor =
          new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path path, BasicFileAttributes attrs)
                throws IOException {
              // On Windows, symbolic links from git repository are checked out as normal files
              // containing a one-line path. In order to distinguish them, paths are read and
              // pointed
              // files are trued to locate. Once the pointed file is found, it will be copied to
              // target.
              // On NTFS length of path must be greater than 0 and less than 4096.
              if (attrs.size() > 0 && attrs.size() <= 4096) {
                File file = path.toFile();
                String linkTo = Files.toString(file, Charsets.UTF_8);
                File linkToFile = new File(templatePath.toFile(), linkTo);
                if (linkToFile.isFile()) {
                  java.nio.file.Files.copy(
                      linkToFile.toPath(), path, StandardCopyOption.REPLACE_EXISTING);
                } else if (linkToFile.isDirectory()) {
                  if (!file.delete()) {
                    throw new IOException();
                  }
                  MoreFiles.copyRecursively(linkToFile.toPath(), path);
                }
              }
              return FileVisitResult.CONTINUE;
            }
          };
      java.nio.file.Files.walkFileTree(destPath, copyDirVisitor);
    }
    isSetUp = true;
  }
コード例 #2
0
  @Test
  public void shouldFindNeededDependenciesFromSymbols() throws IOException, InterruptedException {
    ProjectWorkspace workspace =
        TestDataHelper.createProjectWorkspaceForScenario(this, "symbol_finder", temporaryFolder);
    workspace.setUp();

    ProjectFilesystem projectFilesystem = new ProjectFilesystem(temporaryFolder.getRootPath());
    ImmutableMap<String, String> environment = ImmutableMap.copyOf(System.getenv());

    Config rawConfig =
        Config.createDefaultConfig(
            projectFilesystem.getRootPath(),
            ImmutableMap.<String, ImmutableMap<String, String>>of());
    BuckConfig config =
        new BuckConfig(
            rawConfig, projectFilesystem, Architecture.detect(), Platform.detect(), environment);
    ImmutableSet<Description<?>> allDescriptions =
        DefaultKnownBuildRuleTypes.getDefaultKnownBuildRuleTypes(projectFilesystem)
            .getAllDescriptions();
    BuckEventBus buckEventBus = BuckEventBusFactory.newInstance();

    MissingSymbolsHandler missingSymbolsHandler =
        MissingSymbolsHandler.create(
            projectFilesystem,
            allDescriptions,
            config,
            buckEventBus,
            new TestConsole(),
            DEFAULT_JAVAC_OPTIONS,
            environment);

    MissingSymbolEvent missingSymbolEvent =
        MissingSymbolEvent.create(
            BuildTargetFactory.newInstance(workspace.getDestPath(), "//java/com/example/b:b"),
            "com.example.a.A",
            MissingSymbolEvent.SymbolType.Java);

    ImmutableSetMultimap<BuildTarget, BuildTarget> neededDeps =
        missingSymbolsHandler.getNeededDependencies(ImmutableList.of(missingSymbolEvent));

    assertEquals(
        "MissingSymbolsHandler failed to find the needed dependency.",
        neededDeps,
        ImmutableSetMultimap.of(
            BuildTargetFactory.newInstance(workspace.getDestPath(), "//java/com/example/b:b"),
            BuildTargetFactory.newInstance(workspace.getDestPath(), "//java/com/example/a:a")));
  }
コード例 #3
0
 private AuditOwnerCommand createAuditOwnerCommand(ProjectFilesystem filesystem) {
   KnownBuildRuleTypes buildRuleTypes =
       DefaultKnownBuildRuleTypes.getDefaultKnownBuildRuleTypes(filesystem);
   ArtifactCache artifactCache = new NoopArtifactCache();
   BuckEventBus eventBus = BuckEventBusFactory.newInstance();
   AndroidDirectoryResolver androidDirectoryResolver = new FakeAndroidDirectoryResolver();
   return new AuditOwnerCommand(
       new CommandRunnerParams(
           console,
           filesystem,
           androidDirectoryResolver,
           buildRuleTypes,
           new InstanceArtifactCacheFactory(artifactCache),
           eventBus,
           buckConfig.getPythonInterpreter(),
           Platform.detect(),
           ImmutableMap.copyOf(System.getenv())));
 }