Skip to content

Commit

Permalink
simplify pom, remove non used dependencies and use bom for LTS we use…
Browse files Browse the repository at this point in the history
…. need some changes in mockito (#239)

* simplify pom, remove non used dependencies and use bom for LTS we use

Signed-off-by: olivier lamy <[email protected]>
  • Loading branch information
olamy authored May 13, 2020
1 parent 6cbc5ef commit 82fccea
Show file tree
Hide file tree
Showing 33 changed files with 249 additions and 303 deletions.
6 changes: 1 addition & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
// Builds a module using https://github.com/jenkins-infra/pipeline-library
def configurations = [
[ platform: "linux", jdk: "8", jenkins: null ],
[ platform: "linux", jdk: "11", jenkins: null, javaLevel: "8" ]
]
buildPlugin(configurations: configurations, timeout: 180, useAci: true)
buildPlugin(useAci: false, configurations: buildPlugin.recommendedConfigurations())
73 changes: 25 additions & 48 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.43</version>
<version>4.1</version>
<relativePath />
</parent>

Expand All @@ -19,20 +19,12 @@
<revision>3.0.16</revision>
<changelist>-SNAPSHOT</changelist>
<java.level>8</java.level>
<mockito.version>1.10.19</mockito.version>
<jira-rest-client.version>5.2.1</jira-rest-client.version>
<fugue.version>3.0.0</fugue.version>
<workflow.version>2.0</workflow.version>
<slf4jVersion>1.7.26</slf4jVersion>

<!-- jenkins -->
<jenkins.version>2.176.4</jenkins.version>

<!-- security -->
<spotbugs.failOnError>false</spotbugs.failOnError>

<!-- tests -->
<test.configuration-as-code.version>1.36</test.configuration-as-code.version>
</properties>

<scm>
Expand Down Expand Up @@ -119,6 +111,18 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- not reuse because Mockito record stuff statically and some are changing between tests so it suc... -->
<reuseForks>false</reuseForks>
<!-- to run some tests within your IDE you will need this -->
<!-- <systemPropertyVariables>-->
<!-- <hudson.remoting.ClassFilter>hudson.plugins.jira.JiraFolderProperty,hudson.plugins.jira.JiraSite,hudson.plugins.jira.JiraJobAction</hudson.remoting.ClassFilter>-->
<!-- </systemPropertyVariables>-->
</configuration>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -194,7 +198,6 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>apache-httpcomponents-client-4-api</artifactId>
<version>4.5.10-1.0</version>
</dependency>

<dependency>
Expand All @@ -210,16 +213,13 @@
</dependency>

<!-- Jenkins plugin dependencies -->

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>1.14</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>mailer</artifactId>
<version>1.20</version>
</dependency>

<dependency>
Expand All @@ -231,7 +231,6 @@
<dependency>
<artifactId>workflow-step-api</artifactId>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<version>${workflow.version}</version>
<optional>true</optional>
</dependency>
<dependency>
Expand All @@ -242,7 +241,6 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>${workflow.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -257,65 +255,44 @@
</exclusions>
</dependency>

<!-- Upper bound dependencies -->

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>2.2.1</version>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>io.jenkins.configuration-as-code</groupId>
<artifactId>test-harness</artifactId>
<version>${test.configuration-as-code.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.mifmif</groupId>
<artifactId>generex</artifactId>
<version>1.0.2</version>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-scm-step</artifactId>
<version>${workflow.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${workflow.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-multibranch</artifactId>
<version>2.10</version>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-test-harness</artifactId>
<version>2.63</version>
<scope>test</scope>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.176.x</artifactId>
<version>9</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ private void writeInFile(String filename, Issue issue) throws IOException {
// olamy really weird to write an empty file especially with null
// but backward compat and unit tests assert that.....
// can't believe such stuff has been merged......
try(BufferedWriter bw =Files.newBufferedWriter( Paths.get( filename ) )) {
try(BufferedWriter bw =Files.newBufferedWriter(Paths.get(filename))) {
bw.write(issue.getKey()==null?"null":issue.getKey());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/jira/JiraJobAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public String getServerURL() {
* @param site to fetch issue data
* @throws IOException if something goes wrong fetching the Jira issue
*/
public static void setAction(@Nonnull Job<?, ?> job, @Nonnull JiraSite site) throws IOException {
public static void setAction(@Nonnull Job job, @Nonnull JiraSite site) throws IOException {
// If there is already a action set then skip
if (job.getAction(JiraJobAction.class) != null) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/jira/JiraRestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public List<Issue> getIssuesFromJqlSearch(String jqlSearch, Integer maxResults)
.searchJql(jqlSearch, maxResults, 0, null)
.get(timeout, TimeUnit.SECONDS);
return StreamSupport.stream(searchResult.getIssues().spliterator(), false).
collect( Collectors.toList() );
collect(Collectors.toList());
} catch(TimeoutException e) {
LOGGER.log(WARNING, "Jira REST client timeout from jql search error. cause: " + e.getMessage(), e);
throw e;
Expand Down
27 changes: 16 additions & 11 deletions src/main/java/hudson/plugins/jira/JiraSite.java
Original file line number Diff line number Diff line change
Expand Up @@ -838,20 +838,25 @@ public Set<String> getProjectKeys() {
* if no such was found.
*/
public static JiraSite get(Job<?, ?> p) {
JiraProjectProperty jpp = p.getProperty(JiraProjectProperty.class);
if (jpp != null) {
// Looks in global configuration for the site configured
JiraSite site = jpp.getSite();
if (site != null) {
return site;
if(p != null) {
JiraProjectProperty jpp = p.getProperty(JiraProjectProperty.class);
if (jpp != null) {
// Looks in global configuration for the site configured
JiraSite site = jpp.getSite();
if (site != null) {
return site;
}
}
}

// Check up the folder chain if a site is defined there
// This only supports one site per folder
List<JiraSite> sitesFromFolders = JiraFolderProperty.getSitesFromFolders(p.getParent());
if (sitesFromFolders.size() > 0) {
return sitesFromFolders.get(0);
if(p != null) {
// Check up the folder chain if a site is defined there
// This only supports one site per folder
List<JiraSite> sitesFromFolders = JiraFolderProperty.getSitesFromFolders( p.getParent() );
if ( sitesFromFolders.size() > 0 )
{
return sitesFromFolders.get( 0 );
}
}

// none is explicitly configured. try the default ---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,14 @@ public static class IssueSelectorStepExecution extends AbstractSynchronousNonBlo

@Override
protected Set<String> run() {
return getOptionalJiraSite()
return Optional.ofNullable(JiraSite.get(run.getParent()))
.map(site -> step.getIssueSelector().findIssueIds(run, site, listener))
.orElseGet(() -> {
listener.getLogger().println(Messages.NoJiraSite());
run.setResult(Result.FAILURE);
return new HashSet<>();
});
}

Optional<JiraSite> getOptionalJiraSite() {
return Optional.ofNullable(JiraSite.get(run.getParent()));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void simple_get_with_proxy()
ProxyTestHandler testHandler = new ProxyTestHandler();
prepare( testHandler );

Jenkins.getInstance().proxy = new ProxyConfiguration( "localhost", connector.getLocalPort(), "foo", "bar" );
Jenkins.get().proxy = new ProxyConfiguration( "localhost", connector.getLocalPort(), "foo", "bar" );

ApacheAsyncHttpClient httpClient =
new ApacheAsyncHttpClient( null, buildApplicationProperties(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.protocol.HttpContext;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;

import com.atlassian.sal.api.executor.ThreadLocalContextManager;
Expand All @@ -26,7 +25,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.Future;

@RunWith(MockitoJUnitRunner.class)
@RunWith( MockitoJUnitRunner.class)
public class SettableFuturePromiseHttpPromiseAsyncClientTest
{

Expand Down Expand Up @@ -59,7 +58,7 @@ public void ensureCloseHttpclientOnCompletion() throws IOException
@Override
public Future<HttpResponse> answer(InvocationOnMock invocation) throws Throwable
{
invocation.getArgumentAt(2, FutureCallback.class).completed(response);
invocation.getArgument(2, FutureCallback.class).completed(response);
return mock(Future.class);
}
});
Expand All @@ -77,7 +76,7 @@ public void ensureCloseHttpclientOnFailure() throws IOException
@Override
public Future<HttpResponse> answer(InvocationOnMock invocation) throws Throwable
{
invocation.getArgumentAt(2, FutureCallback.class).failed(null);
invocation.getArgument(2, FutureCallback.class).failed(null);
return mock(Future.class);
}
});
Expand All @@ -95,7 +94,7 @@ public void ensureCloseHttpclientOnCancellation() throws IOException
@Override
public Future<HttpResponse> answer(InvocationOnMock invocation) throws Throwable
{
invocation.getArgumentAt(2, FutureCallback.class).cancelled();
invocation.getArgument(2, FutureCallback.class).cancelled();
return mock(Future.class);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class BuildListenerResultMethodMock implements Answer<Void> {

@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
this.result = invocation.getArgumentAt(0, Result.class);
this.result = invocation.getArgument(0, Result.class);
return null;
}

Expand Down
Loading

0 comments on commit 82fccea

Please sign in to comment.