Author: adietish
Date: 2012-01-05 13:23:20 -0500 (Thu, 05 Jan 2012)
New Revision: 37660
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/LinuxSystem.java
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/LinuxSystemTest.java
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/fakes/LinuxSystemFake.java
Log:
[JBIDE-10577] added javadoc, corrected tests
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/LinuxSystem.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/LinuxSystem.java 2012-01-05
17:38:00 UTC (rev 37659)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/LinuxSystem.java 2012-01-05
18:23:20 UTC (rev 37660)
@@ -40,32 +40,47 @@
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 MintLinuxDistro();
public final LinuxDistro PLD = new LinuxDistro("PLD",
"/etc/pld-release");
public final LinuxDistro REDHAT = new LinuxDistro("RedHat",
"/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 LinuxDistro("Ubuntu",
"/etc/lsb-release");
- public final LinuxDistro MINT = new MintLinuxDistro();
private final LinuxDistro[] ALL = new LinuxDistro[] {
+ /**
+ * Attention: CentOS uses the redhat release file
+ * <p>
+ * <tt>/etc/redhat-release</tt>
+ * <p>
+ * We therefore have to check CentOS before we check for Red Hat.
+ * It is not reliable to check Red Hat first since that check would
+ * result in a false positive on CentOS systems.
+ */
CENTOS,
+ REDHAT,
/**
+ * Attention: Mint uses the default
+ * <p>
+ * <tt>/etc/lsb-release</tt>
+ * <p>
+ * We therefore have to check Mint before we check Ubuntu.
+ * Checking Ubuntu first is not reliable since it is resulting in a
+ * false positive on Mint systems.
+ */
+ MINT,
+ /**
* Attention: ubuntu has 2 release files
* <ul>
* <li>/etc/lsb-release</li>
* <li>/etc/debian_version</li>
* </ul>
* <p>
- * It is not reliable to check Debian first and check there's no
- * /etc/lsb-release exists. Debian may also have a /etc/lsb-release. We must
- * check ubuntu prior to Debian.
+ * We therefore have to check for Ubuntu before we check for Debian.
+ * Checking for Debian results in a false positive on Ubuntu systems.
+ * @see
https://bugs.launchpad.net/ubuntu/+source/base-files/+bug/19353
* @see
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=444678
- * <p>
- * The very same applies to Mint Linux. It also has a /etc/lsb-release and we
- * therefore have to check mint prior to ubuntu and debian.
- *
*/
- MINT,
UBUNTU,
DEBIAN,
FEDORA,
@@ -74,7 +89,6 @@
MANDRAKE,
MANDRIVA,
PLD,
- REDHAT,
SLACKWARE,
SUSE,
YELLOWDOG
@@ -138,6 +152,26 @@
}
}
+ 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 {
/**
@@ -179,16 +213,10 @@
return new StringBuilder().append(getName()).append("
").append(getVersion()).toString();
}
- protected String getReleaseFilePath() {
+ public String getReleaseFilePath() {
return releaseFilePath;
}
- protected boolean exists(String releaseFilePath) {
- return releaseFilePath != null
- && releaseFilePath.length() > 0
- && new File(releaseFilePath).exists();
- }
-
protected boolean distroFileContains(String value) {
try {
boolean fileExists = exists(getReleaseFilePath());
@@ -202,19 +230,9 @@
}
- 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();
+ @Override
+ public String toString() {
+ return name;
}
-
}
}
Modified:
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/LinuxSystemTest.java
===================================================================
---
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/LinuxSystemTest.java 2012-01-05
17:38:00 UTC (rev 37659)
+++
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/LinuxSystemTest.java 2012-01-05
18:23:20 UTC (rev 37660)
@@ -19,13 +19,34 @@
public class LinuxSystemTest {
@Test
- public void canExtractFedoraVersion() {
+ public void canDetectFedora() {
LinuxSystem linuxSystem = new LinuxSystemFake(
- new ReleaseFile(LinuxSystem.INSTANCE.FEDORA.getReleaseFilePath(), "Fedora
release 13 (Goddard)"));
+ new ReleaseFile(LinuxSystem.INSTANCE.FEDORA.getReleaseFilePath(), "Fedora release
13 (Goddard)"));
assertEquals("Fedora 13", linuxSystem.getDistroNameAndVersion());
}
/**
+ * Mint uses the default
+ * <ul>
+ * <li>/etc/lsb-release</li>
+ * </ul>
+ */
+ @Test
+ public void canDetectMintVersion() {
+ LinuxSystem linuxSystem = new LinuxSystemFake(
+ new ReleaseFile(
+ LinuxSystem.INSTANCE.DEBIAN.getReleaseFilePath(), "squeeze/sid"),
+ new ReleaseFile(
+ LinuxSystem.INSTANCE.MINT.getReleaseFilePath(),
+ "DISTRIB_ID=LinuxMint\n" +
+ "DISTRIB_RELEASE=12\n" +
+ "DISTRIB_CODENAME=debian\n" +
+ "DISTRIB_DESCRIPTION=\"Linux Mint 12 Lisa\"")
+ );
+ assertEquals("LinuxMint 12", linuxSystem.getDistroNameAndVersion());
+ }
+
+ /**
* Ubuntu has 2 release files!
* <ul>
* <li>/etc/lsb-release</li>
@@ -33,34 +54,46 @@
* </ul>
*/
@Test
- public void canExtractUbuntuVersion() {
+ public void canDetectUbuntu() {
LinuxSystem linuxSystem = new LinuxSystemFake(
- new ReleaseFile(
- LinuxSystem.INSTANCE.UBUNTU.getReleaseFilePath(),
- "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=9.04\nDISTRIB_CODENAME=jaunty\nDISTRIB_DESCRIPTION=\"Ubuntu
9.04\"")
- , new ReleaseFile(LinuxSystem.INSTANCE.DEBIAN.getReleaseFilePath(),
"squeeze/sid"));
+ new ReleaseFile(
+ LinuxSystem.INSTANCE.DEBIAN.getReleaseFilePath(), "squeeze/sid"),
+ new ReleaseFile(
+ LinuxSystem.INSTANCE.UBUNTU.getReleaseFilePath(),
+ "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=9.04\nDISTRIB_CODENAME=jaunty\nDISTRIB_DESCRIPTION=\"Ubuntu
9.04\""));
assertEquals("Ubuntu 9.04", linuxSystem.getDistroNameAndVersion());
}
@Test
- public void canExtractRedHatVersion() {
+ public void canDetectRed() {
LinuxSystem linuxSystem = new LinuxSystemFake(
- new ReleaseFile(LinuxSystem.INSTANCE.REDHAT.getReleaseFilePath(),
- "Red Hat Enterprise Linux Workstation release 6.0 (Santiago)"));
+ new ReleaseFile(
+ LinuxSystem.INSTANCE.REDHAT.getReleaseFilePath(),
+ "Red Hat Enterprise Linux Workstation release 6.0 (Santiago)"));
assertEquals("RedHat 6.0", linuxSystem.getDistroNameAndVersion());
}
@Test
- public void canExtractGentooVersion() {
+ public void canDetectGentoo() {
LinuxSystem linuxSystem = new LinuxSystemFake(
- new ReleaseFile(LinuxSystem.INSTANCE.GENTOO.getReleaseFilePath(), "Gentoo Base
System release 2.0.1"));
+ new ReleaseFile(
+ LinuxSystem.INSTANCE.GENTOO.getReleaseFilePath(),
+ "Gentoo Base System release 2.0.1"));
assertEquals("Gentoo 2.0.1", linuxSystem.getDistroNameAndVersion());
}
+ /**
+ * CentOS uses the redhat-release file!
+ * <ul>
+ * <li>/etc/redhat-release</li>
+ * </ul>
+ */
@Test
- public void canExtractCentOSVersion() {
+ public void canDetectCentOS() {
LinuxSystem linuxSystem = new LinuxSystemFake(
- new ReleaseFile(LinuxSystem.INSTANCE.CENTOS.getReleaseFilePath(), "CentOS
release 5.3 (Final)"));
+ new ReleaseFile(
+ LinuxSystem.INSTANCE.CENTOS.getReleaseFilePath(),
+ "CentOS release 5.3 (Final)"));
assertEquals("CentOS 5.3", linuxSystem.getDistroNameAndVersion());
}
}
Modified:
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/fakes/LinuxSystemFake.java
===================================================================
---
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/fakes/LinuxSystemFake.java 2012-01-05
17:38:00 UTC (rev 37659)
+++
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/fakes/LinuxSystemFake.java 2012-01-05
18:23:20 UTC (rev 37660)
@@ -30,7 +30,7 @@
/** release file paths on the faked system */
private ReleaseFile[] releaseFiles;
-
+
public LinuxSystemFake(ReleaseFile... releaseFiles) {
this.releaseFiles = releaseFiles;
}