Search in sources :

Example 1 with GitManager

use of org.commonjava.indy.subsys.git.GitManager in project indy by Commonjava.

the class RevisionsManager method setup.

@PostConstruct
public void setup() {
    if (!revisionsConfig.isEnabled()) {
        return;
    }
    try {
        final File dataDir = dataFileManager.getDetachedDataBasedir();
        final File gitignore = new File(dataDir, ".gitignore");
        dataDir.mkdirs();
        FileUtils.write(gitignore, join(DATA_DIR_GITIGNORES, "\n"));
        final GitConfig dataConf = new GitConfig(dataDir, revisionsConfig.getDataUpstreamUrl(), true).setRemoteBranchName(revisionsConfig.getBranchName()).setUserEmail(revisionsConfig.getUserEmail());
        dataFileGit = new GitManager(dataConf);
        // we need a TimerTask that will commit modifications periodically
        Timer timer = new Timer(true);
        timer.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                try {
                    int committed = commitDataUpdates();
                    if (committed > 0) {
                        logger.info("Commit and push data updates, size: " + committed);
                        pushDataUpdates();
                    }
                } catch (GitSubsystemException e) {
                    logger.warn("Failed to push data updates", e);
                }
            }
        }, 1000, // every 1 min
        60 * 1000);
    } catch (GitSubsystemException | IOException e) {
        throw new IllegalStateException("Failed to start revisions manager: " + e.getMessage(), e);
    } finally {
    }
}
Also used : GitManager(org.commonjava.indy.subsys.git.GitManager) Timer(java.util.Timer) TimerTask(java.util.TimerTask) GitConfig(org.commonjava.indy.subsys.git.GitConfig) GitSubsystemException(org.commonjava.indy.subsys.git.GitSubsystemException) IOException(java.io.IOException) DataFile(org.commonjava.indy.subsys.datafile.DataFile) File(java.io.File) PostConstruct(javax.annotation.PostConstruct)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 PostConstruct (javax.annotation.PostConstruct)1 DataFile (org.commonjava.indy.subsys.datafile.DataFile)1 GitConfig (org.commonjava.indy.subsys.git.GitConfig)1 GitManager (org.commonjava.indy.subsys.git.GitManager)1 GitSubsystemException (org.commonjava.indy.subsys.git.GitSubsystemException)1