Author: adietish
Date: 2012-01-18 14:34:29 -0500 (Wed, 18 Jan 2012)
New Revision: 37950
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AbstractImportApplicationOperation.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ConfigureGitSharedProject.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ConfigureUnsharedProject.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/OpenShiftMavenProfile.java
Log:
[JBIDE-10479] now adding and committing modified/created files to local git repo
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AbstractImportApplicationOperation.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AbstractImportApplicationOperation.java 2012-01-18
19:02:35 UTC (rev 37949)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AbstractImportApplicationOperation.java 2012-01-18
19:34:29 UTC (rev 37950)
@@ -65,8 +65,8 @@
* @see AbstractImportApplicationOperation#getApplication()
* @see #getRepositoryPath()
*/
- protected File cloneRepository(IApplication application, String remoteName, File
destination,
- boolean addToRepoView, IProgressMonitor monitor)
+ protected File cloneRepository(IApplication application, String remoteName, File
destination, boolean addToRepoView,
+ IProgressMonitor monitor)
throws OpenShiftException, InvocationTargetException, InterruptedException,
URISyntaxException {
monitor.subTask(NLS.bind("Cloning repository for application {0}...",
application.getName()));
EGitUIUtils.ensureEgitUIIsStarted();
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ConfigureGitSharedProject.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ConfigureGitSharedProject.java 2012-01-18
19:02:35 UTC (rev 37949)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ConfigureGitSharedProject.java 2012-01-18
19:34:29 UTC (rev 37950)
@@ -14,13 +14,18 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.egit.core.op.AddToIndexOperation;
import org.eclipse.osgi.util.NLS;
import org.jboss.ide.eclipse.as.core.util.FileUtil;
import org.jboss.tools.openshift.egit.core.EGitUtils;
@@ -40,17 +45,21 @@
*/
public class ConfigureGitSharedProject extends AbstractImportApplicationOperation {
+ private ArrayList<IResource> modifiedResources;
+
public ConfigureGitSharedProject(String projectName, IApplication application, String
remoteName,
IUser user) {
super(projectName, application, remoteName);
+ this.modifiedResources = new ArrayList<IResource>();
}
/**
* Enables the user chosen project to be used on the chosen OpenShift
- * application.
+ * application.
* <ul>
* <li>clones the application git repository</li>
- * <li>copies the configuration files to the user project (in the
workspace)</li>
+ * <li>copies the configuration files to the user project (in the workspace)
+ * </li>
* <li>adds the appication git repo as remote</li>
* </ul>
*
@@ -86,24 +95,26 @@
IProject project = getProject();
Assert.isTrue(EGitUtils.isSharedWithGit(project));
- File tmpFolder = FileUtils.getRandomTmpFolder();
- File repositoryFile = cloneRepository(getApplication(), getRemoteName(), tmpFolder,
false, monitor);
+ copyOpenshiftConfigurations(getApplication(), getRemoteName(), project, monitor);
- copyOpenshiftConfigurations(repositoryFile, project, monitor);
- FileUtil.safeDelete(tmpFolder);
-
setupGitIgnore(project);
+ project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
EGitUtils.addRemoteTo(
getRemoteName(),
getApplication().getGitUri(),
EGitUtils.getRepository(project));
-
setupOpenShiftMavenProfile(project);
+ addAndCommitModifiedResource(project, monitor);
return Collections.singletonList(project);
}
+ private void addAndCommitModifiedResource(IProject project, IProgressMonitor monitor)
throws CoreException {
+ new AddToIndexOperation(modifiedResources).execute(monitor);
+ EGitUtils.commit(project, monitor);
+ }
+
private void setupOpenShiftMavenProfile(IProject project) throws CoreException {
Assert.isLegal(OpenShiftMavenProfile.isMavenProject(project));
@@ -112,7 +123,8 @@
return;
}
profile.addToPom(project.getName());
- profile.savePom();
+ IFile pomFile = profile.savePom();
+ modifiedResources.add(pomFile);
}
/**
@@ -131,18 +143,51 @@
* the project to copy the configuration to.
* @param monitor
* the monitor to report progress to
+ * @return
* @throws IOException
+ * @throws CoreException
+ * @throws URISyntaxException
+ * @throws InterruptedException
+ * @throws InvocationTargetException
+ * @throws OpenShiftException
*/
- private void copyOpenshiftConfigurations(final File sourceFolder, IProject project,
IProgressMonitor monitor)
- throws IOException {
+ private void copyOpenshiftConfigurations(IApplication application, String remoteName,
IProject project, IProgressMonitor monitor)
+ throws IOException, CoreException, OpenShiftException, InvocationTargetException,
InterruptedException, URISyntaxException {
Assert.isLegal(project != null);
- File projectFolder = project.getLocation().toFile();
monitor.subTask(NLS.bind("Copying openshift configuration to project {0}...",
project.getName()));
- FileUtils.copy(new File(sourceFolder, ".openshift"), projectFolder, false);
- FileUtils.copy(new File(sourceFolder, "deployments"), projectFolder, false);
+ File tmpFolder = FileUtils.getRandomTmpFolder();
+ cloneRepository(application, remoteName, tmpFolder, false, monitor);
+
+ Collection<IResource> copiedResources =
+ copyResources(tmpFolder, new String[] { ".openshift",
"deployments" }, project);
+ modifiedResources.addAll(copiedResources);
+ FileUtil.safeDelete(tmpFolder);
}
+ private Collection<IResource> copyResources(File sourceFolder, String[]
sourcePaths, IProject project)
+ throws IOException {
+ List<IResource> resources = new ArrayList<IResource>();
+ File projectFolder = project.getLocation().toFile();
+
+ for (String sourcePath : sourcePaths) {
+ File source = new File(sourceFolder, sourcePath);
+
+ if (!FileUtils.canRead(source)) {
+ continue;
+ }
+
+ FileUtils.copy(source, projectFolder, false);
+
+ if (source.isDirectory()) {
+ resources.add(project.getFolder(sourcePath));
+ } else {
+ resources.add(project.getFile(sourcePath));
+ }
+ }
+ return resources;
+ }
+
/**
* Adds a predefined set of entries to the gitignore file in (root of) the
* given project. If no .gitignore exists yet, a fresh one is created.
@@ -158,6 +203,8 @@
.add(".project")
.add(".classpath")
.add(".factorypath");
- gitIgnore.write(false);
+ File file = gitIgnore.write(false);
+ IFile gitIgnoreFile = project.getFile(file.getName());
+ modifiedResources.add(gitIgnoreFile);
}
}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ConfigureUnsharedProject.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ConfigureUnsharedProject.java 2012-01-18
19:02:35 UTC (rev 37949)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ConfigureUnsharedProject.java 2012-01-18
19:34:29 UTC (rev 37950)
@@ -89,17 +89,12 @@
// model.shareProject(monitor);
// model.mergeWithApplicationRepository(repository,
// monitor);
- File tmpFolder = FileUtils.getRandomTmpFolder();
IProject project = getProject();
- File repositoryFile = cloneRepository(getApplication(), getRemoteName(), tmpFolder,
false, monitor);
-
- copyOpenshiftConfigurations(repositoryFile, project, monitor);
- FileUtil.safeDelete(tmpFolder);
-
+ copyOpenshiftConfigurations(getApplication(), getRemoteName(), project, monitor);
createGitIgnore(project);
+ shareProject(project, monitor);
- shareProject(project, monitor);
return Collections.singletonList(project);
}
@@ -126,16 +121,27 @@
* @param monitor
* the monitor to report progress to
* @throws IOException
+ * @throws URISyntaxException
+ * @throws InterruptedException
+ * @throws InvocationTargetException
+ * @throws OpenShiftException
*/
- private void copyOpenshiftConfigurations(final File sourceFolder, IProject project,
IProgressMonitor monitor)
- throws IOException {
+ private void copyOpenshiftConfigurations(IApplication application, String remoteName,
IProject project, IProgressMonitor monitor)
+ throws IOException, OpenShiftException, InvocationTargetException,
InterruptedException, URISyntaxException {
Assert.isLegal(project != null);
File projectFolder = project.getLocation().toFile();
+
+ File tmpFolder = FileUtils.getRandomTmpFolder();
+ cloneRepository(getApplication(), getRemoteName(), tmpFolder, false, monitor);
+
monitor.subTask(NLS.bind("Copying openshift configuration to project {0}...",
project.getName()));
- FileUtils.copy(new File(sourceFolder, ".git"), projectFolder, false);
- FileUtils.copy(new File(sourceFolder, ".openshift"), projectFolder, false);
- FileUtils.copy(new File(sourceFolder, "deployments"), projectFolder, false);
- FileUtils.copy(new File(sourceFolder, "pom.xml"), projectFolder, false);
+ FileUtils.copy(new File(tmpFolder, ".git"), projectFolder, false);
+ FileUtils.copy(new File(tmpFolder, ".openshift"), projectFolder, false);
+ FileUtils.copy(new File(tmpFolder, "deployments"), projectFolder, false);
+ FileUtils.copy(new File(tmpFolder, "pom.xml"), projectFolder, false);
+
+ FileUtil.safeDelete(tmpFolder);
+
}
/**
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/OpenShiftMavenProfile.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/OpenShiftMavenProfile.java 2012-01-18
19:02:35 UTC (rev 37949)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/OpenShiftMavenProfile.java 2012-01-18
19:34:29 UTC (rev 37950)
@@ -272,12 +272,13 @@
return new Status(IStatus.ERROR, pluginId, message);
}
- public void savePom() throws CoreException {
+ public IFile savePom() throws CoreException {
Writer writer = null;
try {
writer = new StringWriter();
createTransformer().transform(new DOMSource(getDocument()), new
StreamResult(writer));
pomFile.setContents(new ByteArrayInputStream(writer.toString().getBytes()),
IResource.FORCE, null);
+ return pomFile;
} catch (TransformerConfigurationException e) {
throw new CoreException(createStatus(e));
} catch (TransformerException e) {