@ExtendWith({ RepositoryManagementTestExecutionListener.class, ArtifactManagementTestExecutionListener.class }) @Test public void testSnapshotValidation(@MavenRepository(repositoryId = REPOSITORY_ID_2, policy = SNAPSHOT) Repository repository, @MavenTestArtifact(repositoryId = REPOSITORY_ID_2, id = GROUP_ID + ":" + ARTIFACT_ID, versions = { "1.0-SNAPSHOT", "1.0-20131004.115330-1", "1.0.8-20151025.032208-1", "1.0.8-alpha-1-20151025.032208-1"}) List<Path> validArtifactPaths) throws VersionValidationException, IOException { for (Path validArtifactPath : validArtifactPaths) { RepositoryPath repositoryPath = (RepositoryPath) validArtifactPath.normalize(); ArtifactCoordinates coordinates = RepositoryFiles.readCoordinates(repositoryPath); validator.validate(repository, coordinates); } }
@Override public void validate(Repository repository, ArtifactCoordinates coordinates) throws VersionValidationException { String version = coordinates.getVersion(); if (isSnapshot(version) && !repository.acceptsSnapshots()) { throw new VersionValidationException("Cannot deploy a SNAPSHOT artifact to a repository with a release policy!"); } if (!isSnapshot(version) && repository.acceptsSnapshots() && !repository.acceptsReleases()) { throw new VersionValidationException("Cannot deploy a release artifact to a repository with a SNAPSHOT policy!"); } }
MavenSnapshotVersionValidator implements MavenVersionValidator { @Override public void validate(Repository repository, ArtifactCoordinates coordinates) throws VersionValidationException { String version = coordinates.getVersion(); if (isSnapshot(version) && !repository.acceptsSnapshots()) { throw new VersionValidationException("Cannot deploy a SNAPSHOT artifact to a repository with a release policy!"); } if (!isSnapshot(version) && repository.acceptsSnapshots() && !repository.acceptsReleases()) { throw new VersionValidationException("Cannot deploy a release artifact to a repository with a SNAPSHOT policy!"); } } }
MavenSnapshotVersionValidator implements MavenVersionValidator { @Override public void validate(Repository repository, ArtifactCoordinates coordinates) throws VersionValidationException { String version = coordinates.getVersion(); if (isSnapshot(version) && !repository.acceptsSnapshots()) { throw new VersionValidationException("Cannot deploy a SNAPSHOT artifact to a repository with a release policy!"); } if (!isSnapshot(version) && repository.acceptsSnapshots() && !repository.acceptsReleases()) { throw new VersionValidationException("Cannot deploy a release artifact to a repository with a SNAPSHOT policy!"); } }  }
MavenSnapshotVersionValidator implements MavenVersionValidator { @Override public void validate(Repository repository, ArtifactCoordinates coordinates) throws VersionValidationException { String version = coordinates.getVersion(); if (isSnapshot(version) && !repository.acceptsSnapshots()) { throw new VersionValidationException("Cannot deploy a SNAPSHOT artifact to a repository with a release policy!"); } if (!isSnapshot(version) && repository.acceptsSnapshots() && !repository.acceptsReleases()) { throw new VersionValidationException("Cannot deploy a release artifact to a repository with a SNAPSHOT policy!"); } }  @PostConstruct @Override void register(); @Override String getAlias(); @Override String getDescription(); @Override boolean supports(Repository repository); @Override void validate(Repository repository,
                         ArtifactCoordinates coordinates); }
MavenSnapshotVersionValidator implements MavenVersionValidator { @Override public void validate(Repository repository, ArtifactCoordinates coordinates) throws VersionValidationException { String version = coordinates.getVersion(); if (isSnapshot(version) && !repository.acceptsSnapshots()) { throw new VersionValidationException("Cannot deploy a SNAPSHOT artifact to a repository with a release policy!"); } if (!isSnapshot(version) && repository.acceptsSnapshots() && !repository.acceptsReleases()) { throw new VersionValidationException("Cannot deploy a release artifact to a repository with a SNAPSHOT policy!"); } }  @PostConstruct @Override void register(); @Override String getAlias(); @Override String getDescription(); @Override boolean supports(Repository repository); @Override void validate(Repository repository,
                         ArtifactCoordinates coordinates); static final String ALIAS; static final String DESCRIPTION; }