Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge jenkinsci's version and format like the original plugin

  • Loading branch information...
commit 7ce7b5622e74e796986d22865cbc35c6bcb91541 2 parents 8c4d80c + 6a38144
@jcmuller authored
View
34 pom.xml
@@ -8,9 +8,9 @@
</parent>
<groupId>org.jenkins-ci.plugins</groupId>
- <artifactId>git-parameter</artifactId>
+ <artifactId>git-parameter</artifactId>
<packaging>hpi</packaging>
- <version>0.3-CP</version>
+ <version>0.3-SNAPSHOT</version>
<name>Git Parameter Plug-In</name>
<url>https://github.com/jcmuller/git-parameter</url>
@@ -43,7 +43,7 @@
</plugin>
</plugins>
</build>
-
+
<scm>
<connection>scm:git:ssh://github.com/jcmuller/git-parameter.git</connection>
<developerConnection>scm:git:ssh://git@github.com/jcmuller/git-parameter.git</developerConnection>
@@ -57,14 +57,14 @@
<developers>
<developer>
<id>lukanus</id>
- <name>Łukasz Miłkowski</name>
+ <name>?ukasz Mi?kowski</name>
</developer>
<developer>
<id>jcmuller</id>
<name>Juan C. Müller</name>
</developer>
</developers>
-
+
<repositories>
<repository>
@@ -72,32 +72,32 @@
<name>Eclipse JGit Repository</name>
<url>http://download.eclipse.org/jgit/maven</url>
</repository>
-
+
<repository>
<id>guice-maven</id>
<name>guice maven</name>
<url>http://guice-maven.googlecode.com/svn/trunk</url>
</repository>
-
+
<repository>
<id>maven.jenkins-ci.org.git</id>
<url>http://maven.jenkins-ci.org/content/repositories/releases/</url>
</repository>
-
+
<repository>
- <id>m.g.o-public</id>
- <url>http://maven.glassfish.org/content/groups/public/</url>
+ <id>repo.jenkins-ci.org</id>
+ <url>http://repo.jenkins-ci.org/public/</url>
</repository>
-
+
</repositories>
-
+
<pluginRepositories>
<pluginRepository>
- <id>m.g.o-public</id>
- <url>http://maven.glassfish.org/content/groups/public/</url>
+ <id>repo.jenkins-ci.org</id>
+ <url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
-
+
<dependencies>
<dependency>
<groupId>org.jenkinsci.plugins</groupId>
@@ -125,12 +125,12 @@
<type>jar</type>
</dependency>
</dependencies>
-
+
<distributionManagement>
<repository>
<id>maven.jenkins-ci.org</id>
<url>http://maven.jenkins-ci.org:8081/content/repositories/releases/</url>
</repository>
</distributionManagement>
-
+
</project>
View
165 src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/GitParameterDefinition.java
@@ -20,25 +20,21 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
-
public class GitParameterDefinition
-extends ParameterDefinition
-implements Comparable<GitParameterDefinition>
-{
+ extends ParameterDefinition
+ implements Comparable<GitParameterDefinition> {
private static final long serialVersionUID = 9157832967140868122L;
- public static final String PARAMETER_TYPE_TAG = "PT_TAG";
+ public static final String PARAMETER_TYPE_TAG = "PT_TAG";
public static final String PARAMETER_TYPE_REVISION = "PT_REVISION";
- public static final String PARAMETER_TYPE_BRANCH = "PT_BRANCH";
+ public static final String PARAMETER_TYPE_BRANCH = "PT_BRANCH";
private final UUID uuid;
@Extension
- public static class DescriptorImpl extends ParameterDescriptor
- {
+ public static class DescriptorImpl extends ParameterDescriptor {
@Override
- public String getDisplayName()
- {
+ public String getDisplayName() {
return "Git Parameter";
}
}
@@ -66,33 +62,26 @@ public GitParameterDefinition(String name,
this.uuid = UUID.randomUUID();
}
-
@Override
- public ParameterValue createValue(StaplerRequest request)
- {
+ public ParameterValue createValue(StaplerRequest request) {
String value[] = request.getParameterValues(getName());
- if (value == null)
- {
+ if (value == null) {
return getDefaultParameterValue();
}
return null;
}
@Override
- public ParameterValue createValue(StaplerRequest request, JSONObject jO)
- {
+ public ParameterValue createValue(StaplerRequest request, JSONObject jO) {
Object value = jO.get("value");
String strValue = "";
- if (value instanceof String)
- {
+ if (value instanceof String) {
strValue = (String)value;
}
- else if (value instanceof JSONArray)
- {
+ else if (value instanceof JSONArray) {
JSONArray jsonValues = (JSONArray)value;
- for (int i = 0; i < jsonValues.size(); i++)
- {
+ for (int i = 0; i < jsonValues.size(); i++) {
strValue += jsonValues.getString(i);
if (i < jsonValues.size() - 1) {
strValue += ",";
@@ -100,8 +89,7 @@ else if (value instanceof JSONArray)
}
}
- if ("".equals(strValue))
- {
+ if ("".equals(strValue)) {
strValue = defaultValue;
}
@@ -110,76 +98,60 @@ else if (value instanceof JSONArray)
}
@Override
- public ParameterValue getDefaultParameterValue()
- {
+ public ParameterValue getDefaultParameterValue() {
String defValue = getDefaultValue();
- if (!StringUtils.isBlank(defValue))
- {
+ if (!StringUtils.isBlank(defValue)) {
return new GitParameterValue(getName(), defValue);
}
return super.getDefaultParameterValue();
}
-
@Override
- public String getType()
- {
+ public String getType() {
return type;
}
- public void setType(String type)
- {
+ public void setType(String type) {
if (type.equals(PARAMETER_TYPE_TAG) ||
type.equals(PARAMETER_TYPE_REVISION) ||
- type.equals(PARAMETER_TYPE_BRANCH))
- {
+ type.equals(PARAMETER_TYPE_BRANCH)) {
this.type = type;
}
- else
- {
+ else {
this.errorMessage = "wrongType";
}
}
- public String getBranch()
- {
+ public String getBranch() {
return this.branch;
}
- public void setBranch(String nameOfBranch)
- {
+ public void setBranch(String nameOfBranch) {
this.branch = nameOfBranch;
}
- public String getDefaultValue()
- {
+ public String getDefaultValue() {
return defaultValue;
}
- public void setDefaultValue(String defaultValue)
- {
+ public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}
- public AbstractProject<?,?> getParentProject()
- {
+ public AbstractProject<?,?> getParentProject() {
AbstractProject<?,?> context = null;
List<AbstractProject> jobs = Hudson.getInstance().getItems(AbstractProject.class);
- for (AbstractProject<?,?> project : jobs)
- {
+ for (AbstractProject<?,?> project : jobs) {
ParametersDefinitionProperty property = (ParametersDefinitionProperty) project.getProperty(ParametersDefinitionProperty.class);
- if (property != null)
- {
+ if (property != null) {
List<ParameterDefinition> parameterDefinitions = property.getParameterDefinitions();
- if (parameterDefinitions != null)
- {
- for (ParameterDefinition pd : parameterDefinitions)
- {
+ if (parameterDefinitions != null) {
+ for (ParameterDefinition pd : parameterDefinitions) {
if (pd instanceof GitParameterDefinition &&
- ((GitParameterDefinition) pd).compareTo(this) == 0)
+ ((GitParameterDefinition) pd).compareTo(this) == 0)
{
context = project;
break;
@@ -193,29 +165,23 @@ public void setDefaultValue(String defaultValue)
}
@Override
- public int compareTo(GitParameterDefinition pd)
- {
- if (pd.uuid.equals(uuid))
- {
+ public int compareTo(GitParameterDefinition pd) {
+ if (pd.uuid.equals(uuid)) {
return 0;
}
return -1;
}
-
- public void generateContents(String contentType)
- {
+ public void generateContents(String contentType) {
AbstractProject<?,?> project = getParentProject();
- if (project.getSomeWorkspace() == null)
- {
+ if (project.getSomeWorkspace() == null) {
this.errorMessage = "noWorkspace";
}
SCM scm = project.getScm();
- if (scm instanceof GitSCM)
- {
+ if (scm instanceof GitSCM) {
this.errorMessage = "notGit";
}
@@ -224,32 +190,26 @@ public void generateContents(String contentType)
String defaultGitExe = File.separatorChar != '/' ? "git.exe" : "git";
GitSCM.DescriptorImpl desc = (GitSCM.DescriptorImpl) git.getDescriptor();
- if (desc.getOldGitExe() != null)
- {
+ if (desc.getOldGitExe() != null) {
defaultGitExe = desc.getOldGitExe();
}
EnvVars environment = null;
- try
- {
+ try {
environment = project.getSomeBuildWithWorkspace().getEnvironment(TaskListener.NULL);
- }
- catch(Exception e)
+ } catch(Exception e)
{}
- for (RemoteConfig repository : git.getRepositories())
- {
- for (URIish remoteURL : repository.getURIs())
- {
+ for (RemoteConfig repository : git.getRepositories()) {
+ for (URIish remoteURL : repository.getURIs()) {
IGitAPI newgit = new GitAPI(defaultGitExe,
project.getSomeWorkspace(), TaskListener.NULL,
environment, new String());
newgit.fetch();
- if (type.equalsIgnoreCase(PARAMETER_TYPE_REVISION))
- {
+ if (type.equalsIgnoreCase(PARAMETER_TYPE_REVISION)) {
revisionMap = new HashMap<String, String>();
List<ObjectId> oid;
@@ -259,16 +219,14 @@ public void generateContents(String contentType)
else
oid = newgit.revListAll();
- for (ObjectId noid: oid)
- {
+ for (ObjectId noid: oid) {
Revision r = new Revision(noid);
List<String> test3 = newgit.showRevision(r);
String[] authorDate = test3.get(3).split(">");
String author = authorDate[0].replaceFirst("author ", "").replaceFirst("committer ", "") + ">";
String goodDate = null;
- try
- {
+ try {
String totmp = authorDate[1].trim().split("\\+")[0].trim();
long timestamp = Long.parseLong(totmp,10) * 1000;
Date date = new Date();
@@ -276,32 +234,28 @@ public void generateContents(String contentType)
goodDate = new SimpleDateFormat("yyyy:mm:dd").format(date);
}
- catch (Exception e)
- {
+ catch (Exception e) {
e.toString();
}
revisionMap.put(r.getSha1String(), r.getSha1String() + " " + author + " " + goodDate);
}
}
- else if(type.equalsIgnoreCase(PARAMETER_TYPE_TAG))
- {
+ else if(type.equalsIgnoreCase(PARAMETER_TYPE_TAG)) {
tagMap = new HashMap<String, String>();
- for(String tagName : newgit.getTagNames("*"))
- {
+ for(String tagName : newgit.getTagNames("*")) {
tagMap.put(tagName, tagName);
}
}
- else if (type.equalsIgnoreCase(PARAMETER_TYPE_BRANCH))
- {
+ else if (type.equalsIgnoreCase(PARAMETER_TYPE_BRANCH)) {
branchMap = new TreeMap<String, String>();
- for (hudson.plugins.git.Branch gitBranch : newgit.getBranches())
- {
+ for (hudson.plugins.git.Branch gitBranch : newgit.getBranches()) {
String branchName = gitBranch.getName();
- if ("master".equals(branchName))
+ if ("master".equals(branchName)) {
continue;
+ }
branchMap.put(branchName, branchName);
}
@@ -310,33 +264,26 @@ else if (type.equalsIgnoreCase(PARAMETER_TYPE_BRANCH))
}
}
- public String getErrorMessage()
- {
+ public String getErrorMessage() {
return errorMessage;
}
- public Map<String, String> getRevisionMap()
- {
- if (revisionMap == null || revisionMap.isEmpty())
- {
+ public Map<String, String> getRevisionMap() {
+ if (revisionMap == null || revisionMap.isEmpty()) {
generateContents(PARAMETER_TYPE_REVISION);
}
return revisionMap;
}
- public Map<String, String> getTagMap()
- {
- if (tagMap == null || tagMap.isEmpty())
- {
+ public Map<String, String> getTagMap() {
+ if (tagMap == null || tagMap.isEmpty()) {
generateContents(PARAMETER_TYPE_TAG);
}
return tagMap;
}
- public Map<String, String> getBranchMap()
- {
- if (branchMap == null || branchMap.isEmpty())
- {
+ public Map<String, String> getBranchMap() {
+ if (branchMap == null || branchMap.isEmpty()) {
generateContents(PARAMETER_TYPE_BRANCH);
}
return branchMap;
View
6 src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/GitParameterValue.java
@@ -3,13 +3,11 @@
import hudson.model.StringParameterValue;
import org.kohsuke.stapler.DataBoundConstructor;
-public class GitParameterValue extends StringParameterValue
-{
+public class GitParameterValue extends StringParameterValue {
private static final long serialVersionUID = -8244244942726975701L;
@DataBoundConstructor
- public GitParameterValue(String name, String value)
- {
+ public GitParameterValue(String name, String value) {
super(name, value);
}
}
View
38 src/test/java/net/uaznia/lukanus/hudson/plugins/gitparameter/GitParameterDefinitionTest.java
@@ -18,13 +18,11 @@
* @author lukanus
*/
public class GitParameterDefinitionTest extends HudsonTestCase {
-
public GitParameterDefinitionTest() {
}
@BeforeClass
public static void setUpClass() throws Exception {
-
}
@AfterClass
@@ -69,7 +67,6 @@ public void testCreateValue_StaplerRequest_JSONObject() {
JSONObject jO = JSONObject.fromObject(jsonR);
-
GitParameterDefinition instance = new GitParameterDefinition("name","PT_REVISION","defaultValue","description","branch");
ParameterValue result = instance.createValue(request,jO);
@@ -82,7 +79,6 @@ public void testCreateValue_StaplerRequest_JSONObject() {
*/
@Test
public void testGetDefaultParameterValue() {
-
// TODO review the generated test code and remove the default call to fail.
//fail("The test case is a prototype.");
}
@@ -98,11 +94,9 @@ public void testGetType() {
String result = instance.getType();
assertEquals(expResult, result);
-
instance.setType(expResult);
result = instance.getType();
assertEquals(expResult, result);
-
}
/**
@@ -152,13 +146,12 @@ public void testSetDefaultValue() {
*/
@Test
public void testGenerateContents() {
-
-// System.out.println("generateContents");
- // String contenttype = "";
- // GitParameterDefinition instance = null;
- // instance.generateContents(contenttype);
-
-
+ /*
+ System.out.println("generateContents");
+ String contenttype = "";
+ GitParameterDefinition instance = null;
+ instance.generateContents(contenttype);
+ */
}
/**
@@ -172,7 +165,6 @@ public void testGetErrorMessage() {
String result = instance.getErrorMessage();
assertEquals(expResult, result);*/
// TODO review the generated test code and remove the default call to fail.
-
}
/**
@@ -180,13 +172,12 @@ public void testGetErrorMessage() {
*/
@Test
public void testGetRevisionMap() {
- // System.out.println("getRevisionMap");
- // GitParameterDefinition instance = null;
- // Map expResult = null;
- // Map result = instance.getRevisionMap();
- // assertEquals(expResult, result);
+ // System.out.println("getRevisionMap");
+ // GitParameterDefinition instance = null;
+ // Map expResult = null;
+ // Map result = instance.getRevisionMap();
+ // assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
-
}
/**
@@ -195,8 +186,8 @@ public void testGetRevisionMap() {
@Test
public void testGetTagMap() {
System.out.println("Test of getTagMap method");
- /* GitParameterDefinition instance = new GitParameterDefinition("name","PT_TAG","defaultValue","description","branch");
-
+ /*
+ GitParameterDefinition instance = new GitParameterDefinition("name","PT_TAG","defaultValue","description","branch");
Map<String,String> result = instance.getTagMap();
//assertEquals(expResult, result);
if(!result.isEmpty()) {
@@ -205,8 +196,7 @@ public void testGetTagMap() {
}
@Test
- public void testGetBranchMap()
- {
+ public void testGetBranchMap() {
/*
GitParameterDefinition instance = new GitParameterDefinition("name", "PT_BRANCH", "defaultValue", "description", "branch");
Map<String, String> result = instance.getBranchMap();
Please sign in to comment.
Something went wrong with that request. Please try again.