|
|
@ -24,6 +24,8 @@ import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
import org.gradle.api.Project;
|
|
|
|
import org.gradle.api.Project;
|
|
|
|
import org.gradle.api.artifacts.Configuration;
|
|
|
|
import org.gradle.api.artifacts.Configuration;
|
|
|
|
|
|
|
|
import org.gradle.api.artifacts.Dependency;
|
|
|
|
|
|
|
|
import org.gradle.api.artifacts.FileCollectionDependency;
|
|
|
|
import org.gradle.api.artifacts.ModuleVersionIdentifier;
|
|
|
|
import org.gradle.api.artifacts.ModuleVersionIdentifier;
|
|
|
|
import org.gradle.api.artifacts.ResolvedArtifact;
|
|
|
|
import org.gradle.api.artifacts.ResolvedArtifact;
|
|
|
|
import org.springframework.boot.gradle.SpringBootPluginExtension;
|
|
|
|
import org.springframework.boot.gradle.SpringBootPluginExtension;
|
|
|
@ -72,70 +74,100 @@ class ProjectLibraries implements Libraries {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void doWithLibraries(LibraryCallback callback) throws IOException {
|
|
|
|
public void doWithLibraries(LibraryCallback callback) throws IOException {
|
|
|
|
Set<ResolvedArtifact> custom = getArtifacts(this.customConfigurationName);
|
|
|
|
Set<Library> custom = getLibraries(this.customConfigurationName,
|
|
|
|
|
|
|
|
LibraryScope.CUSTOM);
|
|
|
|
if (custom != null) {
|
|
|
|
if (custom != null) {
|
|
|
|
libraries(LibraryScope.CUSTOM, custom, callback);
|
|
|
|
libraries(custom, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
Set<ResolvedArtifact> compile = getArtifacts("compile");
|
|
|
|
Set<Library> compile = getLibraries("compile", LibraryScope.COMPILE);
|
|
|
|
|
|
|
|
|
|
|
|
Set<ResolvedArtifact> runtime = getArtifacts("runtime");
|
|
|
|
Set<Library> runtime = getLibraries("runtime", LibraryScope.RUNTIME);
|
|
|
|
runtime = minus(runtime, compile);
|
|
|
|
runtime = minus(runtime, compile);
|
|
|
|
|
|
|
|
|
|
|
|
Set<ResolvedArtifact> provided = getArtifacts(this.providedConfigurationName);
|
|
|
|
Set<Library> provided = getLibraries(this.providedConfigurationName,
|
|
|
|
|
|
|
|
LibraryScope.PROVIDED);
|
|
|
|
if (provided != null) {
|
|
|
|
if (provided != null) {
|
|
|
|
compile = minus(compile, provided);
|
|
|
|
compile = minus(compile, provided);
|
|
|
|
runtime = minus(runtime, provided);
|
|
|
|
runtime = minus(runtime, provided);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
libraries(LibraryScope.COMPILE, compile, callback);
|
|
|
|
libraries(compile, callback);
|
|
|
|
libraries(LibraryScope.RUNTIME, runtime, callback);
|
|
|
|
libraries(runtime, callback);
|
|
|
|
libraries(LibraryScope.PROVIDED, provided, callback);
|
|
|
|
libraries(provided, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Set<ResolvedArtifact> getArtifacts(String configurationName) {
|
|
|
|
private Set<Library> getLibraries(String configurationName, LibraryScope scope) {
|
|
|
|
Configuration configuration = (configurationName == null ? null : this.project
|
|
|
|
Configuration configuration = (configurationName == null ? null : this.project
|
|
|
|
.getConfigurations().findByName(configurationName));
|
|
|
|
.getConfigurations().findByName(configurationName));
|
|
|
|
return (configuration == null ? null : configuration.getResolvedConfiguration()
|
|
|
|
if (configuration == null) {
|
|
|
|
.getResolvedArtifacts());
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Set<Library> libraries = new LinkedHashSet<Library>();
|
|
|
|
|
|
|
|
for (ResolvedArtifact artifact : configuration.getResolvedConfiguration()
|
|
|
|
|
|
|
|
.getResolvedArtifacts()) {
|
|
|
|
|
|
|
|
libraries.add(new ResolvedArtifactLibrary(artifact, scope));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Dependency dependency : configuration.getIncoming().getDependencies()) {
|
|
|
|
|
|
|
|
if (dependency instanceof FileCollectionDependency) {
|
|
|
|
|
|
|
|
FileCollectionDependency fileDependency = (FileCollectionDependency) dependency;
|
|
|
|
|
|
|
|
for (File file : fileDependency.resolve()) {
|
|
|
|
|
|
|
|
libraries.add(new Library(file, scope));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return libraries;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Set<ResolvedArtifact> minus(Set<ResolvedArtifact> source,
|
|
|
|
private Set<Library> minus(Set<Library> source, Set<Library> toRemove) {
|
|
|
|
Set<ResolvedArtifact> toRemove) {
|
|
|
|
|
|
|
|
if (source == null || toRemove == null) {
|
|
|
|
if (source == null || toRemove == null) {
|
|
|
|
return source;
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Set<File> filesToRemove = new HashSet<File>();
|
|
|
|
Set<File> filesToRemove = new HashSet<File>();
|
|
|
|
for (ResolvedArtifact artifact : toRemove) {
|
|
|
|
for (Library library : toRemove) {
|
|
|
|
filesToRemove.add(artifact.getFile());
|
|
|
|
filesToRemove.add(library.getFile());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Set<ResolvedArtifact> result = new LinkedHashSet<ResolvedArtifact>();
|
|
|
|
Set<Library> result = new LinkedHashSet<Library>();
|
|
|
|
for (ResolvedArtifact artifact : source) {
|
|
|
|
for (Library library : source) {
|
|
|
|
if (!filesToRemove.contains(artifact.getFile())) {
|
|
|
|
if (!filesToRemove.contains(library.getFile())) {
|
|
|
|
result.add(artifact);
|
|
|
|
result.add(library);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void libraries(LibraryScope scope, Set<ResolvedArtifact> artifacts,
|
|
|
|
private void libraries(Set<Library> libraries, LibraryCallback callback)
|
|
|
|
LibraryCallback callback) throws IOException {
|
|
|
|
throws IOException {
|
|
|
|
if (artifacts != null) {
|
|
|
|
if (libraries != null) {
|
|
|
|
for (ResolvedArtifact artifact : artifacts) {
|
|
|
|
for (Library library : libraries) {
|
|
|
|
callback.library(new Library(artifact.getFile(), scope,
|
|
|
|
callback.library(library);
|
|
|
|
isUnpackRequired(artifact)));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isUnpackRequired(ResolvedArtifact artifact) {
|
|
|
|
/**
|
|
|
|
if (this.extension.getRequiresUnpack() != null) {
|
|
|
|
* Adapts a {@link ResolvedArtifact} to a {@link Library}.
|
|
|
|
ModuleVersionIdentifier id = artifact.getModuleVersion().getId();
|
|
|
|
*/
|
|
|
|
return this.extension.getRequiresUnpack().contains(
|
|
|
|
private class ResolvedArtifactLibrary extends Library {
|
|
|
|
id.getGroup() + ":" + id.getName());
|
|
|
|
|
|
|
|
|
|
|
|
private final ResolvedArtifact artifact;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ResolvedArtifactLibrary(ResolvedArtifact artifact, LibraryScope scope) {
|
|
|
|
|
|
|
|
super(artifact.getFile(), scope);
|
|
|
|
|
|
|
|
this.artifact = artifact;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean isUnpackRequired() {
|
|
|
|
|
|
|
|
if (ProjectLibraries.this.extension.getRequiresUnpack() != null) {
|
|
|
|
|
|
|
|
ModuleVersionIdentifier id = artifact.getModuleVersion().getId();
|
|
|
|
|
|
|
|
return ProjectLibraries.this.extension.getRequiresUnpack().contains(
|
|
|
|
|
|
|
|
id.getGroup() + ":" + id.getName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|