Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
BZ-1085991: git deamon is now disabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
porcelli committed Apr 16, 2014
1 parent 267177c commit 7aa4fc3
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public class JGitFileSystemProvider implements FileSystemProvider,
public static final String SSH_FILE_CERT_ROOT_DIR = ".security";
public static final String DEFAULT_HOST_NAME = "localhost";
public static final String DEFAULT_HOST_ADDR = "127.0.0.1";
public static final boolean DAEMON_DEFAULT_ENABLED = true;
public static final boolean DAEMON_DEFAULT_ENABLED = false;
public static final int DAEMON_DEFAULT_PORT = 9418;
public static final boolean SSH_DEFAULT_ENABLED = true;
public static final int SSH_DEFAULT_PORT = 8001;
Expand Down Expand Up @@ -224,26 +224,24 @@ private void loadConfig() {
}
}

if ( DAEMON_ENABLED ) {
if ( port == null || port.trim().isEmpty() ) {
DAEMON_PORT = DAEMON_DEFAULT_PORT;
} else {
DAEMON_PORT = Integer.valueOf( port );
}
if ( host == null || host.trim().isEmpty() ) {
DAEMON_HOST_ADDR = DEFAULT_HOST_ADDR;
} else {
DAEMON_HOST_ADDR = host;
}
if ( hostName == null || hostName.trim().isEmpty() ) {
if ( host != null && !host.trim().isEmpty() ) {
DAEMON_HOST_NAME = host;
} else {
DAEMON_HOST_NAME = DEFAULT_HOST_NAME;
}
if ( port == null || port.trim().isEmpty() ) {
DAEMON_PORT = DAEMON_DEFAULT_PORT;
} else {
DAEMON_PORT = Integer.valueOf( port );
}
if ( host == null || host.trim().isEmpty() ) {
DAEMON_HOST_ADDR = DEFAULT_HOST_ADDR;
} else {
DAEMON_HOST_ADDR = host;
}
if ( hostName == null || hostName.trim().isEmpty() ) {
if ( host != null && !host.trim().isEmpty() ) {
DAEMON_HOST_NAME = host;
} else {
DAEMON_HOST_NAME = hostName;
DAEMON_HOST_NAME = DEFAULT_HOST_NAME;
}
} else {
DAEMON_HOST_NAME = hostName;
}

if ( sshEnabled == null || sshEnabled.trim().isEmpty() ) {
Expand All @@ -256,32 +254,30 @@ private void loadConfig() {
}
}

if ( SSH_ENABLED ) {
if ( sshPort == null || sshPort.trim().isEmpty() ) {
SSH_PORT = SSH_DEFAULT_PORT;
} else {
SSH_PORT = Integer.valueOf( sshPort );
}
if ( sshHost == null || sshHost.trim().isEmpty() ) {
SSH_HOST_ADDR = DEFAULT_HOST_ADDR;
} else {
SSH_HOST_ADDR = sshHost;
}
if ( sshHostName == null || sshHostName.trim().isEmpty() ) {
if ( sshHost != null && !sshHost.trim().isEmpty() ) {
SSH_HOST_NAME = sshHost;
} else {
SSH_HOST_NAME = DEFAULT_HOST_NAME;
}
if ( sshPort == null || sshPort.trim().isEmpty() ) {
SSH_PORT = SSH_DEFAULT_PORT;
} else {
SSH_PORT = Integer.valueOf( sshPort );
}
if ( sshHost == null || sshHost.trim().isEmpty() ) {
SSH_HOST_ADDR = DEFAULT_HOST_ADDR;
} else {
SSH_HOST_ADDR = sshHost;
}
if ( sshHostName == null || sshHostName.trim().isEmpty() ) {
if ( sshHost != null && !sshHost.trim().isEmpty() ) {
SSH_HOST_NAME = sshHost;
} else {
SSH_HOST_NAME = sshHostName;
SSH_HOST_NAME = DEFAULT_HOST_NAME;
}
} else {
SSH_HOST_NAME = sshHostName;
}

if ( sshCertDir == null || sshCertDir.trim().isEmpty() ) {
SSH_FILE_CERT_DIR = new File( SSH_FILE_CERT_ROOT_DIR );
} else {
SSH_FILE_CERT_DIR = new File( sshCertDir.trim(), SSH_FILE_CERT_ROOT_DIR );
}
if ( sshCertDir == null || sshCertDir.trim().isEmpty() ) {
SSH_FILE_CERT_DIR = new File( SSH_FILE_CERT_ROOT_DIR );
} else {
SSH_FILE_CERT_DIR = new File( sshCertDir.trim(), SSH_FILE_CERT_ROOT_DIR );
}

}
Expand Down Expand Up @@ -464,13 +460,21 @@ public int hashCode() {
gitSSHService.start();
}

private void buildAndStartDaemon() {
daemonService = new Daemon( new InetSocketAddress( DAEMON_HOST_ADDR, DAEMON_PORT ) );
daemonService.setRepositoryResolver( new RepositoryResolverImpl<DaemonClient>() );
try {
daemonService.start();
} catch ( java.io.IOException e ) {
throw new IOException( e );
void buildAndStartDaemon() {
if ( daemonService == null || !daemonService.isRunning() ) {
daemonService = new Daemon( new InetSocketAddress( DAEMON_HOST_ADDR, DAEMON_PORT ) );
daemonService.setRepositoryResolver( new RepositoryResolverImpl<DaemonClient>() );
try {
daemonService.start();
} catch ( java.io.IOException e ) {
throw new IOException( e );
}
}
}

void forceStopDaemon() {
if ( daemonService != null || daemonService.isRunning() ) {
daemonService.stop();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.HashMap;
import java.util.Map;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.uberfire.java.nio.file.FileSystem;

Expand All @@ -32,6 +34,16 @@ public class JGitFileSystemProviderEncodingTest extends AbstractTestInfra {

private static final JGitFileSystemProvider PROVIDER = JGitFileSystemProvider.getInstance();

@BeforeClass
public static void setup() throws IOException {
PROVIDER.buildAndStartDaemon();
}

@AfterClass
public static void tearDown() throws IOException {
PROVIDER.forceStopDaemon();
}

@Test
public void test() throws IOException {
final URI originRepo = URI.create( "git://encoding-origin-name" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.ObjectId;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.uberfire.commons.data.Pair;
Expand Down Expand Up @@ -61,6 +63,16 @@ public class JGitFileSystemProviderTest extends AbstractTestInfra {

private static final JGitFileSystemProvider PROVIDER = JGitFileSystemProvider.getInstance();

@BeforeClass
public static void setup() throws IOException {
PROVIDER.buildAndStartDaemon();
}

@AfterClass
public static void tearDown() throws IOException {
PROVIDER.forceStopDaemon();
}

@Test
@Ignore
public void testDaemob() throws InterruptedException {
Expand Down Expand Up @@ -240,7 +252,7 @@ public void testNewFileSystemCloneAndPush() throws IOException {

assertThat( fs.getPath( "file.txt" ).toFile() ).isNotNull().exists();

commit( ((JGitFileSystem)fs).gitRepo(), "master", "user1", "user1@example.com", "commitx", null, null, false, new HashMap<String, File>() {{
commit( ( (JGitFileSystem) fs ).gitRepo(), "master", "user1", "user1@example.com", "commitx", null, null, false, new HashMap<String, File>() {{
put( "fileXXXXX.txt", tempFile( "temp" ) );
}} );

Expand Down

0 comments on commit 7aa4fc3

Please sign in to comment.