Java code for Importing git project from local in Eclipse -
we follow below steps import local git project in eclipse:
file -> import -> git -> projects git > existing local repository
how can achieve same using java program?
i used org.eclipse.core.resources
import project giving path of .project
file doesn't give git connectivity.
iworkspace workspace = resourcesplugin.getworkspace(); iworkspaceroot root = workspace.getroot(); iproject project = root.getproject("myproject/.project"); // path .project file project.create(new nullprogressmonitor()); project.open(null);
i went through jgit docs, didn't find solution
in order load project eclipse workspace, need load project description (stored in .project file) first. once have iprojectdescription instance, can use create it, i.e. make known eclipse workspace.
for example:
iprojectdescription description = workspace.loadprojectdescription( "path/to/.project" ); iproject project = workspace.getroot().getproject( description.getname() ); project.create( description, new nullprogressmonitor() ); project.open( new nullprogressmonitor() );
in order check whether project of same name known workspace, use code:
workspace.getroot().getproject( description.getname() );
if repository project imported belongs not yet known egit, need register repository first:
repositoryutil.addconfiguredrepository( new file( "path/to/.git-dir" ) );
then can use egit's connectprovideroperation
mark workspace project part of registered repository:
iegitoperation operation = new connectprovideroperation( project, "path/to/.git-dir" ); operation.execute( new nullprogressmonitor() );
all egit types discussed here can found in org.eclipse.egit.core
plug-in.
Comments
Post a Comment