Author: adietish
Date: 2011-12-07 05:57:10 -0500 (Wed, 07 Dec 2011)
New Revision: 37044
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/GitIgnore.java
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/FileUtils.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizardModel.java
Log:
[JBIDE-10171] creating .gitignore
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/GitIgnore.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/GitIgnore.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/GitIgnore.java 2011-12-07
10:57:10 UTC (rev 37044)
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.egit.core;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jgit.lib.Constants;
+
+public class GitIgnore {
+
+ private List<String> entries;
+ private File baseDir;
+
+ public GitIgnore(File baseDir) {
+ this.baseDir = baseDir;
+ this.entries = new ArrayList<String>();
+ }
+
+ public GitIgnore add(String entry) {
+ this.entries.add(entry);
+ return this;
+ }
+
+ /**
+ * Writes the entries in this instance to the .gitignore file. Overwrites
+ * and existing file if the given overwrite is set to <code>true</code>,
+ * appends otherwise.
+ *
+ * @param overwrite
+ * overwrites an existing file if <code>true</code>, appends
+ * otherwise
+ * @throws IOException
+ */
+ public void write(boolean overwrite) throws IOException {
+ File file = getFile();
+ BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file,
!overwrite));
+ try {
+ for (String entry : entries) {
+ out.write(entry.getBytes());
+ out.write('\n');
+ }
+ out.flush();
+ } finally {
+ out.close();
+ }
+ }
+
+ public boolean exists() {
+ return getFile().exists();
+ }
+
+ private File getFile() {
+ File file = new File(baseDir, Constants.GITIGNORE_FILENAME);
+ return file;
+ }
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/GitIgnore.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/FileUtils.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/FileUtils.java 2011-12-07
10:24:40 UTC (rev 37043)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/FileUtils.java 2011-12-07
10:57:10 UTC (rev 37044)
@@ -139,9 +139,15 @@
Assert.isLegal(destination != null);
InputStream in = null;
+ writeTo(new BufferedInputStream(new FileInputStream(source)), destination);
+ }
+
+ private static final void writeTo(InputStream in, File destination) throws IOException
{
+ Assert.isLegal(in != null);
+ Assert.isLegal(destination != null);
+
OutputStream out = null;
try {
- in = new BufferedInputStream(new FileInputStream(source));
out = new BufferedOutputStream(new FileOutputStream(destination));
for (int read = -1; (read = in.read(buffer)) != -1; ) {
out.write(buffer, 0, read);
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizardModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizardModel.java 2011-12-07
10:24:40 UTC (rev 37043)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizardModel.java 2011-12-07
10:57:10 UTC (rev 37044)
@@ -49,6 +49,7 @@
import org.jboss.ide.eclipse.as.core.util.FileUtil;
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
import org.jboss.tools.openshift.egit.core.EGitUtils;
+import org.jboss.tools.openshift.egit.core.GitIgnore;
import org.jboss.tools.openshift.express.client.IApplication;
import org.jboss.tools.openshift.express.client.ICartridge;
import org.jboss.tools.openshift.express.client.IUser;
@@ -191,14 +192,36 @@
private void copyOpenshiftConfiguration(final File sourceFolder, IProgressMonitor
monitor)
throws IOException {
IProject project = getProject();
+ File projectFolder = project.getLocation().toFile();
monitor.subTask(NLS.bind("Copying openshift configuration to project {0}...",
getProjectName()));
- FileUtils.copy(new File(sourceFolder, ".git"),
project.getLocation().toFile(), false);
- FileUtils.copy(new File(sourceFolder, ".openshift"),
project.getLocation().toFile(), false);
- FileUtils.copy(new File(sourceFolder, "deployments"),
project.getLocation().toFile(), false);
- FileUtils.copy(new File(sourceFolder, "pom.xml"),
project.getLocation().toFile(), false);
+ 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);
+ createGitIgnore(projectFolder);
}
/**
+ * Creates the git ignore file with a predefined set of entries. An existing
+ * .gitignore file is not overwritten, we then just dont do anything.
+ *
+ * @param projectFolder
+ * @throws IOException
+ */
+ private void createGitIgnore(File projectFolder) throws IOException {
+ GitIgnore gitIgnore = new GitIgnore(projectFolder);
+ if (gitIgnore.exists()) {
+ return;
+ }
+ gitIgnore.add("target")
+ .add(".settings")
+ .add(".project")
+ .add(".classpath")
+ .add(".factorypath");
+ gitIgnore.write(false);
+ }
+
+ /**
* Returns the user provided project.
*
* @throws OpenShiftException
@@ -244,7 +267,8 @@
* @throws IOException
* The configuration files could not be copied from the git
* clone to the user project
- * @throws CoreException The user project could not be shared with the git
+ * @throws CoreException
+ * The user project could not be shared with the git
*
* @see #cloneRepository
* @see #copyOpenshiftConfiguration