Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
@@ -0,0 +1,40 @@
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.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 {
Artifact artifact = build.details().getArtifacts().get(0);
assertThat(artifact).isNotNull();
assertThat(artifact.getBuildWithDetails()
.getBuild()
.getJobWithDetails()
.getJob()
.getJenkinsServer())
.isNotNull();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,17 @@ 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
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,6 @@ 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);
}
return resultView;
} catch (HttpResponseException e) {
LOGGER.debug("getView(folder={}, name={}) status={}", folder, name, e.getStatusCode());
Expand Down Expand Up @@ -535,13 +507,7 @@ 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();
}
});
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,7 +152,11 @@ public BuildWithDetails(BuildWithDetails details) {
this.changeSet = details.changeSet;
this.builtOn = details.builtOn;
this.culprits = details.culprits;

this.setClient(details.getClient());
if (this.artifacts != null) {
this.artifacts.forEach(a -> a.setBuildWithDetails(this));
}
}

public List<Artifact> getArtifacts() {
Expand Down Expand Up @@ -534,6 +539,15 @@ public void setResult(BuildResult result) {
this.result = result;
}

public BuildWithDetails setBuild(Build build) {
this.build = build;
return this;
}

public Build getBuild() {
return 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
15 changes: 14 additions & 1 deletion jenkins-client/src/main/java/com/offbytwo/jenkins/model/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import com.google.common.collect.Collections2;
import com.google.common.escape.Escaper;
import com.google.common.net.UrlEscapers;
import com.offbytwo.jenkins.JenkinsServer;

public class Job extends BaseModel {

private String name;
private String url;
private String fullName;
private JenkinsServer jenkinsServer;

public Job() {
}
Expand Down Expand Up @@ -55,8 +57,19 @@ public String getFullName() {
return fullName;
}

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

public JenkinsServer getJenkinsServer() {
return jenkinsServer;
}

public JobWithDetails details() throws IOException {
return client.get(url, JobWithDetails.class);
JobWithDetails jobWithDetails = client.get(url, JobWithDetails.class);
jobWithDetails.setJob(this);
return jobWithDetails;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class JobWithDetails extends Job {
private List<Job> downstreamProjects;

private List<Job> upstreamProjects;

private Job job;

public String getDescription() {
return description;
Expand All @@ -80,6 +82,15 @@ public boolean isInQueue() {
return inQueue;
}

public JobWithDetails setJob(Job job) {
this.job = job;
return this;
}

public Job getJob() {
return job;
}

/**
* This method will give you back the builds of a particular job.
*
Expand Down Expand Up @@ -201,6 +212,7 @@ private Build buildWithClient(Build from) {
if (from != null) {
ret = new Build(from);
ret.setClient(client);
ret.setJobWithDetails(this);
}
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
import java.util.List;

import com.google.common.collect.Lists;
import com.offbytwo.jenkins.JenkinsServer;
import com.offbytwo.jenkins.client.JenkinsHttpConnection;

public class MainView extends BaseModel {

private List<Job> jobs;
private List<View> views;
private JenkinsServer jenkinsServer;

/* default constructor needed for Jackson */
public MainView() {
Expand Down Expand Up @@ -45,4 +48,21 @@ public List<View> getViews() {
public void setViews(List<View> views) {
this.views = views;
}

@Override
public void setClient(JenkinsHttpConnection client) {
super.setClient(client);
getJobs().forEach(j -> j.setClient(client));
getViews().forEach(j -> j.setClient(client));
}

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

public JenkinsServer getJenkinsServer() {
return jenkinsServer;
}

}
Loading