Search in sources :

Example 1 with OToolBuild

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>") + "]";
        }
    };
}
Also used : TaskVariantManager(org.fakekoji.jobmanager.manager.TaskVariantManager) JDKProjectManager(org.fakekoji.jobmanager.project.JDKProjectManager) OToolParser(org.fakekoji.core.utils.OToolParser) OToolArchive(org.fakekoji.model.OToolArchive) JDKVersionManager(org.fakekoji.jobmanager.manager.JDKVersionManager) HashMap(java.util.HashMap) Map(java.util.Map) OToolBuild(org.fakekoji.model.OToolBuild)

Example 2 with OToolBuild

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);
    };
}
Also used : Arrays(java.util.Arrays) Platform(org.fakekoji.model.Platform) Task(org.fakekoji.model.Task) Date(java.util.Date) GetBuildList(org.fakekoji.xmlrpc.server.xmlrpcrequestparams.GetBuildList) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Build(hudson.plugins.scm.koji.model.Build) ConfigManager(org.fakekoji.jobmanager.ConfigManager) Matcher(java.util.regex.Matcher) Map(java.util.Map) StorageException(org.fakekoji.storage.StorageException) JavaServerConstants(org.fakekoji.xmlrpc.server.JavaServerConstants) BuildProvider(hudson.plugins.scm.koji.model.BuildProvider) Constants(hudson.plugins.scm.koji.Constants) Predicate(java.util.function.Predicate) JenkinsJobTemplateBuilder(org.fakekoji.jobmanager.JenkinsJobTemplateBuilder) Set(java.util.Set) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) TaskVariantValue(org.fakekoji.model.TaskVariantValue) File(java.io.File) ZoneId(java.time.ZoneId) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) RPM(hudson.plugins.scm.koji.model.RPM) Paths(java.nio.file.Paths) OToolBuild(org.fakekoji.model.OToolBuild) Result(org.fakekoji.functional.Result) TaskVariant(org.fakekoji.model.TaskVariant) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) JDKVersion(org.fakekoji.model.JDKVersion) Comparator(java.util.Comparator) Collections(java.util.Collections) OToolArchive(org.fakekoji.model.OToolArchive) File(java.io.File)

Example 3 with OToolBuild

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));
    };
}
Also used : Arrays(java.util.Arrays) Platform(org.fakekoji.model.Platform) Task(org.fakekoji.model.Task) Date(java.util.Date) GetBuildList(org.fakekoji.xmlrpc.server.xmlrpcrequestparams.GetBuildList) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Build(hudson.plugins.scm.koji.model.Build) ConfigManager(org.fakekoji.jobmanager.ConfigManager) Matcher(java.util.regex.Matcher) Map(java.util.Map) StorageException(org.fakekoji.storage.StorageException) JavaServerConstants(org.fakekoji.xmlrpc.server.JavaServerConstants) BuildProvider(hudson.plugins.scm.koji.model.BuildProvider) Constants(hudson.plugins.scm.koji.Constants) Predicate(java.util.function.Predicate) JenkinsJobTemplateBuilder(org.fakekoji.jobmanager.JenkinsJobTemplateBuilder) Set(java.util.Set) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) TaskVariantValue(org.fakekoji.model.TaskVariantValue) File(java.io.File) ZoneId(java.time.ZoneId) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) RPM(hudson.plugins.scm.koji.model.RPM) Paths(java.nio.file.Paths) OToolBuild(org.fakekoji.model.OToolBuild) Result(org.fakekoji.functional.Result) TaskVariant(org.fakekoji.model.TaskVariant) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) JDKVersion(org.fakekoji.model.JDKVersion) Comparator(java.util.Comparator) Collections(java.util.Collections) OToolArchive(org.fakekoji.model.OToolArchive) RPM(hudson.plugins.scm.koji.model.RPM) Date(java.util.Date) Function(java.util.function.Function) Build(hudson.plugins.scm.koji.model.Build) OToolBuild(org.fakekoji.model.OToolBuild) Supplier(java.util.function.Supplier) GetBuildList(org.fakekoji.xmlrpc.server.xmlrpcrequestparams.GetBuildList) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 4 with OToolBuild

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") + "]";
        }
    };
}
Also used : TaskVariantManager(org.fakekoji.jobmanager.manager.TaskVariantManager) JenkinsCliWrapper(org.fakekoji.jobmanager.JenkinsCliWrapper) Platform(org.fakekoji.model.Platform) JDKTestProjectManager(org.fakekoji.jobmanager.project.JDKTestProjectManager) Task(org.fakekoji.model.Task) TaskVariantManager(org.fakekoji.jobmanager.manager.TaskVariantManager) Job(org.fakekoji.jobmanager.model.Job) HashMap(java.util.HashMap) JDKTestProject(org.fakekoji.jobmanager.model.JDKTestProject) PlatformManager(org.fakekoji.jobmanager.manager.PlatformManager) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Map(java.util.Map) RestUtils.extractParamValue(org.fakekoji.api.http.rest.RestUtils.extractParamValue) StorageException(org.fakekoji.storage.StorageException) Path(java.nio.file.Path) JDKVersionManager(org.fakekoji.jobmanager.manager.JDKVersionManager) Project(org.fakekoji.jobmanager.model.Project) ManagementException(org.fakekoji.jobmanager.ManagementException) FileVisitor(java.nio.file.FileVisitor) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) Collection(java.util.Collection) TaskManager(org.fakekoji.jobmanager.manager.TaskManager) Set(java.util.Set) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) EndpointGroup(io.javalin.apibuilder.EndpointGroup) JDKProject(org.fakekoji.jobmanager.model.JDKProject) Collectors(java.util.stream.Collectors) TaskVariantValue(org.fakekoji.model.TaskVariantValue) Objects(java.util.Objects) FileVisitResult(java.nio.file.FileVisitResult) OToolParser(org.fakekoji.core.utils.OToolParser) List(java.util.List) Stream(java.util.stream.Stream) OToolBuild(org.fakekoji.model.OToolBuild) Result(org.fakekoji.functional.Result) TaskVariant(org.fakekoji.model.TaskVariant) Optional(java.util.Optional) ApiBuilder.get(io.javalin.apibuilder.ApiBuilder.get) Pattern(java.util.regex.Pattern) ApiBuilder.path(io.javalin.apibuilder.ApiBuilder.path) JDKProjectManager(org.fakekoji.jobmanager.project.JDKProjectManager) JDKVersion(org.fakekoji.model.JDKVersion) Comparator(java.util.Comparator) Collections(java.util.Collections) OToolArchive(org.fakekoji.model.OToolArchive) AccessibleSettings(org.fakekoji.core.AccessibleSettings) JDKProject(org.fakekoji.jobmanager.model.JDKProject) OToolParser(org.fakekoji.core.utils.OToolParser) JDKTestProjectManager(org.fakekoji.jobmanager.project.JDKTestProjectManager) JDKProjectManager(org.fakekoji.jobmanager.project.JDKProjectManager) JDKVersionManager(org.fakekoji.jobmanager.manager.JDKVersionManager) HashMap(java.util.HashMap) Map(java.util.Map) JDKTestProject(org.fakekoji.jobmanager.model.JDKTestProject) OToolBuild(org.fakekoji.model.OToolBuild)

Example 5 with OToolBuild

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());
}
Also used : OToolBuild(org.fakekoji.model.OToolBuild) Test(org.junit.Test)

Aggregations

OToolBuild (org.fakekoji.model.OToolBuild)6 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Comparator (java.util.Comparator)3 List (java.util.List)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Predicate (java.util.function.Predicate)3 Pattern (java.util.regex.Pattern)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3 Result (org.fakekoji.functional.Result)3 OToolArchive (org.fakekoji.model.OToolArchive)3 Constants (hudson.plugins.scm.koji.Constants)2 Build (hudson.plugins.scm.koji.model.Build)2 BuildProvider (hudson.plugins.scm.koji.model.BuildProvider)2 RPM (hudson.plugins.scm.koji.model.RPM)2