Skip to content

Commit

Permalink
devonfw#1517 implemented requested changes
Browse files Browse the repository at this point in the history
removed .classpath and .project files
moved timeout values to constants
converted SEARCH_RESPONSES from Object to AbstractSearchResponse
moved regex version number detection to constant
  • Loading branch information
jan-vcapgemini committed Nov 9, 2022
1 parent 0540319 commit 87504b1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 72 deletions.
33 changes: 0 additions & 33 deletions cobigen/core-artifact-retriever/.classpath

This file was deleted.

23 changes: 0 additions & 23 deletions cobigen/core-artifact-retriever/.project

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,26 @@
*/
public abstract class AbstractSearchResponse {

/** The HTTP request write timeout */
private static final int WRITE_TIMEOUT = 30;

/** The HTTP request call timeout */
private static final int CALL_TIMEOUT = 30;

/** The HTTP request read timeout */
private static final int READ_TIMEOUT = 30;

/** The HTTP request connect timeout */
private static final int CONNECT_TIMEOUT = 10;

/** Logger instance. */
@JsonIgnore
private static final Logger LOG = LoggerFactory.getLogger(AbstractSearchResponse.class);

/**
* Getter for {@link MavenSearchRepositoryType} needs to be added to each implementing class to ensure that the
* repository type name is being used
*
* @return the {@link MavenSearchRepositoryType} type
*/
public abstract MavenSearchRepositoryType getRepositoryType();
Expand Down Expand Up @@ -114,10 +129,10 @@ public static String retrieveJsonResponseWithAuthentication(String targetLink,

OkHttpClient.Builder builder = new OkHttpClient.Builder();

builder.connectTimeout(10, TimeUnit.SECONDS);
builder.readTimeout(30, TimeUnit.SECONDS);
builder.callTimeout(30, TimeUnit.SECONDS);
builder.writeTimeout(30, TimeUnit.SECONDS);
builder.connectTimeout(CONNECT_TIMEOUT, TimeUnit.SECONDS);
builder.readTimeout(READ_TIMEOUT, TimeUnit.SECONDS);
builder.callTimeout(CALL_TIMEOUT, TimeUnit.SECONDS);
builder.writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS);
builder.retryOnConnectionFailure(true);

if (serverCredentials.getProxyAddress() != null && serverCredentials.getProxyPort() != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class SearchResponseFactory {
/**
* List of available {@link AbstractSearchResponse} implementations (add new search REST API responses here)
*/
private static final List<Object> SEARCH_RESPONSES = Lists.newArrayList(new MavenSearchResponse(),
private static final List<AbstractSearchResponse> SEARCH_RESPONSES = Lists.newArrayList(new MavenSearchResponse(),
new JfrogSearchResponse(), new Nexus2SearchResponse(), new Nexus3SearchResponse());

/**
Expand Down Expand Up @@ -63,23 +63,20 @@ public static List<URL> searchArtifactDownloadLinks(ServerCredentials serverCred

LOG.debug("Starting search for REST APIs with repository URL: {} and groupId: {} ...", baseUrl, groupId);

for (Object searchResponse : SEARCH_RESPONSES) {
searchRepositoryType = ((AbstractSearchResponse) searchResponse).getRepositoryType();
searchRepositoryTargetLink = ((AbstractSearchResponse) searchResponse).retrieveRestSearchApiTargetLink(baseUrl,
groupId);
for (AbstractSearchResponse searchResponse : SEARCH_RESPONSES) {
searchRepositoryType = searchResponse.getRepositoryType();
searchRepositoryTargetLink = searchResponse.retrieveRestSearchApiTargetLink(baseUrl, groupId);
try {
LOG.debug("Trying to get a response from {} ...", searchRepositoryType);

String jsonResponse = ((AbstractSearchResponse) searchResponse).retrieveJsonResponse(serverCredentials,
groupId);
String jsonResponse = searchResponse.retrieveJsonResponse(serverCredentials, groupId);

if (jsonResponse == null || jsonResponse.isEmpty()) {
LOG.debug("The json response was empty.");
return downloadLinks;
}

AbstractSearchResponse response = (AbstractSearchResponse) mapper.readValue(jsonResponse,
searchResponse.getClass());
AbstractSearchResponse response = mapper.readValue(jsonResponse, searchResponse.getClass());

LOG.debug("The search REST API was able to get a response from {}", searchRepositoryType);

Expand All @@ -92,8 +89,6 @@ public static List<URL> searchArtifactDownloadLinks(ServerCredentials serverCred
return new ArrayList<>();
}

return downloadLinks;

} catch (RestSearchResponseException e) {
LOG.debug("The search REST API was unable to get a response from {}", searchRepositoryType);
if (SEARCH_RESPONSES.indexOf(searchResponse) != (SEARCH_RESPONSES.size() - 1)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
*/
public class TemplateSetArtifactReader {

/** Regular expression to detect the version number inside the file name of the template-set.xml properly */
private static final String VERSION_NUMBER_REGEX = "[-][\\d]*[.][\\d]*[.][\\d]*[-]";

/** Logger instance. */
private static final Logger LOG = LoggerFactory.getLogger(TemplateSetArtifactReader.class);

Expand Down Expand Up @@ -84,7 +87,7 @@ private TemplateSetConfiguration generateMavenTemplateSetConfiguration(Path temp
*/
private String parseVersionFromTemplateSetFile(Path templateSetFile) {

Pattern pattern = Pattern.compile("[-][\\d]*[.][\\d]*[.][\\d]*[-]");
Pattern pattern = Pattern.compile(VERSION_NUMBER_REGEX);
Matcher matcher = pattern.matcher(templateSetFile.getFileName().toString());
String templateSetversion = "";
if (matcher.find()) {
Expand Down

0 comments on commit 87504b1

Please sign in to comment.