Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure NONE only disables alignment allowing version calculation to p… #429

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ private void processPropertiesForBuildCache(File rootProject) throws IOException
}
}

private void writeGmeMarkerFile(Configuration configuration, File rootGradle) throws IOException, ManipulationException {
private void writeGmeMarkerFile(Configuration configuration, File rootGradle) throws IOException {
File rootDir = getProject().getRootDir();
File gmeGradle = new File(rootDir, GME);
Files.copy(getClass().getResourceAsStream('/' + GME), gmeGradle.toPath(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jboss.gm.analyzer.alignment;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -20,10 +21,10 @@
import static org.commonjava.maven.ext.core.state.DependencyState.DependencyPrecedence.NONE;

/**
* An implementation of {@link AlignmentService} that uses the Dependency Analyzer service in order to get the proper
* aligned versions of dependencies (as well as the version of the project itself).
*
* The heavy lifting is done by {@link org.commonjava.maven.ext.io.rest.DefaultTranslator}.
* An implementation of {@link AlignmentService} that uses the Dependency Analyzer service
* in order to get the proper aligned versions of dependencies (as well as the version
* of the project itself). The heavy lifting is done by
* {@link org.commonjava.maven.ext.io.rest.DefaultTranslator}.
*/
public class DAAlignmentService implements AlignmentService {

Expand All @@ -33,15 +34,16 @@ public class DAAlignmentService implements AlignmentService {

private final DependencyState.DependencyPrecedence dependencySource;

private final String endpointUrl;

/**
* Constructs a new Dependency Analyzer service with the given configuration.
*
* @param configuration holds all configuration values for the plugins
*/
public DAAlignmentService(Configuration configuration) {
dependencySource = configuration.dependencyConfiguration();

final String endpointUrl = configuration.daEndpoint();
endpointUrl = configuration.daEndpoint();

logger.debug("endpointUrl = {}, dependencySource = {}", endpointUrl, dependencySource);

Expand All @@ -62,26 +64,29 @@ public DAAlignmentService(Configuration configuration) {
*/
@Override
public Response align(AlignmentService.Request request) throws RestException {
if (dependencySource == NONE) {
logger.warn("No dependencySource configured ; unable to call endpoint");
if (isEmpty(endpointUrl)) {
logger.warn("No restUrl configured ; unable to call endpoint");
return new Response(Collections.emptyMap());
}
final LogLevel originalLevel = FilteringCustomLogger.getContext().getLevel();
final List<ProjectVersionRef> vParams = request.getDependencies();

logger.info("Passing {} GAVs into the REST client api {}", vParams.size(), vParams);

final Map<ProjectVersionRef, String> vMap;
try {
if (originalLevel == LogLevel.LIFECYCLE) {
FilteringCustomLogger.getContext().setLevel(LogLevel.INFO);

if (dependencySource == NONE) {
logger.warn("No dependencySource configured ; unable pass GAVs into endpoint");
vMap = new HashMap<>();
} else {
logger.info("Passing {} GAVs into the REST client api {}", vParams.size(), vParams);
try {
if (originalLevel == LogLevel.LIFECYCLE) {
FilteringCustomLogger.getContext().setLevel(LogLevel.INFO);
}
vMap = restEndpoint.lookupVersions(vParams);
} finally {
FilteringCustomLogger.getContext().setLevel(originalLevel);
}
vMap = restEndpoint.lookupVersions(vParams);
} finally {
FilteringCustomLogger.getContext().setLevel(originalLevel);
logger.info("REST Client returned: {}", vMap);
}
logger.info("REST Client returned: {}", vMap);

final Response response = new Response(vMap);

final List<ProjectVersionRef> pParams = request.getProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,28 @@
import org.aeonbits.owner.ConfigFactory;
import org.apache.commons.io.FileUtils;
import org.commonjava.maven.atlas.ident.ref.ProjectVersionRef;
import org.commonjava.maven.ext.core.state.DependencyState;
import org.commonjava.maven.ext.io.rest.DefaultTranslator;
import org.commonjava.maven.ext.io.rest.RestException;
import org.gradle.api.Project;
import org.gradle.api.logging.LogLevel;
import org.gradle.testfixtures.ProjectBuilder;
import org.jboss.gm.common.Configuration;
import org.jboss.gm.common.rules.LoggingRule;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.contrib.java.lang.system.SystemOutRule;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;

import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.github.tomakehurst.wiremock.junit.WireMockClassRule;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
Expand All @@ -33,19 +42,40 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.jboss.gm.common.versioning.ProjectVersionFactory.withGAV;

@RunWith(Parameterized.class)
public class DAAlignmentServiceWiremockTest {

private static final int PORT = 8089;

@Rule
public final TestRule restoreSystemProperties = new RestoreSystemProperties();

@ClassRule
public static WireMockClassRule wireMockRule = new WireMockClassRule(PORT);

@Rule
public WireMockRule wireMockRule = new WireMockRule(PORT);
public WireMockClassRule instanceRule = wireMockRule;

@Rule
public TemporaryFolder tempDir = new TemporaryFolder();

@Rule
public SystemOutRule systemOutRule = new SystemOutRule().enableLog();//.muteForSuccessfulTests();

@Rule
public final LoggingRule loggingRule = new LoggingRule(LogLevel.INFO);

@Parameters
public static Object[] data() {
return new Object[] {
DependencyState.DependencyPrecedence.REST,
DependencyState.DependencyPrecedence.NONE,
};
}

@Parameter
public DependencyState.DependencyPrecedence precedence;

@Before
public void setup() throws IOException, URISyntaxException {
stubFor(post(urlEqualTo("/da/rest/v-1/" + DefaultTranslator.Endpoint.LOOKUP_GAVS))
Expand All @@ -64,6 +94,7 @@ public void setup() throws IOException, URISyntaxException {
public void alignmentWorksAsExpected()
throws RestException, IOException {
System.setProperty(Configuration.DA, String.format("http://localhost:%d/da/rest/v-1", PORT));
System.setProperty("dependencySource", precedence.toString());
final Configuration configuration = ConfigFactory.create(Configuration.class);

final DAAlignmentService sut = new DAAlignmentService(configuration);
Expand All @@ -84,10 +115,15 @@ public void alignmentWorksAsExpected()
project.setGroup("org.acme");

assertThat(response).isNotNull().satisfies(r -> {
assertThat(r.getNewProjectVersion()).isNull();
assertThat(r.getAlignedVersionOfGav(project, hibernateGav)).isEqualTo("5.3.7.Final-redhat-00001");
assertThat(r.getAlignedVersionOfGav(project, undertowGav)).isEqualTo("2.0.15.Final-redhat-00001");
assertThat(r.getAlignedVersionOfGav(project, mockitoGav)).isNull();
assertThat(r.getNewProjectVersion()).isEqualTo("1.0.0.redhat-00002");
if (precedence != DependencyState.DependencyPrecedence.NONE) {
assertThat(r.getAlignedVersionOfGav(project, hibernateGav)).isEqualTo("5.3.7.Final-redhat-00001");
assertThat(r.getAlignedVersionOfGav(project, undertowGav)).isEqualTo("2.0.15.Final-redhat-00001");
assertThat(r.getAlignedVersionOfGav(project, mockitoGav)).isNull();
} else {
assertThat(systemOutRule.getLog()).contains(
"No dependencySource configured ; unable pass GAVs into endpoint");
}
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"latestVersion": null,
"latestVersion": "1.0.0.redhat-00002",
"version": "1.0.0",
"groupId": "org.acme",
"artifactId": "dummy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public static DokkaVersion parseVersion(String version)
/**
* Removes plugins from a target build file.
* <p>
* </p>
* Will automatically examine build.gradle, settings.gradle, build.gradle.kts, settings.gradle.kts
*
* @param logger the current logger in use
Expand Down