Skip to content

fixes #339 by adding appropriate getters #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ after_script:
# http://www.webupd8.org/2017/06/why-oracle-java-7-and-6-installers-no.html
# - oraclejdk8 is not supported anymore.
jdk:
- openjdk7
- openjdk8
cache:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a separate PR for upgrading Java version? This needs also to be made clear in ReleaseNotes ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change to maven-compiler-plugin should be part of the PR...

Copy link
Contributor Author

@mivola mivola Sep 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created #358 and a PR for this topic.
Could we maybe have a chat/call to discuss a more general topic?

directories:
- $HOME/.m2/repository
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is artifact1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is artifact2 in the "sub folder"
11 changes: 10 additions & 1 deletion jenkins-client-it-docker/jobs/test/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
<command>echo &quot;test&quot;</command>
</hudson.tasks.Shell>
</builders>
<publishers/>
<publishers>
<hudson.tasks.ArtifactArchiver>
<artifacts>**/*.txt</artifacts>
<allowEmptyArchive>false</allowEmptyArchive>
<onlyIfSuccessful>true</onlyIfSuccessful>
<fingerprint>false</fingerprint>
<defaultExcludes>true</defaultExcludes>
<caseSensitive>true</caseSensitive>
</hudson.tasks.ArtifactArchiver>
</publishers>
<buildWrappers/>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class AbstractJenkinsIntegrationCase {
public void waitUntilJenkinsHasBeenStartedUp() throws TimeoutException {
final long start = System.currentTimeMillis();
jenkinsServer = new JenkinsServer(Constant.JENKINS_URI);
System.out.print("Wait until Jenkins is started...");
System.out.print("Wait until Jenkins is started at " + Constant.JENKINS_URI + " ...");
while (!jenkinsServer.isRunning() && !timeOut(start)) {
try {
System.out.print(".");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.offbytwo.jenkins.integration;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.offbytwo.jenkins.model.Artifact;
import com.offbytwo.jenkins.model.BaseModel;
import com.offbytwo.jenkins.model.Build;

@Test(groups = { Groups.NO_EXECUTOR_GROUP })
public class NoExecutorStartedGetArtifactIT extends AbstractJenkinsIntegrationCase {

private Build build;

@BeforeMethod
public void beforeMethod() throws IOException {
build = jenkinsServer.getJob("test").getBuildByNumber(1);
}

@Test
public void getBuildShouldContainTwoArtifacts() throws IOException {
assertThat(build.details().getArtifacts()).hasSize(2);
}

@Test
public void traverseFromArtifactToJenkinsServerShouldNotFail() throws IOException {
build.details().getArtifacts().forEach(a -> assertArtifact(a));
}

private void assertArtifact(Artifact artifact) {
assertBaseModel(artifact);
assertBaseModel(artifact.getBuildWithDetails());
assertBaseModel(artifact.getBuildWithDetails().getBuild());
assertBaseModel(artifact.getBuildWithDetails().getBuild().getJobWithDetails());
assertBaseModel(artifact.getBuildWithDetails().getBuild().getJobWithDetails().getJob());
assertThat(artifact.getBuildWithDetails().getBuild().getJobWithDetails().getJenkinsServer()).isNotNull();
assertThat(artifact.getBuildWithDetails().getBuild().getJobWithDetails().getJob().getJenkinsServer()).isNotNull();
}

private void assertBaseModel(BaseModel baseModel) {
assertThat(baseModel).isNotNull();
// TODO: this will work once #337 is fixed: assertThat(baseModel.getClient()).isNotNull();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.IOException;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;

import com.google.common.base.Joiner;
Expand Down Expand Up @@ -39,12 +40,22 @@ public void beforeMethod() throws IOException {
" <command>echo &quot;test&quot;</command>",
" </hudson.tasks.Shell>",
" </builders>",
" <publishers/>",
" <buildWrappers/>",
" <publishers>",
" <hudson.tasks.ArtifactArchiver>",
" <artifacts>**/*.txt</artifacts>",
" <allowEmptyArchive>false</allowEmptyArchive>",
" <onlyIfSuccessful>true</onlyIfSuccessful>",
" <fingerprint>false</fingerprint>",
" <defaultExcludes>true</defaultExcludes>",
" <caseSensitive>true</caseSensitive>",
" </hudson.tasks.ArtifactArchiver>",
" </publishers>",
" <buildWrappers/>",
"</project>"
};
//@formatter:on

@Ignore
@Test
public void getJobXmlShouldReturnTheExpectedConfigXml() {
String expectedXml = Joiner.on("\n").join(CONFIG_XML);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

package com.offbytwo.jenkins;

import java.io.Closeable;
import java.io.IOException;
import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import javax.xml.bind.JAXBException;

Expand All @@ -20,10 +23,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.offbytwo.jenkins.client.JenkinsHttpClient;
import com.offbytwo.jenkins.client.JenkinsHttpConnection;
import com.offbytwo.jenkins.client.util.EncodingUtils;
Expand All @@ -44,7 +45,6 @@
import com.offbytwo.jenkins.model.QueueItem;
import com.offbytwo.jenkins.model.QueueReference;
import com.offbytwo.jenkins.model.View;
import java.io.Closeable;

/**
* The main starting point for interacting with a Jenkins server.
Expand Down Expand Up @@ -167,13 +167,8 @@ public Map<String, Job> getJobs(FolderJob folder, String view) throws IOExceptio
viewClass = View.class;
}
List<Job> jobs = client.get(path, viewClass).getJobs();
return Maps.uniqueIndex(jobs, new Function<Job, String>() {
@Override
public String apply(Job job) {
job.setClient(client);
return job.getName();
}
});
jobs.forEach(j -> j.setJenkinsServer(this).setClient(client));
return jobs.stream().collect(Collectors.toMap(Job::getName, Function.identity()));
}

/**
Expand All @@ -198,22 +193,8 @@ public Map<String, View> getViews(FolderJob folder) throws IOException {
// This is much better than using &depth=2
// http://localhost:8080/api/json?pretty&tree=views[name,url,jobs[name,url]]
List<View> views = client.get(UrlUtils.toBaseUrl(folder) + "?tree=views[name,url,jobs[name,url]]", MainView.class).getViews();
return Maps.uniqueIndex(views, new Function<View, String>() {
@Override
public String apply(View view) {
view.setClient(client);
// TODO: Think about the following? Does there exists a
// simpler/more elegant method?
for (Job job : view.getJobs()) {
job.setClient(client);
}
for (View item : view.getViews()) {
item.setClient(client);
}

return view.getName();
}
});
views.forEach(v -> v.setJenkinsServer(this).setClient(client));
return views.stream().collect(Collectors.toMap(View::getName, Function.identity()));
}

/**
Expand All @@ -239,15 +220,7 @@ public View getView(FolderJob folder, String name) throws IOException {
try {
View resultView = client.get(UrlUtils.toViewBaseUrl(folder, name) + "/", View.class);
resultView.setClient(client);

// TODO: Think about the following? Does there exists a simpler/more
// elegant method?
for (Job job : resultView.getJobs()) {
job.setClient(client);
}
for (View view : resultView.getViews()) {
view.setClient(client);
}
resultView.setJenkinsServer(this);
return resultView;
} catch (HttpResponseException e) {
LOGGER.debug("getView(folder={}, name={}) status={}", folder, name, e.getStatusCode());
Expand Down Expand Up @@ -282,7 +255,7 @@ public JobWithDetails getJob(FolderJob folder, String jobName) throws IOExceptio
try {
JobWithDetails job = client.get(UrlUtils.toJobBaseUrl(folder, jobName), JobWithDetails.class);
job.setClient(client);

job.setJenkinsServer(this);
return job;
} catch (HttpResponseException e) {
LOGGER.debug("getJob(folder={}, jobName={}) status={}", folder, jobName, e.getStatusCode());
Expand All @@ -302,7 +275,7 @@ public MavenJobWithDetails getMavenJob(FolderJob folder, String jobName) throws
try {
MavenJobWithDetails job = client.get(UrlUtils.toJobBaseUrl(folder, jobName), MavenJobWithDetails.class);
job.setClient(client);

job.setJenkinsServer(this);
return job;
} catch (HttpResponseException e) {
LOGGER.debug("getMavenJob(jobName={}) status={}", jobName, e.getStatusCode());
Expand All @@ -320,7 +293,7 @@ public Optional<FolderJob> getFolderJob(Job job) throws IOException {
return Optional.absent();
}
folder.setClient(client);

folder.setJenkinsServer(this);
return Optional.of(folder);
} catch (HttpResponseException e) {
LOGGER.debug("getForlderJob(job={}) status={}", job, e.getStatusCode());
Expand Down Expand Up @@ -535,13 +508,8 @@ public LabelWithDetails getLabel(String labelName) throws IOException {
*/
public Map<String, Computer> getComputers() throws IOException {
List<Computer> computers = client.get("computer/", Computer.class).getComputers();
return Maps.uniqueIndex(computers, new Function<Computer, String>() {
@Override
public String apply(Computer computer) {
computer.setClient(client);
return computer.getDisplayName().toLowerCase();
}
});
computers.forEach(j -> j.setJenkinsServer(this).setClient(client));
return computers.stream().collect(Collectors.toMap(c -> c.getDisplayName().toLowerCase(), Function.identity()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Artifact extends BaseModel {
private String displayPath;
private String fileName;
private String relativePath;
private BuildWithDetails buildWithDetails;

public String getDisplayPath() {
return displayPath;
Expand All @@ -36,6 +37,15 @@ public void setRelativePath(String relativePath) {
this.relativePath = relativePath;
}

public Artifact setBuildWithDetails(BuildWithDetails buildWithDetails) {
this.buildWithDetails = buildWithDetails;
return this;
}

public BuildWithDetails getBuildWithDetails() {
return buildWithDetails;
}

@Override
public boolean equals(Object o) {
if (this == o)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public BuildWithDetails details() {
private int number;
private int queueId;
private String url;
private JobWithDetails jobWithDetails;

private Build(int number, int queueId, String url) {
super();
Expand Down Expand Up @@ -94,6 +95,15 @@ protected void setUrl(String url) {
this.url = url;
}

public Build setJobWithDetails(JobWithDetails jobWithDetails) {
this.jobWithDetails = jobWithDetails;
return this;
}

public JobWithDetails getJobWithDetails() {
return jobWithDetails;
}

/**
*
* @return The information from Jenkins. In cases the build has never run
Expand All @@ -102,7 +112,9 @@ protected void setUrl(String url) {
* in case of an error.
*/
public BuildWithDetails details() throws IOException {
return client.get(url, BuildWithDetails.class);
BuildWithDetails buildWithDetails = client.get(url, BuildWithDetails.class);
buildWithDetails.setBuild(this);
return buildWithDetails;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public BuildResult getResult() {
private List<BuildChangeSet> changeSets;
private String builtOn;
private List<BuildChangeSetAuthor> culprits;
private Build build;

public BuildWithDetails() {
// Default ctor is needed to jackson.
Expand All @@ -151,6 +152,7 @@ public BuildWithDetails(BuildWithDetails details) {
this.changeSet = details.changeSet;
this.builtOn = details.builtOn;
this.culprits = details.culprits;

this.setClient(details.getClient());
}

Expand Down Expand Up @@ -534,6 +536,18 @@ public void setResult(BuildResult result) {
this.result = result;
}

public BuildWithDetails setBuild(Build build) {
this.build = build;
if (this.artifacts != null) {
this.artifacts.forEach(a -> a.setBuildWithDetails(this));
}
return this;
}

public Build getBuild() {
return build == null ? this : build;
}

public InputStream downloadArtifact(Artifact a) throws IOException, URISyntaxException {
// We can't just put the artifact's relative path at the end of the url
// string, as there could be characters that need to be escaped.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;

import com.google.common.net.UrlEscapers;
import com.offbytwo.jenkins.JenkinsServer;

/**
* @author Kelly Plummer
Expand All @@ -28,6 +29,7 @@ public void setComputer(List<Computer> computer) {
}

List<Computer> computer;
private JenkinsServer jenkinsServer;

public Computer() {
}
Expand All @@ -41,6 +43,15 @@ public String getDisplayName() {
return this.displayName;
}

public Computer setJenkinsServer(JenkinsServer jenkinsServer) {
this.jenkinsServer = jenkinsServer;
return this;
}

public JenkinsServer getJenkinsServer() {
return jenkinsServer;
}

public ComputerWithDetails details() throws IOException {
String name;
if ("master".equals(displayName)) {
Expand Down
Loading