use of com.google.errorprone.annotations.Var in project java-common-lib by sosy-lab.
the class OptionCollector method getSourcePath.
/**
* This method tries to get Source-Path. This path is used to get default values for options
* without instantiating the classes.
*/
@SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
private static Path getSourcePath(CodeSource codeSource) throws URISyntaxException {
// Get base folder for classes, go via URI to handle escaping
@Var Path basePath = Paths.get(codeSource.getLocation().toURI());
if (basePath.endsWith("bin")) {
// this could be a usual eclipse environment, therefore src is the appropriate
// folder to search for sources
basePath = basePath.getParent();
} else if (basePath.endsWith("build/classes/main")) {
// this is a typical project layout for gradle, the sources should be in
// src/main/java/
basePath = basePath.getParent().getParent().getParent();
}
// gradle projects do also in eclipse have another folder for sources
// so check which folder is the actual source folder
List<Path> candidates = ImmutableList.of(Paths.get("src", "main", "java"), Paths.get("src"));
for (Path candidate : candidates) {
Path sourcePath = basePath.resolve(candidate);
if (Files.isDirectory(sourcePath)) {
return sourcePath;
}
}
return basePath;
}
use of com.google.errorprone.annotations.Var in project infrautils by opendaylight.
the class LogRule method apply.
@Override
// findbugs-slf4j cannot understand what we are doing here with a Logger variable instead of class field, so:
@SuppressFBWarnings({ "SLF4J_FORMAT_SHOULD_BE_CONST", "SLF4J_LOGGER_SHOULD_BE_PRIVATE" })
public Statement apply(Statement statement, Description description) {
Logger testLog = LoggerFactory.getLogger(description.getTestClass());
return new Statement() {
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
@SuppressFBWarnings("SLF4J_FORMAT_SHOULD_BE_CONST")
public void evaluate() throws Throwable {
testLog.info(MARKER, HEADER);
testLog.info(MARKER, "BEGIN @Test {}()", description.getMethodName());
long startTimeInMS = System.currentTimeMillis();
@Var Throwable caughtThrowable = null;
try {
statement.evaluate();
} catch (Throwable throwable) {
caughtThrowable = throwable;
throw throwable;
} finally {
long durationInMS = System.currentTimeMillis() - startTimeInMS;
if (caughtThrowable == null) {
testLog.info(MARKER, MESSAGE, "ENDED", durationInMS, description.getMethodName());
} else {
testLog.error(MARKER, MESSAGE, "FAILED", durationInMS, description.getMethodName(), caughtThrowable);
}
}
}
};
}
use of com.google.errorprone.annotations.Var in project infrautils by opendaylight.
the class MBeanUtils method invokeMBeanFunction.
public static Object invokeMBeanFunction(String objName, String functionName) {
@Var Object udpated = "";
try {
ObjectName objectName = new ObjectName(objName);
MBeanServer mplatformMbeanServer = ManagementFactory.getPlatformMBeanServer();
udpated = mplatformMbeanServer.invoke(objectName, functionName, null, null);
} catch (InstanceNotFoundException | MBeanException | ReflectionException | MalformedObjectNameException t) {
LOG.info("CRITICAL : Exception in executing MBean function");
}
return udpated;
}
use of com.google.errorprone.annotations.Var in project infrautils by opendaylight.
the class MBeanUtils method readMBeanAttribute.
@Nullable
public static Object readMBeanAttribute(String objName, String attribute) {
@Var Object attributeObj = null;
try {
ObjectName objectName = new ObjectName(objName);
MBeanServer platformMbeanServer = ManagementFactory.getPlatformMBeanServer();
attributeObj = platformMbeanServer.getAttribute(objectName, attribute);
} catch (AttributeNotFoundException | InstanceNotFoundException | MBeanException | ReflectionException | MalformedObjectNameException t) {
LOG.info("CRITICAL : Exception in executing MXBean function");
}
return attributeObj;
}
use of com.google.errorprone.annotations.Var in project infrautils by opendaylight.
the class AbstractMXBean method registerMBean.
/**
* Registers this bean with the platform MBean server with the domain defined by
* {@link #BASE_JMX_PREFIX}.
*
* @return true is successfully registered, false otherwise.
*/
protected final boolean registerMBean() {
@Var boolean registered = false;
try {
// Object to identify MBean
ObjectName mbeanObjectName = this.getMBeanObjectName();
LOG.debug("Register MBean {}", mbeanObjectName);
// unregistered if already registered
if (server.isRegistered(mbeanObjectName)) {
LOG.debug("MBean {} found to be already registered", mbeanObjectName);
try {
unregisterMBean(mbeanObjectName);
} catch (MBeanRegistrationException | InstanceNotFoundException e) {
LOG.warn("unregister mbean {} caused exception", mbeanObjectName, e);
}
}
server.registerMBean(this, mbeanObjectName);
registered = true;
LOG.debug("MBean {} registered successfully", mbeanObjectName.getCanonicalName());
} catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException | MalformedObjectNameException e) {
LOG.error("MBean {} registration failed", mbeanName, e);
}
return registered;
}
Aggregations