Search in sources :

Example 6 with FileUtils

use of com.google.startupos.common.FileUtils in project startup-os by google.

the class WorkspaceCommandTest method setup.

@Before
public void setup() throws IOException {
    // XXX parametrize test
    FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix());
    TestComponent component = DaggerWorkspaceCommandTest_TestComponent.builder().commonModule(new CommonModule() {

        @Override
        @Provides
        @Singleton
        public FileSystem provideDefaultFileSystem() {
            return fileSystem;
        }
    }).aaModule(new AaModule() {

        @Override
        @Provides
        @Singleton
        @Named("Base path")
        public String provideBasePath(FileUtils fileUtils) {
            return "/base";
        }
    }).build();
    fileUtils = component.getFileUtils();
    initEmptyWorkspace();
    workspaceCommand = component.getCommand();
    outContent = new ByteArrayOutputStream();
    errContent = new ByteArrayOutputStream();
    System.setOut(new PrintStream(outContent));
    System.setErr(new PrintStream(errContent));
    Flags.resetForTesting();
    WorkspaceCommand.force.resetValueForTesting();
}
Also used : PrintStream(java.io.PrintStream) AaModule(com.google.startupos.tools.reviewer.aa.AaModule) FileUtils(com.google.startupos.common.FileUtils) Singleton(javax.inject.Singleton) FileSystem(java.nio.file.FileSystem) CommonModule(com.google.startupos.common.CommonModule) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Provides(dagger.Provides) Before(org.junit.Before)

Example 7 with FileUtils

use of com.google.startupos.common.FileUtils in project startup-os by google.

the class DiffCommand method createDiff.

private Diff createDiff() {
    DiffNumberResponse response = codeReviewBlockingStub.getAvailableDiffNumber(Empty.getDefaultInstance());
    String branchName = String.format("D%s", response.getLastDiffId());
    System.out.println("Creating " + branchName);
    Long currentTime = new Long(System.currentTimeMillis());
    Diff.Builder diffBuilder = Diff.newBuilder().setWorkspace(workspaceName).setDescription(description.get()).addAllIssue(getIssues(buglink.get())).addAllReviewer(getReviewers(reviewers.get())).setId(response.getLastDiffId()).setCreatedTimestamp(currentTime).setModifiedTimestamp(currentTime);
    Map<GitRepo, String> repoToInitialBranch = new HashMap<>();
    try {
        fileUtils.listContents(workspacePath).stream().map(path -> fileUtils.joinToAbsolutePath(workspacePath, path)).filter(fileUtils::folderExists).forEach(path -> {
            String repoName = Paths.get(path).getFileName().toString();
            GitRepo repo = this.gitRepoFactory.create(path);
            repoToInitialBranch.put(repo, repo.currentBranch());
            System.out.println(String.format("[%s/%s]: switching to diff branch", workspaceName, repoName));
            repo.switchBranch(branchName);
        });
        addGithubRepos(diffBuilder);
    } catch (Exception e) {
        repoToInitialBranch.forEach((repo, initialBranch) -> {
            if (!repo.currentBranch().equals(initialBranch)) {
                repo.switchBranch(initialBranch);
            }
        });
        e.printStackTrace();
    }
    return diffBuilder.build();
}
Also used : Arrays(java.util.Arrays) Empty(com.google.startupos.tools.reviewer.local_server.service.Protos.Empty) ManagedChannel(io.grpc.ManagedChannel) FileUtils(com.google.startupos.common.FileUtils) HashMap(java.util.HashMap) Inject(javax.inject.Inject) GitRepoFactory(com.google.startupos.common.repo.GitRepoFactory) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) GitRepo(com.google.startupos.common.repo.GitRepo) Named(javax.inject.Named) FlagDesc(com.google.startupos.common.flags.FlagDesc) Diff(com.google.startupos.tools.reviewer.local_server.service.Protos.Diff) CodeReviewServiceGrpc(com.google.startupos.tools.reviewer.local_server.service.CodeReviewServiceGrpc) Flags(com.google.startupos.common.flags.Flags) Reviewer(com.google.startupos.tools.reviewer.local_server.service.Protos.Reviewer) Collectors(java.util.stream.Collectors) CreateDiffRequest(com.google.startupos.tools.reviewer.local_server.service.Protos.CreateDiffRequest) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) List(java.util.List) DiffRequest(com.google.startupos.tools.reviewer.local_server.service.Protos.DiffRequest) Paths(java.nio.file.Paths) GithubPr(com.google.startupos.tools.reviewer.local_server.service.Protos.GithubPr) DiffNumberResponse(com.google.startupos.tools.reviewer.local_server.service.Protos.DiffNumberResponse) Flag(com.google.startupos.common.flags.Flag) GitRepo(com.google.startupos.common.repo.GitRepo) Diff(com.google.startupos.tools.reviewer.local_server.service.Protos.Diff) HashMap(java.util.HashMap) DiffNumberResponse(com.google.startupos.tools.reviewer.local_server.service.Protos.DiffNumberResponse)

Example 8 with FileUtils

use of com.google.startupos.common.FileUtils in project startup-os by google.

the class RulesUpdater method main.

public static void main(String[] args) {
    Flags.parseCurrentPackage(args);
    FileUtils fileUtils = DaggerCommonComponent.create().getFileUtils();
    String configPath;
    String outputPath;
    String buildWorkspaceDirectory = System.getenv("BUILD_WORKSPACE_DIRECTORY");
    if (Paths.get(config.get()).isAbsolute()) {
        configPath = config.get();
    } else {
        configPath = Paths.get(buildWorkspaceDirectory, config.get()).toAbsolutePath().toString();
    }
    if (Paths.get(output.get()).isAbsolute()) {
        outputPath = output.get();
    } else {
        outputPath = Paths.get(buildWorkspaceDirectory, output.get()).toAbsolutePath().toString();
    }
    ReviewerConfig reviewerConfig = (ReviewerConfig) fileUtils.readPrototxtUnchecked(configPath, ReviewerConfig.newBuilder());
    String rules = String.format(RULES_TEMPLATE, reviewerConfig.getUserList().stream().map(ReviewerProtos.User::getEmail).map(email -> String.format(EMAIL_CLAUSE, email)).collect(Collectors.joining(" || ")));
    fileUtils.writeStringUnchecked(rules, outputPath);
}
Also used : ReviewerProtos(com.google.startupos.tools.reviewer.ReviewerProtos) ReviewerConfig(com.google.startupos.tools.reviewer.ReviewerProtos.ReviewerConfig) FileUtils(com.google.startupos.common.FileUtils)

Aggregations

FileUtils (com.google.startupos.common.FileUtils)8 Provides (dagger.Provides)4 Named (javax.inject.Named)4 AaModule (com.google.startupos.tools.reviewer.aa.AaModule)3 Singleton (javax.inject.Singleton)3 Before (org.junit.Before)3 CommonModule (com.google.startupos.common.CommonModule)2 GitRepo (com.google.startupos.common.repo.GitRepo)2 GitRepoFactory (com.google.startupos.common.repo.GitRepoFactory)2 AuthService (com.google.startupos.tools.reviewer.local_server.service.AuthService)2 CodeReviewService (com.google.startupos.tools.reviewer.local_server.service.CodeReviewService)2 Paths (java.nio.file.Paths)2 ImmutableList (com.google.common.collect.ImmutableList)1 Flag (com.google.startupos.common.flags.Flag)1 FlagDesc (com.google.startupos.common.flags.FlagDesc)1 Flags (com.google.startupos.common.flags.Flags)1 HttpArchiveDepsList (com.google.startupos.tools.build_file_generator.Protos.HttpArchiveDepsList)1 WorkspaceFile (com.google.startupos.tools.build_file_generator.Protos.WorkspaceFile)1 ReviewerProtos (com.google.startupos.tools.reviewer.ReviewerProtos)1 ReviewerConfig (com.google.startupos.tools.reviewer.ReviewerProtos.ReviewerConfig)1