Search in sources :

Example 1 with ResolvableDependencies

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) ZipCopyAction(org.gradle.api.internal.file.archive.ZipCopyAction) Action(org.gradle.api.Action) Configuration(org.gradle.api.artifacts.Configuration) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) DependencySet(org.gradle.api.artifacts.DependencySet) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) JarFile(java.util.jar.JarFile) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) ResolvableDependencies(org.gradle.api.artifacts.ResolvableDependencies)

Example 2 with ResolvableDependencies

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);
}
Also used : UnknownConfigurationException(org.gradle.api.artifacts.UnknownConfigurationException) Configuration(org.gradle.api.artifacts.Configuration) InputStream(java.io.InputStream) DependencySet(org.gradle.api.artifacts.DependencySet) IOException(java.io.IOException) Properties(java.util.Properties) ResolvableDependencies(org.gradle.api.artifacts.ResolvableDependencies) Project(org.gradle.api.Project) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler)

Aggregations

Configuration (org.gradle.api.artifacts.Configuration)2 DependencySet (org.gradle.api.artifacts.DependencySet)2 ResolvableDependencies (org.gradle.api.artifacts.ResolvableDependencies)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 LinkedHashSet (java.util.LinkedHashSet)1 Properties (java.util.Properties)1 JarFile (java.util.jar.JarFile)1 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)1 Action (org.gradle.api.Action)1 Project (org.gradle.api.Project)1 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)1 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)1 ResolvedConfiguration (org.gradle.api.artifacts.ResolvedConfiguration)1 UnknownConfigurationException (org.gradle.api.artifacts.UnknownConfigurationException)1 DependencyHandler (org.gradle.api.artifacts.dsl.DependencyHandler)1 ZipCopyAction (org.gradle.api.internal.file.archive.ZipCopyAction)1