Skip to content

Commit

Permalink
JENKINS-21450
Browse files Browse the repository at this point in the history
  • Loading branch information
emenaceb committed Mar 5, 2014
1 parent 7f6c104 commit 06f4de9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
Expand Up @@ -88,14 +88,18 @@ protected MavenModuleSetBuild getBuild(MavenModuleSet job) {
}

private JSONObject getDependenciesList(MavenModuleSet job) {
JSONObject response = new JSONObject();
MavenModuleSetBuild build = getBuild(job);
if (build == null) {
return response;
}
ModuleNamePattern pattern = getDependencyFilter(job);

List<Dependency> dependencies = BuildUtils.getModuleDependencies(build,
pattern);

String version = findVersion(findVersions(dependencies));
JSONObject response = new JSONObject();

response.accumulate("version", version);

JSONArray deps = new JSONArray();
Expand Down
Expand Up @@ -38,14 +38,12 @@ public String getDisplayName() {
return Messages.MavenVersionColumn_DisplayName();
}


@Override
public boolean shownByDefault() {
return false;
}
}


@DataBoundConstructor
public LastVersionColumn(String columnName) {
super(columnName);
Expand Down Expand Up @@ -77,15 +75,18 @@ private JSONObject getModuleAsJson(MavenModule module) {
}

private JSONObject getModuleList(MavenModuleSet job) {

JSONObject json = new JSONObject();
MavenModuleSetBuild build = getBuild(job);
if (build == null) {
return json;
}
ModuleNamePattern mainPattern = getModulePattern(job);

MavenModule mainModule = BuildUtils.getMainModule(build, mainPattern);
List<MavenModule> modules = BuildUtils.getModules(build);

Collections.sort(modules, new MavenModuleComparator());
JSONObject json = new JSONObject();

json.accumulate("mainModule", getModuleAsJson(mainModule));
JSONArray jsonModules = new JSONArray();
for (MavenModule module : modules) {
Expand All @@ -105,7 +106,7 @@ public String getVersion(MavenModuleSet job) {
ModuleNamePattern mainPattern = getModulePattern(job);

MavenModule m = BuildUtils.getMainModule(build, mainPattern);
return m != null? m.getVersion() : null;
return m != null ? m.getVersion() : null;
}

public boolean isMultipleVersions(MavenModuleSet job) {
Expand All @@ -126,18 +127,20 @@ public boolean isMultipleVersions(MavenModuleSet job) {
}
return false;
}

/**
* Deserialization method to ensure compatibility.
*
* @return
*/
public Object readResolve() {

// 0.0.5 -> 0.1.0 added column name to object fields
// Keep caption
if(getColumnName() == null) {
if (getColumnName() == null) {
setColumnName(Messages.MavenVersionColumn_Caption());
}
return this ;

return this;
}
}
23 changes: 17 additions & 6 deletions src/main/java/jenkins/plugins/maveninfo/util/BuildUtils.java
Expand Up @@ -28,8 +28,15 @@ public class BuildUtils {
private static final Logger LOGGER = Logger.getLogger(BuildUtils.class
.getName());

private static final MavenInfoJobConfig DEFAULT_CONFIG = new MavenInfoJobConfig(
"", "", false, "", false, "");;

public static MavenInfoJobConfig getJobConfig(MavenModuleSet job) {
return job.getProperty(MavenInfoJobConfig.class);
MavenInfoJobConfig cfg = job.getProperty(MavenInfoJobConfig.class);
if (cfg == null) {
cfg = DEFAULT_CONFIG;
}
return cfg;
}

public static MavenModuleSetBuild getLastBuild(MavenModuleSet job) {
Expand All @@ -39,6 +46,9 @@ public static MavenModuleSetBuild getLastBuild(MavenModuleSet job) {
public static MavenModule getMainModule(MavenModuleSetBuild build,
ModuleNamePattern pattern) {

if (build == null) {
return null;
}
MavenModule root = null;
if (pattern != null) {
List<MavenModule> modules = BuildUtils.getModules(build);
Expand Down Expand Up @@ -112,10 +122,11 @@ public static List<Dependency> getModuleDependencies(
}

public static List<MavenModule> getModules(MavenModuleSetBuild build) {

Set<MavenModule> moduleSet = build.getModuleLastBuilds().keySet();
List<MavenModule> modules = new ArrayList<MavenModule>(moduleSet);

return modules;
if (build != null) {
Set<MavenModule> moduleSet = build.getModuleLastBuilds().keySet();
return new ArrayList<MavenModule>(moduleSet);
} else {
return Collections.emptyList();
}
}
}

0 comments on commit 06f4de9

Please sign in to comment.