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

fix - Use project dir instead of project path #171

Merged
merged 1 commit into from
Jul 11, 2024
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 @@ -10,7 +10,7 @@
* In Java this is a project:sourceset dependency on a project:sourceset.
*/
public interface BuildTargetDependency extends Serializable {
public String getProjectPath();
public String getProjectDir();

public String getSourceSetName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,39 @@
public class DefaultBuildTargetDependency implements BuildTargetDependency {
private static final long serialVersionUID = 1L;

private String projectPath;
private String projectDir;

private String sourceSetName;

public DefaultBuildTargetDependency(String projectPath, String sourceSetName) {
this.projectPath = projectPath;
public DefaultBuildTargetDependency(String projectDir, String sourceSetName) {
this.projectDir = projectDir;
this.sourceSetName = sourceSetName;
}

public DefaultBuildTargetDependency(GradleSourceSet sourceSet) {
this(sourceSet.getProjectPath(), sourceSet.getSourceSetName());
this(sourceSet.getProjectDir().getAbsolutePath(), sourceSet.getSourceSetName());
}


/**
* Copy constructor.
*
* @param buildTargetDependency the other instance to copy from.
*/
public DefaultBuildTargetDependency(BuildTargetDependency buildTargetDependency) {
this.projectPath = buildTargetDependency.getProjectPath();
this.projectDir = buildTargetDependency.getProjectDir();
this.sourceSetName = buildTargetDependency.getSourceSetName();
}

public String getProjectPath() {
return projectPath;
@Override
public String getProjectDir() {
return projectDir;
}

public void setProjectPath(String projectPath) {
this.projectPath = projectPath;
public void setProjectDir(String projectDir) {
this.projectDir = projectDir;
}

@Override
public String getSourceSetName() {
return sourceSetName;
}
Expand All @@ -56,7 +57,7 @@ public void setSourceSetName(String sourceSetName) {

@Override
public int hashCode() {
return Objects.hash(projectPath, sourceSetName);
return Objects.hash(projectDir, sourceSetName);
}

@Override
Expand All @@ -71,7 +72,7 @@ public boolean equals(Object obj) {
return false;
}
DefaultBuildTargetDependency other = (DefaultBuildTargetDependency) obj;
return Objects.equals(projectPath, other.projectPath)
return Objects.equals(projectDir, other.projectDir)
&& Objects.equals(sourceSetName, other.sourceSetName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Object buildAll(String modelName, Project rootProject) {
gradleSourceSet.setCleanTaskName(cleanTaskName);
Set<String> taskNames = new HashSet<>();
gradleSourceSet.setTaskNames(taskNames);
String projectName = stripPathPrefix(gradleSourceSet.getProjectPath());
String projectName = stripPathPrefix(projectPath);
if (projectName == null || projectName.length() == 0) {
projectName = gradleSourceSet.getProjectName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public List<BuildTargetIdentifier> store(GradleSourceSets gradleSourceSets) {
changedTargets.add(btId);
}
newCache.put(btId, buildTarget);
// Store the relationship between the project path and the build target id.
// Store the relationship between the project dir and the build target id.
// 'test' and other source sets are ignored.
if ("main".equals(sourceSet.getSourceSetName())) {
projectPathToBuildTargetId.put(sourceSet.getProjectPath(), btId);
projectPathToBuildTargetId.put(sourceSet.getProjectDir().getAbsolutePath(), btId);
}
}
updateBuildTargetDependencies(newCache.values(), projectPathToBuildTargetId);
Expand Down Expand Up @@ -181,7 +181,7 @@ private void updateBuildTargetDependencies(
if (buildTargetDependencies != null) {
List<BuildTargetIdentifier> btDependencies = buildTargetDependencies.stream()
.map(btDependency -> {
String path = btDependency.getProjectPath();
String path = btDependency.getProjectDir();
return projectPathToBuildTargetId.get(path);
})
.filter(Objects::nonNull)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ void testCompositeBuild2() {
private void assertHasBuildTargetDependency(GradleSourceSet sourceSet,
GradleSourceSet dependency) {
boolean exists = sourceSet.getBuildTargetDependencies().stream()
.anyMatch(dep -> dep.getProjectPath().equals(dependency.getProjectPath())
.anyMatch(dep -> dep.getProjectDir().equals(dependency.getProjectDir().getAbsolutePath())
&& dep.getSourceSetName().equals(dependency.getSourceSetName()));
assertTrue(exists, () -> {
String availableDependencies = sourceSet.getBuildTargetDependencies().stream()
.map(ss -> ss.getProjectPath() + ' ' + ss.getSourceSetName())
.map(ss -> ss.getProjectDir() + ' ' + ss.getSourceSetName())
.collect(Collectors.joining(", "));
return "Dependency not found " + dependency.getProjectPath() + ' '
+ dependency.getSourceSetName() + ". Available: " + availableDependencies;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void testBuildTargetDependency() {


BuildTargetDependency buildTargetDependency = mock(BuildTargetDependency.class);
when(buildTargetDependency.getProjectPath()).thenReturn(":foo");
when(buildTargetDependency.getProjectDir()).thenReturn(new File("foo").getAbsolutePath());
Set<BuildTargetDependency> dependencies = new HashSet<>();
dependencies.add(buildTargetDependency);
GradleSourceSet gradleSourceSetBar = getMockedTestGradleSourceSet();
Expand Down
Loading