Skip to content

Commit

Permalink
Migrate parent POM file, fix Javadoc and FindBugs (#89)
Browse files Browse the repository at this point in the history
* [new-parent-pom] Upgrade to the standalone plugin parent POM

* [new-parent-pom] Fix javadoc errors

* Add some missing CheckForNull annotations

* [new-parent-pom] - Make the tests compilable and runnable

* [new-parent-pom] - Escape all jelly files by default

* [parent-pom-upgrade] - Fix Unit tests by enforcing data encoding

* [FindBugs] - Process NPE warnings discovered by FindBugs

* [parent-pom-upgrade] - Fix Javadoc after integrating pull requests

* FindBugs - Fix the unchecked class cast, add dignostic messages (related to JENKINS-32237)

* [parent-pom-upgrade] - Address comments from @armfergom . Java 6, etc.
  • Loading branch information
oleg-nenashev committed Apr 20, 2016
1 parent 30f9c6b commit adfdf61
Show file tree
Hide file tree
Showing 50 changed files with 330 additions and 112 deletions.
71 changes: 27 additions & 44 deletions pom.xml
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.565</version>
<version>2.6</version>
</parent>

<artifactId>promoted-builds</artifactId>
Expand All @@ -15,8 +15,8 @@
<url>http://wiki.jenkins-ci.org/display/JENKINS/Promoted+Builds+Plugin</url>

<properties>
<findbugs-maven-plugin.version>3.0.3</findbugs-maven-plugin.version>
<findbugs.failOnError>true</findbugs.failOnError>
<jenkins.version>1.565</jenkins.version>
<java.level>6</java.level>
</properties>

<developers>
Expand Down Expand Up @@ -97,12 +97,6 @@
<version>1.8.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>token-macro</artifactId>
Expand Down Expand Up @@ -138,40 +132,29 @@
<version>2.30</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-auth</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
<dependency> <!-- required to workaround the missing CookieSpecProvider class -->
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.4</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>${findbugs-maven-plugin.version}</version>
<configuration>
<failOnError>${findbugs.failOnError}</failOnError>
<xmlOutput>true</xmlOutput>
</configuration>
<executions>
<execution>
<id>run-findbugs</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<compatibleSinceVersion>2.22</compatibleSinceVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.util.Collection;

//TODO: needs polishing
/**
* We use this {@link ItemGroup} to create a dangling {@link PromotionProcess}.
*
Expand Down
32 changes: 28 additions & 4 deletions src/main/java/hudson/plugins/promoted_builds/JobPropertyImpl.java
Expand Up @@ -37,6 +37,7 @@
import hudson.model.listeners.ItemListener;
import hudson.remoting.Callable;
import hudson.util.IOUtils;
import javax.annotation.CheckForNull;
import jenkins.model.Jenkins;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
Expand All @@ -47,7 +48,7 @@
* <p>
* TODO: a possible performance problem as every time the owner job is reconfigured,
* all the promotion processes get reloaded from the disk.
*
* </p>
* @author Kohsuke Kawaguchi
*/
public final class JobPropertyImpl extends JobProperty<AbstractProject<?,?>> implements ItemGroup<PromotionProcess> {
Expand All @@ -68,13 +69,16 @@ public final class JobPropertyImpl extends JobProperty<AbstractProject<?,?>> imp
private final Set<String> activeProcessNames = new HashSet<String>();
/**
* Programmatic construction.
* @param owner owner job
*/
public JobPropertyImpl(AbstractProject<?,?> owner) throws Descriptor.FormException, IOException {
this.owner = owner;
init();
}
/**
* Programmatic construction.
* @param other Property to be copied
* @param owner owner job
*/
public JobPropertyImpl(JobPropertyImpl other, AbstractProject<?,?> owner) throws Descriptor.FormException, IOException {
this.owner = owner;
Expand All @@ -94,8 +98,20 @@ private JobPropertyImpl(StaplerRequest req, JSONObject json) throws Descriptor.F
// a hack to get the owning AbstractProject.
// this is needed here so that we can load items
List<Ancestor> ancs = req.getAncestors();
owner = (AbstractProject)ancs.get(ancs.size()-1).getObject();

final Object ancestor = ancs.get(ancs.size()-1).getObject();
if (ancestor instanceof AbstractProject) {
owner = (AbstractProject)ancestor;
} else if (ancestor == null) {
throw new Descriptor.FormException("Cannot retrieve the ancestor item in the request",
"owner");
} else {
throw new Descriptor.FormException("Cannot create Promoted Builds Job Property for " + ancestor.getClass()
+ ". Currently the plugin supports instances of AbstractProject only."
+ ". Other job types are not supported, submit a bug to the plugin, which provides the job type"
+ ". If you use Multi-Branch Project plugin, see https://issues.jenkins-ci.org/browse/JENKINS-32237",
"owner");
}

// newer version of Hudson put "promotions". This code makes it work with or without them.
if(json.has("promotions"))
json = json.getJSONObject("promotions");
Expand Down Expand Up @@ -159,6 +175,9 @@ private void loadProcesses(File[] subdirs) throws IOException {

/**
* Adds a new promotion process of the given name.
* @param name Name of the process to be created
* @return Created process
* @throws IOException Execution error
*/
public synchronized PromotionProcess addProcess(String name) throws IOException {
PromotionProcess p = new PromotionProcess(this, name);
Expand Down Expand Up @@ -212,6 +231,7 @@ protected synchronized void setOwner(AbstractProject<?,?> owner) {

/**
* Builds {@link #activeProcesses}.
* @throws IOException Execution error
*/
private void buildActiveProcess() throws IOException {
activeProcesses = new ArrayList<PromotionProcess>();
Expand Down Expand Up @@ -302,14 +322,18 @@ public PromotionProcess createProcessFromXml(final String name, InputStream xml)

/**
* Gets {@link AbstractProject} that contains us.
* @return Owner project
*/
public synchronized AbstractProject<?,?> getOwner() {
return owner;
}

/**
* Finds a config by name.
* Finds a {@link PromotionProcess} by name.
* @param name Name of the process
* @return {@link PromotionProcess} if it can be found.
*/
@CheckForNull
public synchronized PromotionProcess getItem(String name) {
if (processes == null) {
return null;
Expand Down
Expand Up @@ -16,6 +16,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.CheckForNull;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

Expand All @@ -26,6 +27,8 @@
*/
@ExportedBean
public final class PromotedBuildAction implements BuildBadgeAction {

//TODO: bug: serialization of builds into the badge
public final AbstractBuild<?,?> owner;

/**
Expand Down Expand Up @@ -117,8 +120,9 @@ public List<Promotion> getPromotionBuilds(PromotionProcess promotionProcess) {

/**
* Finds the {@link Status} that has matching {@link Status#name} value.
* Or null if not found.
* Or {@code null} if not found.
*/
@CheckForNull
public Status getPromotion(String name) {
for (Status s : statuses)
if(s.name.equals(name))
Expand Down Expand Up @@ -151,8 +155,10 @@ public List<PromotionProcess> getPendingPromotions() {
}

/**
* Get the specified promotion process by name
* Get the specified promotion process by name.
* @return The discovered process of {@code null} if the promotion cannot be found
*/
@CheckForNull
public PromotionProcess getPromotionProcess(String name) {
JobPropertyImpl pp = getProject().getProperty(JobPropertyImpl.class);
if (pp==null)
Expand Down
Expand Up @@ -10,6 +10,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.CheckForNull;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.QueryParameter;
Expand Down Expand Up @@ -47,6 +48,12 @@ public List<PromotionProcess> getProcesses() {
return property.getActiveItems();
}

/**
* Get the promotion process by name.
* @param name Name of the process
* @return Discovered process or {@code null} if it cannot be found
*/
@CheckForNull
public PromotionProcess getProcess(String name) {
for (PromotionProcess pp : getProcesses() ){
if(pp.getName().equals(name))
Expand Down Expand Up @@ -104,8 +111,8 @@ public List<Promotion> getPromotions(PromotionProcess promotionProcess){
/**
* returns the summary of the latest promotions for a promotion process.
*
* @param promotionProcessName
* @return
* @param promotionProcess Name of the promotion process
* @return List of latest promotions
*/
public List<Promotion> getPromotionsSummary(PromotionProcess promotionProcess){
List<Promotion> promotionList = this.getPromotions(promotionProcess);
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/hudson/plugins/promoted_builds/Promotion.java
Expand Up @@ -47,6 +47,7 @@
import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

/**
Expand Down Expand Up @@ -253,11 +254,26 @@ public List<ParameterValue> getParameterValues(){
return Collections.emptyList();
}

/**
* Gets parameter definitions from the {@link ManualCondition}.
* @return List of parameter definitions to be presented.
* May be empty if there is no {@link ManualCondition}.
*/
@Nonnull
public List<ParameterDefinition> getParameterDefinitionsWithValue(){
List<ParameterDefinition> definitions=new ArrayList<ParameterDefinition>();
ManualCondition manualCondition=(ManualCondition) getProject().getPromotionCondition(ManualCondition.class.getName());
for (ParameterValue pvalue:getParameterValues()){
if (manualCondition == null) {
return definitions;
}

for (ParameterValue pvalue:getParameterValues()){
ParameterDefinition pdef=manualCondition.getParameterDefinition(pvalue.getName());
if (pdef == null) {
// We cannot do anything with such missing definitions.
// May happen only in the case of the wrong form submission
continue;
}
definitions.add(pdef.copyWithDefaultValue(pvalue));
}
return definitions;
Expand Down Expand Up @@ -446,7 +462,9 @@ public static ParametersAction getParametersActions(Promotion build){
* @param build
* @param promotionParams
*/
public static void buildParametersAction(List<Action> actions, AbstractBuild<?, ?> build, List<ParameterValue> promotionParams) {
public static void buildParametersAction(@Nonnull List<Action> actions,
@Nonnull AbstractBuild<?, ?> build,
@CheckForNull List<ParameterValue> promotionParams) {
if (promotionParams == null) {
promotionParams = new ArrayList<ParameterValue>();
}
Expand Down
Expand Up @@ -10,6 +10,7 @@

import java.util.ArrayList;
import java.util.List;
import javax.annotation.CheckForNull;
import jenkins.model.Jenkins;

/**
Expand All @@ -29,6 +30,7 @@ public abstract class PromotionCondition implements ExtensionPoint, Describable<
* Null if otherwise, meaning it shouldn't be promoted.
* @deprecated
*/
@CheckForNull
public PromotionBadge isMet(AbstractBuild<?,?> build) {
return null;
}
Expand Down

0 comments on commit adfdf61

Please sign in to comment.