-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
217 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ bin.includes = plugin.xml,\ | |
.,\ | ||
icons/,\ | ||
contexts.xml,\ | ||
log4j.properties | ||
log4j.properties,\ | ||
resources/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
3 changes: 3 additions & 0 deletions
3
bundles/org.codechecker.eclipse.plugin/resources/config.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
host=${host.log} | ||
port=${port.log} | ||
version=${plugin.version} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...odechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/usage/StatisticUploader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
100 changes: 100 additions & 0 deletions
100
...es/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/usage/UsageInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/usage/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Usage logging. | ||
*/ | ||
package org.codechecker.eclipse.plugin.usage; |