本文整理汇总了Java中git4idea.util.StringScanner类的典型用法代码示例。如果您正苦于以下问题:Java StringScanner类的具体用法?Java StringScanner怎么用?Java StringScanner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringScanner类属于git4idea.util包,在下文中一共展示了StringScanner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPathsDiffBetweenRefs
import git4idea.util.StringScanner; //导入依赖的package包/类
/**
* Returns absolute paths which have changed remotely comparing to the current branch, i.e. performs
* <code>git diff --name-only master..origin/master</code>
* <p/>
* Paths are absolute, Git-formatted (i.e. with forward slashes).
*/
@NotNull
public static Collection<String> getPathsDiffBetweenRefs(@NotNull Git git, @NotNull GitRepository repository,
@NotNull String beforeRef, @NotNull String afterRef) throws VcsException {
List<String> parameters = Arrays.asList("--name-only", "--pretty=format:");
String range = beforeRef + ".." + afterRef;
GitCommandResult result = git.diff(repository, parameters, range);
if (!result.success()) {
LOG.info(String.format("Couldn't get diff in range [%s] for repository [%s]", range, repository.toLogString()));
return Collections.emptyList();
}
final Collection<String> remoteChanges = new HashSet<String>();
for (StringScanner s = new StringScanner(result.getOutputAsJoinedString()); s.hasMoreData(); ) {
final String relative = s.line();
if (StringUtil.isEmptyOrSpaces(relative)) {
continue;
}
final String path = repository.getRoot().getPath() + "/" + unescapePath(relative);
remoteChanges.add(path);
}
return remoteChanges;
}
示例2: getUnmergedPaths
import git4idea.util.StringScanner; //导入依赖的package包/类
/**
* Returns absolute paths to files which are currently unmerged, and also populates myUnmergedPaths with relative paths.
*/
public @NotNull Set<String> getUnmergedPaths() throws VcsException {
String root = myRoot.getPath();
final GitSimpleHandler h = new GitSimpleHandler(myProject, myRoot, GitCommand.LS_FILES);
h.setSilent(true);
h.addParameters("--unmerged");
final String result = h.run();
final Set<String> paths = new HashSet<String>();
for (StringScanner s = new StringScanner(result); s.hasMoreData();) {
if (s.isEol()) {
s.nextLine();
continue;
}
s.boundedToken('\t');
final String relative = s.line();
if (!myUnmergedPaths.add(relative)) {
continue;
}
String path = root + "/" + GitUtil.unescapePath(relative);
paths.add(path);
}
return paths;
}
示例3: loadStashStack
import git4idea.util.StringScanner; //导入依赖的package包/类
public static void loadStashStack(@NotNull Project project, @NotNull VirtualFile root, @NotNull Charset charset,
final Consumer<StashInfo> consumer) {
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.STASH.readLockingCommand());
h.setSilent(true);
h.addParameters("list");
String out;
try {
h.setCharset(charset);
out = h.run();
}
catch (VcsException e) {
GitUIUtil.showOperationError(project, e, h.printableCommandLine());
return;
}
for (StringScanner s = new StringScanner(out); s.hasMoreData();) {
consumer.consume(new StashInfo(s.boundedToken(':'), s.boundedToken(':'), s.line().trim()));
}
}
示例4: parseDiffForPaths
import git4idea.util.StringScanner; //导入依赖的package包/类
public static Collection<String> parseDiffForPaths(final String rootPath, final StringScanner s) throws VcsException {
final Collection<String> result = new ArrayList<String>();
while (s.hasMoreData()) {
if (s.isEol()) {
s.nextLine();
continue;
}
if ("CADUMR".indexOf(s.peek()) == -1) {
// exit if there is no next character
break;
}
assert 'M' != s.peek() : "Moves are not yet handled";
String[] tokens = s.line().split("\t");
String path = tokens[tokens.length - 1];
path = rootPath + File.separator + GitUtil.unescapePath(path);
path = FileUtil.toSystemDependentName(path);
result.add(path);
}
return result;
}
示例5: scanFiles
import git4idea.util.StringScanner; //导入依赖的package包/类
/**
* Scan working tree and detect locally modified files
*
* @param project the project to scan
* @param root the root to scan
* @param files the collection with files
* @throws VcsException if there problem with running git or working tree is dirty in unsupported way
*/
private static void scanFiles(Project project, VirtualFile root, List<String> files) throws VcsException {
String rootPath = root.getPath();
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.DIFF);
h.addParameters("--name-status");
h.setSilent(true);
h.setStdoutSuppressed(true);
StringScanner s = new StringScanner(h.run());
while (s.hasMoreData()) {
if (s.isEol()) {
s.line();
continue;
}
if (s.tryConsume("M\t")) {
String path = rootPath + "/" + GitUtil.unescapePath(s.line());
files.add(path);
}
else {
throw new VcsException("Working tree is dirty in unsupported way: " + s.line());
}
}
}
示例6: getPathsDiffBetweenRefs
import git4idea.util.StringScanner; //导入依赖的package包/类
/**
* Returns absolute paths which have changed remotely comparing to the current branch, i.e. performs
* <code>git diff --name-only master..origin/master</code>
*/
@NotNull
public static Collection<String> getPathsDiffBetweenRefs(@NotNull Git git, @NotNull GitRepository repository,
@NotNull String beforeRef, @NotNull String afterRef) throws VcsException {
List<String> parameters = Arrays.asList("--name-only", "--pretty=format:");
String range = beforeRef + ".." + afterRef;
GitCommandResult result = git.diff(repository, parameters, range);
if (!result.success()) {
LOG.info(String.format("Couldn't get diff in range [%s] for repository [%s]", range, repository.toLogString()));
return Collections.emptyList();
}
final Collection<String> remoteChanges = new HashSet<String>();
for (StringScanner s = new StringScanner(result.getOutputAsJoinedString()); s.hasMoreData(); ) {
final String relative = s.line();
if (StringUtil.isEmptyOrSpaces(relative)) {
continue;
}
final String path = repository.getRoot().getPath() + "/" + unescapePath(relative);
remoteChanges.add(FilePathsHelper.convertPath(path));
}
return remoteChanges;
}
示例7: loadStashStack
import git4idea.util.StringScanner; //导入依赖的package包/类
public static void loadStashStack(@NotNull Project project, @NotNull VirtualFile root, final Charset charset,
final Consumer<StashInfo> consumer) {
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.STASH.readLockingCommand());
h.setSilent(true);
h.addParameters("list");
String out;
try {
h.setCharset(charset);
out = h.run();
}
catch (VcsException e) {
GitUIUtil.showOperationError(project, e, h.printableCommandLine());
return;
}
for (StringScanner s = new StringScanner(out); s.hasMoreData();) {
consumer.consume(new StashInfo(s.boundedToken(':'), s.boundedToken(':'), s.line().trim()));
}
}
示例8: unmergedFiles
import git4idea.util.StringScanner; //导入依赖的package包/类
/**
* Parse changes from lines
*
*
* @param root the git root
* @return a set of unmerged files
* @throws com.intellij.openapi.vcs.VcsException if the input format does not matches expected format
*/
private List<VirtualFile> unmergedFiles(final VirtualFile root) throws VcsException {
GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
if (repository == null) {
LOG.error("Repository not found for root " + root);
return Collections.emptyList();
}
GitCommandResult result = myGit.getUnmergedFiles(repository);
if (!result.success()) {
throw new VcsException(result.getErrorOutputAsJoinedString());
}
String output = StringUtil.join(result.getOutput(), "\n");
HashSet<String> unmergedPaths = ContainerUtil.newHashSet();
for (StringScanner s = new StringScanner(output); s.hasMoreData();) {
if (s.isEol()) {
s.nextLine();
continue;
}
s.boundedToken('\t');
String relative = s.line();
unmergedPaths.add(GitUtil.unescapePath(relative));
}
if (unmergedPaths.size() == 0) {
return Collections.emptyList();
}
else {
List<File> files = ContainerUtil.map(unmergedPaths, new Function<String, File>() {
@Override
public File fun(String path) {
return new File(root.getPath(), path);
}
});
return ContainerUtil.sorted(RefreshVFsSynchronously.refreshFiles(files), GitUtil.VIRTUAL_FILE_COMPARATOR);
}
}
示例9: getRevisionsForDiff
import git4idea.util.StringScanner; //导入依赖的package包/类
/**
* @return The revision range which will be used to find merge diff (merge may be just finished, or in progress)
* or null in case of error or inconsistency.
*/
@Nullable
public String getRevisionsForDiff() throws VcsException {
String root = myRoot.getPath();
GitRevisionNumber currentHead = GitRevisionNumber.resolve(myProject, myRoot, "HEAD");
if (currentHead.equals(myStart)) {
// The head has not advanced. This means that this is a merge that did not commit.
// This could be caused by --no-commit option or by failed two-head merge. The MERGE_HEAD
// should be available. In case of --no-commit option, the MERGE_HEAD might contain
// multiple heads separated by newline. The changes are collected separately for each head
// and they are merged using TreeSet class (that also sorts the changes).
File mergeHeadsFile = new File(root, GitRepositoryFiles.GIT_MERGE_HEAD);
try {
if (mergeHeadsFile.exists()) {
String mergeHeads = new String(FileUtil.loadFileText(mergeHeadsFile, CharsetToolkit.UTF8));
for (StringScanner s = new StringScanner(mergeHeads); s.hasMoreData();) {
String head = s.line();
if (head.length() == 0) {
continue;
}
// note that "..." cause the diff to start from common parent between head and merge head
return myStart.getRev() + "..." + head;
}
}
} catch (IOException e) {
//noinspection ThrowableInstanceNeverThrown
throw new VcsException("Unable to read the file " + mergeHeadsFile + ": " + e.getMessage(), e);
}
} else {
// Otherwise this is a merge that did created a commit. And because of this the incoming changes
// are diffs between old head and new head. The commit could have been multihead commit,
// and the expression below considers it as well.
return myStart.getRev() + "..HEAD";
}
return null;
}
示例10: getChangedFilesExceptUnmerged
import git4idea.util.StringScanner; //导入依赖的package包/类
/**
* Populates the supplied collections of modified, created and removed files returned by 'git diff #revisions' command,
* where revisions is the range of revisions to check.
*/
public void getChangedFilesExceptUnmerged(Collection<String> updated, Collection<String> created, Collection<String> removed, String revisions)
throws VcsException {
if (revisions == null) {
return;
}
String root = myRoot.getPath();
GitSimpleHandler h = new GitSimpleHandler(myProject, myRoot, GitCommand.DIFF);
h.setSilent(true);
// note that moves are not detected here
h.addParameters("--name-status", "--diff-filter=ADMRUX", revisions);
for (StringScanner s = new StringScanner(h.run()); s.hasMoreData();) {
if (s.isEol()) {
s.nextLine();
continue;
}
char status = s.peek();
s.boundedToken('\t');
final String relative = s.line();
// eliminate conflicts
if (myUnmergedPaths.contains(relative)) {
continue;
}
String path = root + "/" + GitUtil.unescapePath(relative);
switch (status) {
case 'M':
updated.add(path);
break;
case 'A':
created.add(path);
break;
case 'D':
removed.add(path);
break;
default:
throw new IllegalStateException("Unexpected status: " + status);
}
}
}
示例11: getRemotelyChanged
import git4idea.util.StringScanner; //导入依赖的package包/类
public Collection<String> getRemotelyChanged(final VirtualFile vcsRoot, final Collection<String> paths) {
try {
final GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, vcsRoot, true);
if (searcher.getLocal() == null || searcher.getRemote() == null) return Collections.emptyList();
ArrayList<String> rc = new ArrayList<String>();
final Collection<FilePath> files = new ArrayList<FilePath>(paths.size());
for (String path : paths) {
files.add(VcsUtil.getFilePath(path));
}
for (List<String> pathList : VcsFileUtil.chunkPaths(vcsRoot, files)) {
GitSimpleHandler handler = new GitSimpleHandler(myProject, vcsRoot, GitCommand.DIFF);
handler.addParameters("--name-status", "--diff-filter=ADCRUX", "-M", "HEAD..." + searcher.getRemote().getFullName());
handler.setSilent(true);
handler.setStdoutSuppressed(true);
handler.endOptions();
handler.addParameters(pathList);
String output = handler.run();
Collection<String> pathCollection = GitChangeUtils.parseDiffForPaths(vcsRoot.getPath(), new StringScanner(output));
rc.addAll(pathCollection);
}
return rc;
}
catch (VcsException e) {
LOG.info(e);
return Collections.emptyList();
}
}
示例12: fetchTags
import git4idea.util.StringScanner; //导入依赖的package包/类
/**
* Fetch tags
*/
private void fetchTags() {
myExistingTags.clear();
GitSimpleHandler h = new GitSimpleHandler(myProject, getGitRoot(), GitCommand.TAG);
h.setSilent(true);
String output = GitHandlerUtil.doSynchronously(h, GitBundle.getString("tag.getting.existing.tags"), h.printableCommandLine());
for (StringScanner s = new StringScanner(output); s.hasMoreData();) {
String line = s.line();
if (line.length() == 0) {
continue;
}
myExistingTags.add(line);
}
}
示例13: parseChanges
import git4idea.util.StringScanner; //导入依赖的package包/类
/**
* Parse changes from lines
*
* @param project the context project
* @param vcsRoot the git root
* @param thisRevision the current revision
* @param parentRevision the parent revision for this change list
* @param s the lines to parse
* @param changes a list of changes to update
* @param ignoreNames a set of names ignored during collection of the changes
* @throws VcsException if the input format does not matches expected format
*/
public static void parseChanges(Project project,
VirtualFile vcsRoot,
@Nullable GitRevisionNumber thisRevision,
GitRevisionNumber parentRevision,
String s,
Collection<Change> changes,
final Set<String> ignoreNames) throws VcsException {
StringScanner sc = new StringScanner(s);
parseChanges(project, vcsRoot, thisRevision, parentRevision, sc, changes, ignoreNames);
if (sc.hasMoreData()) {
throw new IllegalStateException("Unknown file status: " + sc.line());
}
}
示例14: load
import git4idea.util.StringScanner; //导入依赖的package包/类
@NotNull
public List<GitRebaseEntry> load() throws IOException, NoopException {
String encoding = GitConfigUtil.getLogEncoding(myProject, myRoot);
List<GitRebaseEntry> entries = ContainerUtil.newArrayList();
final StringScanner s = new StringScanner(FileUtil.loadFile(new File(myFile), encoding));
boolean noop = false;
while (s.hasMoreData()) {
if (s.isEol() || s.startsWith('#')) {
s.nextLine();
continue;
}
if (s.startsWith("noop")) {
noop = true;
s.nextLine();
continue;
}
String action = s.spaceToken();
String hash = s.spaceToken();
String comment = s.line();
entries.add(new GitRebaseEntry(action, hash, comment));
}
if (noop && entries.isEmpty()) {
throw new NoopException();
}
return entries;
}
示例15: parseTags
import git4idea.util.StringScanner; //导入依赖的package包/类
private List<String> parseTags(String output) {
List<String> tags = Lists.newArrayList();
for (StringScanner s = new StringScanner(output); s.hasMoreData(); ) {
String line = s.line();
Matcher match = SINGLE_TAG_PATTERN.matcher(line);
if (match.matches()) {
tags.add(match.group(1));
} else if (line.contains("tag: ")) {
tags.addAll(parseMultipleTags(line));
}
}
return tags;
}