Skip to content

Commit

Permalink
minor compiler warning, codestyle fixes
Browse files Browse the repository at this point in the history
 - removed redundant import statements
 - added servial version ids to serializable classes
  • Loading branch information
Ishaaq Chandy authored and magnayn committed Sep 3, 2009
1 parent 818dabc commit f670f18
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 66 deletions.
1 change: 1 addition & 0 deletions src/main/java/hudson/plugins/git/Branch.java
Expand Up @@ -5,6 +5,7 @@

public class Branch extends GitObject
{
private static final long serialVersionUID = 1L;

public Branch(String name, ObjectId sha1) {
super(name, sha1);
Expand Down
69 changes: 34 additions & 35 deletions src/main/java/hudson/plugins/git/GitAPI.java
Expand Up @@ -17,13 +17,10 @@
import java.io.PrintStream;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.spearce.jgit.lib.AnyObjectId;
import org.spearce.jgit.lib.Constants;
import org.spearce.jgit.lib.ObjectId;
import org.spearce.jgit.lib.Ref;
Expand All @@ -37,12 +34,12 @@ public class GitAPI implements IGitAPI {
TaskListener listener;
String gitExe;
EnvVars environment;

public GitAPI(String gitExe, FilePath workspace,
TaskListener listener, EnvVars environment) {

//listener.getLogger().println("Git API @ " + workspace.getName() + " / " + workspace.getRemote() + " - " + workspace.getChannel());

this.workspace = workspace;
this.listener = listener;
this.gitExe = gitExe;
Expand All @@ -52,19 +49,19 @@ public GitAPI(String gitExe, FilePath workspace,
for(Map.Entry<String,String> ent : environment.entrySet()) {
log.println("Env: " + ent.getKey() + "=" + ent.getValue());
}

launcher = new LocalLauncher(listener);

}

public String getGitExe() {
return gitExe;
}

public EnvVars getEnvironment() {
return environment;
}

public boolean hasGitRepo() throws GitException {
try {

Expand Down Expand Up @@ -146,9 +143,11 @@ public void clone(final RemoteConfig remoteConfig) throws GitException {

// Assume only 1 URL for this repository
final String source = remoteConfig.getURIs().get(0).toString();

try {
workspace.act(new FileCallable<String>() {
private static final long serialVersionUID = 1L;

public String invoke(File workspace,
VirtualChannel channel) throws IOException {
final ArgumentListBuilder args = new ArgumentListBuilder();
Expand All @@ -163,7 +162,7 @@ public String invoke(File workspace,
throw new GitException("Could not clone " + source, e);
}
}

public void clean() throws GitException {
ArgumentListBuilder args = new ArgumentListBuilder();
args.add(getGitExe(), "clean", "-fdx");
Expand All @@ -176,14 +175,14 @@ public ObjectId revParse(String revName) throws GitException {
String result = launchCommand(args.toCommandArray());
return ObjectId.fromString(firstLine(result).trim());
}

public String describe(String commitIsh) throws GitException {
ArgumentListBuilder args = new ArgumentListBuilder();
args.add(getGitExe(), "describe", "--tags", commitIsh);
String result = launchCommand(args.toCommandArray());
return firstLine(result).trim();
}

private String firstLine(String result) {
BufferedReader reader = new BufferedReader(new StringReader(result));
String line;
Expand All @@ -196,7 +195,7 @@ private String firstLine(String result) {
} catch (IOException e) {
throw new GitException("Error parsing result");
}

return line;
}

Expand Down Expand Up @@ -301,11 +300,11 @@ private String launchCommandIn(String[] args, FilePath workDir) throws GitExcept
try {
int status = launcher.launch(args,
environment, fos, workDir).join();

String result = fos.toString();

System.out.println(result);

if (status != 0) {
throw new GitException("Command returned status code " + status + ": " + result);
}
Expand All @@ -328,10 +327,10 @@ public void push(RemoteConfig repository, String refspec) throws GitException {
// That are possible.
}

private List<Branch> parseBranches(String fos) throws GitException
private List<Branch> parseBranches(String fos) throws GitException
{
// TODO: git branch -a -v --abbrev=0 would do this in one shot..

List<Branch> tags = new ArrayList<Branch>();

BufferedReader rdr = new BufferedReader(new StringReader(fos));
Expand All @@ -357,14 +356,14 @@ public List<Branch> getBranches() throws GitException {
args.add(getGitExe(), "branch", "-a");
return parseBranches(launchCommand(args.toCommandArray()));
}

public List<Branch> getRemoteBranches() throws GitException, IOException {


Repository db = getRepository();
Map<String, Ref> refs = db.getAllRefs();
List<Branch> branches = new ArrayList<Branch>();

for(Ref candidate : refs.values())
{
if( candidate.getName().startsWith(Constants.R_REMOTES) )
Expand All @@ -374,7 +373,7 @@ public List<Branch> getRemoteBranches() throws GitException, IOException {
branches.add( buildBranch );
}
}

return branches;
}

Expand Down Expand Up @@ -407,8 +406,8 @@ public void deleteTag(String tagName) throws GitException {
throw new GitException("Could not delete tag " + tagName, e);
}
}



public List<IndexEntry> lsTree(String treeIsh) throws GitException {
List<IndexEntry> entries = new ArrayList<IndexEntry>();
Expand Down Expand Up @@ -497,15 +496,15 @@ public void fetch(RemoteConfig remoteRepository) throws GitException
{
// Assume there is only 1 URL / refspec for simplicity
fetch(remoteRepository.getURIs().get(0).toString(), remoteRepository.getFetchRefSpecs().get(0).toString());

}

public ObjectId mergeBase(ObjectId id1, ObjectId id2)
{
try {
ArgumentListBuilder args = new ArgumentListBuilder();
args.add(getGitExe(), "merge-base", id1.name(), id2.name());

ByteArrayOutputStream fos = new ByteArrayOutputStream();
int status = launcher.launch(args.toCommandArray(),
environment, fos, workspace).join();
Expand All @@ -516,10 +515,10 @@ public ObjectId mergeBase(ObjectId id1, ObjectId id2)
return null;
}


BufferedReader rdr = new BufferedReader(new StringReader(result));
String line;

while ((line = rdr.readLine()) != null) {
// Add the SHA1
return ObjectId.fromString(line);
Expand All @@ -535,22 +534,22 @@ private Repository getRepository() throws IOException
{
return new Repository(new File(workspace.getRemote(), ".git"));
}

public List<Tag> getTagsOnCommit(String revName) throws GitException, IOException
{
Repository db = getRepository();
ObjectId commit = db.resolve(revName);
List<Tag> ret = new ArrayList<Tag>();

for (final Map.Entry<String, Ref> tag : db.getTags().entrySet()) {

Tag ttag = db.mapTag(tag.getKey());
if( ttag.getObjId().equals(commit) )
{
ret.add(ttag);
}
}
return ret;

}
}
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/git/GitChangeSet.java
Expand Up @@ -30,7 +30,7 @@ public GitChangeSet(List<String> lines) {
}

private void parseCommit(List<String> lines) {

String comment = "";

for (String line : lines) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/hudson/plugins/git/GitException.java
@@ -1,6 +1,8 @@
package hudson.plugins.git;

public class GitException extends RuntimeException {
private static final long serialVersionUID = 1L;

public GitException() {
super();
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/hudson/plugins/git/GitPublisher.java
Expand Up @@ -8,7 +8,6 @@
import hudson.model.BuildListener;
import hudson.model.Descriptor;
import hudson.model.Result;
import hudson.plugins.git.util.BuildData;
import hudson.remoting.VirtualChannel;
import hudson.scm.SCM;
import hudson.tasks.BuildStepDescriptor;
Expand All @@ -28,6 +27,7 @@
import org.spearce.jgit.transport.RemoteConfig;

public class GitPublisher extends Publisher implements Serializable {
private static final long serialVersionUID = 1L;

public Descriptor<Publisher> getDescriptor() {
return DESCRIPTOR;
Expand All @@ -50,7 +50,7 @@ public boolean perform(final AbstractBuild<?, ?> build,
final String projectName = build.getProject().getName();
final int buildNumber = build.getNumber();
final Result buildResult = build.getResult();

boolean canPerform;
try {
canPerform = build.getProject().getWorkspace().act(
Expand Down Expand Up @@ -91,9 +91,9 @@ public Boolean invoke(File workspace,
&& buildResult.isBetterOrEqualTo(
Result.SUCCESS)) {
listener.getLogger().println("Pushing result " + buildnumber + " to " + gitSCM.getMergeOptions().getMergeTarget() + " branch of origin repository");

RemoteConfig remote = gitSCM.getRepositories().get(0);

git.push(remote, "HEAD:" + gitSCM.getMergeOptions().getMergeTarget());
} else {
//listener.getLogger().println("Pushing result " + buildnumber + " to origin repository");
Expand All @@ -107,7 +107,7 @@ public Boolean invoke(File workspace,
listener.error("Failed to push tags to origin repository: " + e.getMessage());
build.setResult(Result.FAILURE);
return false;

}
return canPerform;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/hudson/plugins/git/GitSCM.java
Expand Up @@ -241,6 +241,8 @@ public boolean pollChanges(final AbstractProject project, Launcher launcher,
final String singleBranch = getSingleBranch(lastBuild);

boolean pollChangesResult = workspace.act(new FileCallable<Boolean>() {
private static final long serialVersionUID = 1L;

public Boolean invoke(File localWorkspace, VirtualChannel channel)
throws IOException {

Expand Down Expand Up @@ -427,6 +429,7 @@ public boolean checkout(final AbstractBuild build, Launcher launcher,
final String singleBranch = getSingleBranch(build);

final Revision revToBuild = workspace.act(new FileCallable<Revision>() {
private static final long serialVersionUID = 1L;
public Revision invoke(File localWorkspace, VirtualChannel channel)
throws IOException {
FilePath ws = new FilePath(localWorkspace);
Expand Down Expand Up @@ -506,6 +509,7 @@ public Revision invoke(File localWorkspace, VirtualChannel channel)
if (mergeOptions.doMerge()) {
if (!revToBuild.containsBranchName(mergeOptions.getMergeTarget())) {
returnData = workspace.act(new FileCallable<Object[]>() {
private static final long serialVersionUID = 1L;
public Object[] invoke(File localWorkspace, VirtualChannel channel)
throws IOException {
EnvVars environment;
Expand Down Expand Up @@ -597,6 +601,7 @@ public Object[] invoke(File localWorkspace, VirtualChannel channel)
// No merge

returnData = workspace.act(new FileCallable<Object[]>() {
private static final long serialVersionUID = 1L;
public Object[] invoke(File localWorkspace, VirtualChannel channel)
throws IOException {
IGitAPI git = new GitAPI(gitExe, new FilePath(localWorkspace), listener, environment);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/hudson/plugins/git/SubmoduleConfig.java
Expand Up @@ -4,9 +4,10 @@

public class SubmoduleConfig implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
String submoduleName;
String[] branches;

public String getSubmoduleName()
{
return submoduleName;
Expand Down Expand Up @@ -35,7 +36,7 @@ public boolean revisionMatchesInterest(Revision r)
}
return false;
}

public boolean branchMatchesInterest(Branch br)
{
for (String regex : branches)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/hudson/plugins/git/Tag.java
Expand Up @@ -4,9 +4,10 @@

public class Tag extends GitObject
{
private static final long serialVersionUID = 1L;
public String commitSHA1;
public String commitMessage;

public String getCommitMessage()
{
return commitMessage;
Expand Down
Expand Up @@ -4,8 +4,9 @@

public class PreBuildMergeOptions implements Serializable
{
public String mergeTarget = null;

private static final long serialVersionUID = 1L;
public String mergeTarget = null;

public String getMergeTarget()
{
return mergeTarget;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/hudson/plugins/git/util/BuildChooser.java
@@ -1,8 +1,6 @@
package hudson.plugins.git.util;

import hudson.model.AbstractBuild;
import hudson.model.Action;
import hudson.model.ParametersAction;
import hudson.model.Result;
import hudson.plugins.git.Branch;
import hudson.plugins.git.BranchSpec;
Expand Down

0 comments on commit f670f18

Please sign in to comment.