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

de.pfabulist.loracle.license.LicenseAttributes 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.license;

import java.util.Optional;

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

public class LicenseAttributes {

    private String attis;

    public LicenseAttributes() {
        attis = "S O 2 3 F L W  ";
    }

    public boolean isSPDX() {
        return attis.charAt( 1 ) == 's';
    }

    public void setSPDX( boolean on ) {
        if ( on ) {
            set( 1, 's' );
        }
    }

    public void setFromFedora() {
        set( 1, 'f' );
    }

    public void setFromDeja() {
        set( 1, 'd' );
    }

    public void setFromIFross() {
        set( 1, 'i' );
    }

    public Optional isCopyLeft() {
        return get( 11 );
    }

    public boolean isCopyLeftDef() {
        return isCopyLeft().orElse( false );
    }

    public void setCopyLeft( boolean on ) {
        set( 11, on );
    }

    public Optional isOsiApproved() {
        return get( 3 );
    }

    public void setOsiApproved( boolean on ) {
        set( 3, on );
    }

    public Optional isFedoraApproved() {
        return get( 9 );
    }

    public void setFedoraApproved( boolean on ) {
        set( 9, on );
    }

    public Optional isGpl2Compatible() {
        return get( 5 );
    }

    public void setGpl2Compatible( boolean on ) {
        set( 5, on );
    }

    public Optional isGpl3Compatible() {
        return get( 7 );
    }

    public void setGpl3Compatible( boolean on ) {
        set( 7, on );
    }

    public void setWeakCopyLeft( boolean on ) {
        set( 13, on );
    }

    private Optional get( int idx ) {
        switch( attis.charAt( idx ) ) {
            case '+':
                return Optional.of( true );
            case '-':
                return Optional.of( false );
            default:
                return Optional.empty();
        }
    }

    private void set( int idx, boolean on ) {
        attis = attis.substring( 0, idx ) + ( on ? "+" : "-" ) + attis.substring( idx + 1, attis.length() );
    }

    private void set( int idx, char on ) {
        attis = attis.substring( 0, idx ) + on + attis.substring( idx + 1, attis.length() );
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy