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

org.metaeffekt.artifact.resolver.alpine.AlpineUtils Maven / Gradle / Ivy

The 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.alpine;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

/**
 * Alpine-specific utility methods for dealing with whatever is thrown at us.
 */
public class AlpineUtils {

    private static final Logger LOG = LoggerFactory.getLogger(AlpineUtils.class);

    /**
     * Parses a line as output by our little index-building oneliner.
     * @param mutablePathToNameVer mutable map for writing the preliminary index into
     * @param line the line to parse
     */
    public static void parseAbuildIndexLine(Map> mutablePathToNameVer, String line) {
        if (StringUtils.isBlank(line)) {
            // can't derive useful information from this line. throw it away.
            // this may happen regularly with the end of the line due to how the script currently works
            return;
        }

        final String[] lineSplit = line.split(" ");
        final String path = lineSplit[0];

        if (lineSplit.length < 2) {
            return;
        }

        Set names = new LinkedHashSet<>();
        for (String rawName : Arrays.copyOfRange(lineSplit, 1, lineSplit.length)) {
            if (StringUtils.isBlank(rawName)) {
                continue;
            }

            // split names. we need to parse from the end to the beginning
            // neither rel nor ver nor sub name contain hyphens. pkgname might.
            String[] nameSplit = rawName.split("-");
            if (nameSplit.length <= 2) {
                // can't work with something that seemingly didn't contain -version-release.apk
                LOG.warn("raw pkgname [{}] couldn't be parsed: not in name-(name-)-ver-rel.apk format.", rawName);
            } else {
                // split off rel
                String name = StringUtils.join(nameSplit, "-", 0, nameSplit.length - 1);
                names.add(name);
            }
        }

        mutablePathToNameVer.put(path, new ArrayList<>(names));
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy