Skip to content

Commit

Permalink
upgrade gitlab4j-api@5.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
akphi committed Jul 22, 2022
1 parent 265d10f commit 6ed1e23
Show file tree
Hide file tree
Showing 19 changed files with 152 additions and 83 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![FINOS - Incubating](https://cdn.jsdelivr.net/gh/finos/contrib-toolbox@master/images/badge-incubating.svg)](https://finosfoundation.atlassian.net/wiki/display/FINOS/Incubating)
[![Maven Central](https://img.shields.io/maven-central/v/org.finos.legend.sdlc/legend-sdlc.svg?maxAge=2592000)](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22legend-sdlc)
[![Maven Central](https://img.shields.io/maven-central/v/org.finos.legend.sdlc/legend-sdlc.svg)](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22legend-sdlc)
![Build CI](https://github.com/finos/legend-sdlc/workflows/Build%20CI/badge.svg)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=legend-sdlc&metric=security_rating&token=69394360757d5e1356312ddfee658a6b205e2c97)](https://sonarcloud.io/dashboard?id=legend-sdlc)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=legend-sdlc&metric=bugs&token=69394360757d5e1356312ddfee658a6b205e2c97)](https://sonarcloud.io/dashboard?id=legend-sdlc)
Expand Down
52 changes: 52 additions & 0 deletions legend-sdlc-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-lifecycle</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-jersey</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-healthchecks</artifactId>
Expand All @@ -242,6 +246,54 @@
<artifactId>javax.ws.rs-api</artifactId>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>

<!--
NOTE: we must include this runtime dependency as it is required by
gitlab4j-api >=14.16.0, in particular, gitlab4j-api starts to use
JacksonJaxbJsonProvider (this comes from Jersey >= 2.26); that's a
breaking change from Jersey. If we want to use Jersey 2.26 though
we would need to also upgrade to DropWizard > 2
See https://github.com/dropwizard/dropwizard/issues/2148
For this reason, we will only add this as a runtime dependency
And we would need to address the JacksonFeature class (part of
this dependency) being automatically picked up and configured to
Jersey servers as part of an auto-discoverable feature
See https://eclipse-ee4j.github.io/jersey.github.io/documentation/latest/deployment.html#deployment.autodiscoverable
NOTE: this workaround is sensible because the jackson features configuration
is needed by gitlab4j-api Gitlab client will still continue to be used by this
client, while we only turn these off for our clients/servers specifically
-->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.35</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>jakarta.ws.rs</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

package org.finos.legend.sdlc.server;

import io.dropwizard.setup.Environment;
import org.eclipse.collections.api.factory.Maps;
import org.finos.legend.sdlc.server.config.LegendSDLCServerConfiguration;
import org.glassfish.jersey.CommonProperties;

public class LegendSDLCServer extends BaseLegendSDLCServer<LegendSDLCServerConfiguration>
{
Expand All @@ -23,6 +26,16 @@ public LegendSDLCServer(String mode)
super(mode);
}

@Override
public void run(LegendSDLCServerConfiguration configuration, Environment environment)
{
super.run(configuration, environment);
// Ensure JacksonJaxbJsonProvider coming from org.glassfish.jersey.media:jersey-media-json-jackson
// is not automatically picked up by the Jersey server via AutoDiscoverable mechanism
// See https://eclipse-ee4j.github.io/jersey.github.io/documentation/latest/deployment.html#deployment.autodiscoverable
environment.jersey().getResourceConfig().setProperties(Maps.mutable.of(CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true));
}

@Override
protected ServerPlatformInfo newServerPlatformInfo()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public final class GitLabProjectId
private static final char DELIMITER = '-';

private final String prefix;
private final int gitLabId;
private final long gitLabId;

private GitLabProjectId(String prefix, int gitLabId)
private GitLabProjectId(String prefix, long gitLabId)
{
this.prefix = prefix;
this.gitLabId = gitLabId;
}

public int getGitLabId()
public long getGitLabId()
{
return this.gitLabId;
}
Expand All @@ -54,7 +54,7 @@ public boolean equals(Object other)
@Override
public int hashCode()
{
return Objects.hashCode(this.prefix) ^ this.gitLabId;
return Objects.hashCode(this.prefix) ^ Objects.hashCode(this.gitLabId);
}

@Override
Expand All @@ -63,7 +63,7 @@ public String toString()
return getProjectIdString(this.prefix, this.gitLabId);
}

public static GitLabProjectId newProjectId(String prefix, int gitLabId)
public static GitLabProjectId newProjectId(String prefix, long gitLabId)
{
return new GitLabProjectId(prefix, gitLabId);
}
Expand All @@ -84,19 +84,19 @@ public static GitLabProjectId parseProjectId(String projectId)
return newProjectId(separatorIndex == -1 ? null : projectId.substring(0, separatorIndex), parseGitLabId(projectId, separatorIndex));
}

private static int parseGitLabId(String projectId, int separatorIndex)
private static long parseGitLabId(String projectId, int separatorIndex)
{
try
{
return Integer.parseInt(projectId.substring(separatorIndex + 1));
return Long.parseLong(projectId.substring(separatorIndex + 1));
}
catch (NumberFormatException e)
{
throw new IllegalArgumentException("Invalid project id: " + projectId);
}
}

private static String getProjectIdString(String prefix, int gitLabId)
private static String getProjectIdString(String prefix, long gitLabId)
{
return (prefix != null ? (prefix + DELIMITER) : "") + gitLabId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

package org.finos.legend.sdlc.server.gitlab.api;

import org.eclipse.collections.api.map.primitive.IntObjectMap;
import org.eclipse.collections.api.map.primitive.MutableIntObjectMap;
import org.eclipse.collections.impl.factory.primitive.IntObjectMaps;
import org.eclipse.collections.api.map.primitive.LongObjectMap;
import org.eclipse.collections.api.map.primitive.MutableLongObjectMap;
import org.eclipse.collections.impl.factory.primitive.LongObjectMaps;
import org.finos.legend.sdlc.server.gitlab.GitLabConfiguration;
import org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext;
import org.finos.legend.sdlc.server.gitlab.tools.PagerTools;
Expand All @@ -36,44 +36,44 @@ protected AbstractGitlabWorkflowApi(GitLabConfiguration gitLabConfiguration, Git
super(gitLabConfiguration, userContext, backgroundTaskProcessor);
}

protected Pipeline getMergeRequestPipeline(int gitLabProjectId, int mergeRequestId, int pipelineId) throws GitLabApiException
protected Pipeline getMergeRequestPipeline(long gitLabProjectId, long mergeRequestId, long pipelineId) throws GitLabApiException
{
return PagerTools.stream(getMergeRequestPipelines(gitLabProjectId, mergeRequestId))
.filter(p -> (p.getId() != null) && (p.getId() == pipelineId))
.findAny()
.orElse(null);
}

protected Pager<Pipeline> getMergeRequestPipelines(int gitLabProjectId, int mergeRequestId) throws GitLabApiException
protected Pager<Pipeline> getMergeRequestPipelines(long gitLabProjectId, long mergeRequestId) throws GitLabApiException
{
MergeRequestApi mergeRequestApi = getGitLabApi().getMergeRequestApi();
return withRetries(() -> mergeRequestApi.getMergeRequestPipelines(gitLabProjectId, mergeRequestId, ITEMS_PER_PAGE));
}

protected Pipeline getRefPipeline(int gitLabProjectId, String ref, int pipelineId) throws GitLabApiException
protected Pipeline getRefPipeline(long gitLabProjectId, String ref, long pipelineId) throws GitLabApiException
{
PipelineApi pipelineApi = getGitLabApi().getPipelineApi();
Pipeline pipeline = withRetries(() -> pipelineApi.getPipeline(gitLabProjectId, pipelineId));
return ((pipeline != null) && ref.equals(pipeline.getRef())) ? pipeline : null;
}

protected Pager<Pipeline> getRefPipelines(int gitLabProjectId, String ref) throws GitLabApiException
protected Pager<Pipeline> getRefPipelines(long gitLabProjectId, String ref) throws GitLabApiException
{
PipelineApi pipelineApi = getGitLabApi().getPipelineApi();
return withRetries(() -> pipelineApi.getPipelines(gitLabProjectId, null, null, ref, false, null, null, null, null, ITEMS_PER_PAGE));
}

protected IntObjectMap<Pipeline> indexPipelinesById(Pager<Pipeline> pager, boolean ignoreNullIds, boolean ignoreIdConflicts)
protected LongObjectMap<Pipeline> indexPipelinesById(Pager<Pipeline> pager, boolean ignoreNullIds, boolean ignoreIdConflicts)
{
return indexPipelinesById(PagerTools.stream(pager), ignoreNullIds, ignoreIdConflicts);
}

protected IntObjectMap<Pipeline> indexPipelinesById(Stream<Pipeline> pipelines, boolean ignoreNullIds, boolean ignoreIdConflicts)
protected LongObjectMap<Pipeline> indexPipelinesById(Stream<Pipeline> pipelines, boolean ignoreNullIds, boolean ignoreIdConflicts)
{
MutableIntObjectMap<Pipeline> map = IntObjectMaps.mutable.empty();
MutableLongObjectMap<Pipeline> map = LongObjectMaps.mutable.empty();
pipelines.forEach(p ->
{
Integer id = p.getId();
Long id = p.getId();
if (id == null)
{
if (ignoreNullIds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,22 +492,22 @@ protected static Date toDateIfNotNull(Instant instant)
return (instant == null) ? null : Date.from(instant);
}

protected static Integer parseIntegerIdIfNotNull(String id)
protected static Long parseNumericIdIfNotNull(String id)
{
return parseIntegerIdIfNotNull(id, null);
return parseNumericIdIfNotNull(id, null);
}

protected static Integer parseIntegerIdIfNotNull(String id, Status errorStatus)
protected static Long parseNumericIdIfNotNull(String id, Status errorStatus)
{
return (id == null) ? null : parseIntegerId(id, errorStatus);
return (id == null) ? null : parseNumericId(id, errorStatus);
}

protected static int parseIntegerId(String id)
protected static long parseNumericId(String id)
{
return parseIntegerId(id, null);
return parseNumericId(id, null);
}

protected static int parseIntegerId(String id, Status errorStatus)
protected static long parseNumericId(String id, Status errorStatus)
{
try
{
Expand Down Expand Up @@ -764,7 +764,7 @@ protected MergeRequest getReviewMergeRequest(MergeRequestApi mergeRequestApi, Gi

protected MergeRequest getReviewMergeRequest(MergeRequestApi mergeRequestApi, GitLabProjectId projectId, String reviewId, boolean includeRebaseInProgress)
{
int mergeRequestId = parseIntegerId(reviewId);
long mergeRequestId = parseNumericId(reviewId);
MergeRequest mergeRequest;
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private GitLabBuildAccessContext(String projectId)
@Override
public Build getBuild(String buildId)
{
int pipelineId = parseIntegerIdIfNotNull(buildId);
long pipelineId = parseNumericIdIfNotNull(buildId);
Pipeline pipeline;
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Issue getIssue(String projectId, String issueId)
try
{
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
org.gitlab4j.api.models.Issue issue = withRetries(() -> getGitLabApi().getIssuesApi().getIssue(gitLabProjectId.getGitLabId(), parseIntegerIdIfNotNull(issueId)));
org.gitlab4j.api.models.Issue issue = withRetries(() -> getGitLabApi().getIssuesApi().getIssue(gitLabProjectId.getGitLabId(), parseNumericIdIfNotNull(issueId)));
return fromGitLabIssue(issue);
}
catch (Exception e)
Expand All @@ -62,7 +62,7 @@ public List<Issue> getIssues(String projectId)
try
{
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
Pager<org.gitlab4j.api.models.Issue> pager = withRetries(() -> getGitLabApi().getIssuesApi().getIssues((Integer) gitLabProjectId.getGitLabId(), ITEMS_PER_PAGE));
Pager<org.gitlab4j.api.models.Issue> pager = withRetries(() -> getGitLabApi().getIssuesApi().getIssues(gitLabProjectId.getGitLabId(), ITEMS_PER_PAGE));
return PagerTools.stream(pager).map(GitLabIssueApi::fromGitLabIssue).collect(PagerTools.listCollector(pager));
}
catch (Exception e)
Expand Down Expand Up @@ -103,7 +103,7 @@ public void deleteIssue(String projectId, String issueId)
try
{
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
withRetries(() -> getGitLabApi().getIssuesApi().deleteIssue(gitLabProjectId.getGitLabId(), parseIntegerIdIfNotNull(issueId)));
withRetries(() -> getGitLabApi().getIssuesApi().deleteIssue(gitLabProjectId.getGitLabId(), parseNumericIdIfNotNull(issueId)));
}
catch (LegendSDLCServerException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public ImportReport importProject(String id, String groupId, String artifactId)
GitLabProjectId projectId;
if (id.chars().allMatch(Character::isDigit))
{
projectId = GitLabProjectId.newProjectId(this.getGitLabConfiguration().getProjectIdPrefix(), Integer.parseInt(id));
projectId = GitLabProjectId.newProjectId(this.getGitLabConfiguration().getProjectIdPrefix(), Long.parseLong(id));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.set.primitive.MutableIntSet;
import org.eclipse.collections.impl.factory.primitive.IntSets;
import org.eclipse.collections.api.set.primitive.MutableLongSet;
import org.eclipse.collections.impl.factory.primitive.LongSets;
import org.eclipse.collections.impl.utility.Iterate;
import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration;
import org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency;
Expand Down Expand Up @@ -55,6 +55,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.ws.rs.core.Response.Status;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -65,8 +67,6 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.inject.Inject;
import javax.ws.rs.core.Response.Status;

public class GitLabReviewApi extends GitLabApiWithFileAccess implements ReviewApi
{
Expand Down Expand Up @@ -104,7 +104,7 @@ else if (revisionIds instanceof Set)
// TODO: we might want to do this differently since the number of revision IDs can be huge
// we can have a threshold for which we change our strategy to to make a single call for
// merge requests by the other criteria and then filter by revisionIds.
MutableIntSet mergeRequestIds = IntSets.mutable.empty();
MutableLongSet mergeRequestIds = LongSets.mutable.empty();
CommitsApi commitsApi = getGitLabApi().getCommitsApi();
// Combine all MRs associated with each revision
mergeRequestStream = revisionIdSet.stream().flatMap(revisionId ->
Expand Down Expand Up @@ -915,12 +915,12 @@ private static Review fromGitLabMergeRequest(String projectId, MergeRequest merg
return newReview(mergeRequest.getIid(), projectId, workspaceInfo, mergeRequest.getTitle(), mergeRequest.getDescription(), mergeRequest.getCreatedAt(), mergeRequest.getUpdatedAt(), mergeRequest.getClosedAt(), mergeRequest.getMergedAt(), mergeRequest.getState(), mergeRequest.getAuthor(), mergeRequest.getMergeCommitSha(), mergeRequest.getWebUrl(), mergeRequest.getLabels());
}

private static Review newReview(Integer reviewId, String projectId, WorkspaceInfo workspaceInfo, String title, String description, Date createdAt, Date lastUpdatedAt, Date closedAt, Date committedAt, String reviewState, AbstractUser<?> author, String commitRevisionId, String webURL, List<String> labels)
private static Review newReview(Long reviewId, String projectId, WorkspaceInfo workspaceInfo, String title, String description, Date createdAt, Date lastUpdatedAt, Date closedAt, Date committedAt, String reviewState, AbstractUser<?> author, String commitRevisionId, String webURL, List<String> labels)
{
return newReview(reviewId, projectId, workspaceInfo.getWorkspaceId(), workspaceInfo.getWorkspaceType(), title, description, createdAt, lastUpdatedAt, closedAt, committedAt, reviewState, author, commitRevisionId, webURL, labels);
}

private static Review newReview(Integer reviewId, String projectId, String workspaceId, WorkspaceType workspaceType, String title, String description, Date createdAt, Date lastUpdatedAt, Date closedAt, Date committedAt, String reviewState, AbstractUser<?> author, String commitRevisionId, String webURL, List<String> labels)
private static Review newReview(Long reviewId, String projectId, String workspaceId, WorkspaceType workspaceType, String title, String description, Date createdAt, Date lastUpdatedAt, Date closedAt, Date committedAt, String reviewState, AbstractUser<?> author, String commitRevisionId, String webURL, List<String> labels)
{
return newReview(toStringIfNotNull(reviewId), projectId, workspaceId, workspaceType, title, description, toInstantIfNotNull(createdAt), toInstantIfNotNull(lastUpdatedAt), toInstantIfNotNull(closedAt), toInstantIfNotNull(committedAt), getReviewState(reviewState), fromGitLabAbstractUser(author), commitRevisionId, webURL, labels);
}
Expand Down
Loading

0 comments on commit 6ed1e23

Please sign in to comment.