Commit a40fec7b authored by Brian Long's avatar Brian Long
Browse files

initial checkin

parents
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+5 −0
Original line number Diff line number Diff line
# Maven
target
.project
.classpath
.settings

pom.xml

0 → 100644
+74 −0
Original line number Diff line number Diff line
<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>
	<groupId>me.brianlong</groupId>
	<artifactId>git-utils</artifactId>
	<packaging>jar</packaging>
	<version>1.0-SNAPSHOT</version>

	<name>Git Utilities</name>

	<properties>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.eclipse.jgit</groupId>
			<artifactId>org.eclipse.jgit</artifactId>
			<version>5.9.0.202009080501-r</version>
		</dependency>
		<dependency>
			<groupId>org.eclipse.jgit</groupId>
			<artifactId>org.eclipse.jgit.ssh.jsch</artifactId>
			<version>5.9.0.202009080501-r</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.13</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-slf4j-impl</artifactId>
			<version>2.13.2</version>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<excludes>
						<exclude>**/*IT.class</exclude>
					</excludes>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-failsafe-plugin</artifactId>
				<executions>
					<execution>
						<id>integration-tests</id>
						<phase>integration-test</phase>
						<goals>
							<goal>integration-test</goal>
						</goals>
						<configuration>
							<includes>
								<include>**/*IT.class</include>
							</includes>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

src/jetty/log4j2.xml

0 → 100644
+16 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <Console name="STDOUT" target="SYSTEM_OUT">
      <PatternLayout pattern="[%t] %-5level %logger{36} - %msg%n"/>
    </Console>
  </Appenders>
  <Loggers>
  	<Logger name="me.brianlong" level="trace" additivity="false">
  	  <AppenderRef ref="STDOUT" />
  	</Logger>
    <Root level="trace">
      <AppenderRef ref="STDOUT"/>
    </Root>
  </Loggers>
</Configuration>
+29 −0
Original line number Diff line number Diff line
package me.brianlong.git;

import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.TransportException;
import org.eclipse.jgit.lib.Repository;

public class CachedGit extends Git {
	
	public CachedGit(Git git) {
		super(git.getRepository());
	}
	
	public CachedGit(CloneCommand clone) throws TransportException, InvalidRemoteException, GitAPIException {
		super(clone.call().getRepository());
	}
	
	public CachedGit(Repository repo) {
		super(repo);
	}
	
	@Override
	public void close() {
		LocalRepositoryCache.getInstance().release(this);
	}

}
+42 −0
Original line number Diff line number Diff line
package me.brianlong.git;

import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;

public class CompositeIterator<E> implements Iterator<E> {
	
	private final List<Iterator<E>> iterators = new LinkedList<Iterator<E>>();
	private final Iterator<Iterator<E>> iteratorIterators;
	private Iterator<E> iterator;
	
	public CompositeIterator(@SuppressWarnings("unchecked") Collection<E>... cs) {
		for (Collection<E> c : cs)
			if (c != null && !c.isEmpty())
				this.iterators.add(c.iterator());
		this.iteratorIterators = this.iterators.iterator();
	}
	
	@Override
	public boolean hasNext() {
		if (this.iterator == null) {
			if (!this.iteratorIterators.hasNext())
				return false;
			this.iterator = this.iteratorIterators.next();
		}
		
		while (!this.iterator.hasNext() && this.iteratorIterators.hasNext())
			this.iterator = this.iteratorIterators.next();
		return this.iterator.hasNext();
	}
	
	@Override
	public E next() {
		if (!this.hasNext())
			throw new NoSuchElementException();
		return this.iterator.next();
	}

}
Loading