Search in sources :

Example 1 with ProjectReference

use of org.eclipse.egit.core.ProjectReference in project egit by eclipse.

the class ProjectReferenceImporter method cloneIfNecessary.

private static File cloneIfNecessary(final URIish gitUrl, final String refToCheckout, final IPath workDir, final Set<ProjectReference> projects, IProgressMonitor monitor) throws TeamException, InterruptedException {
    final File repositoryPath = workDir.append(Constants.DOT_GIT_EXT).toFile();
    if (workDir.toFile().exists()) {
        if (repositoryAlreadyExistsForUrl(repositoryPath, gitUrl))
            return repositoryPath;
        else {
            final Collection<String> projectNames = new LinkedList<String>();
            for (final ProjectReference projectReference : projects) projectNames.add(projectReference.getProjectDir());
            throw new TeamException(NLS.bind(CoreText.GitProjectSetCapability_CloneToExistingDirectory, new Object[] { workDir, projectNames, gitUrl }));
        }
    } else {
        try {
            int timeout = 60;
            final CloneOperation cloneOperation = new CloneOperation(gitUrl, true, null, workDir.toFile(), refToCheckout, Constants.DEFAULT_REMOTE_NAME, timeout);
            cloneOperation.run(monitor);
            return repositoryPath;
        } catch (final InvocationTargetException e) {
            throw getTeamException(e);
        }
    }
}
Also used : TeamException(org.eclipse.team.core.TeamException) ProjectReference(org.eclipse.egit.core.ProjectReference) File(java.io.File) LinkedList(java.util.LinkedList) CloneOperation(org.eclipse.egit.core.op.CloneOperation) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with ProjectReference

use of org.eclipse.egit.core.ProjectReference in project egit by eclipse.

the class ProjectReferenceImporter method importProjects.

private List<IProject> importProjects(final Set<ProjectReference> projects, final IPath workDir, final File repositoryPath, final IProgressMonitor monitor) throws TeamException {
    try {
        List<IProject> importedProjects = new ArrayList<IProject>();
        // import projects from the current repository to workspace
        final IWorkspace workspace = ResourcesPlugin.getWorkspace();
        final IWorkspaceRoot root = workspace.getRoot();
        SubMonitor progress = SubMonitor.convert(monitor, projects.size());
        for (final ProjectReference projectToImport : projects) {
            SubMonitor subProgress = SubMonitor.convert(progress.newChild(1), 3);
            final IPath projectDir = workDir.append(projectToImport.getProjectDir());
            final IProjectDescription projectDescription = workspace.loadProjectDescription(projectDir.append(IProjectDescription.DESCRIPTION_FILE_NAME));
            final IProject project = root.getProject(projectDescription.getName());
            if (!project.exists()) {
                project.create(projectDescription, subProgress.newChild(1));
                importedProjects.add(project);
            }
            subProgress.setWorkRemaining(2);
            project.open(subProgress.newChild(1));
            final ConnectProviderOperation connectProviderOperation = new ConnectProviderOperation(project, repositoryPath);
            connectProviderOperation.execute(subProgress.newChild(1));
        }
        return importedProjects;
    } catch (final CoreException e) {
        throw TeamException.asTeamException(e);
    }
}
Also used : ProjectReference(org.eclipse.egit.core.ProjectReference) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) ArrayList(java.util.ArrayList) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProjectDescription(org.eclipse.core.resources.IProjectDescription) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IProject(org.eclipse.core.resources.IProject)

Example 3 with ProjectReference

use of org.eclipse.egit.core.ProjectReference in project egit by eclipse.

the class ProjectReferenceTest method createProjectReferenceFromString.

@Before
public void createProjectReferenceFromString() throws IllegalArgumentException, URISyntaxException {
    String reference = version + "," + url + "," + branch + "," + project;
    projectReference = new ProjectReference(reference);
    assertNotNull(projectReference);
}
Also used : ProjectReference(org.eclipse.egit.core.ProjectReference) Before(org.junit.Before)

Example 4 with ProjectReference

use of org.eclipse.egit.core.ProjectReference in project egit by eclipse.

the class ProjectReferenceImporter method run.

/**
 * Imports the projects as described in the reference strings.
 *
 * @param monitor progress monitor
 * @return the imported projects
 * @throws TeamException
 */
public List<IProject> run(IProgressMonitor monitor) throws TeamException {
    final Map<URIish, Map<String, Set<ProjectReference>>> repositories = parseReferenceStrings();
    final List<IProject> importedProjects = new ArrayList<IProject>();
    SubMonitor progress = SubMonitor.convert(monitor, repositories.size());
    for (final Map.Entry<URIish, Map<String, Set<ProjectReference>>> entry : repositories.entrySet()) {
        final URIish gitUrl = entry.getKey();
        final Map<String, Set<ProjectReference>> refs = entry.getValue();
        SubMonitor subProgress = progress.newChild(1).setWorkRemaining(refs.size());
        for (final Map.Entry<String, Set<ProjectReference>> refEntry : refs.entrySet()) {
            final String refName = refEntry.getKey();
            final Set<ProjectReference> projects = refEntry.getValue();
            final Set<String> allRefs = refs.keySet();
            File repositoryPath = null;
            if (allRefs.size() == 1)
                repositoryPath = findConfiguredRepository(gitUrl);
            SubMonitor subSubProgress = subProgress.newChild(1).setWorkRemaining(repositoryPath == null ? 2 : 1);
            if (repositoryPath == null) {
                try {
                    IPath workDir = getWorkingDir(gitUrl, refName, refs.keySet());
                    repositoryPath = cloneIfNecessary(gitUrl, refName, workDir, projects, subSubProgress.newChild(1));
                } catch (final InterruptedException e) {
                    // was canceled by user
                    return Collections.emptyList();
                }
            }
            getRepositoryUtil().addConfiguredRepository(repositoryPath);
            IPath newWorkDir = new Path(repositoryPath.getAbsolutePath()).removeLastSegments(1);
            List<IProject> p = importProjects(projects, newWorkDir, repositoryPath, subSubProgress.newChild(1));
            importedProjects.addAll(p);
        }
    }
    return importedProjects;
}
Also used : URIish(org.eclipse.jgit.transport.URIish) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ProjectReference(org.eclipse.egit.core.ProjectReference) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File)

Example 5 with ProjectReference

use of org.eclipse.egit.core.ProjectReference in project egit by eclipse.

the class ProjectReferenceImporter method parseReferenceStrings.

private Map<URIish, Map<String, Set<ProjectReference>>> parseReferenceStrings() throws TeamException {
    final Map<URIish, Map<String, Set<ProjectReference>>> repositories = new LinkedHashMap<URIish, Map<String, Set<ProjectReference>>>();
    for (final String reference : referenceStrings) {
        if (reference == null) {
            // so we can receive null references.
            continue;
        }
        try {
            final ProjectReference projectReference = new ProjectReference(reference);
            Map<String, Set<ProjectReference>> repositoryBranches = repositories.get(projectReference.getRepository());
            if (repositoryBranches == null) {
                repositoryBranches = new HashMap<String, Set<ProjectReference>>();
                repositories.put(projectReference.getRepository(), repositoryBranches);
            }
            Set<ProjectReference> projectReferences = repositoryBranches.get(projectReference.getBranch());
            if (projectReferences == null) {
                projectReferences = new LinkedHashSet<ProjectReference>();
                repositoryBranches.put(projectReference.getBranch(), projectReferences);
            }
            projectReferences.add(projectReference);
        } catch (final IllegalArgumentException e) {
            throw new TeamException(reference, e);
        } catch (final URISyntaxException e) {
            throw new TeamException(reference, e);
        }
    }
    return repositories;
}
Also used : URIish(org.eclipse.jgit.transport.URIish) ProjectReference(org.eclipse.egit.core.ProjectReference) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) URISyntaxException(java.net.URISyntaxException) LinkedHashMap(java.util.LinkedHashMap) TeamException(org.eclipse.team.core.TeamException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

ProjectReference (org.eclipse.egit.core.ProjectReference)5 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 IProject (org.eclipse.core.resources.IProject)2 IPath (org.eclipse.core.runtime.IPath)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 URIish (org.eclipse.jgit.transport.URIish)2 TeamException (org.eclipse.team.core.TeamException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 LinkedList (java.util.LinkedList)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 CoreException (org.eclipse.core.runtime.CoreException)1