@ -16,12 +16,15 @@
package org.springframework.boot.gradle.task ;
import java.io.File ;
import java.io.IOException ;
import java.util.Arrays ;
import java.util.Collections ;
import java.util.HashSet ;
import java.util.Set ;
import org.gradle.api.Project ;
import org.gradle.api.artifacts.Configuration ;
import org.gradle.api.file.FileCollection ;
import org.gradle.api. artifacts.ResolvedArtifact ;
import org.springframework.boot.loader.tools.Libraries ;
import org.springframework.boot.loader.tools.LibraryCallback ;
import org.springframework.boot.loader.tools.LibraryScope ;
@ -30,9 +33,14 @@ import org.springframework.boot.loader.tools.LibraryScope;
* Expose Gradle { @link Configuration } s as { @link Libraries } .
*
* @author Phillip Webb
* @author Andy Wilkinson
* /
class ProjectLibraries implements Libraries {
private static final Set < String > SUPPORTED_TYPES = Collections
. unmodifiableSet ( new HashSet < String > ( Arrays . asList ( "jar" , "ejb" ,
"ejb-client" , "test-jar" , "bundle" ) ) ) ;
private final Project project ;
private String providedConfigurationName = "providedRuntime" ;
@ -64,41 +72,48 @@ class ProjectLibraries implements Libraries {
@Override
public void doWithLibraries ( LibraryCallback callback ) throws IOException {
FileCollec tion custom = this . customConfigurationName ! = null ? this . project
Configura tion custom = this . customConfigurationName ! = null ? this . project
. getConfigurations ( ) . findByName ( this . customConfigurationName ) : null ;
if ( custom ! = null ) {
libraries ( LibraryScope . CUSTOM , custom, callback ) ;
libraries ( LibraryScope . CUSTOM , getResolvedArtifacts( custom) , callback ) ;
}
else {
FileCollection compile = this . project . getConfigurations ( )
. getByName ( "compil e") ;
FileCollection runtime = this . project . getConfigurations ( )
. getByName ( "runtime" ) ;
runtime = runtime . minus ( compile ) ;
FileCollection provided = this . project . getConfigurations ( ) . findByName (
this . providedConfigurationName ) ;
if ( provided ! = null ) {
compile = compile . minus ( provided ) ;
runtime = runtime . minus ( provided ) ;
}
Set< ResolvedArtifact > compileArtifacts = getResolvedArtifacts ( "compile" ) ;
Set < ResolvedArtifact > runtimeArtifacts = getResolvedArtifacts ( "runtim e") ;
runtimeArtifacts . removeAll ( compileArtifacts ) ;
Set < ResolvedArtifact > providedArtifacts = getResolvedArtifacts ( this . providedConfigurationName ) ;
compileArtifacts. removeAll ( providedArtifacts ) ;
runtimeArtifacts . removeAll ( providedArtifacts ) ;
libraries ( LibraryScope . COMPILE , compileArtifacts , callback ) ;
libraries ( LibraryScope . RUNTIME , runtimeArtifacts , callback ) ;
libraries ( LibraryScope . PROVIDED , providedArtifacts , callback ) ;
}
}
libraries ( LibraryScope . COMPILE , compile , callback ) ;
libraries ( LibraryScope . RUNTIME , runtime , callback ) ;
libraries ( LibraryScope . PROVIDED , provided , callback ) ;
private Set < ResolvedArtifact > getResolvedArtifacts ( Configuration configuration ) {
if ( configuration ! = null ) {
return configuration . getResolvedConfiguration ( ) . getResolvedArtifacts ( ) ;
}
else {
return Collections . emptySet ( ) ;
}
}
private Set < ResolvedArtifact > getResolvedArtifacts ( String configurationName ) {
Configuration configuration = this . project . getConfigurations ( ) . findByName (
configurationName ) ;
return getResolvedArtifacts ( configuration ) ;
}
private void libraries ( LibraryScope scope , FileCollection files ,
private void libraries ( LibraryScope scope , Set< ResolvedArtifact > artifact s,
LibraryCallback callback ) throws IOException {
if ( files ! = null ) {
for ( File file : files ) {
callback . library ( file, scope ) ;
for ( ResolvedArtifact artifact : artifacts ) {
if ( SUPPORTED_TYPES . contains ( artifact . getType ( ) ) ) {
callback . library ( arti fact. getF ile( ) , scope ) ;
}
}
}
}