org.eclipse.jgit.lib.RepositoryCache Java Examples

The following examples show how to use org.eclipse.jgit.lib.RepositoryCache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitUtils.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the file representing the Git repository directory for the given file path or any of its parent in the filesystem. If the file doesn't exits, is
 * not a Git repository or an error occurred while transforming the given path into a store <code>null</code> is returned.
 *
 * @param file the file to check
 * @return the .git folder if found or <code>null</code> the give path cannot be resolved to a file or it's not under control of a git repository
 */
public static File resolveGitDir(File file) {
	File dot = new File(file, Constants.DOT_GIT);
	if (RepositoryCache.FileKey.isGitRepository(dot, FS.DETECTED)) {
		return dot;
	} else if (dot.isFile()) {
		try {
			return getSymRef(file, dot, FS.DETECTED);
		} catch (IOException ignored) {
			// Continue searching if gitdir ref isn't found
		}
	} else if (RepositoryCache.FileKey.isGitRepository(file, FS.DETECTED)) {
		return file;
	}
	return null;
}
 
Example #2
Source File: GitCloneTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testCloneOverSshWithPassword() throws Exception {
	Assume.assumeTrue(sshRepo != null);
	Assume.assumeTrue(password != null);
	Assume.assumeTrue(knownHosts != null);

	createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
	JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project"), null);
	String workspaceId = workspaceIdFromLocation(workspaceLocation);
	IPath clonePath = getClonePath(workspaceId, project);
	URIish uri = new URIish(sshRepo);
	WebRequest request = new PostGitCloneRequest().setURIish(uri).setFilePath(clonePath).setKnownHosts(knownHosts).setPassword(password).getWebRequest();
	String contentLocation = clone(request);
	File file = getRepositoryForContentLocation(contentLocation).getDirectory().getParentFile();
	assertTrue(file.exists());
	assertTrue(file.isDirectory());
	assertTrue(RepositoryCache.FileKey.isGitRepository(new File(file, Constants.DOT_GIT), FS.DETECTED));
}
 
Example #3
Source File: GitCloneTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testCloneOverSshWithPassphraseProtectedKey() throws Exception {
	Assume.assumeTrue(sshRepo2 != null);
	Assume.assumeTrue(privateKey != null);
	Assume.assumeTrue(passphrase != null);

	createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
	String workspaceId = workspaceIdFromLocation(workspaceLocation);
	JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project"), null);
	IPath clonePath = getClonePath(workspaceId, project);
	URIish uri = new URIish(sshRepo2);
	WebRequest request = new PostGitCloneRequest().setURIish(uri).setFilePath(clonePath).setKnownHosts(knownHosts2).setPrivateKey(privateKey).setPublicKey(publicKey).setPassphrase(passphrase).getWebRequest();
	String contentLocation = clone(request);

	File file = getRepositoryForContentLocation(contentLocation).getDirectory().getParentFile();
	assertTrue(file.exists());
	assertTrue(file.isDirectory());
	assertTrue(RepositoryCache.FileKey.isGitRepository(new File(file, Constants.DOT_GIT), FS.DETECTED));
}
 
Example #4
Source File: UpdaterGenerator.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Davide you might notice that I have made functions smaller.
 * It makes code immensely more readable and you quickly are able
 * to resume the code from where you left.
 * Understanding takes lesser time, as number of lines are lesser.
 * @return 
 */
private boolean init_CheckDir_gitClone(){
    //Check if the given directory exists
    boolean gitUpdated = true;
    if (RepositoryCache.FileKey.isGitRepository(new File(gitDirectory.getAbsolutePath(), ".git"), FS.DETECTED)) {
        // Already cloned. Just need to pull a repository here.
        System.out.println("git pull");
        gitUpdated = gitPull(gitDirectory);
    } else {
        // Not present or not a Git repository.
        System.out.println("git clone");
        gitClone(gitDirectory);
    }return gitUpdated;
}
 
Example #5
Source File: GitConfigMonitorTest.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void setup() throws Exception {
  cleanUpDir(TEST_DIR);

  // Create a bare repository
  RepositoryCache.FileKey fileKey = RepositoryCache.FileKey.exact(remoteDir, FS.DETECTED);
  this.remoteRepo = fileKey.open(false);
  this.remoteRepo.create(true);

  this.gitForPush = Git.cloneRepository().setURI(this.remoteRepo.getDirectory().getAbsolutePath()).setDirectory(cloneDir).call();

  // push an empty commit as a base for detecting changes
  this.gitForPush.commit().setMessage("First commit").call();
  this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();

  this.config = ConfigBuilder.create()
      .addPrimitive(GitConfigMonitor.GIT_CONFIG_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_URI,
          this.remoteRepo.getDirectory().getAbsolutePath())
      .addPrimitive(GitConfigMonitor.GIT_CONFIG_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_DIR, TEST_DIR + "/jobConfig")
      .addPrimitive(FlowCatalog.FLOWSPEC_STORE_DIR_KEY, TEST_DIR + "flowCatalog")
      .addPrimitive(ConfigurationKeys.GIT_MONITOR_POLLING_INTERVAL, 5)
      .build();

  this.flowCatalog = new FlowCatalog(config);
  this.flowCatalog.startAsync().awaitRunning();
  this.gitConfigMonitor = new GitConfigMonitor(this.config, this.flowCatalog);
  this.gitConfigMonitor.setActive(true);
}
 
Example #6
Source File: GitContentRepositoryHelper.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
public boolean deleteSiteGitRepo(String site) {
    boolean toReturn;

    // Get the Sandbox Path
    Path siteSandboxPath = buildRepoPath(GitRepositories.SANDBOX, site);
    // Get parent of that (since every site has two repos: Sandbox and Published)
    Path sitePath = siteSandboxPath.getParent();
    // Get a file handle to the parent and delete it
    File siteFolder = sitePath.toFile();

    try {
        Repository sboxRepo = sandboxes.get(site);
        if (sboxRepo != null) {
            sboxRepo.close();
            sandboxes.remove(site);
            RepositoryCache.close(sboxRepo);
            sboxRepo = null;
        }
        Repository pubRepo = published.get(site);
        if (pubRepo != null) {
            pubRepo.close();
            published.remove(site);
            RepositoryCache.close(pubRepo);
            pubRepo = null;
        }
        FileUtils.deleteDirectory(siteFolder);

        toReturn = true;

        logger.debug("Deleted site: " + site + " at path: " + sitePath);
    } catch (IOException e) {
        logger.error("Failed to delete site: " + site + " at path: " + sitePath + " exception " +
                e.toString());
        toReturn = false;
    }

    return toReturn;
}
 
Example #7
Source File: RestGitBackupService.java    From EDDI with Apache License 2.0 4 votes vote down vote up
public boolean isGitInitialised(String botId) {
    Path gitPath = Paths.get(tmpPath + botId);
    return RepositoryCache.FileKey.isGitRepository(gitPath.toFile(), FS.DETECTED);
}
 
Example #8
Source File: UpdaterGenerator.java    From neembuu-uploader with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void run() {
    /*
     File tmpDir = new File(System.getProperty("java.io.tmpdir"), "tmp"
     + System.currentTimeMillis());
     */
    gitDirectory = new File("C:\\xampp\\htdocs\\nutest");
    outputDirectory = new File("C:\\xampp\\htdocs\\nutestoutput");
    boolean shouldUpdate = true;
    gitDirectory.mkdirs();
    outputDirectory.mkdirs();

    //Check if the given directory exists
    if (RepositoryCache.FileKey.isGitRepository(new File(gitDirectory.getAbsolutePath(), ".git"), FS.DETECTED)) {
        // Already cloned. Just need to pull a repository here.
        System.out.println("git pull");
        shouldUpdate = gitPull(gitDirectory);

    } else {
        // Not present or not a Git repository.
        System.out.println("git clone");
        gitClone(gitDirectory);
    }

    if (shouldUpdate) {
        System.out.println("Updating plugins zip");
        try {
            NUCompiler compiler = new NUCompiler(gitDirectory);
            NUZipFileGenerator zipFileGenerator = new NUZipFileGenerator(gitDirectory, outputDirectory);

            //Compile components in order of dependency
            compiler.compileApi();
            compiler.compileUtils();
            compiler.compileIntAbsImpl();
            compiler.compileUploaders();

            //Create the zip files
            zipFileGenerator.createZipFiles(pluginsToUpdate);
        } catch (Exception ex) {
            Logger.getLogger(UpdaterGenerator.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            //removeDirectory(tmpDir);
        }
    } else {
        System.out.println("No need to update");
    }
}
 
Example #9
Source File: MultiHopFlowCompilerTest.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
@Test (dependsOnMethods = "testUnresolvedFlow")
public void testGitFlowGraphMonitorService()
    throws IOException, GitAPIException, URISyntaxException, InterruptedException {
  File remoteDir = new File(TESTDIR + "/remote");
  File cloneDir = new File(TESTDIR + "/clone");
  File flowGraphDir = new File(cloneDir, "/gobblin-flowgraph");

  //Clean up
  cleanUpDir(TESTDIR);

  // Create a bare repository
  RepositoryCache.FileKey fileKey = RepositoryCache.FileKey.exact(remoteDir, FS.DETECTED);
  Repository remoteRepo = fileKey.open(false);
  remoteRepo.create(true);

  Git gitForPush = Git.cloneRepository().setURI(remoteRepo.getDirectory().getAbsolutePath()).setDirectory(cloneDir).call();

  // push an empty commit as a base for detecting changes
  gitForPush.commit().setMessage("First commit").call();
  RefSpec masterRefSpec = new RefSpec("master");
  gitForPush.push().setRemote("origin").setRefSpecs(masterRefSpec).call();

  URI flowTemplateCatalogUri = this.getClass().getClassLoader().getResource("template_catalog").toURI();

  Config config = ConfigBuilder.create()
      .addPrimitive(GitFlowGraphMonitor.GIT_FLOWGRAPH_MONITOR_PREFIX + "."
          + ConfigurationKeys.GIT_MONITOR_REPO_URI, remoteRepo.getDirectory().getAbsolutePath())
      .addPrimitive(GitFlowGraphMonitor.GIT_FLOWGRAPH_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_DIR, TESTDIR + "/git-flowgraph")
      .addPrimitive(GitFlowGraphMonitor.GIT_FLOWGRAPH_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_POLLING_INTERVAL, 5)
      .addPrimitive(ServiceConfigKeys.TEMPLATE_CATALOGS_FULLY_QUALIFIED_PATH_KEY, flowTemplateCatalogUri.toString())
      .build();

  //Create a MultiHopFlowCompiler instance
  specCompiler = new MultiHopFlowCompiler(config, Optional.absent(), false);

  specCompiler.setActive(true);

  //Ensure node1 is not present in the graph
  Assert.assertNull(specCompiler.getFlowGraph().getNode("node1"));

  // push a new node file
  File nodeDir = new File(flowGraphDir, "node1");
  File nodeFile = new File(nodeDir, "node1.properties");
  nodeDir.mkdirs();
  nodeFile.createNewFile();
  Files.write(FlowGraphConfigurationKeys.DATA_NODE_IS_ACTIVE_KEY + "=true\nparam1=val1" + "\n", nodeFile, Charsets.UTF_8);

  // add, commit, push node
  gitForPush.add().addFilepattern(formNodeFilePath(flowGraphDir, nodeDir.getName(), nodeFile.getName())).call();
  gitForPush.commit().setMessage("Node commit").call();
  gitForPush.push().setRemote("origin").setRefSpecs(masterRefSpec).call();

  // polling is every 5 seconds, so wait twice as long and check
  TimeUnit.SECONDS.sleep(10);

  //Test that a DataNode is added to FlowGraph
  DataNode dataNode = specCompiler.getFlowGraph().getNode("node1");
  Assert.assertEquals(dataNode.getId(), "node1");
  Assert.assertEquals(dataNode.getRawConfig().getString("param1"), "val1");
}
 
Example #10
Source File: GobblinServiceManagerTest.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public void setup() throws Exception {
  cleanUpDir(SERVICE_WORK_DIR);
  cleanUpDir(SPEC_STORE_PARENT_DIR);
  ITestMetastoreDatabase testMetastoreDatabase = TestMetastoreDatabaseFactory.get();

  testingServer = new TestingServer(true);

  flowProperties.put("param1", "value1");
  flowProperties.put(ServiceConfigKeys.FLOW_SOURCE_IDENTIFIER_KEY, TEST_SOURCE_NAME);
  flowProperties.put(ServiceConfigKeys.FLOW_DESTINATION_IDENTIFIER_KEY, TEST_SINK_NAME);

  serviceCoreProperties.put(ConfigurationKeys.STATE_STORE_DB_USER_KEY, "testUser");
  serviceCoreProperties.put(ConfigurationKeys.STATE_STORE_DB_PASSWORD_KEY, "testPassword");
  serviceCoreProperties.put(ConfigurationKeys.STATE_STORE_DB_URL_KEY, testMetastoreDatabase.getJdbcUrl());
  serviceCoreProperties.put("zookeeper.connect", testingServer.getConnectString());
  serviceCoreProperties.put(ConfigurationKeys.STATE_STORE_FACTORY_CLASS_KEY, MysqlJobStatusStateStoreFactory.class.getName());

  serviceCoreProperties.put(ConfigurationKeys.TOPOLOGYSPEC_STORE_DIR_KEY, TOPOLOGY_SPEC_STORE_DIR);
  serviceCoreProperties.put(FlowCatalog.FLOWSPEC_STORE_DIR_KEY, FLOW_SPEC_STORE_DIR);
  serviceCoreProperties.put(ServiceConfigKeys.TOPOLOGY_FACTORY_TOPOLOGY_NAMES_KEY, TEST_GOBBLIN_EXECUTOR_NAME);
  serviceCoreProperties.put(ServiceConfigKeys.TOPOLOGY_FACTORY_PREFIX +  TEST_GOBBLIN_EXECUTOR_NAME + ".description",
      "StandaloneTestExecutor");
  serviceCoreProperties.put(ServiceConfigKeys.TOPOLOGY_FACTORY_PREFIX +  TEST_GOBBLIN_EXECUTOR_NAME + ".version",
      FlowSpec.Builder.DEFAULT_VERSION);
  serviceCoreProperties.put(ServiceConfigKeys.TOPOLOGY_FACTORY_PREFIX +  TEST_GOBBLIN_EXECUTOR_NAME + ".uri",
      "gobblinExecutor");
  serviceCoreProperties.put(ServiceConfigKeys.TOPOLOGY_FACTORY_PREFIX +  TEST_GOBBLIN_EXECUTOR_NAME + ".specExecutorInstance",
      "org.apache.gobblin.service.InMemorySpecExecutor");
  serviceCoreProperties.put(ServiceConfigKeys.TOPOLOGY_FACTORY_PREFIX +  TEST_GOBBLIN_EXECUTOR_NAME + ".specExecInstance.capabilities",
      TEST_SOURCE_NAME + ":" + TEST_SINK_NAME);

  serviceCoreProperties.put(ServiceConfigKeys.GOBBLIN_SERVICE_GIT_CONFIG_MONITOR_ENABLED_KEY, true);
  serviceCoreProperties.put(GitConfigMonitor.GIT_CONFIG_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_URI, GIT_REMOTE_REPO_DIR);
  serviceCoreProperties.put(GitConfigMonitor.GIT_CONFIG_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_DIR, GIT_LOCAL_REPO_DIR);
  serviceCoreProperties.put(GitConfigMonitor.GIT_CONFIG_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_POLLING_INTERVAL, 5);

  serviceCoreProperties.put(FsJobStatusRetriever.CONF_PREFIX + "." + ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY, JOB_STATUS_STATE_STORE_DIR);

  serviceCoreProperties.put(ServiceConfigKeys.GOBBLIN_SERVICE_JOB_STATUS_MONITOR_ENABLED_KEY, false);

  serviceCoreProperties.put(ServiceConfigKeys.GOBBLIN_SERVICE_FLOWCOMPILER_CLASS_KEY, MockedSpecCompiler.class.getCanonicalName());

  // Create a bare repository
  RepositoryCache.FileKey fileKey = RepositoryCache.FileKey.exact(new File(GIT_REMOTE_REPO_DIR), FS.DETECTED);
  fileKey.open(false).create(true);

  this.gitForPush = Git.cloneRepository().setURI(GIT_REMOTE_REPO_DIR).setDirectory(new File(GIT_CLONE_DIR)).call();

  // push an empty commit as a base for detecting changes
  this.gitForPush.commit().setMessage("First commit").call();
  this.gitForPush.push().setRemote("origin").setRefSpecs(new RefSpec("master")).call();

  this.gobblinServiceManager = new MockGobblinServiceManager("CoreService", "1",
      ConfigUtils.propertiesToConfig(serviceCoreProperties), Optional.of(new Path(SERVICE_WORK_DIR)));
  this.gobblinServiceManager.start();

  this.flowConfigClient = new FlowConfigV2Client(String.format("http://127.0.0.1:%s/",
      this.gobblinServiceManager.getRestLiServer().getListeningURI().getPort()));
}