Skip to content

Commit

Permalink
usage logging
Browse files Browse the repository at this point in the history
  • Loading branch information
vodorok committed Sep 2, 2019
1 parent bfac6b0 commit e8cc09f
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 13 deletions.
3 changes: 2 additions & 1 deletion bundles/org.codechecker.eclipse.plugin/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ bin.includes = plugin.xml,\
.,\
icons/,\
contexts.xml,\
log4j.properties
log4j.properties,\
resources/

35 changes: 35 additions & 0 deletions bundles/org.codechecker.eclipse.plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.codechecker.eclipse</groupId>
<artifactId>org.codechecker.eclipse.bundles</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>org.codechecker.eclipse.plugin</artifactId>
<version>0.0.6-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

<properties>
<host.log>empty</host.log>
<port.log>0</port.log>
<plugin.version>${project.version}</plugin.version>
</properties>

<build>
<resources>
<resource>
<directory>resources</directory>
<targetPath>resources</targetPath>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
host=${host.log}
port=${port.log}
version=${plugin.version}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
import java.util.HashSet;
import java.util.Set;

import org.codechecker.eclipse.plugin.CodeCheckerNature;
import org.codechecker.eclipse.plugin.ExternalLogger;
import org.codechecker.eclipse.plugin.Logger;
import org.codechecker.eclipse.plugin.config.CodeCheckerContext;
import org.codechecker.eclipse.plugin.config.global.CcGlobalConfiguration;
import org.codechecker.eclipse.plugin.config.project.CodeCheckerProject;
import org.codechecker.eclipse.plugin.report.job.AnalyzeJob;
import org.codechecker.eclipse.plugin.report.job.JobDoneChangeListener;
import org.codechecker.eclipse.plugin.report.job.PlistParseJob;
import org.codechecker.eclipse.plugin.runtime.SLogger;
import org.codechecker.eclipse.plugin.usage.StatisticUploader;
import org.codechecker.eclipse.plugin.usage.UsageInfo;
import org.codechecker.eclipse.plugin.usage.UsageInfo.CommandType;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
Expand All @@ -24,18 +37,6 @@
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

import org.codechecker.eclipse.plugin.CodeCheckerNature;
import org.codechecker.eclipse.plugin.ExternalLogger;
import org.codechecker.eclipse.plugin.Logger;
import org.codechecker.eclipse.plugin.config.CcConfiguration;
import org.codechecker.eclipse.plugin.config.CodeCheckerContext;
import org.codechecker.eclipse.plugin.config.global.CcGlobalConfiguration;
import org.codechecker.eclipse.plugin.config.project.CodeCheckerProject;
import org.codechecker.eclipse.plugin.report.job.AnalyzeJob;
import org.codechecker.eclipse.plugin.report.job.JobDoneChangeListener;
import org.codechecker.eclipse.plugin.report.job.PlistParseJob;
import org.codechecker.eclipse.plugin.runtime.SLogger;

/**
* This eclipse job is responsible for registering the Build listener.
*
Expand Down Expand Up @@ -83,6 +84,8 @@ public IStatus runInUIThread(IProgressMonitor monitor) {
Logger.log(IStatus.INFO, Logger.getStackTrace(e));
}

new Thread(new StatisticUploader(new UsageInfo(CommandType.started, null))).run();

Logger.log(IStatus.INFO, "adding addResourceChangeListener ");
ResourcesPlugin.getWorkspace().addResourceChangeListener(new ResourceChangeListener(),
IResourceChangeEvent.POST_BUILD | IResourceChangeEvent.POST_CHANGE |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.codechecker.eclipse.plugin.usage;

import java.io.IOException;
import java.io.InputStream;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.Inet4Address;
import java.util.Properties;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.osgi.framework.FrameworkUtil;

import com.google.gson.Gson;

public class StatisticUploader implements Runnable {

private Integer port;
private String host = "none";
private UsageInfo info;

public StatisticUploader(UsageInfo info) {
this.info = info;
}

private void uploadStatistics() {
try (InputStream is = FileLocator.openStream(FrameworkUtil.getBundle(getClass()),
new Path("resources/config.properties"), false)) {
Properties prop = new Properties();
prop.load(is);
host = prop.getProperty("host");
try {
port = Integer.parseInt(prop.getProperty("port"));
} catch (Exception e) {
;
}
} catch (IOException e1) {
;
}

try (DatagramSocket socket = new DatagramSocket()) {
if (port != null) {
DatagramPacket packet = new DatagramPacket(new Gson().toJson(info).getBytes(),
new Gson().toJson(info).getBytes().length,
Inet4Address.getByName(host), port);
socket.send(packet);
}
} catch (IOException e) {
;
}
}

@Override
public void run() {
uploadStatistics();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package org.codechecker.eclipse.plugin.usage;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Properties;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IContributor;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.annotation.Nullable;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;

public class UsageInfo {
private static final String UNKNOWN = "unknown";
private static final String UNKNOWN_VER = "unknown version";

@SuppressWarnings("unused")
private String machine = UNKNOWN;
@SuppressWarnings("unused")
private String hostname = UNKNOWN;
//@SuppressWarnings("unused")
//private String clangsa = UNKNOWN;
@SuppressWarnings("unused")
private String version = UNKNOWN_VER;
// TODO make this parameter dynamic, from build parameters.
@SuppressWarnings("unused")
private String pluginVersion = UNKNOWN_VER;
@SuppressWarnings("unused")
private String user = UNKNOWN;
@SuppressWarnings("unused")
private CommandType command_type;
//@SuppressWarnings("unused")
//private String clang_tidy = UNKNOWN;


public UsageInfo(CommandType ct, @Nullable String ccVersion) {
StringBuilder tempos = new StringBuilder(System.getProperty("os.name"));
tempos.append(" ").append(System.getProperty("os.version"));
tempos.append(" ").append("/ Eclipse ").append(getEclipseVersion());
machine = tempos.toString();
try {
hostname = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ex) {
;
}
if (ccVersion != null)
version = ccVersion;
setPluginVersion();
user = System.getProperty("user.name");
command_type = ct;
}

/**
* Used for returning the eclipse version number. From:
* https://stackoverflow.com/a/28855362/8149485
*
* @return The eclipse version number in 1.2.3.v19700101-0000 format.
*/
private String getEclipseVersion() {
String version = UNKNOWN_VER;
String product = System.getProperty("eclipse.product");
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint point = registry.getExtensionPoint("org.eclipse.core.runtime.products");
if (point != null) {
IExtension[] extensions = point.getExtensions();
for (IExtension ext : extensions)
if (product.equals(ext.getUniqueIdentifier())) {
IContributor contributor = ext.getContributor();
if (contributor != null) {
Bundle bundle = Platform.getBundle(contributor.getName());
if (bundle != null)
version = bundle.getVersion().toString();
}
}
}
return version;
}

private void setPluginVersion() {
try (InputStream is = FileLocator.openStream(FrameworkUtil.getBundle(getClass()),
new Path("resources/config.properties"), false)) {
Properties prop = new Properties();
prop.load(is);
pluginVersion = prop.getProperty("version");
} catch (IOException e1) {
e1.printStackTrace();
}
}

public enum CommandType {
started, analyze_started
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Usage logging.
*/
package org.codechecker.eclipse.plugin.usage;

0 comments on commit e8cc09f

Please sign in to comment.