use of org.gradle.api.artifacts.ResolvableDependencies in project spring-boot by spring-projects.
the class AbstractBootArchiveTests method addContent.
@SuppressWarnings("unchecked")
void addContent() throws IOException {
this.task.getMainClass().set("com.example.Main");
File classesJavaMain = new File(this.temp, "classes/java/main");
File applicationClass = new File(classesJavaMain, "com/example/Application.class");
applicationClass.getParentFile().mkdirs();
applicationClass.createNewFile();
File resourcesMain = new File(this.temp, "resources/main");
File applicationProperties = new File(resourcesMain, "application.properties");
applicationProperties.getParentFile().mkdirs();
applicationProperties.createNewFile();
File staticResources = new File(resourcesMain, "static");
staticResources.mkdir();
File css = new File(staticResources, "test.css");
css.createNewFile();
this.task.classpath(classesJavaMain, resourcesMain, jarFile("first-library.jar"), jarFile("second-library.jar"), jarFile("third-library-SNAPSHOT.jar"), jarFile("first-project-library.jar"), jarFile("second-project-library-SNAPSHOT.jar"));
Set<ResolvedArtifact> artifacts = new LinkedHashSet<>();
artifacts.add(mockLibraryArtifact("first-library.jar", "com.example", "first-library", "1.0.0"));
artifacts.add(mockLibraryArtifact("second-library.jar", "com.example", "second-library", "1.0.0"));
artifacts.add(mockLibraryArtifact("third-library-SNAPSHOT.jar", "com.example", "third-library", "1.0.0.SNAPSHOT"));
artifacts.add(mockProjectArtifact("first-project-library.jar", "com.example", "first-project-library", "1.0.0"));
artifacts.add(mockProjectArtifact("second-project-library-SNAPSHOT.jar", "com.example", "second-project-library", "1.0.0.SNAPSHOT"));
ResolvedConfiguration resolvedConfiguration = mock(ResolvedConfiguration.class);
given(resolvedConfiguration.getResolvedArtifacts()).willReturn(artifacts);
Configuration configuration = mock(Configuration.class);
given(configuration.getResolvedConfiguration()).willReturn(resolvedConfiguration);
ResolvableDependencies resolvableDependencies = mock(ResolvableDependencies.class);
given(configuration.getIncoming()).willReturn(resolvableDependencies);
DependencySet dependencies = mock(DependencySet.class);
DomainObjectSet<ProjectDependency> projectDependencies = mock(DomainObjectSet.class);
given(dependencies.withType(ProjectDependency.class)).willReturn(projectDependencies);
given(configuration.getAllDependencies()).willReturn(dependencies);
willAnswer((invocation) -> {
invocation.getArgument(0, Action.class).execute(resolvableDependencies);
return null;
}).given(resolvableDependencies).afterResolve(any(Action.class));
given(configuration.getIncoming()).willReturn(resolvableDependencies);
populateResolvedDependencies(configuration);
}
use of org.gradle.api.artifacts.ResolvableDependencies in project tomee by apache.
the class TomEEEmbeddedPlugin method apply.
@Override
public void apply(final Project project) {
final List<String> extensions = asList(TomEEEmbeddedExtension.NAME, TomEEEmbeddedExtension.ALIAS);
for (final String name : extensions) {
project.getExtensions().create(name, TomEEEmbeddedExtension.class);
}
project.afterEvaluate(new Action<Project>() {
@Override
public void execute(final Project actionProject) {
for (final String name : extensions) {
final TomEEEmbeddedExtension extension = TomEEEmbeddedExtension.class.cast(actionProject.getExtensions().findByName(name));
if (extension == null) {
return;
}
if (extension.isSkipDefaultRepository() != null && !extension.isSkipDefaultRepository()) {
actionProject.getRepositories().mavenCentral();
return;
}
}
actionProject.getRepositories().mavenCentral();
}
});
String configName = TomEEEmbeddedExtension.ALIAS;
try {
project.getConfigurations().getByName(configName);
} catch (final UnknownConfigurationException uce) {
configName = TomEEEmbeddedExtension.NAME;
}
final Configuration configuration = project.getConfigurations().maybeCreate(configName);
configuration.getIncoming().beforeResolve(new Action<ResolvableDependencies>() {
@Override
public void execute(final ResolvableDependencies resolvableDependencies) {
String tomeeVersion = null;
for (final String name : extensions) {
final TomEEEmbeddedExtension extension = TomEEEmbeddedExtension.class.cast(project.getExtensions().findByName(name));
if (extension == null) {
return;
}
tomeeVersion = extension.getTomeeVersion();
if (tomeeVersion != null) {
break;
}
}
if (tomeeVersion == null) {
try {
try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/maven/org.apache.tomee.gradle/tomee-embedded/pom.properties")) {
final Properties p = new Properties();
p.load(is);
tomeeVersion = p.getProperty("version");
}
} catch (final IOException e) {
// we should never be there
tomeeVersion = "7.0.2";
}
}
final DependencyHandler dependencyHandler = project.getDependencies();
final DependencySet dependencies = configuration.getDependencies();
dependencies.add(dependencyHandler.create("org.apache.tomee:tomee-embedded:" + tomeeVersion));
}
});
project.task(new HashMap<String, Object>() {
{
put("type", TomEEEmbeddedTask.class);
put("group", "Embedded Application Server");
put("description", "Start an embedded Apache TomEE server deploying application classpath");
}
}, TomEEEmbeddedExtension.NAME);
}
Aggregations