[JGIT PATCH v3 12/23] Added the class AddRuleListFactory.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Florian Koeberle <florianskarten@xxxxxx>
---
 .../jgit/treewalk/rules/AddRuleListFactory.java    |   75 ++++++++++++++++++++
 1 files changed, 75 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/AddRuleListFactory.java

diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/AddRuleListFactory.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/AddRuleListFactory.java
new file mode 100644
index 0000000..5c385c1
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/AddRuleListFactory.java
@@ -0,0 +1,75 @@
+/*
+ *  Copyright (C) 2008 Florian Köberle
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public
+ *  License, version 2, as published by the Free Software Foundation.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+ */
+package org.spearce.jgit.treewalk.rules;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.spearce.jgit.errors.InvalidPatternException;
+import org.spearce.jgit.errors.PathNotInProjectDirectoryException;
+
+class AddRuleListFactory {
+
+	private static String getRelativeUnixPath(File projectDirectory, File file)
+			throws PathNotInProjectDirectoryException, IOException {
+		final StringBuilder resultBuilder = new StringBuilder();
+		File currentFile = file.getCanonicalFile();
+		while (!currentFile.equals(projectDirectory)) {
+			if (resultBuilder.length() > 0) {
+				resultBuilder.insert(0, '/');
+			}
+			resultBuilder.insert(0, currentFile.getName());
+			currentFile = currentFile.getParentFile();
+			if (currentFile == null) {
+				throw new PathNotInProjectDirectoryException();
+			}
+		}
+		return resultBuilder.toString();
+	}
+
+	List<Rule> createRuleList(File projectDirectory, File workingDirectory,
+			List<String> filePatternsOfAddCommand)
+			throws PathNotInProjectDirectoryException, IOException,
+			InvalidPatternException {
+
+		final String workingDirectoryPath = getRelativeUnixPath(
+				projectDirectory, workingDirectory);
+
+		final List<Rule> ruleList = new ArrayList<Rule>(
+				filePatternsOfAddCommand.size());
+		for (String pattern : filePatternsOfAddCommand) {
+			boolean matchDirectoriesOnly = false;
+			if (pattern.endsWith(File.separator)) {
+				pattern = pattern.substring(0, pattern.length() - 1);
+				matchDirectoriesOnly = true;
+			}
+			pattern = pattern.replace(File.separatorChar, '/');
+			if (!"".equals(workingDirectoryPath)) {
+				pattern = workingDirectoryPath + "/" + pattern;
+
+			}
+			final FilePattern filePattern = new FilePathPattern(pattern, true,
+					matchDirectoriesOnly);
+			final Rule rule = new Rule(false, filePattern);
+			ruleList.add(rule);
+
+		}
+		return ruleList;
+	}
+}
-- 
1.5.4.3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux