All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.micronaut.starter.build.maven.MavenBuild Maven / Gradle / Ivy

There is a newer version: 4.7.0
Show newest version
/*
 * Copyright 2017-2022 original authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.micronaut.starter.build.maven;

import io.micronaut.core.annotation.NonNull;
import io.micronaut.starter.build.Property;
import io.micronaut.starter.build.dependencies.Coordinate;

import io.micronaut.starter.build.dependencies.DependencyCoordinate;
import io.micronaut.starter.feature.build.maven.Profile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;

import io.micronaut.starter.template.Writable;
import io.micronaut.starter.template.WritableUtils;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class MavenBuild {
    private static final Logger LOG = LoggerFactory.getLogger(MavenBuild.class);

    private final MavenCombineAttribute annotationProcessorCombineAttribute;

    private final MavenCombineAttribute testAnnotationProcessorCombineAttribute;

    private final List testAnnotationProcessors;

    private final List annotationProcessors;

    private final List dependencies;

    private final List plugins;

    private final List properties;

    private final Collection profiles;

    private final List repositories;

    private final List aotDependencies;

    @NonNull
    private final String artifactId;

    public MavenBuild(String artifactId) {
        this(artifactId,
                Collections.emptyList(),
                Collections.emptyList(),
                Collections.emptyList(),
                Collections.emptyList(),
                Collections.emptyList(),
                Collections.emptyList(),
                MavenCombineAttribute.APPEND,
                MavenCombineAttribute.APPEND,
                Collections.emptyList(),
                Collections.emptyList());
    }

    public MavenBuild(@NonNull String artifactId,
                      @NonNull List dependencies,
                      @NonNull List plugins,
                      @NonNull List repositories) {
        this(artifactId,
                Collections.emptyList(),
                Collections.emptyList(),
                dependencies,
                Collections.emptyList(),
                plugins,
                repositories,
                MavenCombineAttribute.APPEND,
                MavenCombineAttribute.APPEND,
                Collections.emptyList(),
                Collections.emptyList());
    }

    public MavenBuild(@NonNull String artifactId,
                      @NonNull List annotationProcessors,
                      @NonNull List testAnnotationProcessors,
                      @NonNull List dependencies,
                      @NonNull List properties,
                      @NonNull List plugins,
                      @NonNull List repositories,
                      @NonNull MavenCombineAttribute annotationProcessorCombineAttribute,
                      @NonNull MavenCombineAttribute testAnnotationProcessorCombineAttribute,
                      @NonNull Collection profiles,
                      @NonNull List aotDependencies) {
        this.artifactId = artifactId;
        this.annotationProcessors = annotationProcessors;
        this.testAnnotationProcessors = testAnnotationProcessors;
        this.dependencies = dependencies;
        this.properties = properties;
        this.plugins = plugins;
        this.repositories = repositories;
        this.annotationProcessorCombineAttribute = annotationProcessorCombineAttribute;
        this.testAnnotationProcessorCombineAttribute = testAnnotationProcessorCombineAttribute;
        this.profiles = profiles;
        this.aotDependencies = aotDependencies;
    }

    @NonNull
    public String getArtifactId() {
        return artifactId;
    }

    @NonNull
    public String renderRepositories(int indentationSpaces) {
        return WritableUtils.renderWritableList(this.repositories.stream()
                .map(Writable.class::cast)
                .collect(Collectors.toList()), indentationSpaces);
    }

    @NonNull
    public String renderPlugins(int indentationSpaces) {
        List writableList = plugins.stream()
                .map(MavenPlugin::getExtension)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
        return WritableUtils.renderWritableList(writableList, indentationSpaces);
    }

    @NonNull
    public List getAnnotationProcessors() {
        return annotationProcessors;
    }

    @NonNull
    public List getTestAnnotationProcessors() {
        return testAnnotationProcessors;
    }

    @NonNull
    public Collection getProfiles() {
        return profiles;
    }

    @NonNull
    public List getDependencies() {
        return dependencies;
    }

    @NonNull
    public List getDependencies(boolean pom) {
        return dependencies
                .stream()
                .filter(it -> it.isPom() == pom)
                .collect(Collectors.toList());
    }

    public boolean hasPomDependency() {
        return dependencies.stream().anyMatch(Coordinate::isPom);
    }

    @NonNull
    public List getProperties() {
        return properties;
    }

    public MavenCombineAttribute getAnnotationProcessorCombineAttribute() {
        return annotationProcessorCombineAttribute;
    }

    @NonNull
    public MavenCombineAttribute getTestAnnotationProcessorCombineAttribute() {
        return testAnnotationProcessorCombineAttribute;
    }

    public List getAotDependencies() {
        return aotDependencies;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy