Permalink
Browse files

Initial commit.:

  • Loading branch information...
0 parents commit 2b347fb8371f0fc7644e393fc8b1d662532811c1 @stephenh committed Dec 23, 2008
Oops, something went wrong.
@@ -0,0 +1 @@
+target
@@ -0,0 +1,13 @@
+<projectDescription>
+ <name>git2</name>
+ <comment>Integrates Hudson to GIT SCM--without starvation</comment>
+ <projects/>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Oops, something went wrong.
@@ -0,0 +1,56 @@
+#Thu Oct 16 15:49:48 CDT 2008
+eclipse.preferences.version=1
+editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
+formatter_profile=_Foo
+formatter_settings_version=11
+sp_cleanup.add_default_serial_version_id=true
+sp_cleanup.add_generated_serial_version_id=false
+sp_cleanup.add_missing_annotations=false
+sp_cleanup.add_missing_deprecated_annotations=true
+sp_cleanup.add_missing_methods=false
+sp_cleanup.add_missing_nls_tags=false
+sp_cleanup.add_missing_override_annotations=true
+sp_cleanup.add_serial_version_id=false
+sp_cleanup.always_use_blocks=true
+sp_cleanup.always_use_parentheses_in_expressions=true
+sp_cleanup.always_use_this_for_non_static_field_access=true
+sp_cleanup.always_use_this_for_non_static_method_access=true
+sp_cleanup.convert_to_enhanced_for_loop=false
+sp_cleanup.correct_indentation=true
+sp_cleanup.format_source_code=true
+sp_cleanup.format_source_code_changes_only=false
+sp_cleanup.make_local_variable_final=false
+sp_cleanup.make_parameters_final=false
+sp_cleanup.make_private_fields_final=true
+sp_cleanup.make_type_abstract_if_missing_method=false
+sp_cleanup.make_variable_declarations_final=false
+sp_cleanup.never_use_blocks=false
+sp_cleanup.never_use_parentheses_in_expressions=false
+sp_cleanup.on_save_use_additional_actions=true
+sp_cleanup.organize_imports=true
+sp_cleanup.qualify_static_field_accesses_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_with_declaring_class=true
+sp_cleanup.qualify_static_method_accesses_with_declaring_class=true
+sp_cleanup.remove_private_constructors=true
+sp_cleanup.remove_trailing_whitespaces=true
+sp_cleanup.remove_trailing_whitespaces_all=true
+sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
+sp_cleanup.remove_unnecessary_casts=true
+sp_cleanup.remove_unnecessary_nls_tags=false
+sp_cleanup.remove_unused_imports=true
+sp_cleanup.remove_unused_local_variables=false
+sp_cleanup.remove_unused_private_fields=true
+sp_cleanup.remove_unused_private_members=false
+sp_cleanup.remove_unused_private_methods=true
+sp_cleanup.remove_unused_private_types=true
+sp_cleanup.sort_members=false
+sp_cleanup.sort_members_all=false
+sp_cleanup.use_blocks=true
+sp_cleanup.use_blocks_only_for_return_and_throw=false
+sp_cleanup.use_parentheses_in_expressions=true
+sp_cleanup.use_this_for_non_static_field_access=true
+sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=false
+sp_cleanup.use_this_for_non_static_method_access=true
+sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=false
@@ -0,0 +1,25 @@
+
+Install
+=======
+
+* Upload target/git.hpi to your instance of Hudson
+* Choose Git as your SCM for your project
+
+That's all I remember as I don't have a Hudson instance in front of me.
+
+Building
+========
+
+* This plugin expects to live in the `hudson/plugins/git2` directory of a Hudson svn checkout
+* Then just run `mvn` from the `git2` directory
+
+Notes
+=====
+
+* The merge into other branches option is about the only code left over from the original git plugin and I haven't personally used it--it may or may not work
+
+Acknowledgements
+================
+
+* The original Hudson git plugin author for providing a great place to start copy/pasting from
+
@@ -0,0 +1,22 @@
+<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.jvnet.hudson.plugins</groupId>
+ <artifactId>plugin</artifactId>
+ <version>1.235</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>git</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>hpi</packaging>
+ <name>Hudson GIT plugin</name>
+ <description>Integrates Hudson to GIT SCM</description>
+ <url>http://hudson.gotdns.com/wiki/display/HUDSON/Git+Plugin</url>
+
+ <scm>
+ <connection>scm:svn:https://guest@svn.dev.java.net/svn/hudson/tags/git-0.1</connection>
+ <developerConnection>scm:svn:https://svn.dev.java.net/svn/hudson/tags/git-0.1</developerConnection>
+ <url>https://hudson.dev.java.net/source/browse/hudson/hudson/plugins/git/tags/git-0.1</url>
+ </scm>
+</project>
@@ -0,0 +1,110 @@
+package hudson.plugins.git;
+
+import hudson.FilePath;
+import hudson.Launcher;
+import hudson.model.TaskListener;
+import hudson.util.ArgumentListBuilder;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
+
+public class GitAPI {
+
+ private final String gitExe;
+ private final Launcher launcher;
+ private final FilePath workspace;
+ private final TaskListener listener;
+
+ public GitAPI(GitSCM.DescriptorImpl descriptor, Launcher launcher, FilePath workspace, TaskListener listener) {
+ this.gitExe = descriptor.getGitExe();
+ this.launcher = launcher;
+ this.workspace = workspace;
+ this.listener = listener;
+ }
+
+ public boolean hasGitRepo() throws InterruptedException, IOException {
+ return this.workspace.child(".git").exists();
+ }
+
+ public boolean hasGitModules() throws InterruptedException, IOException {
+ return this.workspace.child(".gitmodules").exists();
+ }
+
+ public String revParse(String revName) throws InterruptedException, IOException {
+ ArgumentListBuilder args = new ArgumentListBuilder();
+ args.add(this.gitExe, "rev-parse", revName.replace(' ', '_'));
+
+ ByteArrayOutputStream fos = new ByteArrayOutputStream();
+ int code = this.launcher.launch(args.toCommandArray(), this.createEnvVarMap(), fos, this.workspace).join();
+ fos.close();
+ if (code != 0) {
+ this.listener.getLogger().println("Error doing rev-parse: " + fos.toString());
+ return null;
+ }
+
+ return StringUtils.trimToNull(fos.toString());
+ }
+
+ public void log(String revFrom, String revTo, File file) throws InterruptedException, IOException {
+ ArgumentListBuilder args = new ArgumentListBuilder();
+ args.add(this.gitExe, "log", "--numstat", "-M", "--summary", "--pretty=raw", revFrom + ".." + revTo);
+
+ file.delete();
+ FileOutputStream fos = new FileOutputStream(file);
+ // fos.write("<data><![CDATA[".getBytes());
+ int code = this.launcher.launch(args.toCommandArray(), this.createEnvVarMap(), fos, this.workspace).join();
+ // fos.write("]]></data>".getBytes());
+ fos.close();
+ if (code != 0) {
+ this.listener.getLogger().print("Error launching git log: " + FileUtils.readFileToString(file));
+ throw new RuntimeException("Error launching git log");
+ }
+ }
+
+ /** Start from scratch and clone the whole repository. */
+ public void clone(String source) throws InterruptedException, IOException {
+ this.workspace.deleteRecursive();
+ this.launch("Failed to clone " + source, this.gitExe, "clone", source, this.workspace.getRemote());
+ }
+
+ public void fetch() throws InterruptedException, IOException {
+ this.launch("Failed to fetch", this.gitExe, "fetch");
+ }
+
+ public void merge(String revSpec) throws InterruptedException, IOException {
+ this.launch("Error in merging " + revSpec, this.gitExe, "merge", revSpec);
+ }
+
+ public void submoduleInit() throws InterruptedException, IOException {
+ this.launch("Error in submodule init", this.gitExe, "submodule", "init");
+ }
+
+ public void submoduleUpdate() throws InterruptedException, IOException {
+ this.launch("Error in submodule update", this.gitExe, "submodule", "update");
+ }
+
+ public void checkout(String ref) throws InterruptedException, IOException {
+ this.launch("Error checking out " + ref, this.gitExe, "checkout", "-f", ref);
+ }
+
+ private void launch(String error, String... args) throws InterruptedException, IOException {
+ int code = this.launcher.launch(args, this.createEnvVarMap(), this.listener.getLogger(),
+ this.workspace.exists() ? this.workspace : null).join();
+ if (code != 0) {
+ throw new RuntimeException(error);
+ }
+ }
+
+ private final Map<String, String> createEnvVarMap() {
+ Map<String, String> env = new HashMap<String, String>();
+ return env;
+ }
+
+}
@@ -0,0 +1,45 @@
+package hudson.plugins.git;
+
+import hudson.model.AbstractBuild;
+import hudson.scm.ChangeLogParser;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.xml.sax.SAXException;
+
+public class GitChangeLogParser extends ChangeLogParser {
+
+ public GitChangeSetList parse(AbstractBuild build, File changelogFile) throws IOException, SAXException {
+ ArrayList<GitChangeSet> r = new ArrayList<GitChangeSet>();
+
+ // Parse the log file into GitChangeSet items - each one is a commit
+ BufferedReader rdr = new BufferedReader(new FileReader(changelogFile));
+
+ String line;
+ List<String> lines = null;
+ while ((line = rdr.readLine()) != null) {
+ if (line.startsWith("commit ")) {
+ if (lines != null) {
+ r.add(this.parseCommit(lines));
+ }
+ lines = new ArrayList<String>();
+ }
+ lines.add(line);
+ }
+ if (lines != null) {
+ r.add(this.parseCommit(lines));
+ }
+
+ return new GitChangeSetList(build, r);
+ }
+
+ private GitChangeSet parseCommit(List<String> lines) {
+ return new GitChangeSet(lines);
+ }
+
+}
Oops, something went wrong.

0 comments on commit 2b347fb

Please sign in to comment.