Introduce a new module for IO SPI of JGit
PATCH 1/3 Introduce a new module for IO SPI of JGit
From: Imran M Yousuf <[email protected]>
The reason for having a separate module is quite obvious, the IO SPI providers need not have to depend on the whole JGit but rather only on the SPI itself. As of the initial implementation the SPI will also contain the default implementation - local file system provider.
Extract maven POM file to a common file to encapsulate the common setting and configuration to be used across all maven modules for JGit.
---
jgit-maven/jgit-io/pom.xml | 65 +++++++++
jgit-maven/jgit/pom.xml | 287 ++++++++++-------------------------------
jgit-maven/{jgit => }/pom.xml | 31 +----
3 files changed, 143 insertions(+), 240 deletions(-)
create mode 100644 jgit-maven/jgit-io/pom.xml
rewrite jgit-maven/jgit/pom.xml (68%)
rename jgit-maven/{jgit => }/pom.xml (90%)jgit-maven/jgit-io/pom.xml new file +65 -0
@@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +All rights reserved. +Redistribution and use in source and binary forms, with or +without modification, are permitted provided that the following +conditions are met: + +Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following +disclaimer in the documentation and/or other materials provided +with the distribution. + +Neither the name of the Eclipse Foundation, Inc. nor the +names of its contributors may be used to endorse or promote +products derived from this software without specific prior +written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.eclipse</groupId> + <artifactId>jgit-parent</artifactId> + <version>0.6.0-SNAPSHOT</version> + </parent> + <groupId>org.eclipse</groupId> + <artifactId>jgit-io</artifactId> + <packaging>jar</packaging> + <name>jgit-io</name> + <build> + <sourceDirectory>../../org.eclipse.jgit.io/src/</sourceDirectory> + <testResources> + <testResource> + <directory>../../org.eclipse.jgit.test/tst-rsrc/</directory> + </testResource> + </testResources> + <testSourceDirectory>../../org.eclipse.jgit.io/tst/</testSourceDirectory> + </build> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> +</project>
jgit-maven/jgit/pom.xml +71 -216
287 lines not on this page · raw message
jgit-maven/pom.xml renamed from jgit-maven/jgit/pom.xml +7 -24
@@ -37,10 +37,10 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.eclipse</groupId> - <artifactId>jgit</artifactId> - <packaging>jar</packaging> + <artifactId>jgit-parent</artifactId> + <packaging>pom</packaging> <version>0.6.0-SNAPSHOT</version> - <name>jgit</name> + <name>JGit</name> <url>http://repo.or.cz/w/jgit.git</url> <mailingLists> <mailingList>
@@ -141,13 +141,6 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. </license> </licenses> <build> - <sourceDirectory>../../org.eclipse.jgit/src/</sourceDirectory> - <testResources> - <testResource> - <directory>../../org.eclipse.jgit.test/tst-rsrc/</directory> - </testResource> - </testResources> - <testSourceDirectory>../../org.eclipse.jgit.test/tst/</testSourceDirectory> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId>
@@ -191,20 +184,6 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. </plugin> </plugins> </build> - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.jcraft</groupId> - <artifactId>jsch</artifactId> - <version>0.1.41</version> - <scope>compile</scope> - </dependency> - </dependencies> <distributionManagement> <snapshotRepository> <id>jgit-maven-snapshot-repository</id>
@@ -213,4 +192,8 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. <uniqueVersion>true</uniqueVersion> </snapshotRepository> </distributionManagement> + <modules> + <module>jgit</module> + <module>jgit-io</module> + </modules> </project>
Signature · 1 line
1.6.2.1
PATCH 2/3 Add JGit IO SPI and default implementation
From: Imran M Yousuf <[email protected]>
The SPI mainly focus's in providing an API to JGit to be able to perform similar operations to that of java.io.File. All direct I/O is based on the java.io.Input/OutputStream classes.
Different JGit IO SPI provider is designed to be URI scheme based and thus the default implementation is that of "file" scheme. SPI provider will be integrated by their respective users in a manner similar to that of JDBC driver registration. There is a SystemStorageManager that has similar registration capabilities and the system storage providers should be registered with the manager in one of the provided ways.
This SPI is based on the initial requirements for switching to it and thus this SPI will change as required during full migration to it.
--- .../src/org/eclipse/jgit/io/Entry.java | 148 +++++++++++++ .../src/org/eclipse/jgit/io/StorageSystem.java | 58 +++--- .../org/eclipse/jgit/io/StorageSystemManager.java | 154 ++++++++++++++ .../eclipse/jgit/io/localfs/LocalFileEntry.java | 219 ++++++++++++++++++++ .../eclipse/jgit/io/localfs/LocalFileSystem.java | 53 +++--- 5 files changed, 578 insertions(+), 54 deletions(-) create mode 100644 org.eclipse.jgit.io/src/org/eclipse/jgit/io/Entry.java copy org.eclipse.jgit.test/tst/org/eclipse/jgit/util/JGitTestUtil.java => org.eclipse.jgit.io/src/org/eclipse/jgit/io/StorageSystem.java (61%) create mode 100644 org.eclipse.jgit.io/src/org/eclipse/jgit/io/StorageSystemManager.java create mode 100644 org.eclipse.jgit.io/src/org/eclipse/jgit/io/localfs/LocalFileEntry.java copy org.eclipse.jgit/src/org/eclipse/jgit/errors/RepositoryNotFoundException.java => org.eclipse.jgit.io/src/org/eclipse/jgit/io/localfs/LocalFileSystem.java (64%)
org.eclipse.jgit.io/src/org/eclipse/jgit/io/Entry.java new file +148 -0
@@ -0,0 +1,148 @@ +/* + * Copyright (C) 2009, Imran M Yousuf <[email protected]> + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.eclipse.jgit.io; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URI; + +/** + * Represents each entry in a storage system. For example, in a local filesystem + * storage it would represent {@link java.io.File}. Here the storage system + * mainly refers to where repository meta data such as git objects, ref logs, + * packs are stored; for example a '.git' directory and all its contents in a + * clone repo would correspond to an entry. + * @author Imran M Yousuf (imyousuf at smartitengineering.com) + * @since 0.6 + */ +public interface Entry { + + /** + * Retrieves the name of the entry + * @return Name of the entry + */ + public String getName(); + + /** + * Retrieves the absolute path of the entry. + * @return Absoluth path + */ + public String getAbsolutePath(); + + /** + * Retrieves whether the entry represents a directory or not + * @return True if represents a directory else false + */ + public boolean isDirectory(); + + /** + * Signifies whether the entry is a new one or being read from the + * persistent storage + * @return True if being read form storage else false + */ + public boolean isExists(); + + /** + * Make directories upto the entry represented by this instance, provided + * that this instance itself is a directory. + * @return True if directories were created. + */ + public boolean mkdirs(); + + /** + * Retrieves the URI of this entry. URI in this case acts as a primary key + * to identify an entry. + * @return URI to identify this entry instance + */ + public URI getURI(); + + /** + * Retrieves the length of the entry if its predictable. + * @return < 0 if the length is unpredictable else the length of the entry's + * content + */ + public long length(); + + /** + * Retrieves the InputStream for reading the content of the entry + * @return Input stream to read entry content + * @throws IOException If no such file exists or there is any other error + */ + public InputStream getInputStream() + throws IOException; + + /** + * Retrieves the OutputStream for writing content into the entry. It can be + * opened to either overwrite it or append to it. + * @param overwrite False if to write in append mode else true + * @return Output stream to write content to + * @throws IOException If no such file exists in append mode or there is any + * error in retrieving it. + */ + public OutputStream getOutputStream(boolean overwrite) + throws IOException; + + /** + * Retrieve all the child entries of this entries if its a directory. + * @return If not a directory then a empty array else array of sub-entries. + */ + public Entry[] getChildren(); + + /** + * Retrieve a specific child of an entry. It will basically match + * {@link Entry#getName() name} of the children to find and that too only + * the direct children. + * @param name Name of the child to find + * @return If child is not found then NULL or else the child specified by + * the name + */ + public Entry getChild(String name); + + /** + * Retrieve the parent entry of the current entry. + * @return NULL if no parent or else the direct parent of the current entry + */ + public Entry getParent(); + + /** + * Retrieve the storage system this entry either is from or will be + * persisted to. + * @return Storage system of the entry, will never be NULL. + */ + public StorageSystem getStorageSystem(); +}
org.eclipse.jgit.io/src/org/eclipse/jgit/io/StorageSystem.java renamed from org.eclipse.jgit.test/tst/org/eclipse/jgit/util/JGitTestUtil.java +28 -30
71 lines not on this page · raw message
org.eclipse.jgit.io/src/org/eclipse/jgit/io/StorageSystemManager.java new file +154 -0
154 lines not on this page · raw message
org.eclipse.jgit.io/src/org/eclipse/jgit/io/localfs/LocalFileEntry.java new file +219 -0
219 lines not on this page · raw message
org.eclipse.jgit.io/src/org/eclipse/jgit/io/localfs/LocalFileSystem.java renamed from org.eclipse.jgit/src/org/eclipse/jgit/errors/RepositoryNotFoundException.java +29 -24
66 lines not on this page · raw message
Signature · 1 line
1.6.2.1
PATCH 3/3 Incorporate current FileSystem Util implementations to the SPI
From: Imran M Yousuf <[email protected]>
Operations such as setting executable bits if supported and resolving relative path is incorporated with this change, as a result now it should be possible to completely replace the currently being used util FS and java.io.File.
--- .../src/org/eclipse/jgit/io/Entry.java | 35 ++++- .../src/org/eclipse/jgit/io/StorageSystem.java | 17 ++- .../eclipse/jgit/io/localfs/LocalFileEntry.java | 52 ++++++- .../eclipse/jgit/io/localfs/LocalFileSystem.java | 162 +++++++++++++++++++- 4 files changed, 259 insertions(+), 7 deletions(-)
org.eclipse.jgit.io/src/org/eclipse/jgit/io/Entry.java +33 -2
@@ -78,6 +78,24 @@ public boolean isExists(); /** + * Does this operating system and JRE support the execute flag on entries? + * + * @return true if this implementation can provide reasonably accurate + * executable bit information; false otherwise. + */ + public boolean isExecutableSupported(); + + /** + * Determine if the entry is executable (or not). + * <p> + * Not all platforms and JREs support executable flags on entries. If the + * feature is unsupported this method will always return false. + * + * @return true if the entry is believed to be executable by the user. + */ + public boolean isExecutable(); + + /** * Make directories upto the entry represented by this instance, provided * that this instance itself is a directory. * @return True if directories were created.
@@ -85,6 +103,19 @@ public boolean mkdirs(); /** + * Set an entry to be executable by the user. + * <p> + * Not all platforms and JREs support executable flags on entries. If the + * feature is unsupported this method will always return false and no + * changes will be made to the entry specified. + * + * @param executable + * true to enable execution; false to disable it. + * @return true if the change succeeded; false otherwise. + */ + public boolean setExecutable(boolean executable); + + /** * Retrieves the URI of this entry. URI in this case acts as a primary key * to identify an entry. * @return URI to identify this entry instance
@@ -101,7 +132,7 @@ /** * Retrieves the InputStream for reading the content of the entry * @return Input stream to read entry content - * @throws IOException If no such file exists or there is any other error + * @throws IOException If no such entry exists or there is any other error */ public InputStream getInputStream() throws IOException;
@@ -111,7 +142,7 @@ public InputStream getInputStream() * opened to either overwrite it or append to it. * @param overwrite False if to write in append mode else true * @return Output stream to write content to - * @throws IOException If no such file exists in append mode or there is any + * @throws IOException If no such entry exists in append mode or there is any * error in retrieving it. */ public OutputStream getOutputStream(boolean overwrite)
org.eclipse.jgit.io/src/org/eclipse/jgit/io/StorageSystem.java +16 -1
@@ -65,5 +65,20 @@ * @return Entry for current working directory. */ public Entry getWorkingDirectory(); - + + /** + * Retrieve the home directory of the current user + * @return Home directory + */ + public Entry getHomeDirectory(); + + /** + * Resolve relative path with respect to a path and return the absolute + * entry representing the relative path. + * @param entry The point of reference for the relative path + * @param path The relative path + * @return The absolute entry representing the relative path entry + */ + public Entry resolve(Entry entry, + String path); }
org.eclipse.jgit.io/src/org/eclipse/jgit/io/localfs/LocalFileEntry.java +49 -3
80 lines not on this page · raw message
org.eclipse.jgit.io/src/org/eclipse/jgit/io/localfs/LocalFileSystem.java +161 -1
187 lines not on this page · raw message
Signature · 1 line
1.6.2.1