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);
}
}
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations