use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class GitImportWizard method importProjects.
private void importProjects(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
switch(importWithDirectoriesPage.getWizardSelection()) {
case GitSelectWizardPage.EXISTING_PROJECTS_WIZARD:
{
final Set<ProjectRecord> projectsToCreate = new HashSet<>();
final List<IWorkingSet> workingSets = new ArrayList<>();
// get the data from the pages in the UI thread
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
projectsToCreate.addAll(projectsImportPage.getCheckedProjects());
IWorkingSet[] workingSetArray = projectsImportPage.getSelectedWorkingSets();
workingSets.addAll(Arrays.asList(workingSetArray));
projectsImportPage.saveWidgetValues();
}
});
ProjectUtils.createProjects(projectsToCreate, workingSets.toArray(new IWorkingSet[workingSets.size()]), monitor);
break;
}
case GitSelectWizardPage.NEW_WIZARD:
{
final File[] repoDir = new File[1];
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
repoDir[0] = getTargetRepository().getDirectory();
}
});
final List<IProject> previousProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
new NewProjectAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow()).run();
}
});
IWorkspaceRunnable wsr = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor actMonitor) throws CoreException {
IProject[] currentProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
SubMonitor progress = SubMonitor.convert(actMonitor, currentProjects.length);
for (IProject current : currentProjects) if (!previousProjects.contains(current)) {
ConnectProviderOperation cpo = new ConnectProviderOperation(current, repoDir[0]);
cpo.execute(progress.newChild(1));
} else {
progress.worked(1);
}
}
};
try {
ResourcesPlugin.getWorkspace().run(wsr, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
break;
}
case GitSelectWizardPage.GENERAL_WIZARD:
{
final String[] projectName = new String[1];
final boolean[] defaultLocation = new boolean[1];
final String[] path = new String[1];
final File[] repoDir = new File[1];
// get the data from the page in the UI thread
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
projectName[0] = createGeneralProjectPage.getProjectName();
defaultLocation[0] = createGeneralProjectPage.isDefaultLocation();
path[0] = importWithDirectoriesPage.getPath();
repoDir[0] = getTargetRepository().getDirectory();
}
});
try {
IWorkspaceRunnable wsr = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor actMonitor) throws CoreException {
final IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName[0]);
desc.setLocation(new Path(path[0]));
SubMonitor progress = SubMonitor.convert(actMonitor, 4);
IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(desc.getName());
prj.create(desc, progress.newChild(1));
prj.open(progress.newChild(1));
ConnectProviderOperation cpo = new ConnectProviderOperation(prj, repoDir[0]);
cpo.execute(progress.newChild(1));
ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_ONE, progress.newChild(1));
}
};
ResourcesPlugin.getWorkspace().run(wsr, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
break;
}
}
}
use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class NewRepositoryWizard method autoShareProjects.
/**
* auto-share projects which are located inside newly created repository
*
* @param repoToCreate
* @param projects
*/
private void autoShareProjects(Repository repoToCreate, IProject[] projects) {
final Map<IProject, File> projectsMap = new HashMap<>();
for (IProject project : projects) projectsMap.put(project, repoToCreate.getDirectory());
ConnectProviderOperation op = new ConnectProviderOperation(projectsMap);
JobUtil.scheduleUserJob(op, CoreText.Activator_AutoShareJobName, JobFamilies.AUTO_SHARE);
}
use of org.eclipse.egit.core.op.ConnectProviderOperation in project jbosstools-openshift by jbosstools.
the class TestRepository method connect.
/**
* Connect a project to this repository
*
* @param project
* @throws CoreException
*/
public void connect(IProject project) throws CoreException {
ConnectProviderOperation op = new ConnectProviderOperation(project, this.getRepository().getDirectory());
op.execute(null);
}
use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class LocalRepositoryTestCase method shareProjects.
protected void shareProjects(File repositoryDir) throws Exception {
Repository myRepository = lookupRepository(repositoryDir);
FilenameFilter projectFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.equals(".project");
}
};
for (File file : myRepository.getWorkTree().listFiles()) {
if (file.isDirectory()) {
if (file.list(projectFilter).length > 0) {
IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(file.getName());
desc.setLocation(new Path(file.getPath()));
IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(file.getName());
prj.create(desc, null);
prj.open(null);
try {
new ConnectProviderOperation(prj, myRepository.getDirectory()).execute(null);
} catch (Exception e) {
Activator.logError("Failed to connect project to repository", e);
}
assertConnected(prj);
}
}
}
TestUtil.waitForJobs(50, 5000);
}
use of org.eclipse.egit.core.op.ConnectProviderOperation in project egit by eclipse.
the class LocalRepositoryTestCase method createProjectAndCommitToRepository.
protected File createProjectAndCommitToRepository(String repoName, String project1Name, String project2Name) throws Exception {
Repository myRepository = createLocalTestRepository(repoName);
File gitDir = myRepository.getDirectory();
// we need to commit into master first
IProject firstProject = createStandardTestProjectInRepository(myRepository, project1Name);
try {
new ConnectProviderOperation(firstProject, gitDir).execute(null);
} catch (Exception e) {
Activator.logError("Failed to connect project to repository", e);
}
assertConnected(firstProject);
IProject secondProject = null;
if (project2Name != null) {
secondProject = createStandardTestProjectInRepository(myRepository, project2Name);
try {
new ConnectProviderOperation(secondProject, gitDir).execute(null);
} catch (Exception e) {
Activator.logError("Failed to connect project to repository", e);
}
assertConnected(secondProject);
}
IFile dotProject = firstProject.getFile(".project");
assertTrue(".project is not accessible: " + dotProject, dotProject.isAccessible());
IFolder folder = firstProject.getFolder(FOLDER);
IFile textFile = folder.getFile(FILE1);
IFile textFile2 = folder.getFile(FILE2);
IFile[] commitables = null;
if (secondProject != null) {
folder = secondProject.getFolder(FOLDER);
IFile secondtextFile = folder.getFile(FILE1);
IFile secondtextFile2 = folder.getFile(FILE2);
commitables = new IFile[] { dotProject, textFile, textFile2, secondtextFile, secondtextFile2 };
} else {
commitables = new IFile[] { dotProject, textFile, textFile2 };
}
ArrayList<IFile> untracked = new ArrayList<IFile>();
untracked.addAll(Arrays.asList(commitables));
// commit to stable
CommitOperation op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit");
op.execute(null);
// now create a stable branch (from master)
createStableBranch(myRepository);
// and check in some stuff into master again
String newContent = "Touched at " + System.currentTimeMillis();
IFile file = touch(firstProject.getName(), FOLDER + '/' + FILE1, newContent);
addAndCommit(file, newContent);
// Make sure cache entry is already listening for changes
IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
cache.getIndexDiffCacheEntry(lookupRepository(gitDir));
return gitDir;
}
Aggregations