Example usage for org.eclipse.jgit.lib Constants DOT_GIT

List of usage examples for org.eclipse.jgit.lib Constants DOT_GIT

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants DOT_GIT.

Prototype

String DOT_GIT

To view the source code for org.eclipse.jgit.lib Constants DOT_GIT.

Click Source Link

Document

Default name for the Git repository directory

Usage

From source file:org.flowerplatform.web.git.GitUtils.java

License:Open Source License

public boolean findProjectFiles(final Collection<File> files, File directory, Set<String> visistedDirs) {
    if (directory == null)
        return false;

    if (directory.getName().equals(Constants.DOT_GIT) && FileKey.isGitRepository(directory, FS.DETECTED)) {
        return false;
    }/*from  w  ww.j av a  2 s  .c  o m*/
    File[] contents = directory.listFiles();
    if (contents == null || contents.length == 0) {
        return false;
    }
    Set<String> directoriesVisited;
    // Initialize recursion guard for recursive symbolic links
    if (visistedDirs == null) {
        directoriesVisited = new HashSet<String>();
        try {
            directoriesVisited.add(directory.getCanonicalPath());
        } catch (IOException exception) {
            return false;
        }
    } else {
        directoriesVisited = visistedDirs;
    }
    // first look for project description files
    String dotProject = IProjectDescription.DESCRIPTION_FILE_NAME;
    for (int i = 0; i < contents.length; i++) {
        File file = contents[i];
        if (file.isFile() && file.getName().equals(dotProject) && !files.contains(file)) {
            files.add(file);
        }
    }
    // recurse into sub-directories (even when project was found above, for nested projects)
    for (int i = 0; i < contents.length; i++) {
        // Skip non-directories
        if (!contents[i].isDirectory()) {
            continue;
        }
        // Skip .metadata folders
        if (contents[i].getName().equals(".metadata")) {
            continue;
        }
        try {
            String canonicalPath = contents[i].getCanonicalPath();
            if (!directoriesVisited.add(canonicalPath)) {
                // already been here --> do not recurse
                continue;
            }
        } catch (IOException exception) {
            return false;
        }
        findProjectFiles(files, contents[i], directoriesVisited);
    }
    return true;
}

From source file:org.gitective.tests.GitTestCase.java

License:Open Source License

/**
 * Initialize a new repo in a new directory
 *
 * @return created .git folder/*from   w  w w .  ja v  a  2  s .co  m*/
 * @throws GitAPIException
 */
protected File initRepo() throws GitAPIException {
    String tmpDir = System.getProperty("java.io.tmpdir");
    assertNotNull("java.io.tmpdir was null", tmpDir);
    File dir = new File(tmpDir, "git-test-case-" + System.nanoTime());
    assertTrue(dir.mkdir());

    Git.init().setDirectory(dir).setBare(false).call();
    File repo = new File(dir, Constants.DOT_GIT);
    assertTrue(repo.exists());
    repo.deleteOnExit();
    return repo;
}

From source file:org.jboss.as.controller.persistence.GitPersistenceResourceTestCase.java

License:Apache License

@Before
public void createDirectoriesAndFiles() throws Exception {
    root = new File("target", "standalone").toPath();
    Files.createDirectories(root);
    File baseDir = root.toAbsolutePath().toFile();
    File gitDir = new File(baseDir, Constants.DOT_GIT);
    if (!gitDir.exists()) {
        try (Git git = Git.init().setDirectory(baseDir).setGitDir(gitDir).call()) {
            git.commit().setMessage("Repository initialized").call();
        }//w  w  w .  jav a2  s . co  m
    }
    repository = new FileRepositoryBuilder().setWorkTree(baseDir).setGitDir(gitDir).setup().build();
}

From source file:org.jboss.as.controller.persistence.RemoteGitPersistenceResourceTestCase.java

License:Apache License

@Before
public void createDirectoriesAndFiles() throws Exception {
    root = new File("target", "standalone").toPath();
    remoteRoot = new File("target", "remote").toPath().resolve("standalone");
    Files.createDirectories(remoteRoot);
    File baseDir = remoteRoot.toAbsolutePath().toFile();
    createFile(remoteRoot, "standard.xml", "std");
    File gitDir = new File(baseDir, Constants.DOT_GIT);
    if (!gitDir.exists()) {
        try (Git git = Git.init().setDirectory(baseDir).call()) {
            git.add().addFilepattern("standard.xml").call();
            git.commit().setMessage("Repository initialized").call();
        }/*  w  w  w. j a v a 2 s. c o  m*/
    }
    remoteRepository = new FileRepositoryBuilder().setWorkTree(baseDir).setGitDir(gitDir).setup().build();
    repository = new FileRepositoryBuilder().setWorkTree(root.toAbsolutePath().toFile())
            .setGitDir(new File(root.toAbsolutePath().toFile(), Constants.DOT_GIT)).setup().build();
}

From source file:org.jboss.as.controller.persistence.RemoteGitPersistenceResourceTestCase.java

License:Apache License

@Test
public void testDefaultPersistentConfigurationFile() throws Exception {
    Path standard = createFile(root, "standard.xml", "std");
    ConfigurationFile configurationFile = new ConfigurationFile(root.toFile(), "standard.xml", null,
            ConfigurationFile.InteractionPolicy.STANDARD, true);
    Assert.assertEquals(standard.toAbsolutePath().toString(),
            configurationFile.getBootFile().getAbsolutePath());
    GitRepositoryConfiguration.Builder.getInstance().setBasePath(root)
            .setRepository(remoteRoot.resolve(Constants.DOT_GIT).toAbsolutePath().toString()).build();
    try (GitRepository gitRepository = new GitRepository(GitRepositoryConfiguration.Builder.getInstance()
            .setBasePath(root).setRepository(remoteRoot.resolve(Constants.DOT_GIT).toAbsolutePath().toString())
            .build())) {//ww w  .ja v  a 2s  .c o m
        List<String> commits = listCommits(repository);
        Assert.assertEquals(2, commits.size());
        Assert.assertEquals("Adding .gitignore", commits.get(0));
        Assert.assertEquals("Repository initialized", commits.get(1));
        Assert.assertTrue(Files.exists(root));
        commits = listCommits(remoteRepository);
        Assert.assertEquals(1, commits.size());
        Assert.assertEquals("Repository initialized", commits.get(0));
        TestConfigurationFilePersister persister = new TestConfigurationFilePersister(configurationFile,
                gitRepository);
        persister.successfulBoot();
        checkFiles("standard", "std");
        commits = listCommits(repository);
        Assert.assertEquals(2, commits.size());
        Assert.assertEquals("Adding .gitignore", commits.get(0));
        Assert.assertEquals("Repository initialized", commits.get(1));
        store(persister, "One");
        commits = listCommits(repository);
        Assert.assertEquals(3, commits.size());
        Assert.assertEquals("Storing configuration", commits.get(0));
        Assert.assertEquals("Adding .gitignore", commits.get(1));
        Assert.assertEquals("Repository initialized", commits.get(2));
        checkFiles("standard", "One");
        SnapshotInfo infos = persister.listSnapshots();
        Assert.assertTrue(infos.names().isEmpty());
        store(persister, "Two");
        commits = listCommits(repository);
        Assert.assertEquals(4, commits.size());
        Assert.assertEquals("Storing configuration", commits.get(0));
        Assert.assertEquals("Storing configuration", commits.get(1));
        Assert.assertEquals("Adding .gitignore", commits.get(2));
        Assert.assertEquals("Repository initialized", commits.get(3));
        List<String> tags = listTags(repository);
        Assert.assertEquals(0, tags.size());
        persister.snapshot("test_snapshot", "1st snapshot");
        commits = listCommits(repository);
        Assert.assertEquals(5, commits.size());
        Assert.assertEquals("1st snapshot", commits.get(0));
        Assert.assertEquals("Storing configuration", commits.get(1));
        Assert.assertEquals("Storing configuration", commits.get(2));
        Assert.assertEquals("Adding .gitignore", commits.get(3));
        Assert.assertEquals("Repository initialized", commits.get(4));
        tags = listTags(repository);
        Assert.assertEquals(1, tags.size());
        Assert.assertEquals("test_snapshot : 1st snapshot", tags.get(0));
        commits = listCommits(remoteRepository);
        Assert.assertEquals(1, commits.size());
        Assert.assertEquals("Repository initialized", commits.get(0));
        persister.publish(null);
        commits = listCommits(remoteRepository);
        Assert.assertEquals(5, commits.size());
        Assert.assertEquals("1st snapshot", commits.get(0));
        Assert.assertEquals("Storing configuration", commits.get(1));
        Assert.assertEquals("Storing configuration", commits.get(2));
        Assert.assertEquals("Adding .gitignore", commits.get(3));
        Assert.assertEquals("Repository initialized", commits.get(4));
        tags = listTags(remoteRepository);
        Assert.assertEquals(1, tags.size());
        Assert.assertEquals("test_snapshot : 1st snapshot", tags.get(0));
    }
}

From source file:org.jboss.as.server.controller.git.GitConfigurationPersister.java

License:Apache License

public GitConfigurationPersister(GitRepository gitRepository, ConfigurationFile file, QName rootElement,
        XMLElementReader<List<ModelNode>> rootParser, XMLElementWriter<ModelMarshallingContext> rootDeparser,
        boolean suppressLoad) {
    super(file.getBootFile(), rootElement, rootParser, rootDeparser, suppressLoad);
    root = file.getConfigurationDir().getParentFile().toPath();
    mainFile = file.getMainFile();/*from  w  w w. j a v  a 2s  .  c  om*/
    this.gitRepository = gitRepository;
    File baseDir = root.toFile();
    try {
        File gitDir = new File(baseDir, Constants.DOT_GIT);
        if (!gitDir.exists()) {
            gitDir.mkdir();
        }
        if (gitRepository.isBare()) {
            Git.init().setDirectory(baseDir).setGitDir(gitDir).call();
            ServerLogger.ROOT_LOGGER.gitRespositoryInitialized(baseDir.getAbsolutePath());
        }
    } catch (IllegalStateException | GitAPIException e) {
        ControllerLogger.ROOT_LOGGER.error(e);
    }
}

From source file:org.jboss.as.test.manualmode.management.persistence.AbstractGitRepositoryTestCase.java

License:Apache License

@Before
public void prepareEmptyRemoteRepository() throws Exception {
    emptyRemoteRoot = new File("target", "empty-remote").toPath();
    Files.createDirectories(emptyRemoteRoot);
    File gitDir = new File(emptyRemoteRoot.toFile(), Constants.DOT_GIT);
    if (!gitDir.exists()) {
        try (Git git = Git.init().setDirectory(emptyRemoteRoot.toFile()).call()) {
        }/* w  w w. jav  a2 s .  c  o  m*/
    }
    Assert.assertTrue(gitDir.exists());
    emptyRemoteRepository = new FileRepositoryBuilder().setWorkTree(emptyRemoteRoot.toFile()).setGitDir(gitDir)
            .setup().build();
}

From source file:org.jboss.as.test.manualmode.management.persistence.AbstractGitRepositoryTestCase.java

License:Apache License

protected Repository createRepository() throws IOException {
    Repository repo = new FileRepositoryBuilder().setWorkTree(getJbossServerBaseDir().toFile())
            .setGitDir(getDotGitDir().toFile()).setup().build();
    StoredConfig config = repo.getConfig();
    config.setString("remote", "empty", "url",
            "file://" + emptyRemoteRoot.resolve(Constants.DOT_GIT).toAbsolutePath().toString());
    config.save();// ww  w .  j  av  a 2s.  c o  m
    return repo;
}

From source file:org.jboss.as.test.manualmode.management.persistence.RemoteGitRepositoryTestCase.java

License:Apache License

@Before
public void prepareTest() throws Exception {
    remoteRoot = new File("target", "remote").toPath();
    Path repoConfigDir = remoteRoot.resolve("configuration");
    Files.createDirectories(repoConfigDir);
    File baseDir = remoteRoot.toAbsolutePath().toFile();
    PathUtil.copyRecursively(getJbossServerBaseDir().resolve("configuration"), repoConfigDir, true);
    Path properties = repoConfigDir.resolve("logging.properties");
    if (Files.exists(properties)) {
        Files.delete(properties);
    }//from w  ww. j av a2  s .  co  m
    File gitDir = new File(baseDir, Constants.DOT_GIT);
    if (!gitDir.exists()) {
        try (Git git = Git.init().setDirectory(baseDir).call()) {
            git.add().addFilepattern("configuration").call();
            git.commit().setMessage("Repository initialized").call();
        }
    }
    remoteRepository = new FileRepositoryBuilder().setWorkTree(baseDir).setGitDir(gitDir).setup().build();
}

From source file:org.jboss.as.test.manualmode.management.persistence.RemoteGitRepositoryTestCase.java

License:Apache License

/**
 * Start server with parameter --git-repo=file:///my_repo/test/.git
 *//*from w  w w . j ava2  s.c  o  m*/
@Test
public void startGitRepoRemoteTest() throws Exception {
    // start with remote repository containing configuration (--git-repo=file:///my_repo/test/.git)
    container.startGitBackedConfiguration(
            "file://" + remoteRoot.resolve(Constants.DOT_GIT).toAbsolutePath().toString(), Constants.MASTER,
            null);
    Assert.assertTrue("Directory not found " + getDotGitDir(), Files.exists(getDotGitDir()));
    Assert.assertTrue("File not found " + getDotGitIgnore(), Files.exists(getDotGitIgnore()));
    List<String> commits = listCommits(remoteRepository);
    Assert.assertEquals(1, commits.size());
    addSystemProperty();
    publish(null);
    commits = listCommits(remoteRepository);
    Assert.assertEquals(3, commits.size());

    // create branch in remote repo and change master for next test
    try (Git git = new Git(remoteRepository)) {
        git.checkout().setName("my_branch").setCreateBranch(true).call();
    }
    removeSystemProperty();
    publish(null);
    container.stop();
    closeRepository();

    // start with remote repository and branch containing configuration
    // (--git-repo=file:///my_repo/test/.git --git-branch=my_branch)
    container.startGitBackedConfiguration(
            "file://" + remoteRoot.resolve(Constants.DOT_GIT).toAbsolutePath().toString(), "my_branch", null);
    Assert.assertTrue("Directory not found " + getDotGitDir(), Files.exists(getDotGitDir()));
    Assert.assertTrue("File not found " + getDotGitIgnore(), Files.exists(getDotGitIgnore()));
    try {
        addSystemProperty();
        Assert.fail("Operation should have failed");
    } catch (UnsuccessfulOperationException uoe) {
        Assert.assertTrue(uoe.getMessage().contains("WFLYCTL0212"));
    }
}