List of usage examples for org.eclipse.jgit.api StatusCommand call
@Override public Status call() throws GitAPIException, NoWorkTreeException
Executes the Status command with all the options and parameters collected by the setter methods of this class.
From source file:com.centurylink.mdw.dataaccess.file.VersionControlGit.java
License:Apache License
public Status getStatus(String path) throws Exception { fetch();// www.j a va 2 s . c om StatusCommand sc = git.status(); if (path != null) sc.addPath(path); return sc.call(); }
From source file:com.wadpam.gimple.GimpleMojo.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); try {//w ww . j a va 2 s . co m Repository repo = builder.setGitDir(new File(new File(gitDir), ".git")).readEnvironment().findGitDir() .build(); final String branch = repo.getBranch(); if (null != branch) { if (!currentVersion.endsWith(SUFFIX_SNAPSHOT)) { throw new MojoExecutionException("Maven project version not in SNAPSHOT: " + currentVersion); } getLog().info("gimple executing on " + gitDir); getLog().info("branch " + branch); if (null == releaseVersion) { releaseVersion = currentVersion.substring(0, currentVersion.length() - SUFFIX_SNAPSHOT.length()); } getLog().info( "Transforming version from " + currentVersion + " to release version " + releaseVersion); Git git = new Git(repo); StatusCommand statusCommand = git.status(); Status status = statusCommand.call(); if (!status.isClean()) { throw new MojoExecutionException("Git project is not clean: " + status.getUncommittedChanges()); } // versions:set releaseVersion transformPomVersions(git, releaseVersion); // tag release Ref tagRef = git.tag().setMessage(GIMPLE_MAVEN_PLUGIN + "tagging release " + releaseVersion) .setName(releaseVersion).call(); // next development version if (null == nextVersion) { nextVersion = getNextDevelopmentVersion(releaseVersion); } // versions:set nextVersion RevCommit nextRef = transformPomVersions(git, nextVersion); // push it all String developerConnection = mavenProject.getScm().getDeveloperConnection(); if (developerConnection.startsWith(PREFIX_SCM_GIT)) { developerConnection = developerConnection.substring(PREFIX_SCM_GIT.length()); } RefSpec spec = new RefSpec(branch + ":" + branch); git.push().setRemote(developerConnection).setRefSpecs(spec).add(tagRef).call(); } } catch (IOException e) { throw new MojoExecutionException("executing", e); } catch (GitAPIException e) { throw new MojoExecutionException("status", e); } }
From source file:com.wadpam.gimple.GimpleMojo.java
License:Open Source License
private RevCommit transformPomVersions(Git git, String newVersion) throws MojoExecutionException, GitAPIException { executeMojo(plugin("org.codehaus.mojo", "versions-maven-plugin", "2.1"), goal("set"), configuration(element(name("newVersion"), newVersion)), executionEnvironment(mavenProject, mavenSession, pluginManager)); StatusCommand statusCommand = git.status(); Status status = statusCommand.call(); // git add// w w w .j a v a 2 s . c o m for (String uncommitted : status.getUncommittedChanges()) { getLog().info(" adding to git index: " + uncommitted); AddCommand add = git.add(); add.addFilepattern(uncommitted); add.call(); } // git commit CommitCommand commit = git.commit(); commit.setMessage(GIMPLE_MAVEN_PLUGIN + "pom version " + newVersion); return commit.call(); }
From source file:org.ajoberstar.gradle.git.tasks.GitStatus.java
License:Apache License
@TaskAction public void status() { StatusCommand cmd = getGit().status(); try {//from w w w .ja va 2s . c o m this.status = cmd.call(); } catch (GitAPIException e) { throw new GradleException("Problem obtaining status", e); } }
From source file:org.apache.stratos.cartridge.agent.artifact.deployment.synchronizer.git.impl.GitBasedArtifactRepository.java
License:Apache License
/** * Commits any changes in the local repository to the relevant remote repository * * @return//from w w w . j a v a 2 s . c o m */ public void commit(RepositoryInformation repoInfo) { // TODO implement later, this is applicable for management node. // for (Entry<Integer, RepositoryContext> tenantMap : tenantToRepoContextMap // .entrySet()) { int tenantId = Integer.parseInt(repoInfo.getTenantId()); //log.info("map count has values..tenant Id : " + tenantId); RepositoryContext gitRepoCtx = retrieveCachedGitContext(tenantId); Git git = gitRepoCtx.getGit(); StatusCommand statusCmd = git.status(); Status status = null; try { status = statusCmd.call(); } catch (GitAPIException e) { log.error("Git status operation for tenant " + gitRepoCtx.getTenantId() + " failed, ", e); } //log.info("status : " + status.toString()); if (status.isClean()) {// no changes, nothing to commit if (log.isDebugEnabled()) { log.debug("No changes detected in the local repository for tenant " + tenantId); } return; } addArtifacts(gitRepoCtx, getNewArtifacts(status)); addArtifacts(gitRepoCtx, getModifiedArtifacts(status)); removeArtifacts(gitRepoCtx, getRemovedArtifacts(status)); commitToLocalRepo(gitRepoCtx); pushToRemoteRepo(gitRepoCtx); //} //return false; }
From source file:org.apache.stratos.manager.utils.RepositoryCreator.java
License:Apache License
private void createGitFolderStructure(String tenantDomain, String cartridgeName, String[] dirArray) throws Exception { if (log.isDebugEnabled()) { log.debug("Creating git repo folder structure "); }/*from w w w . ja v a2 s. c om*/ String parentDirName = "/tmp/" + UUID.randomUUID().toString(); CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider( System.getProperty(CartridgeConstants.INTERNAL_GIT_USERNAME), System.getProperty(CartridgeConstants.INTERNAL_GIT_PASSWORD).toCharArray()); // Clone // -------------------------- FileRepository localRepo = null; try { localRepo = new FileRepository(new File(parentDirName + "/.git")); } catch (IOException e) { log.error("Exception occurred in creating a new file repository. Reason: " + e.getMessage()); throw e; } Git git = new Git(localRepo); CloneCommand cloneCmd = git.cloneRepository().setURI(System.getProperty(CartridgeConstants.INTERNAL_GIT_URL) + "/git/" + tenantDomain + "/" + cartridgeName + ".git").setDirectory(new File(parentDirName)); cloneCmd.setCredentialsProvider(credentialsProvider); try { log.debug("Clonning git repo"); cloneCmd.call(); } catch (Exception e1) { log.error("Exception occurred in cloning Repo. Reason: " + e1.getMessage()); throw e1; } // ------------------------------------ // --- Adding directory structure -------- File parentDir = new File(parentDirName); parentDir.mkdir(); for (String string : dirArray) { String[] arr = string.split("="); if (log.isDebugEnabled()) { log.debug("Creating dir: " + arr[0]); } File parentFile = new File(parentDirName + "/" + arr[0]); parentFile.mkdirs(); File filess = new File(parentFile, "README"); String content = "Content goes here"; filess.createNewFile(); FileWriter fw = new FileWriter(filess.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.close(); } // ---------------------------------------------------------- // ---- Git status --------------- StatusCommand s = git.status(); Status status = null; try { log.debug("Getting git repo status"); status = s.call(); } catch (Exception e) { log.error("Exception occurred in git status check. Reason: " + e.getMessage()); throw e; } // -------------------------------- // ---------- Git add --------------- AddCommand addCmd = git.add(); Iterator<String> it = status.getUntracked().iterator(); while (it.hasNext()) { addCmd.addFilepattern(it.next()); } try { log.debug("Adding files to git repo"); addCmd.call(); } catch (Exception e) { log.error("Exception occurred in adding files. Reason: " + e.getMessage()); throw e; } // ----------------------------------------- // ------- Git commit ----------------------- CommitCommand commitCmd = git.commit(); commitCmd.setMessage("Adding directories"); try { log.debug("Committing git repo"); commitCmd.call(); } catch (Exception e) { log.error("Exception occurred in committing . Reason: " + e.getMessage()); throw e; } // -------------------------------------------- // --------- Git push ----------------------- PushCommand pushCmd = git.push(); pushCmd.setCredentialsProvider(credentialsProvider); try { log.debug("Git repo push"); pushCmd.call(); } catch (Exception e) { log.error("Exception occurred in Git push . Reason: " + e.getMessage()); throw e; } try { deleteDirectory(new File(parentDirName)); } catch (Exception e) { log.error("Exception occurred in deleting temp files. Reason: " + e.getMessage()); throw e; } log.info(" Folder structure is created ..... "); }
From source file:org.codehaus.mojo.versions.BumpMojo.java
License:Apache License
boolean gitModified() throws MojoExecutionException { StatusCommand statusCommand = git.status(); try {/*ww w . j av a2s .c o m*/ Status status = statusCommand.call(); if (notEmpty(status.getModified())) return true; if (notEmpty(status.getAdded())) return true; if (notEmpty(status.getChanged())) return true; if (notEmpty(status.getConflicting())) return true; if (notEmpty(status.getRemoved())) return true; if (notEmpty(status.getUncommittedChanges())) return true; if (notEmpty(status.getUntracked())) return true; return false; } catch (NoWorkTreeException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (GitAPIException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:org.codehaus.mojo.versions.BumpMojo.java
License:Apache License
/** * Called when this mojo is executed.//from w w w.ja va 2s. com * * @throws org.apache.maven.plugin.MojoExecutionException * when things go wrong. * @throws org.apache.maven.plugin.MojoFailureException * when things go wrong. */ public void execute() throws MojoExecutionException, MojoFailureException { try { init(); if (StringUtils.isEmpty(bump)) { out("Current tags:"); gitLastTags(); out(""); out("type version like 'mvn -q com.github.axet:versions-maven-plugin:bump -Dbump=server-1.0.0'"); System.exit(1); } if (gitTagExists(bump)) { out("Current tags:"); gitLastTags(); out(""); out("tag '" + bump + "' already exist"); System.exit(1); } String tag = bump; String branch; String version; String[] bb = tag.split("-"); branch = bb[0]; version = bb[bb.length - 1]; if (gitModified()) { StatusCommand statusCommand = git.status(); try { out("Can't bump version on modified tree:"); Status status = statusCommand.call(); out(status.getModified()); out((status.getAdded())); out((status.getChanged())); out((status.getConflicting())); out((status.getRemoved())); out((status.getUncommittedChanges())); out((status.getUntracked())); } catch (NoWorkTreeException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (GitAPIException e) { throw new MojoExecutionException(e.getMessage(), e); } System.exit(1); } // merge master. we allowd to change master if it is a readme file // git fetch gitFetch(); // git checkout master gitCheckout(master); // git rebase gitRebase(); // git checkout dev gitCheckout(dev); // git merge -m "Merge master" master gitMerge("Merge master", master); // bump version in dev tree, otherwise it will produce conflict merge on master on second // tag for pom.xml // git checkout dev gitCheckout(dev); final List<String> tags = new ArrayList<String>(); SwitchReleaseMojo release = new SwitchReleaseMojo() { @Override synchronized String incrementModuleVersion(String groupId, String artifactId, String version) { String newVersion = super.incrementVersion(SwitchReleaseMojo.release(version)); tags.add(artifactId + "-" + newVersion); return newVersion; } }; release.projectBuilder = projectBuilder; release.localRepository = localRepository; release.setProject(project); release.setGenerateBackupPoms(false); release.setNewVersion(version); release.setLog(getLog()); release.execute(); // git commit -m "Bump version $BRANCH $VERSION" -a git.commit().setAll(true).setMessage("Bump version " + branch + " " + version).call(); // create proper branch (server-1.0.0), helps produce nice git history // git checkout -b $TAG dev gitCheckoutB(tag); // prepare to merge // git checkout master gitCheckout(master); // do merge with a propertly named branch // git merge --no-ff -m "Merge branch '$TAG'" $TAG gitMergeNFF("Merge branch '" + tag + "'", tag); // do tag last master commit // git tag $TAG gitTag(tag); // tag all other changed (depended) modules for (String t : tags) gitTag(t); tags.clear(); // drop perpared branch // git branch -d $TAG gitBranchD(tag); // switch back to the dev // git checkout dev gitCheckout(dev); // update version with -SNAPSHOT postfix // git commit -m "Bump version $BRANCH $VERSION" -a SwitchSnapshotMojo snapshot = new SwitchSnapshotMojo(); snapshot.projectBuilder = projectBuilder; snapshot.localRepository = localRepository; snapshot.setProject(project); snapshot.setGenerateBackupPoms(false); snapshot.setLog(getLog()); snapshot.execute(); git.commit().setAll(true).setMessage("Bump version " + branch + " " + version).call(); if (push) { out(""); out("All done, push repo"); out(""); // git push origin master || exit 1 // git push --tags || exit 1 // git push origin dev || exit 1 gitPush(master); gitPush(dev); } } catch (GitAPIException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:org.eclipse.che.git.impl.jgit.JGitStatusImpl.java
License:Open Source License
/** * @param branchName/*from w ww.j a v a2 s .c o m*/ * current repository branch name * @param statusCommand * Jgit status command * @param format * the output format for the status * @throws GitException * when any error occurs */ public JGitStatusImpl(String branchName, StatusCommand statusCommand, StatusFormat format) throws GitException { this.branchName = branchName; this.format = format; org.eclipse.jgit.api.Status gitStatus; try { gitStatus = statusCommand.call(); } catch (GitAPIException exception) { throw new GitException(exception.getMessage(), exception); } clean = gitStatus.isClean(); added = new ArrayList<>(gitStatus.getAdded()); changed = new ArrayList<>(gitStatus.getChanged()); removed = new ArrayList<>(gitStatus.getRemoved()); missing = new ArrayList<>(gitStatus.getMissing()); modified = new ArrayList<>(gitStatus.getModified()); untracked = new ArrayList<>(gitStatus.getUntracked()); untrackedFolders = new ArrayList<>(gitStatus.getUntrackedFolders()); conflicting = new ArrayList<>(gitStatus.getConflicting()); }
From source file:org.eclipse.oomph.setup.git.impl.GitCloneTaskImpl.java
License:Open Source License
private static boolean hasWorkTree(Git git) throws Exception { try {/*from w w w . j a v a 2 s . co m*/ StatusCommand statusCommand = git.status(); statusCommand.call(); return true; } catch (NoWorkTreeException ex) { return false; } }