Skip to content

Commit 85d7621

Browse files
committed
Add anonymous stats usage
Add custom settings page to opt out. Simply capture language used.
1 parent 2c4d023 commit 85d7621

File tree

12 files changed

+860
-349
lines changed

12 files changed

+860
-349
lines changed

src/ServiceStackIDEA/.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ServiceStackIDEA/.idea/workspace.xml

Lines changed: 602 additions & 342 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/AddServiceStackRefHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static void handleOk(String addressUrl, String qualifiedPackageName,
7373
if (!writeDtoFile(javaCodeLines, dtoPath, errorMessage)) {
7474
return;
7575
}
76-
76+
Analytics.SubmitAnonymousAddReferenceUsage(getNativeTypesHandler(fileName));
7777
IDEAUtils.refreshFile(module, dtoPath, showDto);
7878
VirtualFileManager.getInstance().syncRefresh();
7979
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package net.servicestack.idea;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.net.MalformedURLException;
7+
import java.net.URL;
8+
import java.net.URLConnection;
9+
10+
/**
11+
* Created by Layoric on 27/05/2016.
12+
*/
13+
public final class Analytics {
14+
15+
private static String addRefUrl = "https://servicestack.net/stats/addref/record?Name=";
16+
17+
public static void SubmitAnonymousAddReferenceUsage(INativeTypesHandler typesHandler) {
18+
PluginSettingsService settings = PluginSettingsService.getInstance();
19+
if(!settings.optOutOfStats) {
20+
String url = addRefUrl + typesHandler.getTypesLanguage().name();
21+
URL serviceUrl = null;
22+
URLConnection javaResponseConnection = null;
23+
BufferedReader javaResponseReader = null;
24+
try {
25+
serviceUrl = new URL(url);
26+
javaResponseConnection = serviceUrl.openConnection();
27+
javaResponseReader = new BufferedReader(
28+
new InputStreamReader(
29+
javaResponseConnection.getInputStream()));
30+
31+
javaResponseReader.close();
32+
} catch (IOException e) {
33+
// Ignore failure (eg no internet connection).
34+
}
35+
}
36+
}
37+
}

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/BaseNativeTypesHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public abstract class BaseNativeTypesHandler implements INativeTypesHandler {
1919
public List<String> getUpdatedCode(String baseUrl, Map<String, String> options) throws IOException, URISyntaxException {
2020
String url;
2121
List<String> javaCodeLines = new ArrayList<String>();
22-
URIBuilder urlBuilder = this.getUrl(baseUrl,options);
22+
URIBuilder urlBuilder = this.getUrl(baseUrl);
2323
for(Map.Entry<String, String> option : options.entrySet()) {
2424
urlBuilder.addParameter(option.getKey(),option.getValue());
2525
}
@@ -41,7 +41,7 @@ public List<String> getUpdatedCode(String baseUrl, Map<String, String> options)
4141
}
4242

4343
@Override
44-
public URIBuilder getUrl(String baseUrl, Map<String, String> options) throws MalformedURLException, URISyntaxException {
44+
public URIBuilder getUrl(String baseUrl) throws MalformedURLException, URISyntaxException {
4545
String serverUrl = baseUrl.endsWith("/") ? baseUrl : (baseUrl + "/");
4646
serverUrl = (serverUrl.startsWith("http://") || serverUrl.startsWith("https://")) ? serverUrl : ("http://" + serverUrl);
4747
URL url = new URL(serverUrl);

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/INativeTypesHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
public interface INativeTypesHandler {
1515
String getFileExtension();
16-
URIBuilder getUrl(String baseUrl, Map<String,String> options) throws MalformedURLException, URISyntaxException;
16+
URIBuilder getUrl(String baseUrl) throws MalformedURLException, URISyntaxException;
1717
List<String> getUpdatedCode(String baseUrl, Map<String, String> options) throws IOException, URISyntaxException;
1818
String getRelativeTypesUrl();
1919
NativeTypesLanguage getTypesLanguage();
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package net.servicestack.idea;
2+
3+
import com.intellij.application.options.CodeStyleAbstractConfigurable;
4+
import com.intellij.openapi.options.Configurable;
5+
import com.intellij.openapi.options.ConfigurableProvider;
6+
import com.intellij.openapi.options.ConfigurationException;
7+
import com.intellij.openapi.options.SearchableConfigurable;
8+
import com.intellij.util.ui.CheckBox;
9+
import org.jetbrains.annotations.Nls;
10+
import org.jetbrains.annotations.NotNull;
11+
import org.jetbrains.annotations.Nullable;
12+
13+
import javax.swing.*;
14+
15+
/**
16+
* Created by Layoric on 27/05/2016.
17+
*/
18+
public class PluginSettingsConfigurable implements SearchableConfigurable {
19+
20+
private PluginSettingsView view;
21+
22+
private PluginSettingsService settings;
23+
24+
public PluginSettingsConfigurable(@NotNull PluginSettingsService settings) {
25+
this.settings = settings;
26+
}
27+
28+
@NotNull
29+
@Override
30+
public String getId() {
31+
return "Settings.ServiceStackIDEA.Preview";
32+
}
33+
34+
@Nullable
35+
@Override
36+
public Runnable enableSearch(String s) {
37+
return null;
38+
}
39+
40+
@Nls
41+
@Override
42+
public String getDisplayName() {
43+
return "ServiceStackIDEA Settings";
44+
}
45+
46+
@Nullable
47+
@Override
48+
public String getHelpTopic() {
49+
return null;
50+
}
51+
52+
@Nullable
53+
@Override
54+
public JComponent createComponent() {
55+
return getForm();
56+
}
57+
58+
59+
@Override
60+
public boolean isModified() {
61+
return !getForm().getOptOutOfUsage().equals(settings.optOutOfStats);
62+
}
63+
64+
@Override
65+
public void apply() throws ConfigurationException {
66+
if(settings == null)
67+
settings = PluginSettingsService.getInstance();
68+
settings.optOutOfStats = getForm().getOptOutOfUsage();
69+
}
70+
71+
@Override
72+
public void reset() {
73+
if(settings == null)
74+
settings = PluginSettingsService.getInstance();
75+
getForm().setOptOutOfUsage(settings.optOutOfStats);
76+
}
77+
78+
@Override
79+
public void disposeUIResources() {
80+
view = null;
81+
}
82+
83+
@NotNull
84+
public PluginSettingsView getForm() {
85+
if (view == null) {
86+
view = new PluginSettingsView();
87+
}
88+
return view;
89+
}
90+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package net.servicestack.idea;
2+
3+
import com.intellij.openapi.components.*;
4+
import com.intellij.util.xmlb.XmlSerializerUtil;
5+
import org.jetbrains.annotations.Nullable;
6+
7+
/**
8+
* Created by Layoric on 27/05/2016.
9+
*/
10+
@State(name = "PluginSettingsService", storages = @Storage(id = "default", file = StoragePathMacros.APP_CONFIG + "/servicestack-settings.xml"))
11+
public class PluginSettingsService implements PersistentStateComponent<PluginSettingsService> {
12+
public Boolean optOutOfStats = false;
13+
14+
@Nullable
15+
@Override
16+
public PluginSettingsService getState() {
17+
return this;
18+
}
19+
20+
@Override
21+
public void loadState(PluginSettingsService pluginSettingsService) {
22+
XmlSerializerUtil.copyBean(pluginSettingsService, this);
23+
}
24+
25+
public static PluginSettingsService getInstance() {
26+
return ServiceManager.getService( PluginSettingsService.class );
27+
}
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.servicestack.idea.PluginSettingsView">
3+
<grid id="27dc6" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="0" left="0" bottom="0" right="0"/>
5+
<constraints>
6+
<xy x="20" y="20" width="500" height="400"/>
7+
</constraints>
8+
<properties/>
9+
<border type="none"/>
10+
<children>
11+
<component id="c76c5" class="javax.swing.JCheckBox" binding="optOutOfUsageCheckBox" default-binding="true">
12+
<constraints>
13+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
14+
</constraints>
15+
<properties>
16+
<text value="Opt out of usage collection "/>
17+
</properties>
18+
</component>
19+
<vspacer id="32dbe">
20+
<constraints>
21+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
22+
</constraints>
23+
</vspacer>
24+
</children>
25+
</grid>
26+
</form>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package net.servicestack.idea;
2+
3+
import com.intellij.uiDesigner.core.GridConstraints;
4+
import com.intellij.uiDesigner.core.GridLayoutManager;
5+
import com.intellij.uiDesigner.core.Spacer;
6+
7+
import javax.swing.*;
8+
import java.awt.*;
9+
10+
/**
11+
* Created by Layoric on 27/05/2016.
12+
*/
13+
public class PluginSettingsView extends JPanel {
14+
private JCheckBox optOutOfUsageCheckBox;
15+
16+
public Boolean getOptOutOfUsage() {
17+
return optOutOfUsageCheckBox.isSelected();
18+
}
19+
20+
public void setOptOutOfUsage(Boolean value) {
21+
optOutOfUsageCheckBox.setSelected(value);
22+
}
23+
24+
public PluginSettingsView() {
25+
super();
26+
setupUi();
27+
}
28+
29+
private void setupUi() {
30+
this.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
31+
this.optOutOfUsageCheckBox = new JCheckBox();
32+
this.optOutOfUsageCheckBox.setText("Opt out of usage collection ");
33+
this.add(optOutOfUsageCheckBox, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
34+
final Spacer spacer1 = new Spacer();
35+
this.add(spacer1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
36+
}
37+
38+
{
39+
// GUI initializer generated by IntelliJ IDEA GUI Designer
40+
// >>> IMPORTANT!! <<<
41+
// DO NOT EDIT OR ADD ANY CODE HERE!
42+
$$$setupUI$$$();
43+
}
44+
45+
/**
46+
* Method generated by IntelliJ IDEA GUI Designer
47+
* >>> IMPORTANT!! <<<
48+
* DO NOT edit this method OR call it in your code!
49+
*
50+
* @noinspection ALL
51+
*/
52+
private void $$$setupUI$$$() {
53+
final JPanel panel1 = new JPanel();
54+
panel1.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
55+
optOutOfUsageCheckBox = new JCheckBox();
56+
optOutOfUsageCheckBox.setText("Opt out of usage collection ");
57+
panel1.add(optOutOfUsageCheckBox, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
58+
final Spacer spacer1 = new Spacer();
59+
panel1.add(spacer1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
60+
}
61+
}

0 commit comments

Comments
 (0)