Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sparseCheckoutDir parameter into devfile spec #14823

Merged
merged 3 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public interface SourceStorage {
*/
String START_POINT_PARAMETER_NAME = "startPoint";

/**
* The key with this name in the parameters designates the directory that should be used for
* sparse checkout, i.e. the only directory of repository which should be created by git.
*/
String SPARSE_CHECKOUT_DIR_PARAMETER_NAME = "sparseCheckoutDir";

String getType();

String getLocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ public interface Source {
* 'startPoint' and provided for convenience.
*/
String getCommitId();

/**
* The directory which is kept by sparse checkout. If this parameter is not null then the only
* given directory will be present after clone.
*/
String getSparseCheckoutDir();
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public SourceStorageDto buildWorkspaceConfigSource(GithubUrl githubUrl) {
* @return newly created source DTO object
*/
public SourceDto buildDevfileSource(GithubUrl githubUrl) {
// T_O_D_O add keepDir support when Devfile will support it
mmorhun marked this conversation as resolved.
Show resolved Hide resolved
return newDto(SourceDto.class)
.withLocation(githubUrl.repositoryLocation())
.withType("github")
.withBranch(githubUrl.getBranch());
.withBranch(githubUrl.getBranch())
.withSparseCheckoutDir(githubUrl.getSubfolder());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,11 @@ public interface SourceDto extends Source {
void setCommitId(String commitId);

SourceDto withCommitId(String commitId);

@Override
String getSparseCheckoutDir();

void setSparseCheckoutDir(String sparseCheckoutDir);

SourceDto withSparseCheckoutDir(String sparseCheckoutDir);
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ private static ProjectDto asDto(Project project) {
.withBranch(source.getBranch())
.withStartPoint(source.getStartPoint())
.withTag(source.getTag())
.withCommitId(source.getCommitId()));
.withCommitId(source.getCommitId())
.withSparseCheckoutDir(source.getSparseCheckoutDir()));
}

private static ComponentDto asDto(Component component) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static java.lang.String.format;
import static org.eclipse.che.api.core.model.workspace.config.SourceStorage.BRANCH_PARAMETER_NAME;
import static org.eclipse.che.api.core.model.workspace.config.SourceStorage.COMMIT_ID_PARAMETER_NAME;
import static org.eclipse.che.api.core.model.workspace.config.SourceStorage.SPARSE_CHECKOUT_DIR_PARAMETER_NAME;
import static org.eclipse.che.api.core.model.workspace.config.SourceStorage.START_POINT_PARAMETER_NAME;
import static org.eclipse.che.api.core.model.workspace.config.SourceStorage.TAG_PARAMETER_NAME;

Expand Down Expand Up @@ -46,6 +47,8 @@ public ProjectImpl toDevfileProject(ProjectConfigImpl projectConfig) {
String startPoint = projectConfig.getSource().getParameters().get(START_POINT_PARAMETER_NAME);
String tag = projectConfig.getSource().getParameters().get(TAG_PARAMETER_NAME);
String commitId = projectConfig.getSource().getParameters().get(COMMIT_ID_PARAMETER_NAME);
String sparseCheckoutDir =
projectConfig.getSource().getParameters().get(SPARSE_CHECKOUT_DIR_PARAMETER_NAME);

SourceImpl source =
new SourceImpl(
Expand All @@ -54,7 +57,8 @@ public ProjectImpl toDevfileProject(ProjectConfigImpl projectConfig) {
branch,
startPoint,
tag,
commitId);
commitId,
sparseCheckoutDir);

String path = projectConfig.getPath();
while (path != null && path.startsWith("/")) {
Expand Down Expand Up @@ -186,5 +190,9 @@ private void updateSourceStorage(Source devfileSource, SourceStorageImpl sourceS
} else if (commitId != null) {
sourceStorage.getParameters().put(COMMIT_ID_PARAMETER_NAME, commitId);
}

if (devfileSource.getSparseCheckoutDir() != null) {
sourceStorage.getParameters().put("keepDir", devfileSource.getSparseCheckoutDir());
mmorhun marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,26 @@ public class SourceImpl implements Source {
@Column(name = "commit_id")
private String commitId;

@Column(name = "sparse_checkout_dir")
private String sparseCheckoutDir;

public SourceImpl() {}

public SourceImpl(
String type, String location, String branch, String startPoint, String tag, String commitId) {
String type,
String location,
String branch,
String startPoint,
String tag,
String commitId,
String sparseCheckoutDir) {
this.type = type;
this.location = location;
this.branch = branch;
this.startPoint = startPoint;
this.tag = tag;
this.commitId = commitId;
this.sparseCheckoutDir = sparseCheckoutDir;
}

public SourceImpl(Source source) {
Expand All @@ -57,7 +67,8 @@ public SourceImpl(Source source) {
source.getBranch(),
source.getStartPoint(),
source.getTag(),
source.getCommitId());
source.getCommitId(),
source.getSparseCheckoutDir());
}

@Override
Expand Down Expand Up @@ -114,6 +125,15 @@ public void setCommitId(String commitId) {
this.commitId = commitId;
}

@Override
public String getSparseCheckoutDir() {
return sparseCheckoutDir;
}

public void setSparseCheckoutDir(String sparseCheckoutDir) {
this.sparseCheckoutDir = sparseCheckoutDir;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -128,12 +148,13 @@ public boolean equals(Object o) {
&& Objects.equals(branch, source.branch)
&& Objects.equals(startPoint, source.startPoint)
&& Objects.equals(tag, source.tag)
&& Objects.equals(commitId, source.commitId);
&& Objects.equals(commitId, source.commitId)
&& Objects.equals(sparseCheckoutDir, source.sparseCheckoutDir);
}

@Override
public int hashCode() {
return Objects.hash(type, location, branch, startPoint, tag, commitId);
return Objects.hash(type, location, branch, startPoint, tag, commitId, sparseCheckoutDir);
}

@Override
Expand All @@ -157,6 +178,9 @@ public String toString() {
+ ", commitId='"
+ commitId
+ '\''
+ ", sparseCheckoutDir='"
+ sparseCheckoutDir
+ '\''
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@
"examples": [
"349d3ad"
]
},
"sparseCheckoutDir": {
"type": "string",
"description": "Part of project to populate in the working directory.",
"examples": [
"/core/",
"core/",
"core",
"/wsmaster/che-core-api-workspace/",
"/d*"
]
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import static org.eclipse.che.api.core.model.workspace.config.SourceStorage.BRANCH_PARAMETER_NAME;
import static org.eclipse.che.api.core.model.workspace.config.SourceStorage.COMMIT_ID_PARAMETER_NAME;
import static org.eclipse.che.api.core.model.workspace.config.SourceStorage.SPARSE_CHECKOUT_DIR_PARAMETER_NAME;
import static org.eclipse.che.api.core.model.workspace.config.SourceStorage.START_POINT_PARAMETER_NAME;
import static org.eclipse.che.api.core.model.workspace.config.SourceStorage.TAG_PARAMETER_NAME;
import static org.testng.Assert.assertEquals;
Expand Down Expand Up @@ -46,7 +47,7 @@ public void testConvertingDevfileProjectToProjectConfig() throws Exception {
new ProjectImpl(
"myProject",
new SourceImpl(
"git", "https://github.com/eclipse/che.git", "master", "3434d", null, null),
"git", "https://github.com/eclipse/che.git", "master", "3434d", null, null, "core"),
null);

ProjectConfigImpl workspaceProject = projectConverter.toWorkspaceProject(devfileProject);
Expand All @@ -58,6 +59,7 @@ public void testConvertingDevfileProjectToProjectConfig() throws Exception {
assertEquals(source.getLocation(), "https://github.com/eclipse/che.git");
assertEquals(source.getParameters().get(BRANCH_PARAMETER_NAME), "master");
assertEquals(source.getParameters().get(START_POINT_PARAMETER_NAME), "3434d");
assertEquals(source.getParameters().get("keepDir"), "core");
}

@Test
Expand Down Expand Up @@ -88,7 +90,8 @@ public void testClonePathSetWhenConvertingDevfileToProjectConfig() throws Except
ProjectImpl devfileProject =
new ProjectImpl(
"myProject",
new SourceImpl("git", "https://github.com/eclipse/che.git", "master", null, null, null),
new SourceImpl(
"git", "https://github.com/eclipse/che.git", "master", null, null, null, null),
"down/the/rabbit/hole/myProject");

ProjectConfigImpl workspaceProject = projectConverter.toWorkspaceProject(devfileProject);
Expand All @@ -105,7 +108,8 @@ public void testClonePathCannotEscapeProjectsRoot() throws Exception {
ProjectImpl devfileProject =
new ProjectImpl(
"myProject",
new SourceImpl("git", "https://github.com/eclipse/che.git", "master", null, null, null),
new SourceImpl(
"git", "https://github.com/eclipse/che.git", "master", null, null, null, null),
"cant/hack/../../../usr/bin");

projectConverter.toWorkspaceProject(devfileProject);
Expand All @@ -116,7 +120,8 @@ public void testClonePathCannotBeAbsolute() throws Exception {
ProjectImpl devfileProject =
new ProjectImpl(
"myProject",
new SourceImpl("git", "https://github.com/eclipse/che.git", "master", null, null, null),
new SourceImpl(
"git", "https://github.com/eclipse/che.git", "master", null, null, null, null),
"/usr/bin");

projectConverter.toWorkspaceProject(devfileProject);
Expand All @@ -127,7 +132,8 @@ public void testUpDirOkInClonePathAsLongAsItDoesntEscapeProjectsRoot() throws Ex
ProjectImpl devfileProject =
new ProjectImpl(
"myProject",
new SourceImpl("git", "https://github.com/eclipse/che.git", "master", null, null, null),
new SourceImpl(
"git", "https://github.com/eclipse/che.git", "master", null, null, null, null),
"cant/hack/../../usr/bin");

ProjectConfigImpl workspaceProject = projectConverter.toWorkspaceProject(devfileProject);
Expand All @@ -140,7 +146,8 @@ public void testCloningIntoProjectsRootFails() throws Exception {
ProjectImpl devfileProject =
new ProjectImpl(
"myProject",
new SourceImpl("git", "https://github.com/eclipse/che.git", "master", null, null, null),
new SourceImpl(
"git", "https://github.com/eclipse/che.git", "master", null, null, null, null),
"not/../in/root/../..");

projectConverter.toWorkspaceProject(devfileProject);
Expand All @@ -163,7 +170,7 @@ public void testOnlyOneOfStartPointAttributesAllowed(
new ProjectImpl(
"myProject",
new SourceImpl(
"git", "https://github.com/eclipse/che.git", null, startPoint, tag, commitId),
"git", "https://github.com/eclipse/che.git", null, startPoint, tag, commitId, null),
null);

projectConverter.toWorkspaceProject(devfileProject);
Expand All @@ -184,7 +191,8 @@ public void testUndefinedCloneParametersNotTransferredToWorkspaceConfig() throws
ProjectImpl devfileProject =
new ProjectImpl(
"myProject",
new SourceImpl("git", "https://github.com/eclipse/che.git", null, null, null, null),
new SourceImpl(
"git", "https://github.com/eclipse/che.git", null, null, null, null, null),
null);

ProjectConfigImpl wsProject = projectConverter.toWorkspaceProject(devfileProject);
Expand All @@ -194,5 +202,6 @@ public void testUndefinedCloneParametersNotTransferredToWorkspaceConfig() throws
assertFalse(wsSource.getParameters().containsKey(START_POINT_PARAMETER_NAME));
assertFalse(wsSource.getParameters().containsKey(TAG_PARAMETER_NAME));
assertFalse(wsSource.getParameters().containsKey(COMMIT_ID_PARAMETER_NAME));
assertFalse(wsSource.getParameters().containsKey(SPARSE_CHECKOUT_DIR_PARAMETER_NAME));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public Object[][] validDevfiles() {
{"editor_plugin_component/devfile_editor_plugins_components_with_memory_limit.yaml"},
{"editor_plugin_component/devfile_plugin_component_with_reference.yaml"},
{"devfile/devfile_just_generatename.yaml"},
{"devfile/devfile_name_and_generatename.yaml"}
{"devfile/devfile_name_and_generatename.yaml"},
{"devfile/devfile_with_sparse_checkout_dir.yaml"}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,14 @@ public void shouldUpdateWorkspaceWithDevfile() throws Exception {
workspace.getDevfile().getProjects().remove(1);

final SourceImpl source3 =
new SourceImpl("type3", "http://location", "branch3", "point3", "tag3", "commit3");
new SourceImpl(
"type3",
"http://location",
"branch3",
"point3",
"tag3",
"commit3",
"sparseCheckoutDir3");
ProjectImpl newProject = new ProjectImpl("project3", source3, "path3");
workspace.getDevfile().getProjects().add(newProject);

Expand All @@ -544,9 +551,10 @@ public void shouldUpdateWorkspaceWithDevfile() throws Exception {
projectCfg.getSource().setLocation("new-location");
projectCfg.getSource().setType("new-type");
projectCfg.getSource().setBranch("new-branch");
projectCfg.getSource().setCommitId(("new-commit"));
projectCfg.getSource().setTag(("new-tag"));
projectCfg.getSource().setStartPoint(("new-point"));
projectCfg.getSource().setCommitId("new-commit");
projectCfg.getSource().setTag("new-tag");
projectCfg.getSource().setStartPoint("new-point");
projectCfg.getSource().setSparseCheckoutDir("new-sparse-checkout-dir");

// Remove an existing command
workspace.getDevfile().getCommands().remove(1);
Expand Down Expand Up @@ -854,11 +862,25 @@ public static WorkspaceImpl createWorkspaceFromDevfile(
private static DevfileImpl createDevfile(String name) {

SourceImpl source1 =
new SourceImpl("type1", "http://location", "branch1", "point1", "tag1", "commit1");
new SourceImpl(
"type1",
"http://location",
"branch1",
"point1",
"tag1",
"commit1",
"sparseCheckoutDir1");
ProjectImpl project1 = new ProjectImpl("project1", source1, "path1");

SourceImpl source2 =
new SourceImpl("type2", "http://location", "branch2", "point2", "tag2", "commit2");
new SourceImpl(
"type2",
"http://location",
"branch2",
"point2",
"tag2",
"commit2",
"sparseCheckoutDir2");
ProjectImpl project2 = new ProjectImpl("project2", source2, "path2");

ActionImpl action1 =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Copyright (c) 2012-2018 Red Hat, Inc.
mmorhun marked this conversation as resolved.
Show resolved Hide resolved
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#

---
apiVersion: 1.0.0
metadata:
name: spring-integration-samples
generateName: spring-integration-samples-
projects:
- name: spring-integration-samples
source:
type: git
location: 'https://github.com/spring-projects/spring-integration-samples.git'
branch: master
sparseCheckoutDir: basic/http/
Loading