Skip to content

Commit

Permalink
CI - Prefer repo from settings over project (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi committed Dec 11, 2023
1 parent 5b4fdef commit 7f4be71
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;

import static org.jfrog.gradle.plugin.artifactory.Constant.*;
import static org.jfrog.gradle.plugin.artifactory.TestConsts.MIN_GRADLE_VERSION_CONFIG_CACHE;
import static org.jfrog.gradle.plugin.artifactory.utils.Utils.createDeployableArtifactsFile;
import static org.testng.Assert.assertEquals;
Expand All @@ -45,6 +44,7 @@ public class GradleFunctionalTestBase {
public final String localRepo = getKeyWithTimestamp(TestConsts.GRADLE_LOCAL_REPO);
public final String virtualRepo = getKeyWithTimestamp(TestConsts.GRADLE_VIRTUAL_REPO);
protected String remoteRepo = getKeyWithTimestamp(TestConsts.GRADLE_REMOTE_REPO);
protected String remoteGoogleRepo = getKeyWithTimestamp(TestConsts.GRADLE_REMOTE_GOOGLE_REPO);

// Test specific attributes
private StringSubstitutor stringSubstitutor;
Expand Down Expand Up @@ -79,6 +79,9 @@ protected void terminate() throws IOException {
if (StringUtils.isNotEmpty(remoteRepo)) {
deleteTestRepo(remoteRepo);
}
if (StringUtils.isNotEmpty(remoteGoogleRepo)) {
deleteTestRepo(remoteGoogleRepo);
}
if (StringUtils.isNotEmpty(localRepo)) {
deleteTestRepo(localRepo);
}
Expand Down Expand Up @@ -171,6 +174,9 @@ private void createTestRepositories() throws IOException {
if (StringUtils.isNotEmpty(remoteRepo)) {
createTestRepo(remoteRepo);
}
if (StringUtils.isNotEmpty(remoteGoogleRepo)) {
createTestRepo(remoteGoogleRepo);
}
if (StringUtils.isNotEmpty(virtualRepo)) {
createTestRepo(virtualRepo);
}
Expand All @@ -180,6 +186,7 @@ private void createStringSubstitutor() {
Map<String, Object> textParameters = new HashMap<>();
textParameters.put(TestConsts.LOCAL_REPO, localRepo);
textParameters.put(TestConsts.REMOTE_REPO, remoteRepo);
textParameters.put(TestConsts.REMOTE_GOOGLE_REPO, remoteGoogleRepo);
stringSubstitutor = new StringSubstitutor(textParameters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ public class TestConsts {
// Repositories
public static final String LOCAL_REPO = "LOCAL_REPO";
public static final String REMOTE_REPO = "REMOTE_REPO";
public static final String REMOTE_GOOGLE_REPO = "REMOTE_GOOGLE_REPO";
public static final String VIRTUAL_REPO = "VIRTUAL_REPO";
public static final String GRADLE_LOCAL_REPO = "build-info-tests-gradle-local";
public static final String GRADLE_REMOTE_REPO = "build-info-tests-gradle-remote";
public static final String GRADLE_REMOTE_GOOGLE_REPO = "build-info-tests-gradle-remote-google";
public static final String GRADLE_VIRTUAL_REPO = "build-info-tests-gradle-virtual";

// Env vars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ allprojects {
version = currentVersion
repositories {
maven {
url "${System.env.BITESTS_PLATFORM_URL}/artifactory/${System.env.BITESTS_ARTIFACTORY_VIRTUAL_REPO}"
url "should-override-me"
credentials {
username "${System.env.BITESTS_PLATFORM_USERNAME}"
password "${System.env.BITESTS_PLATFORM_ADMIN_TOKEN}"
password "should-override-me"
}
}
google()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
def javaProjects() {
subprojects.findAll { new File(it.projectDir, 'src').directory }
subprojects.findAll { new File(it.projectDir, 'src').directory }
}

allprojects {
group = 'org.jfrog.test.gradle.publish'
version = currentVersion
status = 'Integration'
repositories {
maven {
url "${System.env.BITESTS_PLATFORM_URL}/artifactory/${System.env.BITESTS_ARTIFACTORY_VIRTUAL_REPO}"
credentials {
username "${System.env.BITESTS_PLATFORM_USERNAME}"
password "${System.env.BITESTS_PLATFORM_ADMIN_TOKEN}"
}
group = 'org.jfrog.test.gradle.publish'
version = currentVersion
status = 'Integration'
repositories {
maven {
url "should-override-me"
credentials {
username "should-override-me"
}
}
}
}
}

artifactoryPublish.skip = true

project('services') {
artifactoryPublish.skip = true
artifactoryPublish.skip = true
}

configure(javaProjects()) {
apply plugin: 'java'
apply plugin: 'java'

dependencies {
testImplementation 'junit:junit:4.7'
}
dependencies {
testImplementation 'junit:junit:4.7'
}
}
57 changes: 28 additions & 29 deletions src/functionalTest/resources/gradle-example-ci-server/build.gradle
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
def javaProjects() {
subprojects.findAll { new File(it.projectDir, 'src').directory }
subprojects.findAll { new File(it.projectDir, 'src').directory }
}

allprojects {
group = 'org.jfrog.test.gradle.publish'
version = currentVersion
status = 'Integration'
repositories {
maven {
url "${System.env.BITESTS_PLATFORM_URL}/artifactory/${System.env.BITESTS_ARTIFACTORY_VIRTUAL_REPO}"
credentials {
username "${System.env.BITESTS_PLATFORM_USERNAME}"
password "${System.env.BITESTS_PLATFORM_ADMIN_TOKEN}"
}
group = 'org.jfrog.test.gradle.publish'
version = currentVersion
status = 'Integration'
repositories {
maven {
url "should-override-me"
credentials {
password "should-override-me"
}
}
}
}
}

artifactoryPublish.skip = true

project('services') {
artifactoryPublish.skip = true
artifactoryPublish.skip = true
}

configure(javaProjects()) {
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'ivy-publish'
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'ivy-publish'

dependencies {
testImplementation 'junit:junit:4.7'
}
dependencies {
testImplementation 'junit:junit:4.7'
}

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact(file("$rootDir/gradle.properties"))
}
customIvyPublication(IvyPublication) {
from components.java
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact(file("$rootDir/gradle.properties"))
}
customIvyPublication(IvyPublication) {
from components.java
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"packageType": "gradle",
"repoLayoutRef": "maven-2-default",
"url": "https://maven.google.com",
"rclass": "remote"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"packageType": "gradle",
"repositories": [
"${LOCAL_REPO}",
"${REMOTE_REPO}"
"${REMOTE_REPO}",
"${REMOTE_GOOGLE_REPO}"
],
"defaultDeploymentRepo": "${LOCAL_REPO}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.commons.lang3.StringUtils;
import org.gradle.api.Plugin;
import org.gradle.api.initialization.Settings;
import org.gradle.api.initialization.resolve.RepositoriesMode;
import org.gradle.api.logging.Logging;
import org.jfrog.build.api.util.Log;
import org.jfrog.build.extractor.BuildInfoExtractorUtils;
Expand All @@ -23,6 +24,7 @@ public void apply(Settings settings) {
return;
}
String contextUrl = StringUtils.appendIfMissing(resolver.getContextUrl(), "/");
settings.getDependencyResolutionManagement().getRepositoriesMode().set(RepositoriesMode.PREFER_SETTINGS);
settings.getDependencyResolutionManagement().getRepositories().maven(mavenArtifactRepository -> {
mavenArtifactRepository.setName("artifactoryResolutionRepository");
mavenArtifactRepository.setUrl(contextUrl + resolver.getRepoKey());
Expand Down

0 comments on commit 7f4be71

Please sign in to comment.