Skip to content
This repository has been archived by the owner on Oct 27, 2019. It is now read-only.

Commit

Permalink
Merge branch 'refs/heads/master' of ssh://mjanczarska@dev.eclipse.org…
Browse files Browse the repository at this point in the history
…/gitroot/e4/org.eclipse.orion.server.git into HEAD
  • Loading branch information
janczarska committed Feb 3, 2011
2 parents 395858c + 793b610 commit db249cd
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 232 deletions.
Expand Up @@ -28,6 +28,8 @@ public class SshConfigManager {
private static SshConfigManager singleton;

public static SshConfigManager getDefault() {
if (singleton == null)
throw new IllegalStateException("SshConfigManager hasn't been activated. Possible cause: org.eclipse.equinox.ds not included in the launch configuration");
return singleton;
}

Expand Down
@@ -1,58 +1,34 @@
/*******************************************************************************
* Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.orion.internal.server.filesystem.git;

import java.net.URISyntaxException;
import java.net.URL;

import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.util.FS;
import org.eclipse.orion.server.filesystem.git.GitFileStore;

public class Utils {

public static URIish toURIish(final URL u) throws URISyntaxException {
String s = u.toString();
s = s.replace("?" + u.getQuery(), ""); // ignore query
return new URIish(s);
}

public static boolean isValidRemote(GitFileStore gfs) {
Transport transport = null;
try {
URIish remote = toURIish(gfs.getUrl());
Repository local = gfs.getLocalRepo();
if (!Transport.canHandleProtocol(remote, FS.DETECTED))
return false;
transport = Transport.open(local, remote);
transport.setCredentialsProvider(gfs.getCredentialsProvider());
transport.openFetch().close();
return true;
} catch (Exception e) {
// ignore and return false
} finally {
if (transport != null)
transport.close();
}
return false;
}

public static IFileStore getRoot(IFileStore gfs) {
IFileStore parent = null;
while ((parent = gfs.getParent()) != null) {
gfs = parent;
}
return (IFileStore) gfs;
}
}
/*******************************************************************************
* Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.orion.internal.server.filesystem.git;

import java.net.URISyntaxException;
import java.net.URL;

import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.jgit.transport.URIish;

public class Utils {

public static URIish toURIish(final URL u) throws URISyntaxException {
String s = u.toString();
s = s.replace("?" + u.getQuery(), ""); // ignore query
return new URIish(s);
}

public static IFileStore getRoot(IFileStore gfs) {
IFileStore parent = null;
while ((parent = gfs.getParent()) != null) {
gfs = parent;
}
return (IFileStore) gfs;
}
}
Expand Up @@ -144,11 +144,6 @@ public IFileInfo[] childInfos(int options, IProgressMonitor monitor)
@Override
public String[] childNames(int options, IProgressMonitor monitor)
throws CoreException {
if (!Utils.isValidRemote(this)) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PI_GIT,
1, this + " doesn't point to a valid repository."
+ getLocalFile(), null));
}
if (!isCloned()) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PI_GIT,
1, "A private clone for " + this + " doesn't exist."
Expand All @@ -168,13 +163,12 @@ public boolean isCloned() {
@Override
public IFileInfo fetchInfo(int options, IProgressMonitor monitor)
throws CoreException {
if (Utils.isValidRemote(this)) {
if (!isCloned()) {
initCloneCommitPush(monitor);
}
if ((options & EFS.CACHE) == 0) // don't use cache
pull();
if (!isCloned()) {
initCloneCommitPush(monitor);
}
if ((options & EFS.CACHE) == 0) // don't use cache
pull();

FileInfo fi = new FileInfo();
fi.setName(getName());
File f = getLocalFile();
Expand Down Expand Up @@ -374,8 +368,9 @@ private static byte[] readBytes(InputStream is) throws IOException {
* necessary and inits it by pushing a dummy change (.gitignore) file to
* remote
*/
void initCloneCommitPush(IProgressMonitor monitor) throws CoreException {
private void initCloneCommitPush(IProgressMonitor monitor) throws CoreException {
boolean inited = false;
// if it's a local repository try to init it first
if (canInit()) {
try {
inited = initBare();
Expand Down Expand Up @@ -410,26 +405,7 @@ private boolean canInit() {
return false;
}

private boolean canPush() {
Transport transport = null;
try {
URIish remote = Utils.toURIish(getUrl());
Repository local = getLocalRepo();
if (!Transport.canHandleProtocol(remote, FS.DETECTED))
return false;
transport = Transport.open(local, remote);
transport.openPush().close();
return true;
} catch (Exception e) {
// ignore
} finally {
if (transport != null)
transport.close();
}
return false;
}

/*private*/public CredentialsProvider getCredentialsProvider() {
private CredentialsProvider getCredentialsProvider() {
try {
return new OrionUserCredentialsProvider(authority, Utils.toURIish(getUrl()));
} catch (URISyntaxException e) {
Expand Down Expand Up @@ -483,10 +459,6 @@ private boolean initBare() throws URISyntaxException, IOException {
}

private void push() throws CoreException {
if (!canPush()) {
LogHelper.log(new Status(IStatus.WARNING, Activator.PI_GIT, 1, "Ignored push request for " + this, null));
return;
}
try {
Repository local = getLocalRepo();
Git git = new Git(local);
Expand Down Expand Up @@ -542,20 +514,20 @@ private void pull() throws CoreException {

private void rm() throws CoreException {
// TODO: use org.eclipse.jgit.api.RmCommand, see Enhancement 379
try {
if (!isRoot()) {
if (!isRoot()) {
try {
Repository local = getLocalRepo();
Git git = new Git(local);
CommitCommand commit = git.commit();
commit.setAll(true);
commit.setMessage("auto-commit of " + toString());
commit.call();
push();
} // else {cannot commit/push root removal}
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PI_GIT,
IStatus.ERROR, e.getMessage(), e));
}
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PI_GIT,
IStatus.ERROR, e.getMessage(), e));
}
push();
} // else {cannot commit/push root removal}
}

private void commit(boolean dir) throws CoreException {
Expand Down
Expand Up @@ -14,3 +14,4 @@ Require-Bundle: org.eclipse.core.filesystem;bundle-version="1.3.100",
org.eclipse.test.performance;bundle-version="3.7.0",
org.eclipse.equinox.security;bundle-version="1.1.0"
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.eclipse.orion.server.tests.filesystem.Activator
Expand Up @@ -27,7 +27,7 @@
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/Java60"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.orion.server.tests.filesystem.git.AllTests"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -console"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.orion.server.tests.filesystem"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms256m -Xmx768m -Declipse.log.level=WARNING"/>
Expand Down
Expand Up @@ -27,7 +27,7 @@
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/Java60"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.orion.server.tests.filesystem.git.SshTest"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -console"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.orion.server.tests.filesystem"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms256m -Xmx768m -Dorion.sshtest.properties=c:/eclipse/sshtest.properties -Declipse.log.level=WARNING"/>
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010 IBM Corporation and others.
* Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -17,8 +17,7 @@

@RunWith(Suite.class)
@SuiteClasses({ CreateDirectoryTest.class, DeleteTest.class,
OpenOutputStreamTest.class, PutInfoTest.class, UtilsTest.class,
GitFileSystemTest.class, ConcurrentModificationsTest.class,
GitFileStoreTest.class })
OpenOutputStreamTest.class, PutInfoTest.class, GitFileSystemTest.class,
ConcurrentModificationsTest.class, GitFileStoreTest.class })
public class AllTests extends TestCase {
}
Expand Up @@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.orion.server.tests.filesystem.git;

import java.io.IOException;
import java.net.URI;

import org.eclipse.core.filesystem.EFS;
Expand All @@ -25,6 +24,7 @@ public class CreateDirectoryTest extends

private IPath repositoryPath;

@Override
protected void doFSSetUp() throws Exception {
repositoryPath = getRandomLocation();
URI uri = URIUtil.toURI(repositoryPath); //encoded
Expand All @@ -37,11 +37,20 @@ protected void doFSSetUp() throws Exception {
baseStore.mkdir(EFS.NONE, null);
}

protected void doFSTearDown() throws IOException {
// delete <temp>/<repo>
@Override
protected void doFSTearDown() throws Exception {
// nothing to do
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
// remove the repository
FileSystemHelper.clear(repositoryPath.toFile());
// remove the clone
FileSystemHelper.clear(((GitFileStore)baseStore).getLocalFile());
}

public void testGetParentForRoot() {
GitFileStore parent = (GitFileStore) baseStore.getParent();
assertTrue("1.1", ((GitFileStore)baseStore).isRoot());
Expand Down
Expand Up @@ -10,13 +10,13 @@
*******************************************************************************/
package org.eclipse.orion.server.tests.filesystem.git;

import java.io.IOException;
import java.net.URI;

import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.tests.harness.FileSystemHelper;
import org.eclipse.orion.server.filesystem.git.GitFileStore;
import org.eclipse.orion.server.filesystem.git.GitFileSystem;

public class DeleteTest extends org.eclipse.core.tests.filesystem.DeleteTest {
Expand All @@ -35,8 +35,17 @@ protected void doFSSetUp() throws Exception {
baseStore.mkdir(EFS.NONE, null);
}

protected void doFSTearDown() throws IOException {
// delete <temp>/<repo>
@Override
protected void doFSTearDown() throws Exception {
// nothing to do
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
// remove the repository
FileSystemHelper.clear(repositoryPath.toFile());
// remove the clone
FileSystemHelper.clear(((GitFileStore)baseStore).getLocalFile());
}
}
Expand Up @@ -10,13 +10,13 @@
*******************************************************************************/
package org.eclipse.orion.server.tests.filesystem.git;

import java.io.IOException;
import java.net.URI;

import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.tests.harness.FileSystemHelper;
import org.eclipse.orion.server.filesystem.git.GitFileStore;
import org.eclipse.orion.server.filesystem.git.GitFileSystem;

public class OpenOutputStreamTest extends
Expand All @@ -36,8 +36,17 @@ protected void doFSSetUp() throws Exception {
baseStore.mkdir(EFS.NONE, null);
}

protected void doFSTearDown() throws IOException {
// delete <temp>/<repo>
@Override
protected void doFSTearDown() throws Exception {
// nothing to do
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
// remove the repository
FileSystemHelper.clear(repositoryPath.toFile());
// remove the clone
FileSystemHelper.clear(((GitFileStore)baseStore).getLocalFile());
}
}
Expand Up @@ -10,13 +10,13 @@
*******************************************************************************/
package org.eclipse.orion.server.tests.filesystem.git;

import java.io.IOException;
import java.net.URI;

import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.tests.harness.FileSystemHelper;
import org.eclipse.orion.server.filesystem.git.GitFileStore;
import org.eclipse.orion.server.filesystem.git.GitFileSystem;

public class PutInfoTest extends org.eclipse.core.tests.filesystem.PutInfoTest {
Expand All @@ -35,8 +35,17 @@ protected void doFSSetUp() throws Exception {
baseStore.mkdir(EFS.NONE, null);
}

protected void doFSTearDown() throws IOException {
// delete <temp>/<repo>
@Override
protected void doFSTearDown() throws Exception {
// nothing to do
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
// remove the repository
FileSystemHelper.clear(repositoryPath.toFile());
// remove the clone
FileSystemHelper.clear(((GitFileStore)baseStore).getLocalFile());
}
}

0 comments on commit db249cd

Please sign in to comment.