SonarQube don't show new metrics - plugins

I am working on a Sonarqube plugin and I want to show some metrics but Sonarqube don't show anything! Here is a metric in the Metric class:
public static final String TC_PRO_KEY = "project-tc";
public static final Metric<Integer> TC_PRO = new Metric.Builder(TC_PRO_KEY, "Project Test Cases",
Metric.ValueType.INT)
.setDescription("Number of Test Cases for the project")
.setDirection(Metric.DIRECTION_BETTER)
.setQualitative(true)
.setDomain(TL_DOMAIN)
.create();
And in the execute() method of the Sensor:
context.<Integer>newMeasure().forMetric(CatcherMetrics.TC_PRO).on(context.module()).withValue(nbTotalTC).save();
Can you tell me if I do someting wrong.

The problem wasn't here! My metrics were with status required and I used Common properties and the fields were empty so there was an error!

Related

Is there a way to log correlation id (sent from microservice) in Postgres

I am setting up the logging for a project and was wondering, whether it is possible to send id to postges database. Later I would collect all logs with fluentd and use the efk(elastic search, fluentd, kibana) stack to look through the logs. That is why it would be very helpful if can set the id in the database logs.
You can have your connection set the application_name to something that includes the id you want, and then configure your logging to include the application_name field. Or you could include the id in an SQL comment, something like select /* I am number 6 */ whatever from whereever. But then the id will only be visible for log messages that include the sql. (The reason for putting the comment after the select keyword is that some clients will strip out leading comments so the serve never sees them)
Thank you #jjane,
for giving me such a great idea. After some googling I found a page describing how to intercept hibernate logs
then I made some more research on how to add the inspector to spring-boot and this is the solution I came up with:
#Component
public class SqlCommentStatementInspector
implements StatementInspector {
private static final Logger LOGGER = LoggerFactory
.getLogger(
SqlCommentStatementInspector.class
);
private static final Pattern SQL_COMMENT_PATTERN = Pattern
.compile(
"\\/\\*.*?\\*\\/\\s*"
);
#Override
public String inspect(String sql) {
LOGGER.info(
"Repo log, Correlation_id:"+ MDC.get(Slf4jMDCFilter.MDC_UUID_TOKEN_KEY),
sql
);
return String.format("/*Correlation_id: %s*/", MDC.get(Slf4jMDCFilter.MDC_UUID_TOKEN_KEY)) + SQL_COMMENT_PATTERN
.matcher(sql)
.replaceAll("");
}
}
and its configuration:
#Configuration
public class HibernateConfiguration implements HibernatePropertiesCustomizer {
#Autowired
private SqlCommentStatementInspector myInspector;
#Override
public void customize(Map<String, Object> hibernateProperties) {
hibernateProperties.put("hibernate.session_factory.statement_inspector", myInspector);
}
}

Migration from Hibernate 3 to Hibernate 5: sessionFactory (MetadataImplementor) is null

public class EntityMetaData implements SessionFactoryBuilderFactory {
// private static final ThreadLocal<MetadataImplementor> meta = new ThreadLocal<>(); // previously used, but did not work, so used HashMap
private static final Map<String, MetadataImplementor> meta = new HashMap<>();
private static final String METADATAKEY = "M";
#Override
public SessionFactoryBuilder getSessionFactoryBuilder(MetadataImplementor metadata, SessionFactoryBuilderImplementor defaultBuilder) {
// meta.set(metadata);
meta.put(METADATAKEY, metadata);
return defaultBuilder;
}
public static MetadataImplementor getMeta() {
// return meta.get();
return meta.get(METADATAKEY);
}
}
The above code works in tomcat 8 of Local environment, but in tomcat 8 of production environment not working as getMeta() method returns null.
In Local Environment, getSessionFactoryBuilder method is called while server is getting started so that it is working in Local, but in Production environment getSessionFactoryBuilder method not called thus getMeta() returns null.
Any help could be appreciated.
Please help me on this.
Finally I found the answer.
It's a compiling problem. META-INF folder is not there in classes folder, so metadata is not loading (means getSessionFactoryBuilder method not getting called) during server startup. In Local environment, META-INF is there in classes folder..But in Production environment it is not available, so tried to compile META-INF and available in classes folder, then after it's working.

Is it possible to access sonarqube analysis results in a plugin?

As per the sonar logs, I see that sonar first runs the sensors, then the decorators and then stores the analysis results to the database. Is is possible to access analysis results in a sonar plugin?
Thanks
The Sonar web application is available at localhost:9000 (or wherever it's installed).
There is also a plugin for Eclipse to view issues:
http://docs.codehaus.org/display/SONAR/SonarQube+in+Eclipse
I finally found a solution to my problem here.
http://sonarqube.15.x6.nabble.com/sonar-dev-Where-can-I-find-new-issue-information-on-sonar-db-td5021022.html
// this annotation is important to be sure that relevant data on issues are up-to-date.
#DependsUpon(DecoratorBarriers.ISSUES_TRACKED)
public final class MyDecorator implements Decorator {
private final ResourcePerspectives perspectives;
public TechnicalDebtDecorator(ResourcePerspectives perspectives) {
this.perspectives = perspectives;
}
public void decorate(Resource resource, DecoratorContext context) {
Issuable issuable = perspectives.as(Issuable.class, resource);
if (issuable != null) {
List<Issue> issues = issuable.issues();
// Issue has method isNew()
}
}
}

JBoss7.1 final 2 counts of IllegalAnnotationExceptions

I'm trying to migrate app from jboss 5.1 to 7.1 and i have error like this Error message which i'm not sure why i get this. if anyone have any idea please help me.
Update: 1
#Stateless
#Remote(PackageService.class)
#Interceptors(CrossContextSpringBeanAutowiringInterceptor.class)
#WebContext(contextRoot="/appname_web_services", urlPattern="/MaintenanceService", authMethod="", secureWSDLAccess=false)
#WebService(
name="MaintenanceService",
targetNamespace = "http://appname.com/web/services",
serviceName = "MaintenanceService")
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
#HandlerChain(file = "WebServiceHandlerChains.xml")
#TransactionTimeout(10800)
public class MaintenanceServiceBean implements MaintenanceService {
private static final Logger logger = Logger.getLogger( MaintenanceServiceBean.class );
#Resource(mappedName="/ConnectionFactory")
ConnectionFactory connectionFactory;
#Resource(mappedName="topic/manager_system_topic")
javax.jms.Destination systemTopic;
#Autowired
MaintenanceService MigrationService;
#WebMethod
public List<Long> getSoftDeletedPackageIds(Long performedBy) throws Exception {
return MigrationService.getSoftDeletedPackageIds(null);
}
this is the class where i believe it fails.
You are using an interface in your JAXB mappings for which you have not provided enough information to the runtime for it too be able to bind an actual implementation. Without more code included in your question it's hard to recommend a specific solution, but typically you would annotate the included interface with #XmlAnyElement.
You can read through this useful tutorial to determine the best solution for your possible case.

iReports won't read my JavaBeans datasource, but it does load the class file

I've been losing my mind over this for the past week. I've tried tons of tutorials and forums, but nothing works.
Here's the overview: I want to display JavaBean objects in a simple table. I've created the JavaBean object, I've set the classpath, but iReport just won't work with it no matter what I try. Here's the entire Java code:
package mypack;
public class Person
{
private String name;
private static Person[] data = {new Person("John"), new Person("Mark")};
public Person() {}
public Person(String newName) { name = newName; }
public String getName() { return name; }
public void setName(String newName) { name = newName; }
public static Person[] getPersons() { return data; }
}
In iReport, I've created a new "JavaBeans set datasource" connection. Here's how it's filled:
However, when I click on "Test", nothing at all happens. No error but no data either. If Ichange the name of the factory class, then I will get the "class not found" exception, so iReport obviously did load my class, but it's still not working.
I really have no idea what I'm doing wrong in the Java file, because iReport seems to load it fine, but can't "talk" with it.
I've created the Java class with Eclipse Juno and I'm using iReport 4.6.0. Any help woud be really appreciated.
Problem solved. I was building Java file against 1.7, which iReports can't seem to read it seems. Building for 1.6 solves the problem and the above code works fine.