-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
119 additions
and
40 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
40 changes: 0 additions & 40 deletions
40
...main/groovy/pl/allegro/tech/build/axion/release/domain/SnapshotDependenciesChecker.groovy
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
src/main/java/pl/allegro/tech/build/axion/release/domain/SnapshotDependenciesChecker.java
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,61 @@ | ||
package pl.allegro.tech.build.axion.release.domain; | ||
|
||
import org.gradle.api.Project; | ||
import org.gradle.api.artifacts.Configuration; | ||
import org.gradle.api.artifacts.Dependency; | ||
import org.gradle.api.artifacts.DependencyConstraint; | ||
|
||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class SnapshotDependenciesChecker { | ||
|
||
public Collection<String> snapshotVersions(Project project) { | ||
Set<String> projectVersions = project.getRootProject().getAllprojects().stream() | ||
.map(this::toFullVersion) | ||
.collect(Collectors.toSet()); | ||
|
||
Set<Configuration> configurations = project.getRootProject().getAllprojects().stream() | ||
.flatMap(p -> p.getConfigurations().stream()) | ||
.collect(Collectors.toSet()); | ||
|
||
Set<String> allDependenciesVersions = new HashSet<>(); | ||
for (Configuration config : configurations) { | ||
Set<String> versions = config.getAllDependencies().stream() | ||
.filter(this::isSnapshot) | ||
.map(this::toFullVersion) | ||
.collect(Collectors.toSet()); | ||
|
||
Set<String> constraintVersions = config.getAllDependencyConstraints().stream() | ||
.filter(this::isSnapshot) | ||
.map(this::toFullVersion) | ||
.collect(Collectors.toSet()); | ||
|
||
allDependenciesVersions.addAll(versions); | ||
allDependenciesVersions.addAll(constraintVersions); | ||
} | ||
allDependenciesVersions.removeAll(projectVersions); | ||
return allDependenciesVersions; | ||
} | ||
|
||
private boolean isSnapshot(Dependency dependency) { | ||
return dependency.getVersion() != null && dependency.getVersion().endsWith("-SNAPSHOT"); | ||
} | ||
|
||
private boolean isSnapshot(DependencyConstraint dependency) { | ||
return dependency.getVersion() != null && dependency.getVersion().endsWith("-SNAPSHOT"); | ||
} | ||
|
||
private String toFullVersion(Object it) { | ||
if (it instanceof Dependency) { | ||
Dependency dependency = (Dependency) it; | ||
return String.format("%s:%s:%s", dependency.getGroup(), dependency.getName(), dependency.getVersion()); | ||
} else if (it instanceof DependencyConstraint) { | ||
DependencyConstraint constraint = (DependencyConstraint) it; | ||
return String.format("%s:%s:%s", constraint.getGroup(), constraint.getName(), constraint.getVersion()); | ||
} | ||
return ""; | ||
} | ||
} |