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

de.pfabulist.loracle.mojo.UrlToLicense Maven / Gradle / Ivy

Go to download

maven plugin to check the licenses of all dependencies and possible incompatibilities

There is a newer version: 2.0.1
Show newest version
package de.pfabulist.loracle.mojo;

import de.pfabulist.loracle.license.Findings;
import de.pfabulist.loracle.license.LOracle;
import de.pfabulist.loracle.license.LicenseFromText;
import de.pfabulist.loracle.license.MappedLicense;

/**
 * Copyright (c) 2006 - 2016, Stephan Pfab
 * SPDX-License-Identifier: BSD-2-Clause
 */

public class UrlToLicense {

    private final LOracle lOracle;
    private final Findings log;
    private final Downloader downloader;
    private final LicenseFromText lft;

    public UrlToLicense( LOracle lOracle, Findings log ) {
        this.lOracle = lOracle;
        this.log = log;
        this.downloader = new Downloader( log, lOracle );
        this.lft = new LicenseFromText( lOracle, log );
    }

    public MappedLicense getLicense( String url ) {
        MappedLicense ret = lOracle.getByUrl( url );

        if( ret.isPresent() ) {
            return ret;
        }

        downloader.download( url );
        String txt = downloader.get( url );

        if( txt.isEmpty() ) {
            return MappedLicense.empty();
        }

        ret = lft.getLicense( txt );

        ret.ifPresent( lid -> {
            log.debug( "added extension url for license " + url );
            lOracle.addUrl( lid, url );
        } );

        return ret;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy