Skip to content

Commit

Permalink
Merge pull request #1440 from eclipse/CHE-1113
Browse files Browse the repository at this point in the history
CHE-1113: Add ability to clone project with submodules
  • Loading branch information
Igor Vinokur authored Jun 29, 2016
2 parents 38c3ca0 + ffef620 commit 3d89ae7
Show file tree
Hide file tree
Showing 19 changed files with 138 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ public interface GitLocalizationConstant extends Messages {
@Key("view.import.gitImporterPage.projectUrl")
String gitImporterPageProjectUrl();

@Key("view.import.gitImporterPage.recursive")
String gitImporterPageRecursive();

@Key("view.import.gitImporterPage.projectInfo")
String gitImporterPageProjectInfo();

Expand Down Expand Up @@ -692,4 +695,4 @@ public interface GitLocalizationConstant extends Messages {

@Key("console.project.name")
String consoleProjectName(String projectName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ public void projectUrlChanged(@NotNull String url) {
updateDelegate.updateControls();
}

@Override
public void onRecursiveSelected(boolean recursiveSelected) {
if (recursiveSelected) {
projectParameters().put("recursive", null);
} else {
projectParameters().remove("recursive");
}
}

@Override
public void projectDescriptionChanged(@NotNull String projectDescription) {
dataObject.setDescription(projectDescription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ interface ActionDelegate {
/** Performs any actions appropriate in response to the user having changed the project's URL. */
void projectUrlChanged(@NotNull String url);

/** Performs any actions appropriate in response to the user has selected recursive checkbox. */
void onRecursiveSelected(boolean recursiveSelected);

/** Performs any actions appropriate in response to the user having changed the project's description. */
void projectDescriptionChanged(@NotNull String projectDescriptionValue);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class GitImporterPageViewImpl extends Composite implements GitImporterPag
@UiField
TextBox projectUrl;

@UiField
CheckBox recursive;

@UiField
FlowPanel importerPanel;

Expand Down Expand Up @@ -100,6 +103,11 @@ void onProjectUrlChanged(KeyUpEvent event) {
delegate.projectUrlChanged(projectUrl.getValue());
}

@UiHandler("recursive")
void recursiveHandler(ValueChangeEvent<Boolean> event) {
delegate.onRecursiveSelected(event.getValue());
}

@UiHandler("projectDescription")
void onProjectDescriptionChanged(KeyUpEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
debugId="file-importProject-projectUrl"/>
<g:Label ui:field="labelUrlError" width="100%" wordWrap="true" addStyleNames="{style.labelErrorPosition}"/>
</g:FlowPanel>
<g:FlowPanel height="20px" addStyleNames="{style.namePanel}">
<g:CheckBox ui:field="recursive" text="{locale.gitImporterPageRecursive}"
debugId="file-importProject-recursive" addStyleNames="{style.alignLeft}" />
</g:FlowPanel>
<g:FlowPanel height="0" addStyleNames="{style.horizontalLine}"/>
<g:FlowPanel height="35px" addStyleNames="{style.namePanel}">
<g:Label text="{locale.gitImporterPageProjectInfo}" addStyleNames="{style.label}"/>
Expand All @@ -45,7 +49,7 @@
tabIndex="5"/>
</g:FlowPanel>

<g:FlowPanel height="25px" addStyleNames="{style.namePanel}">
<g:FlowPanel height="20px" addStyleNames="{style.namePanel}">
<g:CheckBox ui:field="keepDirectory" text="{locale.gitImporterPageKeepDirectory}"
debugId="file-importProject-keepDirectory" addStyleNames="{style.alignLeft}" />
</g:FlowPanel>
Expand All @@ -56,7 +60,7 @@
tabIndex="9" debugId="file-importProject-keepDirectoryName" title="{locale.gitImporterPageBranchField}"/>
</g:FlowPanel>

<g:FlowPanel height="25px" addStyleNames="{style.namePanel}">
<g:FlowPanel height="20px" addStyleNames="{style.namePanel}">
<g:CheckBox ui:field="branchSelection" text="{locale.gitImporterPageBranch}"
debugId="file-importProject-branch" addStyleNames="{style.alignLeft}" />
</g:FlowPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ importProject.messageStartWithWhiteSpace = The url can not start with a whitespa
#GitImporterPage
view.import.gitImporterPage.projectUrl = URL:
view.import.gitImporterPage.projectInfo = Project Information
view.import.gitImporterPage.recursive = Import recursively (for multi-module projects)
view.import.gitImporterPage.projectName = Name:
view.import.gitImporterPageProjectNamePrompt = Define the name of your project...
view.import.gitImporterPage.projectDescription = Description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,28 @@ public void directoryNameEnteredTest() {
verify(view).highlightDirectoryNameField(false);
}

@Test
public void recursiveCloneSelectedTest() {
Map<String, String> parameters = new HashMap<>();
when(source.getParameters()).thenReturn(parameters);
when(view.getDirectoryName()).thenReturn("recursive");

presenter.onRecursiveSelected(true);

assertTrue(parameters.containsKey("recursive"));
}

@Test
public void recursiveCloneUnSelectedTest() {
Map<String, String> parameters = new HashMap<>();
parameters.put("recursive", null);
when(source.getParameters()).thenReturn(parameters);

presenter.onRecursiveSelected(false);

assertTrue(parameters.isEmpty());
}

private void verifyInvocationsForCorrectUrl(String correctUrl) {
verify(view, never()).markURLInvalid();
verify(source).setLocation(eq(correctUrl));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public interface GitHubLocalizationConstant extends Messages {
@Key("view.import.githubImporterPage.projectUrl")
String githubImporterPageProjectUrl();

@Key("view.import.githubImporterPage.recursive")
String githubImporterPageRecursive();

@Key("view.import.githubImporterPage.projectInfo")
String githubImporterPageProjectInfo();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ public void projectUrlChanged(@NotNull String url) {
updateDelegate.updateControls();
}

@Override
public void onRecursiveSelected(boolean recursiveSelected) {
if (recursiveSelected) {
projectParameters().put("recursive", null);
} else {
projectParameters().remove("recursive");
}
}

@Override
public void projectDescriptionChanged(@NotNull String projectDescription) {
dataObject.setDescription(projectDescription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ interface ActionDelegate {
*/
void projectUrlChanged(@NotNull String url);

/** Performs any actions appropriate in response to the user has selected recursive checkbox. */
void onRecursiveSelected(boolean recursiveSelected);

/**
* Performs any actions appropriate in response to the user having changed the project's description.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ interface GithubImporterPageViewImplUiBinder extends UiBinder<DockLayoutPanel, G
@UiField
TextBox projectUrl;

@UiField
CheckBox recursive;

@UiField
FlowPanel bottomPanel;

Expand Down Expand Up @@ -200,6 +203,11 @@ void onProjectUrlChanged(KeyUpEvent event) {
delegate.projectUrlChanged(projectUrl.getValue());
}

@UiHandler("recursive")
void recursiveHandler(ValueChangeEvent<Boolean> event) {
delegate.onRecursiveSelected(event.getValue());
}

@UiHandler("projectDescription")
void onProjectDescriptionChanged(KeyUpEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
debugId="file-importProject-projectUrl"/>
<g:Label ui:field="labelUrlError" width="100%" wordWrap="true" addStyleNames="{style.labelErrorPosition}"/>
</g:FlowPanel>
<g:FlowPanel height="20px" addStyleNames="{style.namePanel}">
<g:CheckBox ui:field="recursive" text="{locale.githubImporterPageRecursive}"
debugId="file-importProject-recursive" addStyleNames="{style.alignLeft}" />
</g:FlowPanel>
<g:FlowPanel height="0" addStyleNames="{style.horizontalLine}"/>
<g:FlowPanel height="35px" addStyleNames="{style.namePanel}">
<g:Label text="{locale.githubImporterPageProjectInfo}" addStyleNames="{style.label}"/>
Expand All @@ -47,7 +51,7 @@
debugId="file-importProject-projectDescription" title="{locale.githubImporterPageProjectDescriptionPrompt}"
tabIndex="5"/>
</g:FlowPanel>
<g:FlowPanel height="25px" addStyleNames="{style.namePanel}">
<g:FlowPanel height="20px" addStyleNames="{style.namePanel}">
<g:CheckBox ui:field="keepDirectory" text="{locale.githubImporterPageKeepDirectory}"
debugId="file-importProject-keepDirectory" addStyleNames="{style.alignLeft}" />
</g:FlowPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ importProject.message.protocolIncorrect = The transport protocol or url syntax i
importProject.message.startWithWhiteSpace = The url can not start with a whitespace.
#GithubImporterPage
view.import.githubImporterPage.projectUrl = URL:
view.import.githubImporterPage.recursive = Import recursively (for multi-module projects)
view.import.githubImporterPage.projectInfo = Project Information
view.import.githubImporterPage.projectName = Name:
view.import.githubImporterPageProjectNamePrompt = Define the name of your project...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,28 @@ public void keepDirectoryUnSelectedTest() {
verify(view).highlightDirectoryNameField(eq(false));
}

@Test
public void recursiveCloneSelectedTest() {
Map<String, String> parameters = new HashMap<>();
when(source.getParameters()).thenReturn(parameters);
when(view.getDirectoryName()).thenReturn("recursive");

presenter.onRecursiveSelected(true);

assertTrue(parameters.containsKey("recursive"));
}

@Test
public void recursiveCloneUnSelectedTest() {
Map<String, String> parameters = new HashMap<>();
parameters.put("recursive", null);
when(source.getParameters()).thenReturn(parameters);

presenter.onRecursiveSelected(false);

assertTrue(parameters.isEmpty());
}

@Test
public void keepDirectoryNameChangedAndKeepDirectorySelectedTest() {
Map<String, String> parameters = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ public interface CloneRequest extends GitRequest {

CloneRequest withRemoteName(String remoteName);

/** @return true if 'Recursive' parameter enabled */
boolean isRecursive();

void setRecursive(boolean recursive);

CloneRequest withRecursive(boolean recursive);

/**
* @return time (in seconds) to wait without data transfer occurring before aborting fetching data from remote repository. If 0 then
* default timeout may be used. This is implementation specific
Expand All @@ -58,4 +65,4 @@ public interface CloneRequest extends GitRequest {
void setTimeout(int timeout);

CloneRequest withTimeout(int timeout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.che.api.core.UnauthorizedException;
import org.eclipse.che.api.core.model.project.SourceStorage;
import org.eclipse.che.api.core.notification.EventService;
import org.eclipse.che.api.core.util.FileCleaner;
import org.eclipse.che.api.core.util.LineConsumerFactory;
import org.eclipse.che.api.git.shared.Branch;
import org.eclipse.che.api.git.shared.BranchListRequest;
Expand All @@ -36,12 +35,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -123,6 +119,7 @@ public void importSources(FolderEntry baseFolder,
// Delete vcs info if false.
String branchMerge = null;
boolean keepVcs = true;
boolean recursiveEnabled = false;

Map<String, String> parameters = storage.getParameters();
if (parameters != null) {
Expand All @@ -134,6 +131,9 @@ public void importSources(FolderEntry baseFolder,
if (parameters.containsKey("keepVcs")) {
keepVcs = Boolean.parseBoolean(parameters.get("keepVcs"));
}
if (parameters.containsKey("recursive")) {
recursiveEnabled = true;
}
branchMerge = parameters.get("branchMerge");
}
// Get path to local file. Git works with local filesystem only.
Expand All @@ -146,7 +146,7 @@ public void importSources(FolderEntry baseFolder,
git.cloneWithSparseCheckout(keepDir, location, branch == null ? "master" : branch);
} else {
if (baseFolder.getChildren().size() == 0) {
cloneRepository(git, "origin", location, dtoFactory);
cloneRepository(git, "origin", location, dtoFactory, recursiveEnabled);
if (commitId != null) {
checkoutCommit(git, commitId, dtoFactory);
} else if (fetch != null) {
Expand Down Expand Up @@ -198,9 +198,12 @@ public void importSources(FolderEntry baseFolder,
}
}

private void cloneRepository(GitConnection git, String remoteName, String url, DtoFactory dtoFactory)
private void cloneRepository(GitConnection git, String remoteName, String url, DtoFactory dtoFactory, boolean recursiveEnabled)
throws ServerException, UnauthorizedException, URISyntaxException {
final CloneRequest request = dtoFactory.createDto(CloneRequest.class).withRemoteName(remoteName).withRemoteUri(url);
final CloneRequest request = dtoFactory.createDto(CloneRequest.class)
.withRemoteName(remoteName)
.withRemoteUri(url)
.withRecursive(recursiveEnabled);
git.clone(request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ public void clone(CloneRequest request) throws GitException, UnauthorizedExcepti
CloneCommand cloneCommand = Git.cloneRepository()
.setDirectory(new File(request.getWorkingDir()))
.setRemote(request.getRemoteName())
.setCloneSubmodules(request.isRecursive())
.setURI(remoteUri);
if (request.getBranchesToFetch().isEmpty()) {
cloneCommand.setCloneAllBranches(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ public void clone(CloneRequest request) throws URISyntaxException, UnauthorizedE
CloneCommand clone = nativeGit.createCloneCommand();
clone.setRemoteUri(remoteUri);
clone.setRemoteName(request.getRemoteName());
clone.setRecursiveEnabled(request.isRecursive());
if (clone.getTimeout() > 0) {
clone.setTimeout(request.getTimeout());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public class CloneCommand extends RemoteOperationCommand<Void> {

private String remoteName;
private boolean recursiveEnabled;

public CloneCommand(File repository, SshScriptProvider sshScriptProvider, CredentialsLoader credentialsLoader, GitAskPassScript gitAskPassScript) {
super(repository, sshScriptProvider, credentialsLoader, gitAskPassScript);
Expand All @@ -38,6 +39,9 @@ public Void execute() throws GitException {
if (remoteName != null) {
commandLine.add("--origin", remoteName);
} //else default origin name
if (recursiveEnabled) {
commandLine.add("--recursive");
}
commandLine.add(getRemoteUri(), getRepository().getAbsolutePath());
// Progress not shown if not a terminal. Activating progress output. See git clone man page.
commandLine.add("--progress");
Expand All @@ -54,4 +58,14 @@ public CloneCommand setRemoteName(String remoteName) {
this.remoteName = remoteName;
return this;
}

/**
* @param recursiveEnabled
* returnes true if 'recursive' parameter enabled
* @return CloneCommand with established 'recursive' parameter
*/
public CloneCommand setRecursiveEnabled(boolean recursiveEnabled) {
this.recursiveEnabled = recursiveEnabled;
return this;
}
}

0 comments on commit 3d89ae7

Please sign in to comment.