Permalink
Browse files

Initial implementation of Clone

* Cloning of local repositories and remote (using git:// protocol)
  currently working.
* Caveats:
  * OutputLogger text needs cleaning up.
  * All protocols not testing.
  * URL validation not working correctly -- after entering an invalid
    URL, wizard must be cancelled.
  * GitProgressMonitor implementation of JGit's ProgressMonitor is
    not accurate, and needs better understanding of NetBeans progress
    support APIs.

Signed-off-by: Alex Coles <alex@alexcolesportfolio.com>
  • Loading branch information...
myabc committed Aug 16, 2009
1 parent b1c8ef5 commit 1b180301736ab27863af6fa0f0bf0d142c814fe3
Showing with 4,983 additions and 1 deletion.
  1. +4 −0 src/org/nbgit/GitAnnotator.java
  2. +107 −0 src/org/nbgit/GitProgressMonitor.java
  3. +21 −0 src/org/nbgit/GitProgressSupport.java
  4. +98 −0 src/org/nbgit/ui/clone/Bundle.properties
  5. +118 −0 src/org/nbgit/ui/clone/Clone.java
  6. +302 −0 src/org/nbgit/ui/clone/CloneAction.java
  7. +84 −0 src/org/nbgit/ui/clone/CloneCompleted.java
  8. +60 −0 src/org/nbgit/ui/clone/CloneExternalAction.java
  9. +170 −0 src/org/nbgit/ui/clone/ClonePanel.form
  10. +257 −0 src/org/nbgit/ui/clone/ClonePanel.java
  11. +109 −0 src/org/nbgit/ui/repository/Bundle.properties
  12. +720 −0 src/org/nbgit/ui/repository/GitRepositoryUI.java
  13. +56 −0 src/org/nbgit/ui/repository/GitURIScheme.java
  14. +56 −0 src/org/nbgit/ui/repository/RepositoryDialogPanel.form
  15. +97 −0 src/org/nbgit/ui/repository/RepositoryDialogPanel.java
  16. +371 −0 src/org/nbgit/ui/repository/RepositoryPanel.form
  17. +243 −0 src/org/nbgit/ui/repository/RepositoryPanel.java
  18. +80 −0 src/org/nbgit/ui/wizards/Bundle.properties
  19. +153 −0 src/org/nbgit/ui/wizards/CloneDestinationDirectoryPanel.form
  20. +285 −0 src/org/nbgit/ui/wizards/CloneDestinationDirectoryPanel.java
  21. +197 −0 src/org/nbgit/ui/wizards/CloneDestinationDirectoryWizardPanel.java
  22. +146 −0 src/org/nbgit/ui/wizards/ClonePathsPanel.form
  23. +138 −0 src/org/nbgit/ui/wizards/ClonePathsPanel.java
  24. +312 −0 src/org/nbgit/ui/wizards/ClonePathsWizardPanel.java
  25. +432 −0 src/org/nbgit/ui/wizards/CloneRepositoryWizardPanel.java
  26. +172 −0 src/org/nbgit/ui/wizards/CloneWizardAction.java
  27. +176 −0 src/org/nbgit/ui/wizards/WizardStepProgressSupport.java
  28. +19 −1 src/org/nbgit/util/GitUtils.java
@@ -52,6 +52,8 @@
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level;
import javax.swing.Action;
+import org.nbgit.ui.clone.CloneAction;
+import org.nbgit.ui.clone.CloneExternalAction;
import org.nbgit.ui.commit.CommitAction;
import org.nbgit.ui.custom.CustomMenu;
import org.nbgit.ui.diff.DiffAction;
@@ -254,12 +256,14 @@ public Image annotateIcon(Image icon, VCSContext context) {
actions.add(new ExportDiffAction(loc.getString("CTL_PopupMenuItem_ExportDiff"), ctx)); // NOI18N
actions.add(new ApplyDiffAction(loc.getString("CTL_PopupMenuItem_ImportDiff"), ctx)); // NOI18N
actions.add(null);
+ */
if (root != null) {
actions.add(new CloneAction(NbBundle.getMessage(GitAnnotator.class, "CTL_PopupMenuItem_CloneLocal", // NOI18N
root.getName()), ctx));
}
actions.add(new CloneExternalAction(loc.getString("CTL_PopupMenuItem_CloneOther"), ctx)); // NOI18N
actions.add(null);
+ /*
actions.add(new FetchAction(NbBundle.getMessage(GitAnnotator.class, "CTL_PopupMenuItem_FetchLocal"), ctx)); // NOI18N
actions.add(new PushAction(NbBundle.getMessage(GitAnnotator.class, "CTL_PopupMenuItem_PushLocal"), ctx)); // NOI18N
actions.add(new PushOtherAction(loc.getString("CTL_PopupMenuItem_PushOther"), ctx)); // NOI18N
@@ -0,0 +1,107 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Alexander Coles (Ikonoklastik Productions).
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file.
+ *
+ * This particular file is subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ */
+package org.nbgit;
+
+import org.netbeans.api.progress.aggregate.AggregateProgressFactory;
+import org.netbeans.api.progress.aggregate.AggregateProgressHandle;
+import org.netbeans.api.progress.aggregate.ProgressContributor;
+import org.spearce.jgit.lib.ProgressMonitor;
+
+/**
+ *
+ * @author alexbcoles
+ */
+public class GitProgressMonitor implements ProgressMonitor {
+
+ //private final GitProgressSupport support;
+ private final AggregateProgressHandle rootHandle;
+ private ProgressContributor contributor;
+ private boolean started = false;
+
+ public GitProgressMonitor(/*final GitProgressSupport support*/) {
+ //this.support = support;
+ // TODO: make this cancellable
+ rootHandle = AggregateProgressFactory.createHandle("Task", null, null, null);
+ }
+
+ public void start(int totalTasks) {
+ if (!started) {
+ rootHandle.start();
+ started = true;
+ }
+ }
+
+ public void beginTask(String title, int total) {
+ endTask();
+
+ contributor = AggregateProgressFactory.createProgressContributor(title + new java.util.Random());
+ rootHandle.addContributor(contributor);
+
+ if (total == UNKNOWN) {
+ contributor.start(1000);
+ } else {
+ contributor.start(total);
+ }
+ }
+
+ public void update(int completed) {
+ if (contributor == null) {
+ return;
+ }
+
+ contributor.progress(completed);
+ }
+
+ public void endTask() {
+ if (contributor != null) {
+ try {
+ contributor.finish();
+ } finally {
+ contributor = null;
+ }
+ }
+ }
+
+ public boolean isCancelled() {
+ // TODO: figure out how to implement this
+ return false;
+
+ //if (contributor != null) {
+ //
+ //}
+ }
+
+}
@@ -41,13 +41,17 @@
*/
package org.nbgit;
+import java.net.URISyntaxException;
import java.util.logging.Level;
+import javax.swing.JComponent;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.progress.ProgressHandleFactory;
import org.openide.util.Cancellable;
+import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;
import org.openide.util.TaskListener;
+import org.spearce.jgit.transport.URIish;
/**
*
@@ -79,6 +83,15 @@ public void taskFinished(org.openide.util.Task task) {
return task;
}
+ public JComponent getProgressComponent() {
+ return ProgressHandleFactory.createProgressComponent(getProgressHandle());
+ }
+
+ public void setRepositoryRoot(String repositoryRoot) {
+ this.repositoryRoot = repositoryRoot;
+ logger = null;
+ }
+
public void run() {
setProgress();
performIntern();
@@ -169,4 +182,12 @@ public OutputLogger getLogger() {
}
return logger;
}
+
+ public URIish getRepositoryRoot() {
+ try {
+ return new URIish(repositoryRoot);
+ } catch (URISyntaxException ex) {
+ return new URIish();
+ }
+ }
}
@@ -0,0 +1,98 @@
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+#
+# Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+#
+# The contents of this file are subject to the terms of either the GNU
+# General Public License Version 2 only ("GPL") or the Common
+# Development and Distribution License("CDDL") (collectively, the
+# "License"). You may not use this file except in compliance with the
+# License. You can obtain a copy of the License at
+# http://www.netbeans.org/cddl-gplv2.html
+# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+# specific language governing permissions and limitations under the
+# License. When distributing the software, include this License Header
+# Notice in each file and include the License file at
+# nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Sun in the GPL Version 2 section of the License file that
+# accompanied this code. If applicable, add the following below the
+# License Header, with the fields enclosed by brackets [] replaced by
+# your own identifying information:
+# "Portions Copyrighted [year] [name of copyright owner]"
+#
+# Contributor(s):
+#
+# The Original Software is NetBeans. The Initial Developer of the Original
+# Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
+# Microsystems, Inc. All Rights Reserved.
+#
+# If you wish your version of this file to be governed by only the CDDL
+# or only the GPL Version 2, indicate your decision by adding
+# "[Contributor] elects to include this software in this distribution
+# under the [CDDL or GPL Version 2] license." If you do not indicate a
+# single choice of license, a recipient has the option to distribute
+# your version of this file under either the CDDL, the GPL Version 2 or
+# to extend the choice of license to its licensees as provided above.
+# However, if you add GPL Version 2 code and therefore, elected the GPL
+# Version 2 license, then the option applies only if the new code is
+# made subject to such option by the copyright holder.
+
+CTL_CloneExternalAction=Clone...
+MSG_CLONE_TITLE = Git Clone
+MSG_CLONE_TITLE_SEP = ---------------
+MSG_CLONE_FROM = INFO Clone From: {0} - {1}
+MSG_CLONE_TO = INFO To: {0} - {1}
+MSG_CLONE_DONE = INFO: End of Clone
+MSG_EXTERNAL_CLONE_FROM = INFO Clone From: {0}
+MSG_EXTERNAL_CLONE_TO = INFO To: {0}
+MSG_CLONE_NOTHING = Nothing yet comitted, so nothing to Clone.
+
+LBL_Clone_Progress=Cloning {0}...
+ClonePanel.fromLabel.text=Source Repository:
+ClonePanel.toLabel.text=&Parent Directory:
+ClonePanel.browseButton.text=&Browse...
+
+CTL_CloneForm_Action_Clone=C&lone
+ACSN_CloneForm_Action_Clone=Clone
+ACSD_CloneForm_Action_Clone=Clone
+CTL_CloneForm_Action_Cancel=Can&cel
+ACSN_CloneForm_Action_Cancel=Cancel
+ACSD_CloneForm_Action_Cancel=Cancel
+CTL_CloneDialog=Clone Repository
+ACSD_CloneDialog=Clone Repository
+
+ACSD_BrowseFolder = Lets you browse for directory for target git repository.
+Browse_title=Browse for the Parent Directory
+OK_Button=OK
+Folders=Folders
+
+#CloneCompleted
+ACSD_CloneCompleted_Dialog = This dialog lets you choose further actions to do after you successfully clone a repository.
+BK3001=<html><b>Clone Completed</b><p>\nYou can continue with: <ul><li>opening an existing NetBeans project or <li>creating a new one from cloned sources.</ul>
+BK3002=Do Not Show This Message Again
+BK3003=Open Project..
+BK3004=Create Project...
+BK3005=&Close
+BK3008=Clone Completed
+# {0} contains number
+BK3009=<html>{0} projects were cloned.<p>Do you want to open a project?
+BK3010=<html>Do you want to create an IDE project from the cloned sources?
+# {0} project name
+BK3011=<html>{0} project was cloned.<p>Do you want to set cloned project as Main project?
+BK3012=Open Project
+BK1014=Can not find project for {0}
+
+
+TT_Close=Dismiss the dialog
+TT_OpenProject=Go to file explorer and select a project to open from cloned sources
+TT_CreateProject=Go to project wizard to create a new project from cloned sources
+ClonePanel.toName.text=Clone &Name:
+
+destinationLabel.text=Destination:
+openCheckbox.text=&Set Cloned Project as Main
+MSG_EXTERNAL_CLONE_PRJ_NOT_FOUND_CANT_SETASMAIN = INFO: Unable to open project.\nINFO: This is either not a top level NetBeans Project or all the NetBeans project files have not been committed in the source Project.\n\n
+ACSD_Browse=Browse for parent of destination repository
+ACSD_setMainCheckBox=The cloned project will be set as Main project
+ACSD_toCloneField=Specifies name of cloned project
+ACSD_toTextField=Specifies the parent directory of cloned project
+ACSD_fromTextField=Specifies the repository to be cloned
@@ -0,0 +1,118 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * The Original Software is NetBeans. The Initial Developer of the Original
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ * Portions Copyright 2009 Alexander Coles (Ikonoklastik Productions).
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ */
+package org.nbgit.ui.clone;
+
+
+import java.awt.Dialog;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import javax.swing.JButton;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import org.openide.DialogDescriptor;
+import org.openide.DialogDisplayer;
+import org.openide.util.HelpCtx;
+
+
+public class Clone implements PropertyChangeListener {
+
+ private final ClonePanel panel;
+ private final JButton okButton;
+ private final JButton cancelButton;
+ private final DocumentListener listener;
+
+ public Clone(File repository, File to) {
+ panel = new ClonePanel(repository, to);
+ okButton = new JButton();
+ org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(CloneAction.class, "CTL_CloneForm_Action_Clone"));
+ okButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(Clone.class, "ACSN_CloneForm_Action_Clone")); // NOI18N
+ okButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(Clone.class, "ACSD_CloneForm_Action_Clone")); // NOI18N
+
+ cancelButton = new JButton();
+ org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(CloneAction.class, "CTL_CloneForm_Action_Cancel"));
+ cancelButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(Clone.class, "ACSD_CloneForm_Action_Cancel")); // NOI18N
+ cancelButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(Clone.class, "ACSN_CloneForm_Action_Cancel")); // NOI18N
+
+ this.listener = new DocumentListener() {
+ public void insertUpdate(DocumentEvent e) { nameChange(); }
+ public void removeUpdate(DocumentEvent e) { nameChange(); }
+ public void changedUpdate(DocumentEvent e) { nameChange(); }
+ };
+ panel.toTextField.getDocument().addDocumentListener(listener);
+ }
+
+ public boolean showDialog() {
+ DialogDescriptor dialogDescriptor = new DialogDescriptor(panel, org.openide.util.NbBundle.getMessage(Clone.class, "CTL_CloneDialog"), // NOI18N
+ true, new Object[]{okButton, cancelButton}, okButton, DialogDescriptor.DEFAULT_ALIGN, new HelpCtx(this.getClass()), null);
+ dialogDescriptor.setValid(false);
+
+ Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
+ dialog.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(Clone.class, "ACSD_CloneDialog")); // NOI18N
+ dialog.setVisible(true);
+ dialog.setResizable(false);
+ boolean ret = dialogDescriptor.getValue() == okButton;
+ return ret;
+ }
+
+ private void nameChange() {
+ if (panel.toTextField.getText().trim().length() > 0)
+ okButton.setEnabled(true);
+ else
+ okButton.setEnabled(false);
+ }
+
+ public void propertyChange(PropertyChangeEvent evt) {
+ if(okButton != null) {
+ boolean valid = ((Boolean)evt.getNewValue()).booleanValue();
+ okButton.setEnabled(valid);
+ }
+ }
+
+ public File getTargetDir() {
+ if (panel == null) {
+ return null;
+ }
+ return panel.getTargetDir();
+ }
+
+}
Oops, something went wrong.

0 comments on commit 1b18030

Please sign in to comment.