de.flapdoodle.os.linux.LsbReleaseFiles Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2020
* Michael Mosmann
*
* 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 de.flapdoodle.os.linux;
import de.flapdoodle.os.common.DistinctPeculiarity;
import de.flapdoodle.os.common.attributes.Attribute;
import de.flapdoodle.os.common.matcher.Matchers;
import de.flapdoodle.os.common.types.LsbReleaseFile;
import de.flapdoodle.os.common.types.LsbReleaseFileConverter;
import java.util.regex.Pattern;
public class LsbReleaseFiles {
public static String RELEASE_FILE_NAME = "/etc/lsb-release";
public static String NAME="DISTRIB_ID";
public static String VERSION_ID="DISTRIB_RELEASE";
public static String VERSION_CODENAME="DISTRIB_CODENAME";
static Attribute lsbReleaseFile() {
return releaseFile(RELEASE_FILE_NAME);
}
static Attribute releaseFile(String path) {
return de.flapdoodle.os.common.attributes.Attributes.mappedTextFile(path, LsbReleaseFileConverter.INSTANCE);
}
static DistinctPeculiarity nameMatches(Attribute osReleaseFile, String name) {
return DistinctPeculiarity.of(osReleaseFile, Matchers.lsbReleaseFileEntry(NAME, ".*" + name + ".*"));
}
static DistinctPeculiarity versionMatches(Attribute osReleaseFile, String version) {
return DistinctPeculiarity.of(osReleaseFile, Matchers.lsbReleaseFileEntry(VERSION_ID, Pattern.quote(version) + ".*"));
}
static DistinctPeculiarity versionIs(Attribute osReleaseFile, String version) {
return DistinctPeculiarity.of(osReleaseFile, Matchers.lsbReleaseFileEntry(VERSION_ID, Pattern.quote(version)));
}
static DistinctPeculiarity versionCodeNameIs(Attribute osReleaseFile, String version) {
return DistinctPeculiarity.of(osReleaseFile, Matchers.lsbReleaseFileEntry(VERSION_CODENAME, Pattern.quote(version)));
}
static DistinctPeculiarity lsbReleaseFileNameMatches(String name) {
return nameMatches(lsbReleaseFile(), name);
}
static DistinctPeculiarity lsbReleaseFileVersionMatches(String version) {
return versionMatches(lsbReleaseFile(), version);
}
static DistinctPeculiarity lsbReleaseFileVersionIs(String version) {
return versionIs(lsbReleaseFile(), version);
}
static DistinctPeculiarity lsbReleaseFileVersionCodeNameIs(String version) {
return versionCodeNameIs(lsbReleaseFile(), version);
}
}