Skip to content
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 @@ -29,7 +29,7 @@
* A version filter that combines multiple version filters into a chain where each filter gets invoked one after the
* other, thereby accumulating their filtering effects.
*/
public final class ChainedVersionFilter implements VersionFilter {
public class ChainedVersionFilter implements VersionFilter {

private final VersionFilter[] filters;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.eclipse.aether.util.graph.version;

import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.collection.DependencyCollectionContext;
import org.eclipse.aether.collection.VersionFilter;

/**
* A version filter that blocks "*-SNAPSHOT" versions if the
* {@link VersionFilterContext#getDependency()} ancestor whose range is being filtered is not a snapshot.
*/
public class ContextualAncestorSnapshotVersionFilter implements VersionFilter {
private final SnapshotVersionFilter filter;

/**
* Creates a new instance of this version filter.
*/
public ContextualAncestorSnapshotVersionFilter() {
filter = new SnapshotVersionFilter();
}

@Override
public void filterVersions(VersionFilterContext context) {
Artifact ancestor = context.getDependency().getArtifact();
if (!ancestor.isSnapshot()) {
filter.filterVersions(context);
}
}

@Override
public VersionFilter deriveChildFilter(DependencyCollectionContext context) {
return this;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (null == obj || !getClass().equals(obj.getClass())) {
return false;
}
return true;
}

@Override
public int hashCode() {
return getClass().hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@
/**
* A version filter that blocks "*-SNAPSHOT" versions if the
* {@link org.eclipse.aether.collection.CollectRequest#getRootArtifact() root artifact} of the dependency graph is not a
* snapshot. Alternatively, this filter can be forced to always ban snapshot versions by setting the boolean
* {@link RepositorySystemSession#getConfigProperties() configuration property} {@link #CONFIG_PROP_ENABLE} to
* {@code true}.
* snapshot.
*/
public final class ContextualSnapshotVersionFilter implements VersionFilter {
public class ContextualSnapshotVersionFilter implements VersionFilter {
/**
* The key in the repository session's {@link RepositorySystemSession#getConfigProperties() configuration
* properties} used to store a {@link Boolean} flag whether this filter should be forced to ban snapshots. By
Expand All @@ -41,7 +39,9 @@ public final class ContextualSnapshotVersionFilter implements VersionFilter {
* @configurationSource {@link RepositorySystemSession#getConfigProperties()}
* @configurationType {@link java.lang.Boolean}
* @configurationDefaultValue false
* @deprecated Use snapshot filter instead to always ban snapshots.
*/
@Deprecated
public static final String CONFIG_PROP_ENABLE = ConfigurationProperties.PREFIX_AETHER + "snapshotFilter";

private final SnapshotVersionFilter filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* A version filter that excludes any version except the highest one.
*/
public final class HighestVersionFilter implements VersionFilter {
public class HighestVersionFilter implements VersionFilter {
private final int count;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* @since 2.0.0
*/
public final class LowestVersionFilter implements VersionFilter {
public class LowestVersionFilter implements VersionFilter {
private final int count;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
* @since 2.0.0
*/
public final class PredicateVersionFilter implements VersionFilter {
public class PredicateVersionFilter implements VersionFilter {
private final Predicate<Artifact> artifactPredicate;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.eclipse.aether.util.graph.version;

/**
* A version filter that (unconditionally) blocks non "*-SNAPSHOT" versions.
*/
public class ReleaseVersionFilter extends VersionPredicateVersionFilter {

/**
* Creates a new instance of this version filter.
*/
public ReleaseVersionFilter() {
super(v -> v.toString().endsWith("SNAPSHOT"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,16 @@
*/
package org.eclipse.aether.util.graph.version;

import java.util.Iterator;

import org.eclipse.aether.collection.DependencyCollectionContext;
import org.eclipse.aether.collection.VersionFilter;
import org.eclipse.aether.version.Version;

/**
* A version filter that (unconditionally) blocks "*-SNAPSHOT" versions. For practical purposes,
* {@link ContextualSnapshotVersionFilter} is usually more desirable.
*/
public final class SnapshotVersionFilter implements VersionFilter {
public class SnapshotVersionFilter extends VersionPredicateVersionFilter {

/**
* Creates a new instance of this version filter.
*/
public SnapshotVersionFilter() {}

@Override
public void filterVersions(VersionFilterContext context) {
for (Iterator<Version> it = context.iterator(); it.hasNext(); ) {
String version = it.next().toString();
if (version.endsWith("SNAPSHOT")) {
it.remove();
}
}
}

@Override
public VersionFilter deriveChildFilter(DependencyCollectionContext context) {
return this;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (null == obj || !getClass().equals(obj.getClass())) {
return false;
}
return true;
}

@Override
public int hashCode() {
return getClass().hashCode();
public SnapshotVersionFilter() {
super(v -> !v.toString().endsWith("SNAPSHOT"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.eclipse.aether.util.graph.version;

import java.util.Iterator;
import java.util.Objects;
import java.util.function.Predicate;

import org.eclipse.aether.collection.DependencyCollectionContext;
import org.eclipse.aether.collection.VersionFilter;
import org.eclipse.aether.version.Version;

import static java.util.Objects.requireNonNull;

/**
* A version filter that excludes any version that is blacklisted.
*
* @since 2.0.11
*/
public class VersionPredicateVersionFilter implements VersionFilter {
private final Predicate<Version> versionPredicate;

/**
* Creates a new instance of this version filter. It will filter out versions not matched by predicate.
* Note: filter always operates with baseVersions.
*/
public VersionPredicateVersionFilter(Predicate<Version> versionPredicate) {
this.versionPredicate = requireNonNull(versionPredicate);
}

@Override
public void filterVersions(VersionFilterContext context) {
for (Iterator<Version> it = context.iterator(); it.hasNext(); ) {
if (!versionPredicate.test(it.next())) {
it.remove();
}
}
}

@Override
public VersionFilter deriveChildFilter(DependencyCollectionContext context) {
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
VersionPredicateVersionFilter that = (VersionPredicateVersionFilter) o;
return Objects.equals(versionPredicate, that.versionPredicate);
}

@Override
public int hashCode() {
return getClass().hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.eclipse.aether.util.graph.versions;

import org.eclipse.aether.collection.VersionFilter.VersionFilterContext;
import org.eclipse.aether.util.graph.version.ReleaseVersionFilter;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertSame;

public class ReleaseVersionFilterTest extends AbstractVersionFilterTest {

@Test
void testFilterVersions() {
ReleaseVersionFilter filter = new ReleaseVersionFilter();
VersionFilterContext ctx = newContext("g:a:[1,9]", "1", "2-SNAPSHOT", "3.1", "4.0-SNAPSHOT", "5.0.0");
filter.filterVersions(ctx);
assertVersions(ctx, "2-SNAPSHOT", "4.0-SNAPSHOT");
}

@Test
void testDeriveChildFilter() {
ReleaseVersionFilter filter = new ReleaseVersionFilter();
assertSame(filter, derive(filter, "g:a:1"));
}

@SuppressWarnings("EqualsWithItself")
@Test
void testEquals() {
ReleaseVersionFilter filter = new ReleaseVersionFilter();
assertNotEquals(null, filter);
assertEquals(filter, filter);
assertEquals(filter, new ReleaseVersionFilter());
}
}