public void run() throws Exception { addCommand.addFilepattern(CRUISE_CONFIG_XML).call(); git.commit().setAuthor(rev.getUsername(), STUDIOS_PRODUCT).setMessage(rev.getComment()).call(); } });
@Test (dependsOnMethods = "testDelete") public void testGitCreate() throws Exception { // push a new config file File testFlowFile = new File(GIT_CLONE_DIR + "/gobblin-config/testGroup/testFlow.pull"); testFlowFile.getParentFile().mkdirs(); Files.write("flow.name=testFlow\nflow.group=testGroup\nparam1=value20\n", testFlowFile, Charsets.UTF_8); Collection<Spec> specs = this.gobblinServiceManager.flowCatalog.getSpecs(); Assert.assertTrue(specs.size() == 0); // add, commit, push this.gitForPush.add().addFilepattern("gobblin-config/testGroup/testFlow.pull").call(); this.gitForPush.commit().setMessage("second commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(new RefSpec("master")).call(); // polling is every 5 seconds, so wait twice as long and check TimeUnit.SECONDS.sleep(10); specs = this.gobblinServiceManager.flowCatalog.getSpecs(); Assert.assertTrue(specs.size() == 1); FlowSpec spec = (FlowSpec) (specs.iterator().next()); Assert.assertEquals(spec.getUri(), new URI("gobblin-flow:/testGroup/testFlow")); Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_NAME_KEY), "testFlow"); Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_GROUP_KEY), "testGroup"); Assert.assertEquals(spec.getConfig().getString("param1"), "value20"); }
@Test(dependsOnMethods = "testAddConfig") public void testUpdateConfig() throws IOException, GitAPIException, URISyntaxException { // push an updated config file Files.write("flow.name=testFlow\nflow.group=testGroup\nparam1=value2\n", testFlowFile, Charsets.UTF_8); // add, commit, push this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile.getName())) .call(); this.gitForPush.commit().setMessage("Third commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitConfigMonitor.processGitConfigChanges(); Collection<Spec> specs = this.flowCatalog.getSpecs(); Assert.assertTrue(specs.size() == 1); FlowSpec spec = (FlowSpec) (specs.iterator().next()); Assert.assertEquals(spec.getUri(), new URI("gobblin-flow:/testGroup/testFlow")); Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_NAME_KEY), "testFlow"); Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_GROUP_KEY), "testGroup"); Assert.assertEquals(spec.getConfig().getString("param1"), "value2"); }
@Test public void testAddConfig() throws IOException, GitAPIException, URISyntaxException { // push a new config file this.testGroupDir.mkdirs(); this.testFlowFile.createNewFile(); Files.write("flow.name=testFlow\nflow.group=testGroup\nparam1=value1\n", testFlowFile, Charsets.UTF_8); // add, commit, push this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile.getName())) .call(); this.gitForPush.commit().setMessage("Second commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitConfigMonitor.processGitConfigChanges(); Collection<Spec> specs = this.flowCatalog.getSpecs(); Assert.assertTrue(specs.size() == 1); FlowSpec spec = (FlowSpec) (specs.iterator().next()); Assert.assertEquals(spec.getUri(), new URI("gobblin-flow:/testGroup/testFlow")); Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_NAME_KEY), "testFlow"); Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_GROUP_KEY), "testGroup"); Assert.assertEquals(spec.getConfig().getString("param1"), "value1"); }
@Signature public void add(String filePattern, ArrayMemory settings) throws GitAPIException { AddCommand addCommand = getWrappedObject().add(); addCommand.addFilepattern(filePattern); if (settings != null && settings.isNotNull()) { addCommand.setUpdate(settings.valueOfIndex("update").toBoolean()); } DirCache dirCache = addCommand.call(); }
this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile.getName())) .call(); this.gitForPush.commit().setMessage("Seventh commit").call();
private void addEdge(File edgeDir, File edgeFile, String fileContents) throws IOException, GitAPIException { createNewFile(edgeDir, edgeFile, fileContents); // add, commit, push edge this.gitForPush.add().addFilepattern(formEdgeFilePath(edgeDir.getParentFile().getName(), edgeDir.getName(), edgeFile.getName())).call(); this.gitForPush.commit().setMessage("Edge commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); }
@Test (dependsOnMethods = "testAddNode") public void testUpdateEdge() throws IOException, GitAPIException, URISyntaxException, ExecutionException, InterruptedException { //Update edge1 file String fileContents = buildEdgeFileContents("node1", "node2", "edge1", "value2"); addEdge(this.edge1Dir, this.edge1File, fileContents); // add, commit, push this.gitForPush.add().addFilepattern(formEdgeFilePath(this.edge1Dir.getParentFile().getName(), this.edge1Dir.getName(), this.edge1File.getName())).call(); this.gitForPush.commit().setMessage("Edge commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitFlowGraphMonitor.processGitConfigChanges(); //Check if new edge1 has been added to the FlowGraph testIfEdgeSuccessfullyAdded("node1", "node2", "edge1", "value2"); }
this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile.getName())) .call(); this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile2.getName())) .call(); this.gitForPush.commit().setMessage("Fifth commit").call(); this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile2.getName())) .call(); this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile3.getName())) .call(); this.gitForPush.commit().setMessage("Sixth commit").call();
private void addNode(File nodeDir, File nodeFile, String fileContents) throws IOException, GitAPIException { createNewFile(nodeDir, nodeFile, fileContents); // add, commit, push node this.gitForPush.add().addFilepattern(formNodeFilePath(nodeDir.getName(), nodeFile.getName())).call(); this.gitForPush.commit().setMessage("Node commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); }
gitForPush.add().addFilepattern(formNodeFilePath(flowGraphDir, nodeDir.getName(), nodeFile.getName())).call(); gitForPush.commit().setMessage("Node commit").call(); gitForPush.push().setRemote("origin").setRefSpecs(masterRefSpec).call();
this.gitForPush.add().addFilepattern(formNodeFilePath(this.node1Dir.getName(), this.node1File.getName())).call(); this.gitForPush.add().addFilepattern(formNodeFilePath(this.node2Dir.getName(), this.node2File.getName())).call(); this.gitForPush.commit().setMessage("Add nodes commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitForPush.add().addFilepattern(formEdgeFilePath(this.edge1Dir.getParentFile().getName(), this.edge1Dir.getName(), this.edge1File.getName())).call(); this.gitForPush.commit().setMessage("Add nodes and edges commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitForPush.add().addFilepattern(formNodeFilePath(this.node1Dir.getName(), this.node1File.getName())).call(); this.gitForPush.commit().setMessage("Add node1 commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
private void commitSomething(Path path) { try (Git git = Git.open(path.toFile())) { Path emptyFilePath = Paths.get(path.toString(), EMPTY_FILE); try { Files.createFile(emptyFilePath); } catch (FileAlreadyExistsException ignore) { } git.add() .addFilepattern(".") .call(); git.commit() .setMessage("add test branch") .call(); } catch (Throwable e) { log.error("Method: commitSomething Exception", e); } }
private static void createCommit(Repository repository, Git git, String fileName, String content) throws IOException, GitAPIException { // create the file File myFile = new File(repository.getDirectory().getParent(), fileName); FileUtils.writeStringToFile(myFile, content, "UTF-8"); // run the add git.add() .addFilepattern(fileName) .call(); // and then commit the changes RevCommit revCommit = git.commit() .setMessage("Added " + fileName) .call(); System.out.println("Committed file " + myFile + " as " + revCommit + " to repository at " + repository.getDirectory()); } }
private static void createCommit(Repository repository, Git git, String fileName, String content) throws IOException, GitAPIException { // create the file File myFile = new File(repository.getDirectory().getParent(), fileName); FileUtils.writeStringToFile(myFile, content, "UTF-8"); // run the add git.add() .addFilepattern(fileName) .call(); // and then commit the changes RevCommit revCommit = git.commit() .setMessage("Added " + fileName) .call(); System.out.println("Committed file " + myFile + " as " + revCommit + " to repository at " + repository.getDirectory()); } }
public static void main(String[] args) throws IOException, GitAPIException { final File localPath; // prepare a new test-repository try (Repository repository = CookbookHelper.createNewRepository()) { localPath = repository.getWorkTree(); try (Git git = new Git(repository)) { // create the file File myFile = new File(repository.getDirectory().getParent(), "testfile"); if(!myFile.createNewFile()) { throw new IOException("Could not create file " + myFile); } // run the add-call git.add() .addFilepattern("testfile") .call(); System.out.println("Added file " + myFile + " to repository at " + repository.getDirectory()); } } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(localPath); } }
public static void main(String[] args) throws IOException, GitAPIException { final File localPath; // prepare a new test-repository try (Repository repository = CookbookHelper.createNewRepository()) { localPath = repository.getWorkTree(); try (Git git = new Git(repository)) { // create the file File myFile = new File(repository.getDirectory().getParent(), "testfile"); if(!myFile.createNewFile()) { throw new IOException("Could not create file " + myFile); } // run the add-call git.add() .addFilepattern("testfile") .call(); System.out.println("Added file " + myFile + " to repository at " + repository.getDirectory()); } } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(localPath); } }
private static File createSampleGitRepo() throws IOException, GitAPIException { try (Repository repository = CookbookHelper.createNewRepository()) { System.out.println("Temporary repository at " + repository.getDirectory()); // create the file File myFile = new File(repository.getDirectory().getParent(), "testfile"); if(!myFile.createNewFile()) { throw new IOException("Could not create file " + myFile); } // run the add-call try (Git git = new Git(repository)) { git.add() .addFilepattern("testfile") .call(); // and then commit the changes git.commit() .setMessage("Added testfile") .call(); } System.out.println("Added file " + myFile + " to repository at " + repository.getDirectory()); return repository.getDirectory(); } } }
private static File createSampleGitRepo() throws IOException, GitAPIException { try (Repository repository = CookbookHelper.createNewRepository()) { System.out.println("Temporary repository at " + repository.getDirectory()); // create the file File myFile = new File(repository.getDirectory().getParent(), "testfile"); if(!myFile.createNewFile()) { throw new IOException("Could not create file " + myFile); } // run the add-call try (Git git = new Git(repository)) { git.add() .addFilepattern("testfile") .call(); // and then commit the changes git.commit() .setMessage("Added testfile") .call(); } System.out.println("Added file " + myFile + " to repository at " + repository.getDirectory()); return repository.getDirectory(); } } }
public Repository createCommit(File srcFolder, String applicationName) throws IOException, GitAPIException { Repository repository = repositoryService.createRepository(new Repository().setName(applicationName)); String cloneUrl = repository.getCloneUrl(); InitCommand init = new InitCommand(); init.setDirectory(srcFolder); init.setBare(false); Git git = init.call(); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", cloneUrl); config.save(); UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(accessToken, ""); git.add().addFilepattern(".").call(); git.commit().setMessage(COMMIT_MESSAGE).call(); git.push().setCredentialsProvider(user).call(); return repository; } }