From jbosstools-commits at lists.jboss.org Wed Jan 11 07:38:41 2012 Content-Type: multipart/mixed; boundary="===============6716459553244030552==" MIME-Version: 1.0 From: jbosstools-commits at lists.jboss.org To: jbosstools-commits at lists.jboss.org Subject: [jbosstools-commits] JBoss Tools SVN: r37760 - in trunk/usage: tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test and 1 other directory. Date: Wed, 11 Jan 2012 07:38:41 -0500 Message-ID: <201201111238.q0BCcfXL015640@svn01.web.mwc.hst.phx2.redhat.com> --===============6716459553244030552== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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/goog= leanalytics/eclipse/LinuxSystem.java trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/t= est/LinuxSystemTest.java Log: [JBIDE-10577] now set all linux distros with identical release files to ch= eck 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/usa= ge/googleanalytics/eclipse/LinuxSystem.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/goo= gleanalytics/eclipse/LinuxSystem.java 2012-01-11 12:21:04 UTC (rev 37759) +++ trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/goo= gleanalytics/eclipse/LinuxSystem.java 2012-01-11 12:38:39 UTC (rev 37760) @@ -22,7 +22,7 @@ public class LinuxSystem { = public static final LinuxSystem INSTANCE =3D new LinuxSystem(); - + = /** * @see an * extensive list of release file locations @@ -31,8 +31,7 @@ * href=3D"http://superuser.com/questions/11008/how-do-i-find-out-wh= at-version-of-linux-im-running"> * release-file strings */ - = - public final LinuxDistro CENTOS =3D new CentOSDistro(); + public final LinuxDistro CENTOS =3D new ReleaseFileContentCheckedDistro("= CentOS", "/etc/redhat-release"); public final LinuxDistro DEBIAN =3D new LinuxDistro("Debian", "/etc/debia= n_version"); public final LinuxDistro FEDORA =3D new LinuxDistro("Fedora", "/etc/fedor= a-release"); public final LinuxDistro GENTOO =3D new LinuxDistro("Gentoo", "/etc/gento= o-release"); @@ -40,47 +39,16 @@ public final LinuxDistro KNOPPIX =3D new LinuxDistro("Knoppix", "knoppix_= version"); public final LinuxDistro MANDRAKE =3D new LinuxDistro("Mandrake", "/etc/m= andrake-release"); public final LinuxDistro MANDRIVA =3D new LinuxDistro("Mandriva", "/etc/m= andriva-release"); - public final LinuxDistro MINT =3D new MintLinuxDistro(); + public final LinuxDistro MINT =3D new ReleaseFileContentCheckedDistro("Li= nuxMint", "/etc/lsb-release"); public final LinuxDistro PLD =3D new LinuxDistro("PLD", "/etc/pld-release= "); - public final LinuxDistro REDHAT =3D new LinuxDistro("RedHat", "/etc/redha= t-release"); + public final LinuxDistro REDHAT =3D new ReleaseFileContentCheckedDistro("= Red Hat", "/etc/redhat-release"); public final LinuxDistro SLACKWARE =3D new LinuxDistro("Slackware", "/etc= /slackware-version"); public final LinuxDistro SUSE =3D new LinuxDistro("SUSE", "/etc/SuSE-rele= ase"); - public final LinuxDistro UBUNTU =3D new LinuxDistro("Ubuntu", "/etc/lsb-r= elease"); + public final LinuxDistro UBUNTU =3D new ReleaseFileContentCheckedDistro("= Ubuntu", "/etc/lsb-release"); = private final LinuxDistro[] ALL =3D new LinuxDistro[] { - /** - * Attention: CentOS uses the redhat release file - *

- * /etc/redhat-release - *

- * 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 - *

- * /etc/lsb-release - *

- * 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 - *

- *

- * 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=3D444678 - */ 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 !=3D null) { return distro.getNameAndVersion(); } else { - return ""; + return "Unknown"; } } = - protected class CentOSDistro extends LinuxDistro { - private static final String CENTOS_NAME =3D "CentOS"; - private static final String REDHAT_RELEASE_FILE =3D "/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 CentOS. - * @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 =3D "LinuxMint"; - private static final String LSB_RELEASE_FILE =3D "/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 LinuxMint. - * 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 !=3D null && releaseFilePath.length() > 0 && new File(releaseFilePath).exists(); } - = + protected String getDistroFileContent(String filePath) throws IOException= { int charachtersToRead =3D 1024; StringBuilder builder =3D 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 releaseFilePa= th) { + 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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=3DUbuntu\nDISTRIB_RELEASE=3D9.04\nDISTRIB_CODENAME=3Djaunt= y\nDISTRIB_DESCRIPTION=3D\"Ubuntu 9.04\"")); + "DISTRIB_ID=3DUbuntu\n" + + "DISTRIB_RELEASE=3D9.04\n" + + "DISTRIB_CODENAME=3Djaunty\n" + + "DISTRIB_DESCRIPTION=3D\"Ubuntu 9.04\"")); assertEquals("Ubuntu 9.04", linuxSystem.getDistroNameAndVersion()); } = @Test - public void canDetectRed() { + public void returnsUnknownIfLSBReleaseWithUnknownContent() { LinuxSystem linuxSystem =3D new LinuxSystemFake( new ReleaseFile( + "/etc/lsb-release", = + "adietish(a)redhat.com")); + assertEquals("Unknown", linuxSystem.getDistroNameAndVersion()); + } + + @Test + public void canDetectRedHat() { + LinuxSystem linuxSystem =3D 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 =3D new LinuxSystemFake( + new ReleaseFile( + LinuxSystem.INSTANCE.REDHAT.getReleaseFilePath(), = + "adietish(a)redhat.com")); + assertEquals("Unknown", linuxSystem.getDistroNameAndVersion()); + } + } --===============6716459553244030552==--