Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

FORGE-224: Added Tracking APIs #208

Merged
merged 1 commit into from

2 participants

@gastaldi
Owner

Added Google Analytics support. Don't push this until reviewed

@lincolnthree lincolnthree was assigned
@gastaldi gastaldi was assigned
...a/org/jboss/forge/tracking/GoogleAnalyticsPlugin.java
((58 lines not shown))
+ "UA-34467975-2");
+
+ public void onStartup(@Observes PostStartup startup)
+ {
+ Boolean enabled = configuration.getBoolean(ANALYTICS_ENABLED, null);
+ if (enabled == null)
+ {
+ if (Boolean.getBoolean("forge.analytics.no_prompt"))
+ {
+ enabled = Boolean.FALSE;
+ }
+ else
+ {
+ enabled = shell
+ .promptBoolean(
+ "Will you allow Forge team to receive anonymous usage statistics for this Forge installation ?",
@lincolnthree Owner

"Will you allow the Forge team to receive anonymous usage statistics for this instance of JBoss Forge?"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@lincolnthree lincolnthree commented on the diff
...a/org/jboss/forge/tracking/GoogleAnalyticsPlugin.java
((112 lines not shown))
+
+ /**
+ * Returns whether analytics is enabled or not
+ *
+ * @return
+ */
+ boolean isEnabled()
+ {
+ return configuration.getBoolean(ANALYTICS_ENABLED, Boolean.FALSE);
+ }
+
+ /**
+ * Display info about the analytics usage
+ */
+ @Command("info")
+ public void displayInfo()
@lincolnthree Owner

This needs to print out all of the information that is being sent, like this: http://www.jboss.org/dms/tools/images/usage-reporting-preferences.png - this can just be printed to the console as a key-value pair.


Forge Version: 1.1.0.Final
Operating system: Windows
Java Version: 1.6.0_32_b12
Plugins installed: X, Y, Z

@gastaldi Owner

Done. Now I just need to fit all this info in the Analytics API. Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@gastaldi
Owner

It should be ok now. @lincolnthree: could you review it again ? Thanks

@gastaldi gastaldi merged commit b713a9b into forge:master
@gastaldi gastaldi deleted the gastaldi:tracking branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 7, 2013
  1. @gastaldi
This page is out of date. Refresh to see the latest.
View
2  .gitignore
@@ -8,7 +8,7 @@ target/
*.ipr
*.iws
/*/src/main/java/META-INF
-.gitignore.swp
+*.swp
docs/reference/src/main/docbook/en-US/version_info.xml
.idea
.forge_settings
View
21 dist/build.xml
@@ -216,7 +216,7 @@
<module-def name="org.apache.commons.codec">
<maven-resource group="commons-codec" artifact="commons-codec" />
</module-def>
-
+
<module-def name="org.apache.commons.logging" />
<module-def name="org.apache.httpcomponents">
@@ -248,7 +248,7 @@
<!-- BEGIN Forge Modules -->
<module-def name="org.jboss.forge">
<maven-resource group="org.jboss.forge" artifact="forge-shell" />
-
+
<!-- TODO make this a separate auto-install plugin -->
<maven-resource group="org.jboss.forge" artifact="forge-dev-plugins" />
</module-def>
@@ -257,7 +257,7 @@
<maven-resource group="org.jboss.forge" artifact="forge-event-bus" />
</module-def>
- <!-- TODO this needs to be an extension, not built in (consider
+ <!-- TODO this needs to be an extension, not built in (consider
dynamically providing extensions to the system via custom module loader) -->
<module-def name="org.jboss.forge.javaee.api">
<maven-resource group="org.jboss.forge" artifact="forge-javaee-api" />
@@ -275,7 +275,7 @@
<module-def name="org.jboss.forge.maven.api">
<maven-resource group="org.jboss.forge" artifact="forge-maven-api" />
-
+
<!-- TODO this needs to be pulled into a module -->
<maven-resource group="commons-cli" artifact="commons-cli" />
<maven-resource group="org.apache.maven" artifact="maven-aether-provider" />
@@ -328,11 +328,11 @@
<module-def name="org.jboss.forge.parser.xml">
<maven-resource group="org.jboss.forge" artifact="forge-parser-xml" />
</module-def>
-
+
<module-def name="org.jboss.forge.scaffold.api">
<maven-resource group="org.jboss.forge" artifact="forge-scaffold-api" />
</module-def>
-
+
<module-def name="org.jboss.forge.scaffold.impl">
<maven-resource group="org.jboss.forge" artifact="forge-scaffold-plugins" />
<maven-resource group="org.jboss.forge" artifact="forge-scaffold-faces" />
@@ -342,6 +342,10 @@
<module-def name="org.jboss.forge.shell.api">
<maven-resource group="org.jboss.forge" artifact="forge-shell-api" />
</module-def>
+
+ <module-def name="org.jboss.forge.tracking">
+ <maven-resource group="org.jboss.forge" artifact="forge-tracking" />
+ </module-def>
<!-- END Forge Modules -->
<module-def name="org.jboss.interceptor">
@@ -355,7 +359,7 @@
<module-def name="javax.interceptor.api">
<maven-resource group="org.jboss.spec.javax.interceptor" artifact="jboss-interceptors-api_1.1_spec" />
</module-def>
-
+
<module-def name="org.jboss.logging">
<maven-resource group="org.jboss.logging" artifact="jboss-logging"/>
</module-def>
@@ -423,6 +427,9 @@
<module-def name="sun.misc" />
+ <module-def name="com.dmurph.JGoogleAnalyticsTracker">
+ <maven-resource group="com.dmurph" artifact="JGoogleAnalyticsTracker" />
+ </module-def>
</target>
<target name="bundles">
View
5 dist/pom.xml
@@ -220,6 +220,11 @@
</dependency>
<dependency>
+ <groupId>org.jboss.forge</groupId>
+ <artifactId>forge-tracking</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.jboss.interceptor</groupId>
<artifactId>jboss-interceptor-core</artifactId>
</dependency>
View
19 dist/src/main/resources/modules/com/dmurph/JGoogleAnalyticsTracker/main/module.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ ~
+ ~ Licensed under the Eclipse Public License version 1.0, available at
+ ~ http://www.eclipse.org/legal/epl-v10.html
+-->
+
+<module xmlns="urn:jboss:module:1.0" name="com.dmurph.JGoogleAnalyticsTracker">
+ <resources>
+ <!-- Insert resources here -->
+ </resources>
+
+ <dependencies>
+ <module name="org.slf4j" />
+ <module name="javax.api"/>
+ </dependencies>
+</module>
View
17 dist/src/main/resources/modules/org/jboss/forge/main/module.xml
@@ -17,7 +17,7 @@
<dependencies>
<module name="com.sun.xml.bind" />
-
+
<module name="javax.annotation.api" />
<module name="javax.interceptor.api" />
<module name="jline" />
@@ -109,14 +109,21 @@
<include path="META-INF" />
</imports>
</module>
-
+
+ <module name="org.jboss.forge.tracking" services="import">
+ <imports>
+ <include path="**" />
+ <include path="META-INF" />
+ </imports>
+ </module>
+
<module name="org.jboss.seam.render" services="import">
<imports>
<include path="**" />
<include path="META-INF" />
</imports>
</module>
-
+
<module name="org.jboss.solder" services="import">
<imports>
<include path="**" />
@@ -131,7 +138,7 @@
<include path="META-INF" />
</imports>
</module>
-
+
<module name="org.jboss.weld.core" services="import" />
<module name="org.jboss.weld.spi" services="import" />
<module name="org.jboss.weld.api" services="import" />
@@ -140,7 +147,7 @@
<module name="org.yaml" />
<module name="sun.jdk" />
<module name="sun.misc" />
-
+
<module name="javax.api" />
</dependencies>
View
28 dist/src/main/resources/modules/org/jboss/forge/tracking/main/module.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ ~
+ ~ Licensed under the Eclipse Public License version 1.0, available at
+ ~ http://www.eclipse.org/legal/epl-v10.html
+-->
+
+<module xmlns="urn:jboss:module:1.0" name="org.jboss.forge.tracking">
+
+ <resources>
+ <!-- Insert resources here -->
+ </resources>
+
+ <dependencies>
+ <module name="org.jboss.forge.shell.api" services="import">
+ <imports>
+ <include path="**" />
+ <include path="META-INF" />
+ </imports>
+ </module>
+
+ <module name="com.dmurph.JGoogleAnalyticsTracker" />
+ <module name="javax.api" />
+ </dependencies>
+
+</module>
View
8 pom.xml
@@ -340,6 +340,12 @@
</dependency>
<dependency>
+ <groupId>org.jboss.forge</groupId>
+ <artifactId>forge-tracking</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit.pgm</artifactId>
<version>${jgit.version}</version>
@@ -857,6 +863,7 @@
<module>scaffold-faces</module>
<module>dev-plugins</module>
<module>plugin-loader</module>
+ <module>tracking</module>
<module>dist</module>
</modules>
</profile>
@@ -887,5 +894,4 @@
<developerConnection>${forge.developer.connection}</developerConnection>
<url>${forge.scm.url}</url>
</scm>
-
</project>
View
1  test-harness/src/main/java/org/jboss/forge/test/AbstractShellTest.java
@@ -52,6 +52,7 @@
static
{
System.setProperty("forge.debug.no_auto_init_streams", "true");
+ System.setProperty("forge.analytics.no_prompt", "true");
}
@Deployment
View
3  test-harness/src/main/java/org/jboss/forge/test/SingletonAbstractShellTest.java
@@ -51,8 +51,9 @@
static
{
System.setProperty("forge.debug.no_auto_init_streams", "true");
+ System.setProperty("forge.analytics.no_prompt", "true");
}
-
+
@Deployment
public static JavaArchive getDeployment()
{
View
26 tracking/pom.xml
@@ -0,0 +1,26 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jboss.forge</groupId>
+ <artifactId>forge-parent</artifactId>
+ <version>1.1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>forge-tracking</artifactId>
+ <name>Forge - Tracking</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.forge</groupId>
+ <artifactId>forge-shell-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.dmurph</groupId>
+ <artifactId>JGoogleAnalyticsTracker</artifactId>
+ <version>1.2.0</version>
+ </dependency>
+ </dependencies>
+
+</project>
View
245 tracking/src/main/java/org/jboss/forge/tracking/GoogleAnalyticsPlugin.java
@@ -0,0 +1,245 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.tracking;
+
+import java.io.InputStream;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.enterprise.event.Observes;
+import javax.inject.Inject;
+
+import org.jboss.forge.ForgeEnvironment;
+import org.jboss.forge.env.Configuration;
+import org.jboss.forge.parser.xml.Node;
+import org.jboss.forge.parser.xml.XMLParser;
+import org.jboss.forge.resources.Resource;
+import org.jboss.forge.shell.Shell;
+import org.jboss.forge.shell.ShellColor;
+import org.jboss.forge.shell.events.PostStartup;
+import org.jboss.forge.shell.plugins.Alias;
+import org.jboss.forge.shell.plugins.Command;
+import org.jboss.forge.shell.plugins.DefaultCommand;
+import org.jboss.forge.shell.plugins.Option;
+import org.jboss.forge.shell.plugins.Plugin;
+import org.jboss.forge.shell.util.OSUtils;
+import org.jboss.forge.shell.util.Streams;
+
+import com.dmurph.tracking.AnalyticsConfigData;
+import com.dmurph.tracking.JGoogleAnalyticsTracker;
+import com.dmurph.tracking.JGoogleAnalyticsTracker.GoogleAnalyticsVersion;
+
+@Alias("analytics")
+public class GoogleAnalyticsPlugin implements Plugin
+{
+ private static final String ANALYTICS_ENABLED = "forge.analytics.enabled";
+ private static final String ANALYTICS_LAST_RUN = "forge.analytics.lastrun";
+
+ private static final String ANALYTICS_DATE_MASK = "yyyyMMdd";
+
+ public static final String VALUE_NO_REFERRAL = "0";
+
+ @Inject
+ private Configuration configuration;
+
+ @Inject
+ private Shell shell;
+
+ @Inject
+ private ForgeEnvironment environment;
+
+ private JGoogleAnalyticsTracker analyticsTracker;
+
+ /**
+ * Google Analytics key used for tracking Forge installations
+ */
+ private static final String FORGE_GOOGLE_ANALYTICS_KEY = System.getProperty("forge.google_analytics.key",
+ "UA-34467975-2");
+
+ public void onStartup(@Observes PostStartup startup)
+ {
+ Boolean enabled = configuration.getBoolean(ANALYTICS_ENABLED, null);
+ if (enabled == null)
+ {
+ if (Boolean.getBoolean("forge.analytics.no_prompt"))
+ {
+ enabled = Boolean.FALSE;
+ }
+ else
+ {
+ enabled = shell
+ .promptBoolean(
+ "Will you allow the Forge team to receive anonymous usage statistics for this instance of JBoss Forge?",
+ true);
+ }
+ configuration.setProperty(ANALYTICS_ENABLED, enabled);
+ }
+ setEnabled(enabled);
+ if (enabled && isAllowedToRun())
+ {
+ sendInfoToAnalytics();
+ }
+ }
+
+ /**
+ *
+ * @return
+ */
+ boolean isAllowedToRun()
+ {
+ boolean ret = true;
+ String lastRunDate = configuration.getString(ANALYTICS_LAST_RUN, null);
+ if (lastRunDate != null)
+ {
+ SimpleDateFormat sdf = new SimpleDateFormat(ANALYTICS_DATE_MASK);
+ String now = sdf.format(new Date());
+ ret = !now.equals(lastRunDate);
+ }
+ return ret;
+ }
+
+ @DefaultCommand
+ public void setEnabled(@Option(name = "enabled", required = true) Boolean enabled)
+ {
+ configuration.setProperty(ANALYTICS_ENABLED, enabled);
+ getAnalyticsTracker().setEnabled(enabled);
+ }
+
+ /**
+ * Returns whether analytics is enabled or not
+ *
+ * @return
+ */
+ boolean isEnabled()
+ {
+ return configuration.getBoolean(ANALYTICS_ENABLED, Boolean.FALSE);
+ }
+
+ /**
+ * Display info about the analytics usage
+ */
+ @Command("info")
+ public void displayInfo()
@lincolnthree Owner

This needs to print out all of the information that is being sent, like this: http://www.jboss.org/dms/tools/images/usage-reporting-preferences.png - this can just be printed to the console as a key-value pair.


Forge Version: 1.1.0.Final
Operating system: Windows
Java Version: 1.6.0_32_b12
Plugins installed: X, Y, Z

@gastaldi Owner

Done. Now I just need to fit all this info in the Analytics API. Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ {
+ shell.print("Analytics is: ");
+ shell.println(ShellColor.BOLD, isEnabled() ? "enabled" : "disabled");
+ Date lastRunDate = getLastRunDate();
+ if (lastRunDate != null)
+ {
+ DateFormat dateInstance = DateFormat.getDateInstance(DateFormat.LONG);
+ shell.print("Analytics was last run at: ");
+ shell.println(ShellColor.BOLD, dateInstance.format(lastRunDate));
+ }
+ shell.print("Forge Version: ");
+ shell.println(ShellColor.BOLD, getForgeVersion());
+
+ shell.print("Operating System: ");
+ shell.println(ShellColor.BOLD, getOS());
+
+ shell.print("Java Version: ");
+ shell.println(ShellColor.BOLD, getJavaVersion());
+
+ shell.print("Installed Plugins: ");
+ shell.println(ShellColor.BOLD, getInstalledPlugins().toString());
+ }
+
+ private Date getLastRunDate()
+ {
+ Date date = null;
+ String lastRunDate = configuration.getString(ANALYTICS_LAST_RUN, null);
+ if (lastRunDate != null)
+ {
+ SimpleDateFormat sdf = new SimpleDateFormat(ANALYTICS_DATE_MASK);
+ try
+ {
+ return sdf.parse(lastRunDate);
+ }
+ catch (ParseException e)
+ {
+ return null;
+ }
+ }
+ return date;
+ }
+
+ private void setLastRunDate(Date date)
+ {
+ SimpleDateFormat sdf = new SimpleDateFormat(ANALYTICS_DATE_MASK);
+ configuration.setProperty(ANALYTICS_LAST_RUN, sdf.format(date));
+ }
+
+ private JGoogleAnalyticsTracker getAnalyticsTracker()
+ {
+ if (analyticsTracker == null)
+ {
+ AnalyticsConfigData config = new AnalyticsConfigData(FORGE_GOOGLE_ANALYTICS_KEY);
+ config.setFlashVersion(getJavaVersion());
+ analyticsTracker = new JGoogleAnalyticsTracker(config, GoogleAnalyticsVersion.V_4_7_2);
+ }
+ return analyticsTracker;
+ }
+
+ /**
+ * Sends the current data to Google Analytics
+ */
+ private void sendInfoToAnalytics()
+ {
+ getAnalyticsTracker().trackPageView(getOS(), getForgeVersion(), "");
+ for (String plugin : getInstalledPlugins())
+ {
+ getAnalyticsTracker().trackEvent("plugin", plugin);
+ }
+ setLastRunDate(new Date());
+ }
+
+ private String getOS()
+ {
+ if (OSUtils.isLinux())
+ {
+ return LinuxSystem.INSTANCE.getDistroNameAndVersion();
+ }
+ return OSUtils.getOsName();
+ }
+
+ private String getForgeVersion()
+ {
+ return environment.getRuntimeVersion();
+ }
+
+ private String getJavaVersion()
+ {
+ return System.getProperty("java.version");
+ }
+
+ private List<String> getInstalledPlugins()
+ {
+ List<String> plugins = new ArrayList<String>();
+ Resource<?> registry = environment.getPluginDirectory().getChild("installed.xml");
+ InputStream is = null;
+ if (registry.exists())
+ {
+ try
+ {
+ is = registry.getResourceInputStream();
+ for (Node plugin : XMLParser.parse(is).get("plugin"))
+ {
+ plugins.add(plugin.getAttribute("name"));
+ }
+ }
+ finally
+ {
+ Streams.closeQuietly(is);
+ }
+ }
+ return plugins;
+ }
+}
View
210 tracking/src/main/java/org/jboss/forge/tracking/LinuxSystem.java
@@ -0,0 +1,210 @@
+/*******************************************************************************
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.forge.tracking;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author André Dietisheim
+ */
+public class LinuxSystem
+{
+
+ public static final LinuxSystem INSTANCE = new LinuxSystem();
+
+ /**
+ * @see <a href="http://linuxmafia.com/faq/Admin/release-files.html"> an extensive list of release file locations</a>
+ *
+ * @see <a href="http://superuser.com/questions/11008/how-do-i-find-out-what-version-of-linux-im-running">
+ * release-file strings</a>
+ */
+ public final LinuxDistro CENTOS = new ReleaseFileContentCheckedDistro("CentOS", "/etc/redhat-release");
+ public final LinuxDistro DEBIAN = new LinuxDistro("Debian", "/etc/debian_version");
+ public final LinuxDistro FEDORA = new LinuxDistro("Fedora", "/etc/fedora-release");
+ public final LinuxDistro GENTOO = new LinuxDistro("Gentoo", "/etc/gentoo-release");
+ public final LinuxDistro YELLOWDOG = new LinuxDistro("YellowDog", "/etc/yellowdog-release");
+ public final LinuxDistro KNOPPIX = new LinuxDistro("Knoppix", "knoppix_version");
+ public final LinuxDistro MANDRAKE = new LinuxDistro("Mandrake", "/etc/mandrake-release");
+ public final LinuxDistro MANDRIVA = new LinuxDistro("Mandriva", "/etc/mandriva-release");
+ public final LinuxDistro MINT = new ReleaseFileContentCheckedDistro("LinuxMint", "/etc/lsb-release");
+ public final LinuxDistro PLD = new LinuxDistro("PLD", "/etc/pld-release");
+ public final LinuxDistro REDHAT = new ReleaseFileContentCheckedDistro("Red Hat", "/etc/redhat-release");
+ public final LinuxDistro SLACKWARE = new LinuxDistro("Slackware", "/etc/slackware-version");
+ public final LinuxDistro SUSE = new LinuxDistro("SUSE", "/etc/SuSE-release");
+ public final LinuxDistro UBUNTU = new ReleaseFileContentCheckedDistro("Ubuntu", "/etc/lsb-release");
+
+ private final LinuxDistro[] ALL = new LinuxDistro[] {
+ CENTOS,
+ MINT,
+ UBUNTU,
+ DEBIAN,
+ FEDORA,
+ GENTOO,
+ KNOPPIX,
+ MANDRAKE,
+ MANDRIVA,
+ PLD,
+ REDHAT,
+ SLACKWARE,
+ SUSE,
+ YELLOWDOG
+ };
+
+ public LinuxDistro getDistro()
+ {
+ for (LinuxDistro distro : ALL)
+ {
+ if (distro.isDistro())
+ {
+ return distro;
+ }
+ }
+ return null;
+
+ }
+
+ public String getDistroNameAndVersion()
+ {
+ LinuxDistro distro = getDistro();
+ if (distro != null)
+ {
+ return distro.getNameAndVersion();
+ }
+ else
+ {
+ return "Unknown";
+ }
+ }
+
+ protected boolean exists(String releaseFilePath)
+ {
+ return releaseFilePath != null
+ && releaseFilePath.length() > 0
+ && new File(releaseFilePath).exists();
+ }
+
+ protected String getDistroFileContent(String filePath) throws IOException
+ {
+ int charachtersToRead = 1024;
+ StringBuilder builder = new StringBuilder(charachtersToRead);
+ BufferedReader reader = new BufferedReader(new FileReader(filePath));
+ char[] buf = new char[charachtersToRead];
+ int charRead = 0;
+ while ((charRead = reader.read(buf)) != -1 && builder.length() < charachtersToRead)
+ {
+ String readData = String.valueOf(buf, 0, charRead);
+ builder.append(readData);
+ }
+ reader.close();
+ return builder.toString();
+ }
+
+ public class LinuxDistro
+ {
+
+ /**
+ * The pattern to match the contents of the release-file - /etc/fedora-release etc. Attention: Ubuntu has
+ * multi-line release file
+ */
+ private final Pattern VERSION_REGEX = Pattern.compile("([0-9.]+)");
+
+ protected final String releaseFilePath;
+ private String name;
+
+ protected LinuxDistro(String name, String releaseFilePath)
+ {
+ this.name = name;
+ this.releaseFilePath = releaseFilePath;
+ }
+
+ protected boolean isDistro()
+ {
+ return exists(getReleaseFilePath());
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getVersion()
+ {
+ try
+ {
+ String distroString = getDistroFileContent(getReleaseFilePath());
+ Matcher matcher = VERSION_REGEX.matcher(distroString);
+ if (matcher.find())
+ {
+ return matcher.group(1);
+ }
+ }
+ catch (IOException e)
+ {
+ }
+ return "";
+ }
+
+ public String getNameAndVersion()
+ {
+ return new StringBuilder().append(getName()).append(" ").append(getVersion()).toString();
+ }
+
+ public String getReleaseFilePath()
+ {
+ return releaseFilePath;
+ }
+
+ protected boolean distroFileContains(String value)
+ {
+ try
+ {
+ boolean fileExists = exists(getReleaseFilePath());
+ if (fileExists)
+ {
+ String content = getDistroFileContent(getReleaseFilePath());
+ return content != null && content.indexOf(value) >= 0;
+ }
+ }
+ catch (IOException e)
+ {
+ }
+ return false;
+
+ }
+
+ @Override
+ public String toString()
+ {
+ return name;
+ }
+ }
+
+ /**
+ * A distribution definition that checks for presence of the given distro name in the given release file.
+ */
+ public class ReleaseFileContentCheckedDistro extends LinuxDistro
+ {
+
+ public ReleaseFileContentCheckedDistro(String name, String releaseFilePath)
+ {
+ super(name, releaseFilePath);
+ }
+
+ protected boolean isDistro()
+ {
+ return distroFileContains(getName());
+ }
+ }
+}
View
3  tracking/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd" />
Something went wrong with that request. Please try again.