Search in sources :

Example 71 with RepositoryMapping

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 "";
}
Also used : RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IResource(org.eclipse.core.resources.IResource)

Example 72 with RepositoryMapping

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 "";
}
Also used : RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) File(java.io.File) IResource(org.eclipse.core.resources.IResource) NonNull(org.eclipse.jgit.annotations.NonNull)

Example 73 with RepositoryMapping

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()]);
}
Also used : RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IProject(org.eclipse.core.resources.IProject) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 74 with RepositoryMapping

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);
    }
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) RepositoryFinder(org.eclipse.egit.core.project.RepositoryFinder) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) File(java.io.File)

Example 75 with RepositoryMapping

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());
    }
}
Also used : AdditionalRefNode(org.eclipse.egit.ui.internal.repository.tree.AdditionalRefNode) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode) AdditionalRefNode(org.eclipse.egit.ui.internal.repository.tree.AdditionalRefNode) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) RevObject(org.eclipse.jgit.revwalk.RevObject) File(java.io.File) IResource(org.eclipse.core.resources.IResource) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)87 Repository (org.eclipse.jgit.lib.Repository)40 IResource (org.eclipse.core.resources.IResource)31 IProject (org.eclipse.core.resources.IProject)23 IPath (org.eclipse.core.runtime.IPath)20 IOException (java.io.IOException)18 File (java.io.File)17 CoreException (org.eclipse.core.runtime.CoreException)15 IFile (org.eclipse.core.resources.IFile)12 Path (org.eclipse.core.runtime.Path)12 RevCommit (org.eclipse.jgit.revwalk.RevCommit)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 GitProjectData (org.eclipse.egit.core.project.GitProjectData)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 HashSet (java.util.HashSet)6 IStatus (org.eclipse.core.runtime.IStatus)6 Status (org.eclipse.core.runtime.Status)6 RevWalk (org.eclipse.jgit.revwalk.RevWalk)6 HashMap (java.util.HashMap)5