All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.boothub.repo.SingleSkeletonRepo.groovy Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2018 the original author or authors.
 *
 * Licensed 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.boothub.repo

import org.boothub.Result

class SingleSkeletonRepo implements SkeletonRepo {
    private final String skeletonId
    private final SkeletonGroup skeletonGroup

    SingleSkeletonRepo(String baseRepoDir = '.') {
        def repoPath = System.properties['boothubRepoPath']
        if(!repoPath) throw new IllegalArgumentException("System property boothubRepoPath not set")
        def dir = new File(repoPath)
        if(!dir.directory) throw new IllegalArgumentException("Directory not found: $dir.absolutePath")
        def repoEntry = RepoEntry.fromDir(dir)
        this.skeletonId = repoEntry.id
        this.skeletonGroup = new SkeletonGroup(name: repoEntry.name, caption: repoEntry.caption, entries: [(repoEntry.version): repoEntry])
    }

    @Override
    Result> getSkeletons(SkeletonSearchOptions options) {
        if (options.skeletonId && skeletonId != options.skeletonId) return [:]
        if (options.version && skeletonGroup.entries[0].version != options.version) return [:]
        if(options.searchPattern) {
            skeletonGroup.keepOnlyMatches(options.searchPattern)
        }
        new Result(type: Result.Type.SUCCESS, value: [(this.skeletonId): skeletonGroup])
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy