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

org.metaeffekt.artifact.resolver.ArtifactResolverConfig Maven / Gradle / Ivy

There is a newer version: 0.134.0
Show newest version
/*
 * Copyright 2021-2024 the original author or 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
 *
 *     http://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 org.metaeffekt.artifact.resolver;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.metaeffekt.artifact.resolver.alpine.AlpinePackageResolverConfig;
import org.metaeffekt.artifact.resolver.deb.DebArtifactResolverConfig;
import org.metaeffekt.artifact.resolver.generic.IndexConfig;
import org.metaeffekt.artifact.resolver.manager.execenv.EnvironmentManagerConfig;
import org.metaeffekt.artifact.resolver.maven.MavenArtifactResolverConfig;
import org.metaeffekt.artifact.resolver.rpm.index.RpmIndexConfig;
import org.metaeffekt.core.util.FileUtils;

import java.io.File;
import java.io.IOException;

@Getter
@Setter
@Slf4j
public class ArtifactResolverConfig {

    private MavenArtifactResolverConfig mavenConfig;

    private IndexConfig indexConfig;

    private EnvironmentManagerConfig environmentManagerConfig;

    private AlpinePackageResolverConfig alpinePackageResolverConfig;

    private RpmIndexConfig rpmIndexConfig;

    private DebArtifactResolverConfig debArtifactResolverConfig;

    // using this approach causes downstream procedures to freeze due to some dependency issue related to jackson.
    //  Example: ObserveFolderFlowTest (when jackson was below many other dependencies)
    public static ArtifactResolverConfig parseFromYaml(File yamlFile) throws IOException {
        log.trace("Reading config file content from [{}] to string.", yamlFile);
        final String content = FileUtils.readFileToString(yamlFile, FileUtils.ENCODING_UTF_8);

        if (StringUtils.isEmpty(content)) {
            return new ArtifactResolverConfig();
        }

        YAMLFactory factory = new YAMLFactory();
        ObjectMapper mapper = new ObjectMapper(factory);

        log.trace("Creating ArtifactResolverConfig from content of file [{}].", yamlFile);
        return mapper.readValue(content, ArtifactResolverConfig.class);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy