use of org.commonjava.maven.galley.maven.spi.type.TypeMapper in project indy by Commonjava.
the class MavenMetadataGeneratorTest method setup.
@Before
public void setup() throws Exception {
stores = new MemoryStoreDataManager(true);
final LocationExpander locations = new IndyLocationExpander(stores);
final DownloadManager downloads = new DefaultDownloadManager(stores, fixture.getTransferManager(), locations);
final XMLInfrastructure xml = new XMLInfrastructure();
final TypeMapper types = new StandardTypeMapper();
final MavenMetadataMerger merger = new MavenMetadataMerger(Collections.emptyList());
final GroupMergeHelper helper = new GroupMergeHelper(downloads);
DefaultDirectContentAccess contentAccess = new DefaultDirectContentAccess(downloads, Executors.newCachedThreadPool());
generator = new MavenMetadataGenerator(contentAccess, stores, xml, types, merger, helper, new MemoryNotFoundCache());
metadataReader = new MavenMetadataReader(xml, locations, fixture.getArtifactMetadataManager(), fixture.getXPathManager());
}
use of org.commonjava.maven.galley.maven.spi.type.TypeMapper in project galley by Commonjava.
the class ArtifactPathUtilsTest method handleRemoteSnapshotArtifactPath.
@Test
public void handleRemoteSnapshotArtifactPath() throws Exception {
final ProjectVersionRef pvr = new SimpleProjectVersionRef("org.group", "artifact-id", "1.0-20140603.151226-11");
final TypeMapper mapper = new StandardTypeMapper();
final String path = ArtifactPathUtils.formatArtifactPath(pvr.asJarArtifact(), mapper);
assertThat(path.equals("org/group/artifact-id/1.0-SNAPSHOT/artifact-id-" + pvr.getVersionString() + ".jar"), equalTo(true));
}
use of org.commonjava.maven.galley.maven.spi.type.TypeMapper in project indy by Commonjava.
the class KojiBuildAuthority method isAuthorized.
@IndyMetrics(measure = @Measure(timers = @MetricNamed(name = IndyMetricsKojiNames.METHOD_BUILDAUTHORITY_ISAUTHORIZED + IndyMetricsNames.TIMER), meters = @MetricNamed(name = IndyMetricsKojiNames.METHOD_BUILDAUTHORITY_ISAUTHORIZED + IndyMetricsNames.METER)))
public boolean isAuthorized(String path, EventMetadata eventMetadata, ProjectRef ref, KojiBuildInfo build, KojiSessionInfo session, Map<Integer, KojiBuildArchiveCollection> seenBuildArchives) throws KojiClientException {
ArtifactStore authoritativeStore = getAuthoritativeStore();
if (authoritativeStore != null) {
KojiBuildArchiveCollection archiveCollection = seenBuildArchives.get(build.getId());
if (archiveCollection == null) {
archiveCollection = kojiClient.listArchivesForBuild(build, session);
seenBuildArchives.put(build.getId(), archiveCollection);
}
if (archiveCollection == null) {
throw new KojiClientException("Failed to retrieve archives for build: %s", build);
}
// @formatter:off
Predicate<KojiArchiveInfo> archiveInfoFilter = (archive) -> EXCLUDED_FILE_ENDINGS.stream().allMatch(ending -> !archive.getFilename().endsWith(ending));
List<KojiArchiveInfo> sortedArchives = archiveCollection.getArchives().stream().filter(archiveInfoFilter).sorted((a1, a2) -> {
TypePriority t1 = TypePriority.get(a1.getExtension());
TypePriority t2 = TypePriority.get(a2.getExtension());
return Integer.valueOf(t1.ordinal()).compareTo(t2.ordinal());
}).collect(Collectors.toList());
for (KojiArchiveInfo archive : sortedArchives) {
try {
if (isMavenArtifact(archive)) {
// skip non-Maven artifacts
continue;
}
if (containsPlaceholders(archive)) {
return false;
}
String artifactPath = ArtifactPathUtils.formatArtifactPath(archive.asArtifact(), typeMapper);
String md5 = checksumArtifact(authoritativeStore, artifactPath, eventMetadata);
if (isNotBlank(md5)) {
//FIXME: not sure if all koji archives are using md5 as checksum type for maven build
String kojiMd5 = archive.getChecksum();
Logger logger = LoggerFactory.getLogger(getClass());
logger.info("Checking checksum for {} (path: {}) in auth store {}, auth store checksum:{}, koji build check sum:{}", ref, path, authoritativeStore, md5, kojiMd5);
if (!md5.equals(kojiMd5)) {
// if checksum is not the same, it means the artifact in koji is DIFFERENT from the one in the authoritative store. Reject this.
return false;
}
}
} catch (Exception e) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.error("SHOULD NEVER HAPPEN: Failed to transform artifact to path: " + e.getMessage(), e);
}
}
}
return true;
}
Aggregations