Author: adietish
Date: 2010-09-30 13:10:05 -0400 (Thu, 30 Sep 2010)
New Revision: 25348
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/LinuxSystem.java
Removed:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/CurrentLinuxDistro.java
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/AbstractEclipseEnvironment.java
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/LinuxDistroTest.java
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/fakes/LinuxDistroFake.java
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/fakes/ReportingEclipseEnvironmentFake.java
Log:
[JBIDE-7208] refactored
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/AbstractEclipseEnvironment.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/AbstractEclipseEnvironment.java 2010-09-30
16:29:25 UTC (rev 25347)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/AbstractEclipseEnvironment.java 2010-09-30
17:10:05 UTC (rev 25348)
@@ -180,7 +180,7 @@
}
protected String getLinuxDistroNameAndVersion() {
- return CurrentLinuxDistro.getNameAndVersion();
+ return LinuxSystem.getDistroNameAndVersion();
}
}
Deleted:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/CurrentLinuxDistro.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/CurrentLinuxDistro.java 2010-09-30
16:29:25 UTC (rev 25347)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/CurrentLinuxDistro.java 2010-09-30
17:10:05 UTC (rev 25348)
@@ -1,127 +0,0 @@
-/*******************************************************************************
- * 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.tools.usage.googleanalytics.eclipse;
-
-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;
-
-public class CurrentLinuxDistro {
-
- public static final LinuxDistro DEBIAN = new LinuxDistro("Debian",
"/etc/debian_version");
- public static final LinuxDistro FEDORA = new LinuxDistro("Fedora",
"/etc/fedora-release");
- public static final LinuxDistro GENTOO = new LinuxDistro("Gentoo",
"/etc/gentoo-release");
- public static final LinuxDistro KNOPPIX = new LinuxDistro("Knoppix",
"knoppix_version");
- public static final LinuxDistro MANDRAKE = new LinuxDistro("Mandrake",
"/etc/mandrake-release");
- public static final LinuxDistro MANDRIVA = new LinuxDistro("Mandriva",
"/etc/mandriva-release");
- public static final LinuxDistro PLD = new LinuxDistro("PLD",
"/etc/pld-release");
- public static final LinuxDistro REDHAT = new LinuxDistro("RedHat",
"/etc/redhat-release");
- public static final LinuxDistro SLACKWARE = new LinuxDistro("Slackware",
"/etc/slackware-version");
- public static final LinuxDistro SUSE = new LinuxDistro("SUSE",
"/etc/SuSE-release");
- public static final LinuxDistro UBUNTU = new LinuxDistro("Ubuntu",
"/etc/lsb-release");
- public static final LinuxDistro YELLOWDOG = new LinuxDistro("YellowDog",
"/etc/yellowdog-release");
-
- private static final LinuxDistro[] ALL = new LinuxDistro[] {
- DEBIAN,
- FEDORA,
- GENTOO,
- KNOPPIX,
- MANDRAKE,
- MANDRIVA,
- PLD,
- REDHAT,
- SLACKWARE,
- SUSE,
- UBUNTU,
- YELLOWDOG
- };
-
- public static LinuxDistro getDistro() {
- for (LinuxDistro distro : ALL) {
- if (distro.currentSysIsDistro()) {
- return distro;
- }
- }
- return null;
-
- }
-
- public static String getNameAndVersion() {
- LinuxDistro distro = getDistro();
- if (distro != null) {
- return distro.getNameAndVersion();
- } else {
- return "";
- }
- }
-
- public static class LinuxDistro {
-
- /**
- * The pattern to match the contents of the release-file -
- * /etc/fedora-release etc. Attention: Ubuntu has multi-line release
- * file
- *
- * @see <a
- *
href="http://superuser.com/questions/11008/how-do-i-find-out-what-ve...
- * strings</a>
- */
- private final Pattern VERSION_REGEX = Pattern.compile("([0-9.]+)");
-
- private final String releaseFilePath;
- private String name;
-
- protected LinuxDistro(String name, String releaseFilePath) {
- this.name = name;
- this.releaseFilePath = releaseFilePath;
- }
-
- private boolean currentSysIsDistro() {
- return new File(releaseFilePath).exists();
- }
-
- public String getName() {
- return name;
- }
-
- public String getVersion() {
- try {
- String distroString = getDistroFileContent(releaseFilePath);
- 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(getVersion()).toString();
- }
-
- 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();
- }
- }
-}
Copied:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/LinuxSystem.java
(from rev 25340,
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/CurrentLinuxDistro.java)
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/LinuxSystem.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/LinuxSystem.java 2010-09-30
17:10:05 UTC (rev 25348)
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * 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.tools.usage.googleanalytics.eclipse;
+
+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;
+
+public class LinuxSystem {
+
+ public static final LinuxDistro DEBIAN = new LinuxDistro("Debian",
"/etc/debian_version");
+ public static final LinuxDistro FEDORA = new LinuxDistro("Fedora",
"/etc/fedora-release");
+ public static final LinuxDistro GENTOO = new LinuxDistro("Gentoo",
"/etc/gentoo-release");
+ public static final LinuxDistro KNOPPIX = new LinuxDistro("Knoppix",
"knoppix_version");
+ public static final LinuxDistro MANDRAKE = new LinuxDistro("Mandrake",
"/etc/mandrake-release");
+ public static final LinuxDistro MANDRIVA = new LinuxDistro("Mandriva",
"/etc/mandriva-release");
+ public static final LinuxDistro PLD = new LinuxDistro("PLD",
"/etc/pld-release");
+ public static final LinuxDistro REDHAT = new LinuxDistro("RedHat",
"/etc/redhat-release");
+ public static final LinuxDistro SLACKWARE = new LinuxDistro("Slackware",
"/etc/slackware-version");
+ public static final LinuxDistro SUSE = new LinuxDistro("SUSE",
"/etc/SuSE-release");
+ public static final LinuxDistro UBUNTU = new LinuxDistro("Ubuntu",
"/etc/lsb-release");
+ public static final LinuxDistro YELLOWDOG = new LinuxDistro("YellowDog",
"/etc/yellowdog-release");
+
+ private static final LinuxDistro[] ALL = new LinuxDistro[] {
+ DEBIAN,
+ FEDORA,
+ GENTOO,
+ KNOPPIX,
+ MANDRAKE,
+ MANDRIVA,
+ PLD,
+ REDHAT,
+ SLACKWARE,
+ SUSE,
+ UBUNTU,
+ YELLOWDOG
+ };
+
+ public static LinuxDistro getDistro() {
+ for (LinuxDistro distro : ALL) {
+ if (distro.currentSysIsDistro()) {
+ return distro;
+ }
+ }
+ return null;
+
+ }
+
+ public static String getDistroNameAndVersion() {
+ LinuxDistro distro = getDistro();
+ if (distro != null) {
+ return distro.getNameAndVersion();
+ } else {
+ return "";
+ }
+ }
+
+ public static class LinuxDistro {
+
+ /**
+ * The pattern to match the contents of the release-file -
+ * /etc/fedora-release etc. Attention: Ubuntu has multi-line release
+ * file
+ *
+ * @see <a
+ *
href="http://superuser.com/questions/11008/how-do-i-find-out-what-ve...
+ * strings</a>
+ */
+ private final Pattern VERSION_REGEX = Pattern.compile("([0-9.]+)");
+
+ private final String releaseFilePath;
+ private String name;
+
+ protected LinuxDistro(String name, String releaseFilePath) {
+ this.name = name;
+ this.releaseFilePath = releaseFilePath;
+ }
+
+ private boolean currentSysIsDistro() {
+ return new File(releaseFilePath).exists();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getVersion() {
+ try {
+ String distroString = getDistroFileContent(releaseFilePath);
+ 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(getVersion()).toString();
+ }
+
+ 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();
+ }
+ }
+}
Property changes on:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/LinuxSystem.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/LinuxDistroTest.java
===================================================================
---
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/LinuxDistroTest.java 2010-09-30
16:29:25 UTC (rev 25347)
+++
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/LinuxDistroTest.java 2010-09-30
17:10:05 UTC (rev 25348)
@@ -11,8 +11,8 @@
import static org.junit.Assert.assertEquals;
-import org.jboss.tools.usage.googleanalytics.eclipse.CurrentLinuxDistro;
-import org.jboss.tools.usage.googleanalytics.eclipse.CurrentLinuxDistro.LinuxDistro;
+import org.jboss.tools.usage.googleanalytics.eclipse.LinuxSystem;
+import org.jboss.tools.usage.googleanalytics.eclipse.LinuxSystem.LinuxDistro;
import org.jboss.tools.usage.test.fakes.LinuxDistroFake;
import org.junit.Test;
@@ -20,27 +20,27 @@
@Test
public void canExtractFedoraVersion() {
- LinuxDistro distro = new LinuxDistroFake(CurrentLinuxDistro.FEDORA.getName(),
"Fedora release 13 (Goddard)");
+ LinuxDistro distro = new LinuxDistroFake(LinuxSystem.FEDORA.getName(), "Fedora
release 13 (Goddard)");
assertEquals("13", distro.getVersion());
}
@Test
public void canExtractUbuntuVersion() {
- LinuxDistro distro = new LinuxDistroFake(CurrentLinuxDistro.UBUNTU.getName(),
+ LinuxDistro distro = new LinuxDistroFake(LinuxSystem.UBUNTU.getName(),
"DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=9.04\nDISTRIB_CODENAME=jaunty\nDISTRIB_DESCRIPTION=\"Ubuntu
9.04\"");
assertEquals("Ubuntu9.04", distro.getNameAndVersion());
}
@Test
public void canExtractRedHatVersion() {
- LinuxDistro distro = new LinuxDistroFake(CurrentLinuxDistro.REDHAT.getName(),
+ LinuxDistro distro = new LinuxDistroFake(LinuxSystem.REDHAT.getName(),
"Red Hat Enterprise Linux Workstation release 6.0 (Santiago)");
assertEquals("RedHat6.0", distro.getNameAndVersion());
}
@Test
public void canExtractGentooVersion() {
- LinuxDistro distro = new LinuxDistroFake(CurrentLinuxDistro.GENTOO.getName(),
+ LinuxDistro distro = new LinuxDistroFake(LinuxSystem.GENTOO.getName(),
"Gentoo Base System release 2.0.1");
assertEquals("Gentoo2.0.1", distro.getNameAndVersion());
}
Modified:
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/fakes/LinuxDistroFake.java
===================================================================
---
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/fakes/LinuxDistroFake.java 2010-09-30
16:29:25 UTC (rev 25347)
+++
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/fakes/LinuxDistroFake.java 2010-09-30
17:10:05 UTC (rev 25348)
@@ -11,7 +11,7 @@
import java.io.IOException;
-import org.jboss.tools.usage.googleanalytics.eclipse.CurrentLinuxDistro.LinuxDistro;
+import org.jboss.tools.usage.googleanalytics.eclipse.LinuxSystem.LinuxDistro;
public class LinuxDistroFake extends LinuxDistro {
Modified:
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/fakes/ReportingEclipseEnvironmentFake.java
===================================================================
---
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/fakes/ReportingEclipseEnvironmentFake.java 2010-09-30
16:29:25 UTC (rev 25347)
+++
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/fakes/ReportingEclipseEnvironmentFake.java 2010-09-30
17:10:05 UTC (rev 25348)
@@ -11,7 +11,7 @@
package org.jboss.tools.usage.test.fakes;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.jboss.tools.usage.googleanalytics.eclipse.CurrentLinuxDistro;
+import org.jboss.tools.usage.googleanalytics.eclipse.LinuxSystem;
import org.jboss.tools.usage.googleanalytics.eclipse.IEclipseUserAgent;
import org.jboss.tools.usage.internal.reporting.JBossToolsEclipseEnvironment;
@@ -70,6 +70,6 @@
@Override
protected String getLinuxDistroNameAndVersion() {
- return new LinuxDistroFake(CurrentLinuxDistro.FEDORA.getName(), "Fedora release 13
(Goddard)").getNameAndVersion();
+ return new LinuxDistroFake(LinuxSystem.FEDORA.getName(), "Fedora release 13
(Goddard)").getNameAndVersion();
}
}