Author: adietish
Date: 2012-01-11 07:38:39 -0500 (Wed, 11 Jan 2012)
New Revision: 37760
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
Log:
[JBIDE-10577] now set all linux distros with identical release files to check the content
(RedHat/CentOS, Ubuntu/Mint). So no false positive possible for those. If none matches, I
return "Unknown".
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-11
12:21:04 UTC (rev 37759)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/LinuxSystem.java 2012-01-11
12:38:39 UTC (rev 37760)
@@ -22,7 +22,7 @@
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>
@@ -31,8 +31,7 @@
*
href="http://superuser.com/questions/11008/how-do-i-find-out-what-ve...
* release-file strings</a>
*/
-
- public final LinuxDistro CENTOS = new CentOSDistro();
+ 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");
@@ -40,47 +39,16 @@
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 MINT = new
ReleaseFileContentCheckedDistro("LinuxMint", "/etc/lsb-release");
public final LinuxDistro PLD = new LinuxDistro("PLD",
"/etc/pld-release");
- public final LinuxDistro REDHAT = new LinuxDistro("RedHat",
"/etc/redhat-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 LinuxDistro("Ubuntu",
"/etc/lsb-release");
+ public final LinuxDistro UBUNTU = new
ReleaseFileContentCheckedDistro("Ubuntu", "/etc/lsb-release");
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>
- * 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
- */
UBUNTU,
DEBIAN,
FEDORA,
@@ -89,10 +57,11 @@
MANDRAKE,
MANDRIVA,
PLD,
+ REDHAT,
SLACKWARE,
SUSE,
YELLOWDOG
- };
+ };
public LinuxDistro getDistro() {
for (LinuxDistro distro : ALL) {
@@ -109,55 +78,16 @@
if (distro != null) {
return distro.getNameAndVersion();
} else {
- return "";
+ return "Unknown";
}
}
- protected class CentOSDistro extends LinuxDistro {
- private static final String CENTOS_NAME = "CentOS";
- private static final String REDHAT_RELEASE_FILE = "/etc/redhat-release";
-
- protected CentOSDistro() {
- super(CENTOS_NAME, REDHAT_RELEASE_FILE);
- }
-
- /**
- * Checks if the current system is a CentOS distribution.
- * It checks if /etc/lsb-release contains <tt>CentOS</tt>.
- * @return true if /etc/redhat-release contains CentoOS
- */
- @Override
- protected boolean isDistro() {
- return distroFileContains(CENTOS_NAME);
- }
- }
-
- protected class MintLinuxDistro extends LinuxDistro {
- private static final String MINTLINUX_NAME = "LinuxMint";
- private static final String LSB_RELEASE_FILE = "/etc/lsb-release";
-
- protected MintLinuxDistro() {
- super(MINTLINUX_NAME, LSB_RELEASE_FILE);
- }
-
- /**
- * Checks if the current system is a Mint Linux distribution.
- * It checks if /etc/lsb-release contains <tt>LinuxMint</tt>.
- * We could also check for presence of /etc/linuxmint(/info)
- * @return true if /etc/lsb-release contains LinuxMint
- */
- @Override
- protected boolean isDistro() {
- return distroFileContains(MINTLINUX_NAME);
- }
- }
-
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);
@@ -192,7 +122,7 @@
protected boolean isDistro() {
return exists(getReleaseFilePath());
}
-
+
public String getName() {
return name;
}
@@ -229,10 +159,25 @@
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());
+ }
+ }
}
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-11
12:21:04 UTC (rev 37759)
+++
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/LinuxSystemTest.java 2012-01-11
12:38:39 UTC (rev 37760)
@@ -60,17 +60,29 @@
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\""));
+ "DISTRIB_ID=Ubuntu\n" +
+ "DISTRIB_RELEASE=9.04\n" +
+ "DISTRIB_CODENAME=jaunty\n" +
+ "DISTRIB_DESCRIPTION=\"Ubuntu 9.04\""));
assertEquals("Ubuntu 9.04", linuxSystem.getDistroNameAndVersion());
}
@Test
- public void canDetectRed() {
+ public void returnsUnknownIfLSBReleaseWithUnknownContent() {
LinuxSystem linuxSystem = new LinuxSystemFake(
new ReleaseFile(
+ "/etc/lsb-release",
+ "adietish(a)redhat.com"));
+ assertEquals("Unknown", linuxSystem.getDistroNameAndVersion());
+ }
+
+ @Test
+ public void canDetectRedHat() {
+ LinuxSystem linuxSystem = new LinuxSystemFake(
+ new ReleaseFile(
LinuxSystem.INSTANCE.REDHAT.getReleaseFilePath(),
"Red Hat Enterprise Linux Workstation release 6.0 (Santiago)"));
- assertEquals("RedHat 6.0", linuxSystem.getDistroNameAndVersion());
+ assertEquals("Red Hat 6.0", linuxSystem.getDistroNameAndVersion());
}
@Test
@@ -96,4 +108,14 @@
"CentOS release 5.3 (Final)"));
assertEquals("CentOS 5.3", linuxSystem.getDistroNameAndVersion());
}
+
+ @Test
+ public void returnsUnknownIfRedHatReleaseWithUnknownContent() {
+ LinuxSystem linuxSystem = new LinuxSystemFake(
+ new ReleaseFile(
+ LinuxSystem.INSTANCE.REDHAT.getReleaseFilePath(),
+ "adietish(a)redhat.com"));
+ assertEquals("Unknown", linuxSystem.getDistroNameAndVersion());
+ }
+
}