Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add initial build repository model

  • Loading branch information...
commit 335c6b27825754a7db39893db9fd463d329442d0 0 parents
@kevinsawicki authored
3  .gitignore
@@ -0,0 +1,3 @@
+work
+target
+bin
73 plugin/pom.xml
@@ -0,0 +1,73 @@
+<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.jenkins-ci.plugins</groupId>
+ <artifactId>plugin</artifactId>
+ <version>1.427</version>
+ </parent>
+
+ <groupId>org.jenkinsci.plugins</groupId>
+ <artifactId>gitng-plugin</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <packaging>hpi</packaging>
+ <name>Jenkins Git plugin</name>
+ <description>Integrates Jenkins with the Git version control system</description>
+
+ <licenses>
+ <license>
+ <name>MIT License</name>
+ <url>http://www.opensource.org/licenses/mit-license.php</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+ <scm>
+ <connection>scm:git:git://github.com/kevinsawicki/gitng-plugin.git</connection>
+ <developerConnection>scm:git:git@github.com:kevinsawicki/gitng-plugin.git</developerConnection>
+ <url>http://github.com/kevinsawicki/gitng-plugin</url>
+ </scm>
+
+ <developers>
+ <developer>
+ <email>kevinsawicki@gmail.com</email>
+ <name>Kevin Sawicki</name>
+ <url>https://github.com/kevinsawicki</url>
+ <id>kevinsawicki</id>
+ </developer>
+ </developers>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ </properties>
+
+ <repositories>
+ <repository>
+ <id>jgit-repository</id>
+ <name>Eclipse JGit Repository</name>
+ <url>http://download.eclipse.org/jgit/maven</url>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.jgit</groupId>
+ <artifactId>org.eclipse.jgit</artifactId>
+ <version>[1.0,)</version>
+ </dependency>
+ <dependency>
+ <groupId>org.gitective</groupId>
+ <artifactId>gitective-core</artifactId>
+ <version>0.9-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
116 plugin/src/main/java/org/jenkinsci/git/BuildRepository.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2011 GitHub Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+package org.jenkinsci.git;
+
+import java.io.Serializable;
+
+import org.gitective.core.Check;
+import org.kohsuke.stapler.DataBoundConstructor;
+import org.kohsuke.stapler.export.Exported;
+
+/**
+ * Repository used in a build
+ *
+ * @author Kevin Sawicki (kevin@github.com)
+ */
+public class BuildRepository implements Serializable {
+
+ /** serialVersionUID */
+ private static final long serialVersionUID = 6313364458960227507L;
+
+ private transient int hashCode = -1;
+
+ private String branch;
+
+ private String directory;
+
+ private String uri;
+
+ /**
+ * Create build repository
+ *
+ * @param uri
+ * @param branch
+ * @param directory
+ */
+ @DataBoundConstructor
+ public BuildRepository(String uri, String branch, String directory) {
+ this.uri = uri;
+ this.branch = branch;
+ this.directory = directory;
+ }
+
+ /**
+ * @return branch
+ */
+ @Exported
+ public String getBranch() {
+ return branch;
+ }
+
+ /**
+ * @return directory
+ */
+ @Exported
+ public String getDirectory() {
+ return directory;
+ }
+
+ /**
+ * @return uri
+ */
+ @Exported
+ public String getUri() {
+ return uri;
+ }
+
+ public boolean equals(Object other) {
+ if (other == this)
+ return true;
+ if (!(other instanceof BuildRepository))
+ return false;
+ BuildRepository otherRepo = (BuildRepository) other;
+ return Check.equals(uri, otherRepo.uri)
+ && Check.equals(branch, otherRepo.branch)
+ && Check.equals(directory, otherRepo.directory);
+ }
+
+ public int hashCode() {
+ if (hashCode == -1)
+ hashCode = toString().hashCode();
+ return hashCode;
+ }
+
+ public String toString() {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(uri);
+ buffer.append(' ');
+ buffer.append('[');
+ buffer.append(branch);
+ buffer.append(']');
+ buffer.append(' ');
+ buffer.append('-');
+ buffer.append(' ');
+ buffer.append(directory);
+ return buffer.toString();
+ }
+}
71 plugin/src/test/java/org/jenkinsci/git/BuildRepositoryTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2011 GitHub Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+package org.jenkinsci.git;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Unit tests of {@link BuildRepository}
+ */
+public class BuildRepositoryTest {
+
+ /**
+ * Test getters for values passed into constructor
+ */
+ @Test
+ public void getters() {
+ BuildRepository repo = new BuildRepository("git://host/repo.git",
+ "master", ".");
+ assertEquals("git://host/repo.git", repo.getUri());
+ assertEquals("master", repo.getBranch());
+ assertEquals(".", repo.getDirectory());
+ }
+
+ /**
+ * Test different {@link BuildRepository} instances being equal
+ */
+ @Test
+ public void equalsRepository() {
+ BuildRepository repo1 = new BuildRepository("git://host/repo.git",
+ "master", ".");
+ assertTrue(repo1.equals(repo1));
+ assertFalse(repo1.equals(null));
+ assertFalse(repo1.equals("string"));
+ assertEquals(repo1.hashCode(), repo1.hashCode());
+ assertEquals(repo1.toString(), repo1.toString());
+
+ BuildRepository repo2 = new BuildRepository(null, null, null);
+ assertFalse(repo1.equals(repo2));
+ repo2 = new BuildRepository("git://host/repo.git", null, null);
+ assertFalse(repo1.equals(repo2));
+ repo2 = new BuildRepository("git://host/repo.git", "master", null);
+ assertFalse(repo1.equals(repo2));
+ repo2 = new BuildRepository("git://host/repo.git", "master", ".");
+ assertTrue(repo1.equals(repo2));
+ assertEquals(repo1.hashCode(), repo2.hashCode());
+ assertEquals(repo1.toString(), repo2.toString());
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.