use of org.fakekoji.model.OToolBuild in project jenkins-scm-koji-plugin by judovana.
the class GetterAPI method getProjectHandler.
private QueryHandler getProjectHandler() {
final JDKProjectManager jdkProjectManager = settings.getConfigManager().jdkProjectManager;
final JDKVersionManager jdkVersionManager = settings.getConfigManager().jdkVersionManager;
final TaskVariantManager taskVariantManager = settings.getConfigManager().taskVariantManager;
return new QueryHandler() {
@Override
public Result<String, String> handle(Map<String, List<String>> queryParams) throws StorageException {
final Optional<String> archiveOpt = extractParamValue(queryParams, ARCHIVE);
final Optional<String> buildOpt = extractParamValue(queryParams, BUILD);
final OToolParser parser = new OToolParser(jdkProjectManager.readAll(), jdkVersionManager.readAll(), taskVariantManager.getBuildVariants());
if (archiveOpt.isPresent()) {
final String archive = archiveOpt.get();
return parser.parseArchive(archive).map(OToolArchive::getProjectName);
}
if (buildOpt.isPresent()) {
final String build = buildOpt.get();
return parser.parseBuild(build).map(OToolBuild::getProjectName);
}
return Result.err(ERROR_PARAMETERS_EXPECTED);
}
@Override
public String about() {
return "/project?[" + String.join("|", ARCHIVE + "=<NVRA>", BUILD + "=<NVR>") + "]";
}
};
}
use of org.fakekoji.model.OToolBuild in project jenkins-scm-koji-plugin by judovana.
the class BuildHelper method getBuildPlatformPredicate.
public Predicate<OToolBuild> getBuildPlatformPredicate() {
// if params contains buildPlatform variant in buildVariants field, check whether archive of that platform
// exists or not depending on params' isBuilt field
final String buildPlatform = buildVariantMap.get(buildPlatformVariant);
if (buildPlatform == null) {
return build -> true;
}
final String requiredFilename = buildVariantString + '.' + buildPlatform;
final ArchiveState archiveState = params.isBuilt() ? ArchiveState.BUILT : ArchiveState.NOT_BUILT;
return build -> {
final File archiveRoot = new File(getBuildRoot(build), requiredFilename);
return getArchiveRootPredicate(archiveState).test(archiveRoot);
};
}
use of org.fakekoji.model.OToolBuild in project jenkins-scm-koji-plugin by judovana.
the class BuildHelper method getBuildParser.
public Function<OToolBuild, Optional<Build>> getBuildParser() {
final List<String> platforms = Arrays.asList(params.getPlatforms().trim().split("\\p{javaWhitespace}+"));
return build -> {
final String packageName = build.getPackageName();
final String version = build.getVersion();
final String release = build.getRelease();
final String nvr = packageName + '-' + version + '-' + release;
// get directory of build: /name/version/release.project
final File buildRoot = getBuildRoot(build);
// get directories where required archives (src, dbg.jvm.os.arch)
// are stored: /name/version/release.project/*
final Supplier<Stream<File>> archiveRootStreamSupplier = () -> platforms.stream().map(archiveName -> new File(buildRoot, archiveName.equals(JenkinsJobTemplateBuilder.SOURCES) ? archiveName : buildVariantString + '.' + archiveName));
// check if all needed archives are built
if (!archiveRootStreamSupplier.get().allMatch(getArchiveRootPredicate(ArchiveState.BUILT))) {
return Optional.empty();
}
final List<File> archiveFiles = archiveRootStreamSupplier.get().map(file -> Objects.requireNonNull(file.listFiles())[0]).collect(Collectors.toList());
final File newestArchive = archiveFiles.stream().min(getArchiveComparator()).orElse(buildRoot);
final Function<File, RPM> toRPMs = archiveFile -> {
final boolean isSource = archiveFile.getParentFile().getName().equals(JenkinsJobTemplateBuilder.SOURCES);
final String[] parts = archiveFile.getName().split("\\.");
final int length = parts.length;
// final OToolArchive archive = oToolParser.parseArchive(archiveFile.getName());
final String platform = isSource ? parts[length - 2] : parts[length - 3] + '.' + parts[length - 2];
return new RPM(packageName, version, release, isSource ? nvr : nvr + '.' + buildVariantString, platform, archiveFile.getName(), String.join("/", "http://" + buildProvider.getDownloadUrl(), packageName, version, release, archiveFile.getParentFile().getName(), archiveFile.getName()));
};
final List<RPM> rpms = archiveFiles.stream().map(toRPMs).collect(Collectors.toList());
final String completionTime = Constants.DTF.format(new Date(newestArchive.lastModified()).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
return Optional.of(new Build(buildRoot.hashCode(), packageName, version, release, nvr, completionTime, rpms, Collections.emptySet(), buildProvider, null));
};
}
use of org.fakekoji.model.OToolBuild in project jenkins-scm-koji-plugin by judovana.
the class GetterAPI method getProductHandler.
private QueryHandler getProductHandler() {
final JDKProjectManager jdkProjectManager = settings.getConfigManager().jdkProjectManager;
final JDKTestProjectManager jdkTestProjectManager = settings.getConfigManager().jdkTestProjectManager;
final JDKVersionManager jdkVersionManager = settings.getConfigManager().jdkVersionManager;
final TaskVariantManager taskVariantManager = settings.getConfigManager().taskVariantManager;
return new QueryHandler() {
@Override
public Result<String, String> handle(Map<String, List<String>> queryParams) throws StorageException {
final Optional<String> archiveOpt = extractParamValue(queryParams, ARCHIVE);
if (archiveOpt.isPresent()) {
final String archive = archiveOpt.get();
return new OToolParser(jdkProjectManager.readAll(), jdkVersionManager.readAll(), taskVariantManager.getBuildVariants()).parseArchive(archive).map(OToolBuild::getPackageName);
}
final Optional<String> projectOpt = extractParamValue(queryParams, PROJECT);
if (projectOpt.isPresent()) {
final String project = projectOpt.get();
final List<JDKProject> jdkProjects = jdkProjectManager.readAll();
final Optional<JDKProject> optionalJDKProject = jdkProjects.stream().filter(proj -> proj.getId().equals(project)).findFirst();
if (optionalJDKProject.isPresent()) {
final JDKProject jdkProject = optionalJDKProject.get();
return Result.ok(jdkProject.getProduct().getPackageName());
}
final List<JDKTestProject> jdkTestProjects = jdkTestProjectManager.readAll();
final Optional<JDKTestProject> optionalJDKTestProject = jdkTestProjects.stream().filter(proj -> proj.getId().equals(project)).findFirst();
if (optionalJDKTestProject.isPresent()) {
final JDKTestProject jdkTestProject = optionalJDKTestProject.get();
return Result.ok(jdkTestProject.getProduct().getPackageName());
}
return Result.err(ERROR_PROJECT_NOT_FOUND);
}
final Optional<String> buildOpt = extractParamValue(queryParams, BUILD);
if (buildOpt.isPresent()) {
final String build = buildOpt.get();
return new OToolParser(jdkProjectManager.readAll(), jdkVersionManager.readAll(), taskVariantManager.getBuildVariants()).parseBuild(build).map(OToolBuild::getPackageName);
}
return Result.err(ERROR_PARAMETERS_EXPECTED);
}
@Override
public String about() {
return "/product?[" + String.join("|", ARCHIVE + "=<NVRA>", BUILD + "=<NVR>", PROJECT + "=projectName") + "]";
}
};
}
use of org.fakekoji.model.OToolBuild in project jenkins-scm-koji-plugin by judovana.
the class OToolParserTest method parseValidNVRWithNoGarbage.
@Test
public void parseValidNVRWithNoGarbage() {
final String nvr = VALID_NAME_VERSION + "-" + VALID_RELEASE;
final Result<OToolBuild, String> result = parser.parseBuild(nvr);
Assert.assertEquals(new OToolBuild(JDK_8_PACKAGE_NAME, VERSION, CHANGE_SET, "", PROJECT_NAME_U), result.getValue());
}
Aggregations