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();
}
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();
}
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);
}
Aggregations