Skip to content

Commit

Permalink
Revert "devonfw#1454 adjusted retrieval of template set xml download …
Browse files Browse the repository at this point in the history
…links"

This reverts commit 925de2c.
  • Loading branch information
jan-vcapgemini committed Mar 1, 2023
1 parent 925de2c commit 7e43176
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.devonfw.cobigen.retriever;

import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -28,28 +27,24 @@ public class ArtifactRetriever {
private static final Logger LOG = LoggerFactory.getLogger(ArtifactRetriever.class);

/**
* Retrieves a list of maven artifact download URLs by given groupIds and maven settings file
* Retrieves a list of maven artifact download URLs
*
* @param groupIdsList grouIds for template-sets
* @param mavenSettingsFile Path to maven's settings.xml
* @param mavenSettings string of maven's settings.xml
* @return list of maven artifact download URLs
* @throws IOException if an error occurred while reading the settings file
*
*/
protected static List<URL> retrieveTemplateSetXmlDownloadLinks(List<String> groupIdsList, Path mavenSettingsFile)
throws IOException {

String mavenSettingsString = new String(Files.readAllBytes(mavenSettingsFile));
protected static List<URL> retrieveTemplateSetXmlDownloadLinks(List<String> groupIdsList, String mavenSettings) {

List<URL> downloadLinks = new ArrayList<>();

MavenSettingsModel model = MavenSettings.generateMavenSettingsModel(mavenSettingsString);
MavenSettingsModel model = MavenSettings.generateMavenSettingsModel(mavenSettings);

MavenSettingsProxyModel activeProxy = MavenSettings
.determineActiveProxy(MavenSettings.generateMavenSettingsModel(mavenSettingsString));
.determineActiveProxy(MavenSettings.generateMavenSettingsModel(mavenSettings));

List<MavenSettingsRepositoryModel> allActiveRepositories = MavenSettings
.retrieveRepositoriesFromMavenSettings(mavenSettingsString);
.retrieveRepositoriesFromMavenSettings(mavenSettings);

List<MavenSettingsRepositoryModel> repositoriesWhichAreUsingTheProxy = MavenProxy
.obtainRepositories(allActiveRepositories, activeProxy, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
import java.util.Arrays;
import java.util.List;

import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;

import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;
import com.devonfw.cobigen.retriever.settings.MavenSettings;
import com.devonfw.cobigen.retriever.settings.to.model.MavenSettingsModel;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.junit.WireMockRule;

Expand All @@ -33,12 +36,47 @@ public class ArtifactRetrieverTest {
*/
private final static String testdataRoot = "src/test/resources/testdata/unittest/ArtifactRetrieverTest";

/**
* {@link MavenSettingsModel} without a proxy
*/
private static MavenSettingsModel modelNonProxy;

/**
* {@link MavenSettingsModel} with a proxy
*/
private static MavenSettingsModel modelProxy;

/**
* Maven settings string without a proxy
*/
private static String mavenSettingsNonProxy;

/**
* Maven settings string without a proxy
*/
private static String mavenSettingsProxy;

/**
* WireMock rule to initialize
*/
@Rule
public WireMockRule wireMockRule = new WireMockRule(options().disableRequestJournal());

/**
* Used to initialize data needed for the tests
*
* @throws Exception if reading the maven settings fails
*/
@BeforeClass
public static void setUpClass() throws Exception {

mavenSettingsNonProxy = new String(Files.readAllBytes(Paths.get(testdataRoot).resolve("settingsNonProxy.xml")));
mavenSettingsProxy = new String(Files.readAllBytes(Paths.get(testdataRoot).resolve("settingsProxy.xml")));

modelNonProxy = MavenSettings.generateMavenSettingsModel(mavenSettingsNonProxy);
modelProxy = MavenSettings.generateMavenSettingsModel(mavenSettingsProxy);
}

/**
* Tests a retrieval of download URLs using using a settings.xml and basic authentication
*
Expand All @@ -53,9 +91,7 @@ public void testRetrieveTemplateSetXmlDownloadLinksWithBasicAuthentication() thr

List<String> groupIds = Arrays.asList("com.devonfw.cobigen.templates");

List<URL> downloadUrls = ArtifactRetriever.retrieveTemplateSetXmlDownloadLinks(groupIds,
Paths.get(testdataRoot).resolve("settingsNonProxy.xml"));

List<URL> downloadUrls = ArtifactRetriever.retrieveTemplateSetXmlDownloadLinks(groupIds, mavenSettingsNonProxy);
assertThat(downloadUrls).contains(new URL(
"http://localhost:8080/artifactory/api/storage/libs-release-local/com/devonfw/cobigen/templates/crud-java-server-app/2021.08.001/crud-java-server-app-2021.08.001-template-set.xml"));
}
Expand All @@ -73,9 +109,7 @@ public void testRetrieveTemplateSetXmlDownloadLinksWithoutProxy() throws IOExcep

List<String> groupIds = Arrays.asList("com.devonfw.cobigen.templates");

List<URL> downloadUrls = ArtifactRetriever.retrieveTemplateSetXmlDownloadLinks(groupIds,
Paths.get(testdataRoot).resolve("settingsNonProxy.xml"));

List<URL> downloadUrls = ArtifactRetriever.retrieveTemplateSetXmlDownloadLinks(groupIds, mavenSettingsNonProxy);
assertThat(downloadUrls).contains(new URL(
"http://localhost:8080/artifactory/api/storage/libs-release-local/com/devonfw/cobigen/templates/crud-java-server-app/2021.08.001/crud-java-server-app-2021.08.001-template-set.xml"));
}
Expand All @@ -97,9 +131,7 @@ public void testRetrieveTemplateSetXmlDownloadLinksWithProxy() throws IOExceptio

List<String> groupIds = Arrays.asList("com.devonfw.cobigen.templates");

List<URL> downloadUrls = ArtifactRetriever.retrieveTemplateSetXmlDownloadLinks(groupIds,
Paths.get(testdataRoot).resolve("settingsProxy.xml"));

List<URL> downloadUrls = ArtifactRetriever.retrieveTemplateSetXmlDownloadLinks(groupIds, mavenSettingsProxy);
assertThat(downloadUrls).contains(new URL(
"http://localhost:8080/artifactory/api/storage/libs-release-local/com/devonfw/cobigen/templates/crud-java-server-app/2021.08.001/crud-java-server-app-2021.08.001-template-set.xml"));
}
Expand Down

0 comments on commit 7e43176

Please sign in to comment.