Skip to content

Commit

Permalink
[#noissue] Update plugins-it version filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehong-kim committed Oct 8, 2024
1 parent 56898af commit 6e35e3f
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

@PluginTest
@PinpointAgent(AgentPath.PATH)
@Dependency({"io.lettuce:lettuce-core:[5.0,6.4.0.RELEASE]",
@Dependency({"io.lettuce:lettuce-core:[5.0,]",
"org.latencyutils:LatencyUtils:[2.0.3]",
PluginITConstants.VERSION})
@SharedDependency({PluginITConstants.VERSION, TestcontainersOption.TEST_CONTAINER})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
public class DefaultPluginForkedTestSuite extends AbstractPluginForkedTestSuite {
private static final Map<String, Object> RESOLVER_OPTION = createResolverOption();
private static final DependencyResolverFactory RESOLVER_FACTORY = new DependencyResolverFactory(RESOLVER_OPTION);
private static final DependencyVersionFilter DEPENDENCY_VERSION_FILTER = new DependencyVersionFilter();
private final TaggedLogger logger = TestLogger.getLogger();

private final ClassLoding classLoding;
Expand Down Expand Up @@ -138,7 +139,7 @@ private List<PluginForkedTestInstance> createSharedCasesWithDependencies(PluginF
final String sharedClassName = sharedClass == null ? null : sharedClass.getName();
SharedProcessManager sharedProcessManager = new SharedProcessManager(context, sharedClassName, sharedLibs);

Map<String, List<Artifact>> dependencyMap = resolver.resolveDependencySets(dependencies);
Map<String, List<Artifact>> dependencyMap = resolver.resolveDependencySets(DEPENDENCY_VERSION_FILTER, dependencies);
if (logger.isDebugEnabled()) {
for (Map.Entry<String, List<Artifact>> entry : dependencyMap.entrySet()) {
logger.debug("{} {}", entry.getKey(), entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
public class DefaultPluginTestSuite extends AbstractPluginTestSuite {
private static final Map<String, Object> RESOLVER_OPTION = createResolverOption();
private static final DependencyResolverFactory RESOLVER_FACTORY = new DependencyResolverFactory(RESOLVER_OPTION);
private static final DependencyVersionFilter DEPENDENCY_VERSION_FILTER = new DependencyVersionFilter();
private final TaggedLogger logger = TestLogger.getLogger();

private final ClassLoding classLoding;
Expand Down Expand Up @@ -158,7 +159,7 @@ private List<PluginTestInstance> createCasesWithDependencies(PluginTestContext c
}
}

final Map<String, List<Artifact>> dependencyCases = resolver.resolveDependencySets(dependencies);
final Map<String, List<Artifact>> dependencyCases = resolver.resolveDependencySets(DEPENDENCY_VERSION_FILTER, dependencies);
for (Map.Entry<String, List<Artifact>> dependencyCase : dependencyCases.entrySet()) {
final String testId = dependencyCase.getKey();
final List<String> libs = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package com.navercorp.pinpoint.test.plugin;

import com.navercorp.pinpoint.common.util.Filter;
import com.navercorp.pinpoint.test.plugin.shared.ArtifactIdUtils;
import com.navercorp.pinpoint.test.plugin.util.TestLogger;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
Expand Down Expand Up @@ -226,14 +227,22 @@ public DependencyResolver(RepositorySystem system, RepositorySystemSession sessi
this.repositories = repositories;
}

public List<Version> getVersions(Artifact artifact) throws VersionRangeResolutionException {
public List<Version> getVersions(Artifact artifact, Filter<String> filter) throws VersionRangeResolutionException {
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(artifact);
rangeRequest.setRepositories(repositories);

VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);

List<Version> versions = new ArrayList<>(rangeResult.getVersions());
List<Version> versions = new ArrayList<>();
if (filter != null) {
for (Version version : rangeResult.getVersions()) {
if (Filter.NOT_FILTERED == filter.filter(version.toString())) {
versions.add(version);
}
}
} else {
versions = new ArrayList<>(rangeResult.getVersions());
}
versions.sort(Comparator.naturalOrder());

return versions;
Expand Down Expand Up @@ -289,6 +298,10 @@ public String getNewestVersion(String groupId, String artifactId) throws Version
}

public Map<String, List<Artifact>> resolveDependencySets(String... dependencies) {
return resolveDependencySets(null, dependencies);
}

public Map<String, List<Artifact>> resolveDependencySets(Filter<String> filter, String... dependencies) {
List<List<Artifact>> companions = resolve(dependencies);

List<List<List<Artifact>>> xxx = new ArrayList<>();
Expand All @@ -299,7 +312,7 @@ public Map<String, List<Artifact>> resolveDependencySets(String... dependencies)
List<Version> versions;

try {
versions = getVersions(representative);
versions = getVersions(representative, filter);
} catch (VersionRangeResolutionException e) {
throw new IllegalArgumentException("Fail to resolve version of: " + representative);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2024 NAVER Corp.
*
* 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.
*/

package com.navercorp.pinpoint.test.plugin;

import com.navercorp.pinpoint.common.util.Filter;

import java.util.regex.Pattern;

public class DependencyVersionFilter implements Filter<String> {

private static final Pattern RC_PATTERN = Pattern.compile(".*[Rr][Cc]-?\\.?\\d*$");
private static final Pattern M_PATTERN = Pattern.compile(".*[Mm]-?\\.?\\d*$");
private static final Pattern ALPHA_PATTERN = Pattern.compile(".*[Aa][Ll][Pp][Hh][Aa]-?\\.?\\d*$");
private static final Pattern BETA_PATTERN = Pattern.compile(".*[Bb][Ee][Tt][Aa]-?\\.?\\d*$");
private static final Pattern PATCH_PATTERN = Pattern.compile(".*[Pp][Aa][Tt][Cc][Hh]-?\\.?\\d*$");
private static final Pattern TEST_PATTERN = Pattern.compile(".*[Tt][Ee][Ss][Tt]-?\\.?\\d*$");
private static final Pattern MILESTONE_PATTERN = Pattern.compile(".*[Mm][Ii][Ll][Ee][Ss][Tt][Oo][Nn][Ee]-?\\.?\\d*$");
private static final Pattern PRE_PATTERN = Pattern.compile(".*[Pp][Rr][Ee]-?\\.?\\d*$");

private static final Pattern[] PATTERNS = new Pattern[]{RC_PATTERN, M_PATTERN, ALPHA_PATTERN, BETA_PATTERN, PATCH_PATTERN, TEST_PATTERN, MILESTONE_PATTERN, PRE_PATTERN};


@Override
public boolean filter(String value) {
for (Pattern pattern : PATTERNS) {
if (pattern.matcher(value).matches()) {
return FILTERED;
}
}
return NOT_FILTERED;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2024 NAVER Corp.
*
* 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.
*/

package com.navercorp.pinpoint.test.plugin;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class DependencyVersionFilterTest {

@Test
public void filter() {
DependencyVersionFilter filter = new DependencyVersionFilter();
assertFalse(filter.filter("5.0.5.RELEASE"));
assertTrue(filter.filter("5.0.0.RC2"));
assertTrue(filter.filter("5.0.0.RC1"));
assertTrue(filter.filter("5.0.0.M2"));

assertFalse(filter.filter("4.0.0"));
assertTrue(filter.filter("4.0.0-rc1"));
assertTrue(filter.filter("4.0.0-beta3"));
assertTrue(filter.filter("4.0.0-beta2"));
assertTrue(filter.filter("4.0.0-beta1"));
assertTrue(filter.filter("4.0.0-alpha3"));

assertTrue(filter.filter("0.3.2-patch11"));
assertTrue(filter.filter("0.3.2-patch1"));
assertTrue(filter.filter("0.3.2-test3"));

assertTrue(filter.filter("3.0.0-milestone2"));
assertTrue(filter.filter("1.15.0-rc"));
assertTrue(filter.filter("1.14.1-beta"));
assertTrue(filter.filter("1.14.1-beta-2"));
assertTrue(filter.filter("1.4.0-rc.7"));
}
}

0 comments on commit 6e35e3f

Please sign in to comment.