Author: adietish
Date: 2010-10-06 09:52:08 -0400 (Wed, 06 Oct 2010)
New Revision: 25523
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
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/fakes/ReportingEclipseEnvironmentFake.java
Log:
[JBIDE-7268] changed checking order: checking ubuntu prior to debian (no other reliable
variant known to me so far)
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 2010-10-06
13:35:53 UTC (rev 25522)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/eclipse/LinuxSystem.java 2010-10-06
13:52:08 UTC (rev 25523)
@@ -28,6 +28,7 @@
*
href="http://superuser.com/questions/11008/how-do-i-find-out-what-ve...
* release-file strings</a>
*/
+
public final LinuxDistro CENTOS = new CentOSDistro("CentOS",
"/etc/redhat-release");
public final LinuxDistro DEBIAN = new LinuxDistro("Debian",
"/etc/debian_version");
public final LinuxDistro FEDORA = new LinuxDistro("Fedora",
"/etc/fedora-release");
@@ -44,6 +45,21 @@
private final LinuxDistro[] ALL = new LinuxDistro[] {
CENTOS,
+ /**
+ * Attention: ubuntu has 2 release files
+ * <ul>
+ * <li>/etc/lsb-release</li>
+ * <li>/etc/debian_version</li>
+ * </ul>
+ *
+ * It is not reliable to check Debian first and check there if no
+ * /etc/lsb-release exists. Debian may also have a /etc/lsb-release. We must
+ * check ubuntu prior to Debian.
+ *
+ * @see
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=444678
+ *
+ */
+ UBUNTU,
DEBIAN,
FEDORA,
GENTOO,
@@ -54,7 +70,6 @@
REDHAT,
SLACKWARE,
SUSE,
- UBUNTU,
YELLOWDOG
};
@@ -76,7 +91,7 @@
return "";
}
}
-
+
protected class CentOSDistro extends LinuxDistro {
private static final String CENTOS_NAME = "CentOS";
@@ -138,16 +153,16 @@
public String getNameAndVersion() {
return new StringBuilder().append(getName()).append("
").append(getVersion()).toString();
}
-
+
public String getReleaseFilePath() {
return releaseFilePath;
}
}
-
+
protected boolean exists(String releaseFilePath) {
- return new File(releaseFilePath).exists();
+ return new File(releaseFilePath).exists();
}
-
+
protected String getDistroFileContent(String filePath) throws IOException {
int charachtersToRead = 1024;
StringBuilder builder = new StringBuilder(charachtersToRead);
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 2010-10-06
13:35:53 UTC (rev 25522)
+++
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/LinuxSystemTest.java 2010-10-06
13:52:08 UTC (rev 25523)
@@ -13,41 +13,54 @@
import org.jboss.tools.usage.googleanalytics.eclipse.LinuxSystem;
import org.jboss.tools.usage.test.fakes.LinuxSystemFake;
+import org.jboss.tools.usage.test.fakes.LinuxSystemFake.ReleaseFile;
import org.junit.Test;
public class LinuxSystemTest {
@Test
public void canExtractFedoraVersion() {
- LinuxSystem linuxSystem = new
LinuxSystemFake(LinuxSystem.INSTANCE.FEDORA.getReleaseFilePath(), "Fedora release 13
(Goddard)");
+ LinuxSystem linuxSystem = new LinuxSystemFake(
+ new ReleaseFile(LinuxSystem.INSTANCE.FEDORA.getReleaseFilePath(), "Fedora
release 13 (Goddard)"));
assertEquals("Fedora 13", linuxSystem.getDistroNameAndVersion());
}
+ /**
+ * Ubuntu has 2 release files!
+ * <ul>
+ * <li>/etc/lsb-release</li>
+ * <li>/etc/debian_version</li>
+ * </ul>
+ */
@Test
public void canExtractUbuntuVersion() {
- LinuxSystem linuxSystem = new
LinuxSystemFake(LinuxSystem.INSTANCE.UBUNTU.getReleaseFilePath(),
- "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=9.04\nDISTRIB_CODENAME=jaunty\nDISTRIB_DESCRIPTION=\"Ubuntu
9.04\"");
+ 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"));
assertEquals("Ubuntu 9.04", linuxSystem.getDistroNameAndVersion());
}
@Test
public void canExtractRedHatVersion() {
- LinuxSystem linuxSystem = new
LinuxSystemFake(LinuxSystem.INSTANCE.REDHAT.getReleaseFilePath(),
- "Red Hat Enterprise Linux Workstation release 6.0 (Santiago)");
+ 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());
}
@Test
public void canExtractGentooVersion() {
- LinuxSystem linuxSystem = new
LinuxSystemFake(LinuxSystem.INSTANCE.GENTOO.getReleaseFilePath(),
- "Gentoo Base System release 2.0.1");
+ LinuxSystem linuxSystem = new LinuxSystemFake(
+ new ReleaseFile(LinuxSystem.INSTANCE.GENTOO.getReleaseFilePath(), "Gentoo Base
System release 2.0.1"));
assertEquals("Gentoo 2.0.1", linuxSystem.getDistroNameAndVersion());
}
-
+
@Test
public void canExtractCentOSVersion() {
- LinuxSystem linuxSystem = new
LinuxSystemFake(LinuxSystem.INSTANCE.CENTOS.getReleaseFilePath(),
- "CentOS release 5.3 (Final)");
+ LinuxSystem linuxSystem = new LinuxSystemFake(
+ 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 2010-10-06
13:35:53 UTC (rev 25522)
+++
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/fakes/LinuxSystemFake.java 2010-10-06
13:52:08 UTC (rev 25523)
@@ -28,23 +28,50 @@
*/
public class LinuxSystemFake extends LinuxSystem {
- private String releaseFilePath;
+ /** release file paths on the faked system */
+ private ReleaseFile[] releaseFiles;
- private String releaseFileContent;
-
- public LinuxSystemFake(String releaseFilePath, String releaseFileContent) {
- super();
- this.releaseFilePath = releaseFilePath;
- this.releaseFileContent = releaseFileContent;
+ public LinuxSystemFake(ReleaseFile... releaseFiles) {
+ this.releaseFiles = releaseFiles;
}
@Override
protected boolean exists(String releaseFilePath) {
- return this.releaseFilePath.equals(releaseFilePath);
+ for (ReleaseFile releaseFile : releaseFiles) {
+ if(releaseFile.getPath().equals(releaseFilePath)) {
+ return true;
+ }
+ }
+ return false;
}
@Override
protected String getDistroFileContent(String filePath) throws IOException {
- return releaseFileContent;
+ for (ReleaseFile releaseFile : releaseFiles) {
+ if (releaseFile.getPath().equals(filePath)) {
+ return releaseFile.getContent();
+ }
+ }
+ return null;
}
+
+ public static class ReleaseFile {
+ private String path;
+ private String content;
+
+ public ReleaseFile(String path, String content) {
+ this.path = path;
+ this.content = content;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public String getContent() {
+ return content;
+ }
+ }
+
+
}
\ No newline at end of file
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-10-06
13:35:53 UTC (rev 25522)
+++
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/fakes/ReportingEclipseEnvironmentFake.java 2010-10-06
13:52:08 UTC (rev 25523)
@@ -11,15 +11,16 @@
package org.jboss.tools.usage.test.fakes;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.jboss.tools.usage.googleanalytics.eclipse.IEclipseUserAgent;
import org.jboss.tools.usage.googleanalytics.eclipse.LinuxSystem;
-import org.jboss.tools.usage.googleanalytics.eclipse.IEclipseUserAgent;
import org.jboss.tools.usage.internal.reporting.JBossToolsEclipseEnvironment;
+import org.jboss.tools.usage.test.fakes.LinuxSystemFake.ReleaseFile;
/**
* @author Andre Dietisheim
*/
public class ReportingEclipseEnvironmentFake extends JBossToolsEclipseEnvironment {
-
+
public static final String GANALYTICS_ACCOUNTNAME = "UA-17645367-1";
public static final String HOSTNAME = "jboss.org";
public static final String JAVA_VERSION = "1.6.0_20";
@@ -70,6 +71,6 @@
@Override
protected String getLinuxDistroNameAndVersion() {
- return new LinuxSystemFake(LinuxSystem.INSTANCE.FEDORA.getName(), "Fedora release
13 (Goddard)").getDistroNameAndVersion();
+ return new LinuxSystemFake(new
ReleaseFile(LinuxSystem.INSTANCE.FEDORA.getReleaseFilePath(), "Fedora release 13
(Goddard)")).getDistroNameAndVersion();
}
}