Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure checkstyle, remove code-assert #1803

Merged
merged 4 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Checkstyle
if: contains(matrix.os, 'ubuntu') && contains(matrix.java, '8')
run: ./mvnw checkstyle:check
- name: Test with Maven
run: ./mvnw test -B
- name: Report Coverage to Coveralls
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Checkstyle
if: contains(matrix.os, 'ubuntu')
run: ./mvnw checkstyle:check
- name: Test with Maven
run: ./mvnw test -B
- name: Report Coverage to Coveralls for Pull Requests
Expand Down
43 changes: 43 additions & 0 deletions config/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN"
"https://checkstyle.org/dtds/suppressions_1_0.dtd">

<suppressions>
<suppress checks=".*" files="\.properties"/>
<suppress checks=".*" files="\.xml"/>
<suppress checks=".*" files="[\\/]demo[\\/].*"/>

<suppress checks="DesignForExtension" files="\.java"/>
<suppress checks="FinalParameters" files="\.java"/>
<suppress checks="HiddenField" files="\.java"/>
<suppress checks="InnerAssignment" files="\.java"/>
<suppress checks="JavadocStyle" files="\.java"/>
<suppress checks="JavadocVariable" files="\.java"/>
<suppress checks="LineLength" files="\.java"/>
<suppress checks="MagicNumber" files="\.java"/>
<suppress checks="MethodLength" files="\.java"/>
<suppress checks="MissingJavadocMethod" files="\.java"/>
<suppress checks="NewlineAtEndOfFile" files="\.java"/>
<suppress checks="NoWhitespaceAfter" files="\.java"/>
<suppress checks="OperatorWrap" files="\.java"/>
<suppress checks="ParameterNumber" files="\.java"/>

<!-- Intentional style breaks -->
<suppress checks="ConstantName" files="ParseUtil\.java" lines="115-135"/>
<suppress checks="VisibilityModifier" files="SmcUtil\.java"/>
<suppress checks="VisibilityModifier" files="WmiQueryHandler\.*" lines="63,66"/>
<suppress checks="VisibilityModifier" files="Memoizer\.*" lines="76-78"/>

<!-- JNA convention -->
<suppress checks="InterfaceIsType" files="[\\/]jna[\\/].*"/>
<suppress checks="VisibilityModifier" files="[\\/]jna[\\/].*"/>

<suppress checks="ConstantName" files="[\\/]jna[\\/].*"/>
<suppress checks="MemberName" files="[\\/]jna[\\/].*"/>
<suppress checks="MethodName" files="[\\/]jna[\\/].*"/>
<suppress checks="ParameterName" files="[\\/]jna[\\/].*"/>
<suppress checks="TypeName" files="[\\/]jna[\\/].*"/>

<!-- Imports for classes linked in javadocs -->
<suppress checks="UnusedImports" files="CentralProcessor\.java|OSDesktopWindow\.java|OSProcess\.java"/>
</suppressions>
16 changes: 0 additions & 16 deletions oshi-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,5 @@
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>guru.nidi</groupId>
<artifactId>code-assert</artifactId>
<version>${code-assert.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
12 changes: 6 additions & 6 deletions oshi-core/src/main/java/oshi/SystemInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class SystemInfo {

// The platform isn't going to change, and making this static enables easy
// access from outside this class
private static final PlatformEnum currentPlatform = PlatformEnum.getValue(Platform.getOSType());
private static final PlatformEnum CURRENT_PLATFORM = PlatformEnum.getValue(Platform.getOSType());

private static final String NOT_SUPPORTED = "Operating system not supported: ";

Expand Down Expand Up @@ -85,7 +85,7 @@ public SystemInfo() {
* @return Returns the current platform
*/
public static PlatformEnum getCurrentPlatform() {
return currentPlatform;
return CURRENT_PLATFORM;
}

/**
Expand All @@ -99,7 +99,7 @@ public OperatingSystem getOperatingSystem() {
}

private static OperatingSystem createOperatingSystem() {
switch (currentPlatform) {
switch (CURRENT_PLATFORM) {
case WINDOWS:
return new WindowsOperatingSystem();
case LINUX:
Expand All @@ -115,7 +115,7 @@ private static OperatingSystem createOperatingSystem() {
case OPENBSD:
return new OpenBsdOperatingSystem();
default:
throw new UnsupportedOperationException(NOT_SUPPORTED + currentPlatform.getName());
throw new UnsupportedOperationException(NOT_SUPPORTED + CURRENT_PLATFORM.getName());
}
}

Expand All @@ -130,7 +130,7 @@ public HardwareAbstractionLayer getHardware() {
}

private static HardwareAbstractionLayer createHardware() {
switch (currentPlatform) {
switch (CURRENT_PLATFORM) {
case WINDOWS:
return new WindowsHardwareAbstractionLayer();
case LINUX:
Expand All @@ -146,7 +146,7 @@ private static HardwareAbstractionLayer createHardware() {
case OPENBSD:
return new OpenBsdHardwareAbstractionLayer();
default:
throw new UnsupportedOperationException(NOT_SUPPORTED + currentPlatform.getName());
throw new UnsupportedOperationException(NOT_SUPPORTED + CURRENT_PLATFORM.getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
public final class UserGroupInfo {

// Temporarily cache users and groups, update each minute
private static final Supplier<Map<String, String>> usersIdMap = memoize(UserGroupInfo::getUserMap,
private static final Supplier<Map<String, String>> USERS_ID_MAP = memoize(UserGroupInfo::getUserMap,
TimeUnit.MINUTES.toNanos(1));
private static final Supplier<Map<String, String>> groupsIdMap = memoize(UserGroupInfo::getGroupMap,
private static final Supplier<Map<String, String>> GROUPS_ID_MAP = memoize(UserGroupInfo::getGroupMap,
TimeUnit.MINUTES.toNanos(1));

private UserGroupInfo() {
Expand All @@ -60,7 +60,7 @@ private UserGroupInfo() {
* as the second
*/
public static String getUser(String userId) {
return usersIdMap.get().getOrDefault(userId, Constants.UNKNOWN);
return USERS_ID_MAP.get().getOrDefault(userId, Constants.UNKNOWN);
}

/**
Expand All @@ -71,7 +71,7 @@ public static String getUser(String userId) {
* @return a {@link java.lang.String} object.
*/
public static String getGroupName(String groupId) {
return groupsIdMap.get().getOrDefault(groupId, Constants.UNKNOWN);
return GROUPS_ID_MAP.get().getOrDefault(groupId, Constants.UNKNOWN);
}

private static Map<String, String> getUserMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public static List<SoundCard> getSoundCards() {
}
}
List<SoundCard> soundCards = new ArrayList<>();
for (String _key : sounds) {
soundCards.add(new FreeBsdSoundCard(productMap.get(_key), vendorMap.get(_key) + " " + productMap.get(_key),
productMap.get(_key)));
for (String s : sounds) {
soundCards.add(new FreeBsdSoundCard(productMap.get(s), vendorMap.get(s) + " " + productMap.get(s),
productMap.get(s)));
}
return soundCards;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@ThreadSafe
final class FreeBsdVirtualMemory extends AbstractVirtualMemory {

FreeBsdGlobalMemory global;
private final FreeBsdGlobalMemory global;

private final Supplier<Long> used = memoize(FreeBsdVirtualMemory::querySwapUsed, defaultExpiration());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@ThreadSafe
final class OpenBsdVirtualMemory extends AbstractVirtualMemory {

OpenBsdGlobalMemory global;
private final OpenBsdGlobalMemory global;

private final Supplier<Triplet<Integer, Integer, Integer>> usedTotalPgin = memoize(
OpenBsdVirtualMemory::queryVmstat, defaultExpiration());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public static List<SoundCard> getSoundCards() {
}
}
List<SoundCard> soundCards = new ArrayList<>();
for (String _key : sounds) {
soundCards.add(new SolarisSoundCard(productMap.get(_key) + " " + DEFAULT_AUDIO_DRIVER,
vendorMap.get(_key) + " " + productMap.get(_key), productMap.get(_key)));
for (String s : sounds) {
soundCards.add(new SolarisSoundCard(productMap.get(s) + " " + DEFAULT_AUDIO_DRIVER,
vendorMap.get(s) + " " + productMap.get(s), productMap.get(s)));
}
return soundCards;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
public class AixOperatingSystem extends AbstractOperatingSystem {

private final Supplier<perfstat_partition_config_t> config = memoize(PerfstatConfig::queryConfig);
Supplier<perfstat_process_t[]> procCpu = memoize(PerfstatProcess::queryProcesses, defaultExpiration());
private final Supplier<perfstat_process_t[]> procCpu = memoize(PerfstatProcess::queryProcesses,
defaultExpiration());

private static final long BOOTTIME = querySystemBootTimeMillis() / 1000L;

Expand Down
4 changes: 2 additions & 2 deletions oshi-core/src/main/java/oshi/util/Memoizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@ThreadSafe
public final class Memoizer {

private static final Supplier<Long> defaultExpirationNanos = memoize(Memoizer::queryExpirationConfig,
private static final Supplier<Long> DEFAULT_EXPIRATION_NANOS = memoize(Memoizer::queryExpirationConfig,
TimeUnit.MINUTES.toNanos(1));

private Memoizer() {
Expand All @@ -54,7 +54,7 @@ private static long queryExpirationConfig() {
* @return The number of nanoseconds to keep memoized values before refreshing
*/
public static long defaultExpiration() {
return defaultExpirationNanos.get();
return DEFAULT_EXPIRATION_NANOS.get();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public final class PerfCounterQuery {
private static final boolean IS_VISTA_OR_GREATER = VersionHelpers.IsWindowsVistaOrGreater();

// Use a thread safe set to cache failed pdh queries
private static final Set<String> failedQueryCache = ConcurrentHashMap.newKeySet();
private static final Set<String> FAILED_QUERY_CACHE = ConcurrentHashMap.newKeySet();

// For XP, use a map to cache localization strings
private static final ConcurrentHashMap<String, String> localizeCache = IS_VISTA_OR_GREATER ? null
private static final ConcurrentHashMap<String, String> LOCALIZE_CACHE = IS_VISTA_OR_GREATER ? null
: new ConcurrentHashMap<>();

/*
Expand Down Expand Up @@ -92,14 +92,14 @@ private PerfCounterQuery() {
*/
public static <T extends Enum<T>> Map<T, Long> queryValues(Class<T> propertyEnum, String perfObject,
String perfWmiClass) {
if (!failedQueryCache.contains(perfObject)) {
if (!FAILED_QUERY_CACHE.contains(perfObject)) {
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
Map<T, Long> valueMap = queryValuesFromPDH(propertyEnum, perfObject);
if (!valueMap.isEmpty()) {
return valueMap;
}
// If we are here, query failed
LOG.warn("Disabling further attempts to query {}.", perfObject);
failedQueryCache.add(perfObject);
FAILED_QUERY_CACHE.add(perfObject);
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
}
return queryValuesFromWMI(propertyEnum, perfWmiClass);
}
Expand Down Expand Up @@ -205,7 +205,7 @@ public static <T extends Enum<T>> Map<T, Long> queryValuesFromWMI(Class<T> prope
*/
public static String localizeIfNeeded(String perfObject) {
return IS_VISTA_OR_GREATER ? perfObject
: localizeCache.computeIfAbsent(perfObject, PerfCounterQuery::localizeUsingPerfIndex);
: LOCALIZE_CACHE.computeIfAbsent(perfObject, PerfCounterQuery::localizeUsingPerfIndex);
}

private static String localizeUsingPerfIndex(String perfObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public final class PerfCounterWildcardQuery {
private static final Logger LOG = LoggerFactory.getLogger(PerfCounterWildcardQuery.class);

// Use a thread safe set to cache failed pdh queries
private static final Set<String> failedQueryCache = ConcurrentHashMap.newKeySet();
private static final Set<String> FAILED_QUERY_CACHE = ConcurrentHashMap.newKeySet();

private PerfCounterWildcardQuery() {
}
Expand All @@ -83,15 +83,15 @@ private PerfCounterWildcardQuery() {
*/
public static <T extends Enum<T>> Pair<List<String>, Map<T, List<Long>>> queryInstancesAndValues(
Class<T> propertyEnum, String perfObject, String perfWmiClass) {
if (!failedQueryCache.contains(perfObject)) {
if (!FAILED_QUERY_CACHE.contains(perfObject)) {
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
Pair<List<String>, Map<T, List<Long>>> instancesAndValuesMap = queryInstancesAndValuesFromPDH(propertyEnum,
perfObject);
if (!instancesAndValuesMap.getA().isEmpty()) {
return instancesAndValuesMap;
}
// If we are here, query failed
LOG.warn("Disabling further attempts to query {}.", perfObject);
failedQueryCache.add(perfObject);
FAILED_QUERY_CACHE.add(perfObject);
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
}
return queryInstancesAndValuesFromWMI(propertyEnum, perfWmiClass);
}
Expand Down
80 changes: 0 additions & 80 deletions oshi-core/src/test/java/oshi/SourceCodeTest.java

This file was deleted.