-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
concord-repository: support for
mvn://
scheme (#1063)
- Loading branch information
Showing
14 changed files
with
223 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
it/server/src/test/java/com/walmartlabs/concord/it/server/MavenRepoIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.walmartlabs.concord.it.server; | ||
|
||
/*- | ||
* ***** | ||
* Concord | ||
* ----- | ||
* Copyright (C) 2017 - 2018 Walmart Inc. | ||
* ----- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ===== | ||
*/ | ||
|
||
import com.walmartlabs.concord.client2.*; | ||
import com.walmartlabs.concord.common.IOUtils; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.nio.file.StandardCopyOption; | ||
import java.util.Collections; | ||
|
||
import static com.walmartlabs.concord.it.common.ServerClient.assertLog; | ||
import static com.walmartlabs.concord.it.common.ServerClient.waitForCompletion; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class MavenRepoIT extends AbstractServerIT { | ||
|
||
@Test | ||
public void test() throws Exception { | ||
// prepare local mvn repo | ||
Path localMavenRepo; | ||
try { | ||
localMavenRepo = Path.of(System.getProperty("local.mvn.repo")); | ||
} catch (NullPointerException e) { | ||
localMavenRepo = Path.of(System.getProperty("user.home")).resolve(".m2/repository"); | ||
} | ||
Path mvnDirectory = localMavenRepo.resolve("com/walmartlabs/concord/mvn-concord/0.0.1"); | ||
|
||
Path src = Paths.get(MavenRepoIT.class.getResource("mvnRepoFiles").toURI()); | ||
IOUtils.copy(src, mvnDirectory, StandardCopyOption.REPLACE_EXISTING); | ||
|
||
String url = "mvn://com.walmartlabs.concord:mvn-concord:zip"; | ||
String projectName = "project_" + randomString(); | ||
String repoName = "repo_" + randomString(); | ||
|
||
ProjectsApi projectsApi = new ProjectsApi(getApiClient()); | ||
projectsApi.createOrUpdateProject("Default", new ProjectEntry() | ||
.name(projectName) | ||
.acceptsRawPayload(false) | ||
.repositories(Collections.singletonMap(repoName, new RepositoryEntry() | ||
.name(repoName) | ||
.url(url) | ||
.branch("0.0.1")))); | ||
|
||
// --- | ||
|
||
StartProcessResponse spr = start("Default", projectName, repoName, null, null); | ||
assertTrue(spr.getOk()); | ||
|
||
// --- | ||
|
||
ProcessEntry pe = waitForCompletion(getApiClient(), spr.getInstanceId()); | ||
assertEquals(ProcessEntry.StatusEnum.FINISHED, pe.getStatus()); | ||
|
||
// --- | ||
|
||
byte[] ab = getLog(pe.getInstanceId()); | ||
assertLog(".*OK.*", ab); | ||
} | ||
} |
Binary file added
BIN
+204 Bytes
...r/src/test/resources/com/walmartlabs/concord/it/server/mvnRepoFiles/mvn-concord-0.0.1.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
repository/src/main/java/com/walmartlabs/concord/repository/MavenRepositoryProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.walmartlabs.concord.repository; | ||
|
||
import com.walmartlabs.concord.common.IOUtils; | ||
import com.walmartlabs.concord.dependencymanager.DependencyManager; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardCopyOption; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* ***** | ||
* Concord | ||
* ----- | ||
* Copyright (C) 2025 Walmart Inc. | ||
* ----- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ===== | ||
*/ | ||
public class MavenRepositoryProvider implements RepositoryProvider { | ||
|
||
private static final String URL_PREFIX = "mvn://"; | ||
private static final Logger log = LoggerFactory.getLogger(MavenRepositoryProvider.class); | ||
private final DependencyManager dependencyManager; | ||
|
||
public MavenRepositoryProvider(DependencyManager dependencyManager) { | ||
this.dependencyManager = dependencyManager; | ||
} | ||
|
||
/** | ||
* @param url maven repo url in format mvn://groupId:artifactId:extension | ||
* @return boolean can handle or not | ||
*/ | ||
@Override | ||
public boolean canHandle(String url) { | ||
return url.startsWith(URL_PREFIX); | ||
} | ||
|
||
/** | ||
* @param request fetchRequest | ||
* @return fetchResult | ||
*/ | ||
@Override | ||
public FetchResult fetch(FetchRequest request) { | ||
Path dst = request.destination(); | ||
try { | ||
URI uri = new URI(request.url().concat(":").concat(request.version().value())); | ||
Path dependencyPath = dependencyManager.resolveSingle(uri).getPath(); | ||
IOUtils.unzip(dependencyPath, dst, false, StandardCopyOption.REPLACE_EXISTING); | ||
return null; | ||
} catch (URISyntaxException | IOException e) { | ||
try { | ||
IOUtils.deleteRecursively(request.destination()); | ||
} catch (IOException ee) { | ||
log.warn("fetch ['{}', '{}', '{}'] -> cleanup error: {}", | ||
request.url(), request.version(), request.destination(), e.getMessage()); | ||
} | ||
throw new RepositoryException("Error while fetching a repository", e); | ||
} | ||
} | ||
|
||
/** | ||
* @param src source of the fetched repo | ||
* @param dst destination to be copied to | ||
* @param ignorePatterns ignore some files while copying | ||
* @return snapshot of copied files | ||
* @throws IOException exception during IO operation | ||
*/ | ||
@Override | ||
public Snapshot export(Path src, Path dst, List<String> ignorePatterns) throws IOException { | ||
LastModifiedSnapshot snapshot = new LastModifiedSnapshot(); | ||
List<String> allIgnorePatterns = new ArrayList<>(); | ||
allIgnorePatterns.addAll(ignorePatterns); | ||
IOUtils.copy(src, dst, allIgnorePatterns, snapshot, StandardCopyOption.REPLACE_EXISTING); | ||
return snapshot; | ||
} | ||
} |
Oops, something went wrong.