Consolidate windows platform tests to a single class
This saves us from defining the same method 3 times. Change-Id: I00cf7c6827dee48fb2105b15bc56fe33996b8805 Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -30,10 +30,11 @@ import com.google.gerrit.pgm.util.IoUtil;
|
||||
import com.google.gerrit.pgm.util.SiteProgram;
|
||||
import com.google.gerrit.server.config.SitePath;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.server.git.LocalDiskRepositoryManager;
|
||||
import com.google.gerrit.server.git.GitProjectImporter;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.LocalDiskRepositoryManager;
|
||||
import com.google.gerrit.server.schema.SchemaUpdater;
|
||||
import com.google.gerrit.server.util.HostPlatform;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.CreationException;
|
||||
@@ -194,7 +195,7 @@ public class Init extends SiteProgram {
|
||||
|
||||
void start() throws IOException {
|
||||
if (flags.autoStart) {
|
||||
if (IoUtil.isWin32()) {
|
||||
if (HostPlatform.isWin32()) {
|
||||
System.err.println("Automatic startup not supported on Win32.");
|
||||
|
||||
} else {
|
||||
|
||||
@@ -14,19 +14,11 @@
|
||||
|
||||
package com.google.gerrit.pgm.util;
|
||||
|
||||
import org.eclipse.jgit.util.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public final class IoUtil {
|
||||
public static final boolean isWin32() {
|
||||
final String osDotName = System.getProperty("os.name");
|
||||
return osDotName != null
|
||||
&& StringUtils.toLowerCase(osDotName).indexOf("windows") != -1;
|
||||
}
|
||||
|
||||
public static void copyWithThread(final InputStream src,
|
||||
final OutputStream dst) {
|
||||
new Thread("IoUtil-Copy") {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server;
|
||||
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.util.HostPlatform;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@@ -22,12 +23,10 @@ import eu.medsea.mimeutil.MimeException;
|
||||
import eu.medsea.mimeutil.MimeType;
|
||||
import eu.medsea.mimeutil.MimeUtil2;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -52,7 +51,7 @@ public class MimeUtilFileTypeRegistry implements FileTypeRegistry {
|
||||
mimeUtil = new MimeUtil2();
|
||||
register("eu.medsea.mimeutil.detector.ExtensionMimeDetector");
|
||||
register("eu.medsea.mimeutil.detector.MagicMimeMimeDetector");
|
||||
if (isWin32()) {
|
||||
if (HostPlatform.isWin32()) {
|
||||
register("eu.medsea.mimeutil.detector.WindowsRegistryMimeDetector");
|
||||
}
|
||||
}
|
||||
@@ -61,17 +60,6 @@ public class MimeUtilFileTypeRegistry implements FileTypeRegistry {
|
||||
mimeUtil.registerMimeDetector(name);
|
||||
}
|
||||
|
||||
private static boolean isWin32() {
|
||||
final String osDotName =
|
||||
AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||
public String run() {
|
||||
return System.getProperty("os.name");
|
||||
}
|
||||
});
|
||||
return osDotName != null
|
||||
&& osDotName.toLowerCase().indexOf("windows") != -1;
|
||||
}
|
||||
|
||||
public MimeType getMimeType(final String path, final byte[] content) {
|
||||
Set<MimeType> mimeTypes = new HashSet<MimeType>();
|
||||
if (content != null && content.length > 0) {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright (C) 2009 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.util;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
public final class HostPlatform {
|
||||
private static final boolean win32 = computeWin32();
|
||||
|
||||
/** @return true if this JVM is running on a Windows platform. */
|
||||
public static final boolean isWin32() {
|
||||
return win32;
|
||||
}
|
||||
|
||||
private static final boolean computeWin32() {
|
||||
final String osDotName =
|
||||
AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||
public String run() {
|
||||
return System.getProperty("os.name");
|
||||
}
|
||||
});
|
||||
return osDotName != null
|
||||
&& osDotName.toLowerCase().indexOf("windows") != -1;
|
||||
}
|
||||
|
||||
private HostPlatform() {
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.config;
|
||||
|
||||
import com.google.gerrit.server.util.HostPlatform;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.File;
|
||||
@@ -84,7 +86,7 @@ public class SitePathsTest extends TestCase {
|
||||
assertNotNull(site.resolve("a"));
|
||||
assertEquals(new File(root, "a"), site.resolve("a"));
|
||||
|
||||
final String pfx = isWin32() ? "C:/" : "/";
|
||||
final String pfx = HostPlatform.isWin32() ? "C:/" : "/";
|
||||
assertNotNull(site.resolve(pfx + "a"));
|
||||
assertEquals(new File(pfx + "a"), site.resolve(pfx + "a"));
|
||||
}
|
||||
@@ -93,10 +95,4 @@ public class SitePathsTest extends TestCase {
|
||||
final File t = new File("target");
|
||||
return new File(t, "random-name-" + UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
private static boolean isWin32() {
|
||||
final String osDotName = System.getProperty("os.name");
|
||||
return osDotName != null
|
||||
&& osDotName.toLowerCase().indexOf("windows") != -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user