use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitVariableResolver method getGitRepoRelativePath.
private String getGitRepoRelativePath(String argument) throws CoreException {
IResource res = getResource(argument);
RepositoryMapping mapping = RepositoryMapping.getMapping(res);
if (mapping != null) {
String repoRelativePath = mapping.getRepoRelativePath(res);
if (repoRelativePath == null) {
// $NON-NLS-1$
return "";
}
if (// $NON-NLS-1$
repoRelativePath.equals(""))
// $NON-NLS-1$
return ".";
else
return repoRelativePath;
}
// $NON-NLS-1$
return "";
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitVariableResolver method getGitWorkTree.
@NonNull
private String getGitWorkTree(String argument) throws CoreException {
IResource res = getResource(argument);
RepositoryMapping mapping = RepositoryMapping.getMapping(res);
if (mapping != null) {
File workTree = mapping.getWorkTree();
if (workTree != null) {
return workTree.getAbsolutePath();
}
}
// $NON-NLS-1$
return "";
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class CommitUI method getProjectsOfRepositories.
private IProject[] getProjectsOfRepositories() {
Set<IProject> ret = new HashSet<>();
final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (IProject project : projects) {
RepositoryMapping mapping = RepositoryMapping.getMapping(project);
if (mapping != null && mapping.getRepository() == repo)
ret.add(project);
}
return ret.toArray(new IProject[ret.size()]);
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class ProjectUtils method createProjects.
/**
* Create (import) a set of existing projects. The projects are
* automatically connected to the repository they reside in.
*
* @param projectsToCreate
* the projects to create
* @param open
* true to open existing projects, false to leave in current
* state
* @param selectedWorkingSets
* the workings sets to add the created projects to, may be null
* or empty
* @param monitor
* @throws InvocationTargetException
* @throws InterruptedException
*/
public static void createProjects(final Set<ProjectRecord> projectsToCreate, final boolean open, final IWorkingSet[] selectedWorkingSets, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (projectsToCreate.isEmpty()) {
return;
}
IWorkspaceRunnable wsr = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor actMonitor) throws CoreException {
IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
if (actMonitor.isCanceled()) {
throw new OperationCanceledException();
}
Map<IProject, File> projectsToConnect = new HashMap<>();
SubMonitor progress = SubMonitor.convert(actMonitor, projectsToCreate.size() * 2 + 1);
for (ProjectRecord projectRecord : projectsToCreate) {
if (progress.isCanceled()) {
throw new OperationCanceledException();
}
progress.setTaskName(projectRecord.getProjectLabel());
IProject project = createExistingProject(projectRecord, open, progress.newChild(1));
if (project == null) {
continue;
}
RepositoryFinder finder = new RepositoryFinder(project);
finder.setFindInChildren(false);
Collection<RepositoryMapping> mappings = finder.find(progress.newChild(1));
if (!mappings.isEmpty()) {
RepositoryMapping mapping = mappings.iterator().next();
IPath absolutePath = mapping.getGitDirAbsolutePath();
if (absolutePath != null) {
projectsToConnect.put(project, absolutePath.toFile());
}
}
if (selectedWorkingSets != null && selectedWorkingSets.length > 0) {
workingSetManager.addToWorkingSets(project, selectedWorkingSets);
}
}
if (!projectsToConnect.isEmpty()) {
ConnectProviderOperation connect = new ConnectProviderOperation(projectsToConnect);
connect.execute(progress.newChild(1));
}
}
};
try {
ResourcesPlugin.getWorkspace().run(wsr, monitor);
} catch (OperationCanceledException e) {
throw new InterruptedException();
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitHistoryPage method inputSet.
@Override
public boolean inputSet() {
try {
if (trace)
GitTraceLocation.getTrace().traceEntry(GitTraceLocation.HISTORYVIEW.getLocation());
if (this.input != null)
return true;
Object o = super.getInput();
if (o == null) {
setErrorMessage(UIText.GitHistoryPage_NoInputMessage);
return false;
}
boolean showHead = false;
boolean showRef = false;
boolean showTag = false;
Repository repo = null;
RevCommit selection = null;
Ref ref = null;
if (o instanceof IResource) {
RepositoryMapping mapping = RepositoryMapping.getMapping((IResource) o);
if (mapping != null) {
repo = mapping.getRepository();
input = new HistoryPageInput(repo, new IResource[] { (IResource) o });
showHead = true;
}
} else if (o instanceof RepositoryTreeNode) {
RepositoryTreeNode repoNode = (RepositoryTreeNode) o;
repo = repoNode.getRepository();
switch(repoNode.getType()) {
case FILE:
File file = ((FileNode) repoNode).getObject();
input = new HistoryPageInput(repo, new File[] { file });
showHead = true;
break;
case FOLDER:
File folder = ((FolderNode) repoNode).getObject();
input = new HistoryPageInput(repo, new File[] { folder });
showHead = true;
break;
case REF:
input = new HistoryPageInput(repo);
ref = ((RefNode) repoNode).getObject();
showRef = true;
break;
case ADDITIONALREF:
input = new HistoryPageInput(repo);
ref = ((AdditionalRefNode) repoNode).getObject();
showRef = true;
break;
case TAG:
input = new HistoryPageInput(repo);
ref = ((TagNode) repoNode).getObject();
showTag = true;
break;
default:
input = new HistoryPageInput(repo);
showHead = true;
break;
}
} else if (o instanceof HistoryPageInput) {
input = (HistoryPageInput) o;
} else {
IResource resource = AdapterUtils.adaptToAnyResource(o);
if (resource != null) {
RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
if (mapping != null) {
repo = mapping.getRepository();
input = new HistoryPageInput(repo, new IResource[] { resource });
}
}
}
if (repo == null) {
repo = AdapterUtils.adapt(o, Repository.class);
if (repo != null) {
File file = AdapterUtils.adapt(o, File.class);
if (file == null) {
input = new HistoryPageInput(repo);
} else {
input = new HistoryPageInput(repo, new File[] { file });
}
}
}
selection = AdapterUtils.adapt(o, RevCommit.class);
if (input == null) {
// $NON-NLS-1$
this.name = "";
setErrorMessage(UIText.GitHistoryPage_NoInputMessage);
return false;
}
final IResource[] inResources = input.getItems();
final File[] inFiles = input.getFileList();
this.name = calculateName(input);
// disable the filters if we have a Repository as input
boolean filtersActive = inResources != null || inFiles != null;
actions.showAllRepoVersionsAction.setEnabled(filtersActive);
actions.showAllProjectVersionsAction.setEnabled(filtersActive);
// the repository itself has no notion of projects
actions.showAllFolderVersionsAction.setEnabled(inResources != null);
actions.showAllResourceVersionsAction.setEnabled(filtersActive);
setErrorMessage(null);
try {
initAndStartRevWalk(false);
} catch (IllegalStateException e) {
Activator.handleError(e.getMessage(), e, true);
return false;
}
if (showHead)
showHead(repo);
if (showRef)
showRef(ref, repo);
if (showTag)
showTag(ref, repo);
if (selection != null)
graph.selectCommitStored(selection);
return true;
} finally {
if (trace)
GitTraceLocation.getTrace().traceExit(GitTraceLocation.HISTORYVIEW.getLocation());
}
}
Aggregations