-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: get closer to supporting isolated projects.
Don't mutate another project's dependencies.
- Loading branch information
1 parent
ef5cc23
commit a4630ea
Showing
9 changed files
with
212 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/functionalTest/groovy/com/autonomousapps/jvm/NoAutoApplySpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.autonomousapps.jvm | ||
|
||
import com.autonomousapps.jvm.projects.NoAutoApplyProject | ||
|
||
import static com.autonomousapps.utils.Runner.build | ||
import static com.google.common.truth.Truth.assertThat | ||
|
||
/** Here we test what happens when some modules don't have DAGP applied. */ | ||
final class NoAutoApplySpec extends AbstractJvmSpec { | ||
|
||
def "can do complete analysis with autoapply=false (#gradleVersion)"() { | ||
given: | ||
def project = new NoAutoApplyProject() | ||
gradleProject = project.gradleProject | ||
|
||
when: | ||
build(gradleVersion, gradleProject.rootDir, 'buildHealth') | ||
|
||
then: | ||
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth()) | ||
|
||
where: | ||
gradleVersion << gradleVersions() | ||
} | ||
|
||
def "can do targeted analysis with autoapply=false (#gradleVersion)"() { | ||
given: | ||
def project = new NoAutoApplyProject(':proj1') | ||
gradleProject = project.gradleProject | ||
|
||
when: | ||
def result = build(gradleVersion, gradleProject.rootDir, 'buildHealth') | ||
|
||
then: | ||
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth()) | ||
|
||
and: 'No tasks from :proj1 were requested' | ||
def proj1Tasks = result.tasks.findAll { it.path.startsWith(':proj1') } | ||
assertThat(proj1Tasks).isEmpty() | ||
|
||
where: | ||
gradleVersion << gradleVersions() | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/functionalTest/groovy/com/autonomousapps/jvm/projects/NoAutoApplyProject.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.autonomousapps.jvm.projects | ||
|
||
import com.autonomousapps.AbstractProject | ||
import com.autonomousapps.kit.GradleProject | ||
import com.autonomousapps.kit.Source | ||
import com.autonomousapps.kit.SourceType | ||
import com.autonomousapps.kit.gradle.Plugin | ||
import com.autonomousapps.model.ProjectAdvice | ||
|
||
import static com.autonomousapps.AdviceHelper.actualProjectAdvice | ||
import static com.autonomousapps.AdviceHelper.emptyProjectAdviceFor | ||
import static com.autonomousapps.utils.Strings.ensurePrefix | ||
|
||
final class NoAutoApplyProject extends AbstractProject { | ||
|
||
private final Set<String> noApplies | ||
final GradleProject gradleProject | ||
|
||
/** | ||
* @param noApplies the set of projects (by path) that should not have DAGP applied. | ||
*/ | ||
NoAutoApplyProject(String... noApplies = []) { | ||
this.noApplies = noApplies.collect { ensurePrefix(it) } as Set<String> | ||
gradleProject = build() | ||
} | ||
|
||
private GradleProject build() { | ||
return newGradleProjectBuilder() | ||
.withSubproject('proj1') { s -> | ||
s.sources = proj1Sources | ||
s.withBuildScript { bs -> | ||
bs.plugins = plugins('proj1') | ||
} | ||
} | ||
.withSubproject('proj2') { s -> | ||
s.sources = proj2Sources | ||
s.withBuildScript { bs -> | ||
bs.plugins = plugins('proj2') | ||
} | ||
} | ||
.withSubproject('proj3') { s -> | ||
s.sources = proj3Sources | ||
s.withBuildScript { bs -> | ||
bs.plugins = plugins('proj3') | ||
} | ||
} | ||
.write() | ||
} | ||
|
||
private List<Plugin> plugins(String projectPath) { | ||
if (noApplies.contains(ensurePrefix(projectPath))) { | ||
return kotlinOnly | ||
} else { | ||
return kotlin | ||
} | ||
} | ||
|
||
def proj1Sources = [ | ||
new Source( | ||
SourceType.KOTLIN, "One", "com/example/one", | ||
"""\ | ||
package com.example.one | ||
class One""".stripIndent() | ||
) | ||
] | ||
|
||
def proj2Sources = [ | ||
new Source( | ||
SourceType.KOTLIN, "Two", "com/example/two", | ||
"""\ | ||
package com.example.two | ||
class Two""".stripIndent() | ||
) | ||
] | ||
|
||
def proj3Sources = [ | ||
new Source( | ||
SourceType.KOTLIN, "Three", "com/example/three", | ||
"""\ | ||
package com.example.three | ||
class Three""".stripIndent() | ||
) | ||
] | ||
|
||
Set<ProjectAdvice> actualBuildHealth() { | ||
return actualProjectAdvice(gradleProject) | ||
} | ||
|
||
Set<ProjectAdvice> expectedBuildHealth() { | ||
return [':proj1', ':proj2', ':proj3'] | ||
.findAll { !noApplies.contains(it) } | ||
.collect { emptyProjectAdviceFor(it) } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/functionalTest/groovy/com/autonomousapps/utils/Strings.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.autonomousapps.utils | ||
|
||
final class Strings { | ||
|
||
private Strings() { | ||
} | ||
|
||
static String ensurePrefix(String string, String prefix = ':') { | ||
if (string.startsWith(prefix)) { | ||
return string | ||
} else { | ||
return prefix + string | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters