summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Merks2013-08-11 13:19:15 (EDT)
committerEd Merks2013-08-11 13:19:15 (EDT)
commitaf1ff6dcc442f056464ed44d414f8dc994b1c1be (patch)
tree15417ac1b495cef73d645c9c718b556a38a4fd26
parent48f31a63f08d3de8c2f054610dd1ccb1158979f6 (diff)
downloadcdo-af1ff6dcc442f056464ed44d414f8dc994b1c1be.zip
cdo-af1ff6dcc442f056464ed44d414f8dc994b1c1be.tar.gz
cdo-af1ff6dcc442f056464ed44d414f8dc994b1c1be.tar.bz2
Signed-off-by: Ed Merks <ed.merks@gmail.com>
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.setup.ide/src/org/eclipse/emf/cdo/releng/setup/ide/GitClones.java96
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.setup.product/src/org/eclipse/emf/cdo/releng/setup/product/SetupDialog.java77
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/setup/helper/Files.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/setup/helper/OS.java11
4 files changed, 151 insertions, 49 deletions
diff --git a/plugins/org.eclipse.emf.cdo.releng.setup.ide/src/org/eclipse/emf/cdo/releng/setup/ide/GitClones.java b/plugins/org.eclipse.emf.cdo.releng.setup.ide/src/org/eclipse/emf/cdo/releng/setup/ide/GitClones.java
index b0be852..8c0953b 100644
--- a/plugins/org.eclipse.emf.cdo.releng.setup.ide/src/org/eclipse/emf/cdo/releng/setup/ide/GitClones.java
+++ b/plugins/org.eclipse.emf.cdo.releng.setup.ide/src/org/eclipse/emf/cdo/releng/setup/ide/GitClones.java
@@ -13,13 +13,26 @@ package org.eclipse.emf.cdo.releng.setup.ide;
import org.eclipse.emf.cdo.releng.setup.Branch;
import org.eclipse.emf.cdo.releng.setup.GitClone;
import org.eclipse.emf.cdo.releng.setup.Setup;
+import org.eclipse.emf.cdo.releng.setup.helper.Files;
+import org.eclipse.emf.cdo.releng.setup.helper.OS;
import org.eclipse.emf.cdo.releng.setup.helper.Progress;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.jgit.api.CheckoutCommand;
import org.eclipse.jgit.api.CloneCommand;
+import org.eclipse.jgit.api.CreateBranchCommand;
+import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.ResetCommand;
+import org.eclipse.jgit.api.ResetCommand.ResetType;
+import org.eclipse.jgit.api.StatusCommand;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.errors.NoWorkTreeException;
+import org.eclipse.jgit.lib.ConfigConstants;
+import org.eclipse.jgit.lib.CoreConfig.AutoCRLF;
import org.eclipse.jgit.lib.ProgressMonitor;
+import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.transport.RefSpec;
@@ -28,6 +41,7 @@ import org.eclipse.jgit.transport.RemoteConfig;
import java.io.File;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
/**
* @author Eike Stepper
@@ -47,16 +61,27 @@ public final class GitClones
File workDir = CONTEXT.getWorkDir(gitClone);
Repository repository = null;
- Git git;
+ Git git = null;
try
{
+ boolean needsClone = true;
if (workDir.isDirectory())
{
Progress.log().addLine("Opening Git clone " + workDir);
git = Git.open(workDir);
+ if (hasWorkingDirectory(git))
+ {
+ needsClone = false;
+ }
+ else
+ {
+ Files.rename(workDir);
+ }
}
- else
+
+ String checkoutBranch = gitClone.getCheckoutBranch();
+ if (needsClone)
{
URI baseURI = URI.createURI(gitClone.getRemoteURI());
String remote = URI.createHierarchicalURI(baseURI.scheme(), userName + "@" + baseURI.authority(),
@@ -64,10 +89,10 @@ public final class GitClones
Progress.log().addLine("Cloning Git repo " + remote + " to " + workDir);
CloneCommand command = Git.cloneRepository();
+ command.setNoCheckout(true);
command.setURI(remote);
command.setRemote("origin");
- command.setBranchesToClone(Collections.singleton(gitClone.getCheckoutBranch()));
- command.setBranch(gitClone.getCheckoutBranch());
+ command.setBranchesToClone(Collections.singleton(checkoutBranch));
command.setDirectory(workDir);
command.setTimeout(10);
command.setProgressMonitor(new ProgressLogWrapper());
@@ -78,7 +103,14 @@ public final class GitClones
repository = git.getRepository();
StoredConfig config = repository.getConfig();
- String gerritQueue = "refs/for/" + gitClone.getCheckoutBranch();
+ boolean changed = false;
+ if (OS.INSTANCE.isLineEndingConversionNeeded())
+ {
+ changed = true;
+ config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.TRUE);
+ }
+
+ String gerritQueue = "refs/for/" + checkoutBranch;
List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(config);
for (RemoteConfig remoteConfig : remoteConfigs)
@@ -93,8 +125,42 @@ public final class GitClones
remoteConfig.addPushRefSpec(refSpec);
remoteConfig.update(config);
- config.save();
+ changed = true;
}
+
+ break;
+ }
+ }
+
+ if (changed)
+ {
+ config.save();
+ }
+
+ Map<String, Ref> allRefs = repository.getAllRefs();
+ if (!allRefs.containsKey("refs/heads/" + checkoutBranch))
+ {
+ {
+ CreateBranchCommand command = git.branchCreate();
+ command.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM);
+ command.setName(checkoutBranch);
+ command.setStartPoint("refs/remotes/origin/" + checkoutBranch);
+
+ command.call();
+ }
+
+ {
+ CheckoutCommand command = git.checkout();
+ command.setName(checkoutBranch);
+
+ command.call();
+ }
+
+ {
+ ResetCommand command = git.reset();
+ command.setMode(ResetType.HARD);
+
+ command.call();
}
}
}
@@ -108,6 +174,24 @@ public final class GitClones
}
}
+ private static boolean hasWorkingDirectory(Git git) throws GitAPIException
+ {
+ try
+ {
+ StatusCommand statusCommand = git.status();
+ statusCommand.call();
+ return true;
+ }
+ catch (NoWorkTreeException ex)
+ {
+ return false;
+ }
+ catch (GitAPIException ex)
+ {
+ throw ex;
+ }
+ }
+
private static boolean hasGerritPushRefSpec(List<RefSpec> pushRefSpecs, String gerritQueue)
{
for (RefSpec refSpec : pushRefSpecs)
diff --git a/plugins/org.eclipse.emf.cdo.releng.setup.product/src/org/eclipse/emf/cdo/releng/setup/product/SetupDialog.java b/plugins/org.eclipse.emf.cdo.releng.setup.product/src/org/eclipse/emf/cdo/releng/setup/product/SetupDialog.java
index b1e7a51..b06a2f6 100644
--- a/plugins/org.eclipse.emf.cdo.releng.setup.product/src/org/eclipse/emf/cdo/releng/setup/product/SetupDialog.java
+++ b/plugins/org.eclipse.emf.cdo.releng.setup.product/src/org/eclipse/emf/cdo/releng/setup/product/SetupDialog.java
@@ -50,6 +50,7 @@ import org.eclipse.emf.edit.ui.provider.DecoratingColumLabelProvider;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.CellEditor;
@@ -341,6 +342,7 @@ public class SetupDialog extends TitleAreaDialog
{
public void modifyText(ModifyEvent e)
{
+ preferences.setUserName(userNameText.getText());
validate();
}
});
@@ -360,6 +362,7 @@ public class SetupDialog extends TitleAreaDialog
{
public void modifyText(ModifyEvent e)
{
+ preferences.setInstallFolder(installFolderText.getText());
validate();
}
});
@@ -395,6 +398,7 @@ public class SetupDialog extends TitleAreaDialog
{
public void modifyText(ModifyEvent e)
{
+ preferences.setGitPrefix(gitPrefixText.getText());
validate();
}
});
@@ -524,6 +528,11 @@ public class SetupDialog extends TitleAreaDialog
private void validate()
{
+ if (viewer != null)
+ {
+ viewer.refresh(true);
+ }
+
Button installButton = getButton(IDialogConstants.OK_ID);
if (installButton == null)
{
@@ -532,68 +541,48 @@ public class SetupDialog extends TitleAreaDialog
if (viewer.getCheckedElements().length == 0)
{
- setErrorMessage("Select one or more project branches to install.");
+ setMessage("Select one or more project branches to install.", IMessageProvider.ERROR);
installButton.setEnabled(false);
return;
}
if (userNameText.getText().length() == 0)
{
- setErrorMessage("Enter your user name.");
+ setMessage("Enter your user name.", IMessageProvider.WARNING);
installButton.setEnabled(false);
return;
}
if (installFolderText.getText().length() == 0)
{
- setErrorMessage("Enter the install folder.");
- installButton.setEnabled(false);
- return;
- }
-
- String gitPrefix = gitPrefixText.getText();
- if (gitPrefix.length() == 0)
- {
- setErrorMessage("Enter the Git prefix folder (which contains 'etc/gitconfig').");
- installButton.setEnabled(false);
- return;
- }
-
- File etc = new File(gitPrefix, "etc");
- File gitconfig = new File(etc, "gitconfig");
- if (!gitconfig.isFile())
- {
- setErrorMessage("The Git prefix folder does not contain 'etc/gitconfig'.");
+ setMessage("Enter the install folder.", IMessageProvider.WARNING);
installButton.setEnabled(false);
return;
}
if (Platform.OS_WIN32.equals(Platform.getOS()))
{
- if (!containsAutoCRLF(gitconfig))
+ String gitPrefix = gitPrefixText.getText();
+ if (gitPrefix.length() == 0)
{
- setErrorMessage("The gitconfig file must contain 'autocrlf = true' on Windows.\nWhen you've added this line modify the Git Prefix field to revalidate...");
- installButton.setEnabled(false);
+ setMessage("Enter the Git installation folder to use its 'etc/gitconfig' in the installed IDE.",
+ IMessageProvider.WARNING);
+ installButton.setEnabled(true);
return;
}
- }
-
- setErrorMessage(null);
- setMessage("Click the Install button to start the installation process.");
- installButton.setEnabled(true);
- }
- private boolean containsAutoCRLF(File file)
- {
- for (String line : OS.INSTANCE.readText(file))
- {
- if (line.contains("autocrlf") && line.contains("true"))
+ File etc = new File(gitPrefix, "etc");
+ File gitconfig = new File(etc, "gitconfig");
+ if (!gitconfig.isFile())
{
- return true;
+ setMessage("The Git prefix folder does not contain 'etc/gitconfig'.", IMessageProvider.WARNING);
+ installButton.setEnabled(true);
+ return;
}
}
- return false;
+ setMessage("Click the Install button to start the installation process.", IMessageProvider.NONE);
+ installButton.setEnabled(true);
}
private String safe(String string)
@@ -620,8 +609,12 @@ public class SetupDialog extends TitleAreaDialog
private URI getSetupURI(Branch branch)
{
- File installFolder = new File(installFolderText.getText());
- File projectFolder = new File(installFolder, branch.getProject().getName());
+ return getSetupURI(branch, installFolderText.getText());
+ }
+
+ private URI getSetupURI(Branch branch, String installFolder)
+ {
+ File projectFolder = new File(installFolder, branch.getProject().getName().toLowerCase());
File branchFolder = new File(projectFolder, branch.getName());
File setupFile = new File(branchFolder, "setup.xmi");
return URI.createFileURI(setupFile.getAbsolutePath());
@@ -726,7 +719,9 @@ public class SetupDialog extends TitleAreaDialog
setup.getUpdateLocations().add(p2Repository);
}
- setup.eResource().save(null);
+ Resource setupResource = setup.eResource();
+ setupResource.setURI(getSetupURI(branch, installFolder));
+ setupResource.save(null);
new File(branchFolder, "ws").mkdirs();
launchIDE(setup, branchFolder);
@@ -886,10 +881,6 @@ public class SetupDialog extends TitleAreaDialog
private void savePreferences()
{
- preferences.setUserName(userNameText.getText());
- preferences.setInstallFolder(installFolderText.getText());
- preferences.setGitPrefix(gitPrefixText.getText());
-
try
{
XMLResource xmlResource = (XMLResource)preferences.eResource();
diff --git a/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/setup/helper/Files.java b/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/setup/helper/Files.java
index 0f0a57a..ca4bc42 100644
--- a/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/setup/helper/Files.java
+++ b/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/setup/helper/Files.java
@@ -27,6 +27,22 @@ import java.util.List;
*/
public final class Files
{
+ public static void rename(File from) throws IOException, InterruptedException
+ {
+ File to = new File(from.getParentFile(), from.getName() + "." + System.currentTimeMillis());
+ for (int i = 0; i < 1000; i++)
+ {
+ if (from.renameTo(to))
+ {
+ return;
+ }
+
+ Thread.sleep(5);
+ }
+
+ throw new IOException("Could not rename '" + from.getAbsolutePath() + "' to '" + to.getAbsolutePath() + "'");
+ }
+
public static void rename(File from, File to) throws IOException, InterruptedException
{
for (int i = 0; i < 1000; i++)
diff --git a/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/setup/helper/OS.java b/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/setup/helper/OS.java
index 8495e48..3b50327 100644
--- a/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/setup/helper/OS.java
+++ b/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/setup/helper/OS.java
@@ -33,6 +33,11 @@ public abstract class OS
{
public static final OS INSTANCE = create();
+ public boolean isLineEndingConversionNeeded()
+ {
+ return false;
+ }
+
public List<String> readText(File file)
{
FileInputStream in = null;
@@ -141,6 +146,12 @@ public abstract class OS
private static final class Win extends OS
{
@Override
+ public boolean isLineEndingConversionNeeded()
+ {
+ return true;
+ }
+
+ @Override
public String getEclipseExecutable()
{
return "eclipse.exe";