summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2015-05-26 13:13:59 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2015-05-26 13:14:00 -0400
commit5635d9e1af61c054740037aa0934fca8ef34eaa4 (patch)
tree23da7506525cb0846a98f052e9344c8261c571b9 /org.eclipse.jgit
parent527ac377816de4d4e5fdfc68d0df0ca7da6b518c (diff)
parent744c370c1be8044d1ccaaf84cd164324961fea1a (diff)
downloadjgit-5635d9e1af61c054740037aa0934fca8ef34eaa4.tar.gz
jgit-5635d9e1af61c054740037aa0934fca8ef34eaa4.zip
Merge "Add getters to RepoProject."
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java22
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java97
3 files changed, 102 insertions, 27 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java
index ec9fdfa4e2..fa27948a64 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java
@@ -205,7 +205,7 @@ public class ManifestParser extends DefaultHandler {
throw new SAXException(RepoText.get().invalidManifest);
currentProject.addCopyFile(new CopyFile(
rootRepo,
- currentProject.path,
+ currentProject.getPath(),
attributes.getValue("src"), //$NON-NLS-1$
attributes.getValue("dest"))); //$NON-NLS-1$
} else if ("include".equals(qName)) { //$NON-NLS-1$
@@ -266,7 +266,7 @@ public class ManifestParser extends DefaultHandler {
throw new SAXException(e);
}
for (RepoProject proj : projects) {
- String remote = proj.remote;
+ String remote = proj.getRemote();
if (remote == null) {
if (defaultRemote == null) {
if (filename != null)
@@ -286,7 +286,7 @@ public class ManifestParser extends DefaultHandler {
remoteUrl = remoteUrl + "/"; //$NON-NLS-1$
remoteUrls.put(remote, remoteUrl);
}
- proj.setUrl(remoteUrl + proj.name)
+ proj.setUrl(remoteUrl + proj.getName())
.setDefaultRevision(defaultRevision);
}
@@ -339,7 +339,7 @@ public class ManifestParser extends DefaultHandler {
boolean inGroups(RepoProject proj) {
for (String group : minusGroups) {
- if (proj.groups.contains(group)) {
+ if (proj.inGroup(group)) {
// minus groups have highest priority.
return false;
}
@@ -349,7 +349,7 @@ public class ManifestParser extends DefaultHandler {
return true;
}
for (String group : plusGroups) {
- if (proj.groups.contains(group))
+ if (proj.inGroup(group))
return true;
}
return false;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java
index d258250fea..b39dd8a1f2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java
@@ -379,10 +379,10 @@ public class RepoCommand extends GitCommand<RevCommit> {
try {
parser.read(inputStream);
for (RepoProject proj : parser.getFilteredProjects()) {
- addSubmodule(proj.url,
- proj.path,
+ addSubmodule(proj.getUrl(),
+ proj.getPath(),
proj.getRevision(),
- proj.copyfiles);
+ proj.getCopyFiles());
}
} catch (GitAPIException | IOException e) {
throw new ManifestErrorException(e);
@@ -403,17 +403,17 @@ public class RepoCommand extends GitCommand<RevCommit> {
try (RevWalk rw = new RevWalk(repo)) {
Config cfg = new Config();
for (RepoProject proj : bareProjects) {
- String name = proj.path;
- String nameUri = proj.name;
+ String name = proj.getPath();
+ String nameUri = proj.getName();
cfg.setString("submodule", name, "path", name); //$NON-NLS-1$ //$NON-NLS-2$
cfg.setString("submodule", name, "url", nameUri); //$NON-NLS-1$ //$NON-NLS-2$
// create gitlink
DirCacheEntry dcEntry = new DirCacheEntry(name);
ObjectId objectId;
- if (ObjectId.isId(proj.revision))
- objectId = ObjectId.fromString(proj.revision);
+ if (ObjectId.isId(proj.getRevision()))
+ objectId = ObjectId.fromString(proj.getRevision());
else {
- objectId = callback.sha1(nameUri, proj.revision);
+ objectId = callback.sha1(nameUri, proj.getRevision());
}
if (objectId == null)
throw new RemoteUnavailableException(nameUri);
@@ -421,9 +421,9 @@ public class RepoCommand extends GitCommand<RevCommit> {
dcEntry.setFileMode(FileMode.GITLINK);
builder.add(dcEntry);
- for (CopyFile copyfile : proj.copyfiles) {
+ for (CopyFile copyfile : proj.getCopyFiles()) {
byte[] src = callback.readFile(
- nameUri, proj.revision, copyfile.src);
+ nameUri, proj.getRevision(), copyfile.src);
objectId = inserter.insert(Constants.OBJ_BLOB, src);
dcEntry = new DirCacheEntry(copyfile.dest);
dcEntry.setObjectId(objectId);
@@ -495,7 +495,7 @@ public class RepoCommand extends GitCommand<RevCommit> {
List<CopyFile> copyfiles) throws GitAPIException, IOException {
if (repo.isBare()) {
RepoProject proj = new RepoProject(url, name, revision, null, null);
- proj.copyfiles.addAll(copyfiles);
+ proj.addCopyFiles(copyfiles);
bareProjects.add(proj);
} else {
SubmoduleAddCommand add = git
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java
index dfd4f1bba8..1fff1c3532 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java
@@ -49,6 +49,8 @@ import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -62,14 +64,14 @@ import org.eclipse.jgit.lib.Repository;
* @since 4.0
*/
public class RepoProject implements Comparable<RepoProject> {
- final String name;
- final String path;
- final String revision;
- final String remote;
- final Set<String> groups;
- final List<CopyFile> copyfiles;
- String url;
- String defaultRevision;
+ private final String name;
+ private final String path;
+ private final String revision;
+ private final String remote;
+ private final Set<String> groups;
+ private final List<CopyFile> copyfiles;
+ private String url;
+ private String defaultRevision;
/**
* The representation of a copy file configuration.
@@ -82,10 +84,13 @@ public class RepoProject implements Comparable<RepoProject> {
/**
* @param repo
+ * the super project.
* @param path
* the path of the project containing this copyfile config.
* @param src
+ * the source path relative to the sub repo.
* @param dest
+ * the destination path relative to the super project.
*/
public CopyFile(Repository repo, String path, String src, String dest) {
this.repo = repo;
@@ -108,7 +113,8 @@ public class RepoProject implements Comparable<RepoProject> {
FileOutputStream output = new FileOutputStream(destFile);
try {
FileChannel channel = input.getChannel();
- output.getChannel().transferFrom(channel, 0, channel.size());
+ output.getChannel().transferFrom(
+ channel, 0, channel.size());
} finally {
output.close();
}
@@ -120,10 +126,15 @@ public class RepoProject implements Comparable<RepoProject> {
/**
* @param name
+ * the relative path to the {@code remote}
* @param path
+ * the relative path to the super project
* @param revision
+ * a SHA-1 or branch name or tag name
* @param remote
+ * name of the remote definition
* @param groups
+ * comma separated group list
*/
public RepoProject(String name, String path, String revision,
String remote, String groups) {
@@ -163,15 +174,70 @@ public class RepoProject implements Comparable<RepoProject> {
}
/**
+ * Get the name (relative path to the {@code remote}) of this sub repo.
+ *
+ * @return {@code name}
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get the path (relative path to the super project) of this sub repo.
+ *
+ * @return {@code path}
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
* Get the revision of the sub repo.
*
- * @return revision if set, or default revision.
+ * @return {@code revision} if set, or {@code defaultRevision}.
*/
public String getRevision() {
return revision == null ? defaultRevision : revision;
}
/**
+ * Getter for the copyfile configurations.
+ *
+ * @return Immutable copy of {@code copyfiles}
+ */
+ public List<CopyFile> getCopyFiles() {
+ return Collections.unmodifiableList(copyfiles);
+ }
+
+ /**
+ * Get the url of the sub repo.
+ *
+ * @return {@code url}
+ */
+ public String getUrl() {
+ return url;
+ }
+
+ /**
+ * Get the name of the remote definition of the sub repo.
+ *
+ * @return {@remote}
+ */
+ public String getRemote() {
+ return remote;
+ }
+
+ /**
+ * Test whether this sub repo belongs to a specified group.
+ *
+ * @param group
+ * @return true if {@code group} is present.
+ */
+ public boolean inGroup(String group) {
+ return groups.contains(group);
+ }
+
+ /**
* Add a copy file configuration.
*
* @param copyfile
@@ -180,7 +246,16 @@ public class RepoProject implements Comparable<RepoProject> {
copyfiles.add(copyfile);
}
- String getPathWithSlash() {
+ /**
+ * Add a bunch of copyfile configurations.
+ *
+ * @param copyfiles
+ */
+ public void addCopyFiles(Collection<CopyFile> copyfiles) {
+ this.copyfiles.addAll(copyfiles);
+ }
+
+ private String getPathWithSlash() {
if (path.endsWith("/")) //$NON-NLS-1$
return path;
else