Search in sources :

Example 6 with Reporter

use of aQute.service.reporter.Reporter in project bndtools by bndtools.

the class ReposTemplateLoader method findTemplates.

@Override
public Promise<List<Template>> findTemplates(String templateType, final Reporter reporter) {
    String filterStr = String.format("(%s=%s)", NS_TEMPLATE, templateType);
    final Requirement requirement = new CapReqBuilder(NS_TEMPLATE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filterStr).buildSyntheticRequirement();
    // Try to get the repositories and BundleLocator from the workspace
    List<Repository> workspaceRepos;
    BundleLocator tmpLocator;
    try {
        if (workspace == null)
            workspace = Central.getWorkspace();
        workspaceRepos = workspace.getPlugins(Repository.class);
        tmpLocator = new RepoPluginsBundleLocator(workspace.getRepositories());
    } catch (Exception e) {
        workspaceRepos = Collections.emptyList();
        tmpLocator = new DirectDownloadBundleLocator();
    }
    final BundleLocator locator = tmpLocator;
    // Setup the repos
    List<Repository> repos = new ArrayList<>(workspaceRepos.size() + 1);
    repos.addAll(workspaceRepos);
    addPreferenceConfiguredRepos(repos, reporter);
    // Map List<Repository> to Promise<List<Template>>
    Promise<List<Template>> promise = repos.stream().map(repo -> promiseFactory.submit(() -> {
        Map<Requirement, Collection<Capability>> providerMap = repo.findProviders(Collections.singleton(requirement));
        return providerMap.get(requirement).stream().map(cap -> {
            IdentityCapability idcap = ResourceUtils.getIdentityCapability(cap.getResource());
            Object id = idcap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
            Object ver = idcap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
            try {
                String engineName = (String) cap.getAttributes().get("engine");
                if (engineName == null)
                    engineName = "stringtemplate";
                TemplateEngine engine = engines.get(engineName);
                if (engine != null)
                    return new CapabilityBasedTemplate(cap, locator, engine);
                reporter.error("Error loading template from resource '%s' version %s: no Template Engine available matching '%s'", id, ver, engineName);
            } catch (Exception e) {
                reporter.error("Error loading template from resource '%s' version %s: %s", id, ver, e.getMessage());
            }
            return null;
        }).filter(Objects::nonNull).collect(toList());
    })).collect(toPromise(promiseFactory)).map(ll -> ll.stream().flatMap(List::stream).collect(toList()));
    return promise;
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) ResourceUtils(aQute.bnd.osgi.resource.ResourceUtils) PromiseCollectors.toPromise(aQute.lib.promise.PromiseCollectors.toPromise) Constants(org.osgi.framework.Constants) IdentityNamespace(org.osgi.framework.namespace.IdentityNamespace) BndPreferences(bndtools.preferences.BndPreferences) HashMap(java.util.HashMap) Template(org.bndtools.templating.Template) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Capability(org.osgi.resource.Capability) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) TemplateLoader(org.bndtools.templating.TemplateLoader) Component(org.osgi.service.component.annotations.Component) OSGiRepository(aQute.bnd.repository.osgi.OSGiRepository) Workspace(aQute.bnd.build.Workspace) Map(java.util.Map) PromiseFactory(org.osgi.util.promise.PromiseFactory) Activate(org.osgi.service.component.annotations.Activate) Repository(org.osgi.service.repository.Repository) ExecutorService(java.util.concurrent.ExecutorService) HttpClient(aQute.bnd.http.HttpClient) Processor(aQute.bnd.osgi.Processor) Reporter(aQute.service.reporter.Reporter) Deactivate(org.osgi.service.component.annotations.Deactivate) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Central(bndtools.central.Central) Collection(java.util.Collection) TemplateEngine(org.bndtools.templating.TemplateEngine) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Namespace(org.osgi.resource.Namespace) ReferencePolicy(org.osgi.service.component.annotations.ReferencePolicy) Executors(java.util.concurrent.Executors) Promise(org.osgi.util.promise.Promise) Objects(java.util.Objects) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ReferencePolicyOption(org.osgi.service.component.annotations.ReferencePolicyOption) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) Strings(aQute.lib.strings.Strings) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) ArrayList(java.util.ArrayList) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Requirement(org.osgi.resource.Requirement) TemplateEngine(org.bndtools.templating.TemplateEngine) OSGiRepository(aQute.bnd.repository.osgi.OSGiRepository) Repository(org.osgi.service.repository.Repository) Objects(java.util.Objects) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 7 with Reporter

use of aQute.service.reporter.Reporter in project bndtools by bndtools.

the class GitHubWorkspaceTemplateLoader method findTemplates.

@Override
public Promise<List<Template>> findTemplates(String type, Reporter reporter) {
    if (!TEMPLATE_TYPE.equals(type)) {
        return promiseFactory.resolved(Collections.emptyList());
    }
    GitHub gitHub = new GitHub(cache, promiseFactory);
    Parameters githubRepos = new GitRepoPreferences().getGithubRepos();
    return githubRepos.entrySet().stream().map(entry -> {
        String repo = GitRepoPreferences.removeDuplicateMarker(entry.getKey());
        Attrs attribs = entry.getValue();
        return gitHub.loadRepoDetails(repo).map(detailsDTO -> {
            if (detailsDTO.clone_url == null)
                throw new IllegalArgumentException("Missing clone URL");
            // Generate icon URI from the owner avatar. The s=16 parameter
            // is added to select a 16x16 icon.
            URI avatarUri = null;
            if (detailsDTO.owner.avatar_url != null)
                avatarUri = URI.create(detailsDTO.owner.avatar_url + "&s=16");
            String name = attribs.get("name");
            if (name == null)
                name = repo;
            String branch = attribs.get("branch");
            final GitCloneTemplateParams params = new GitCloneTemplateParams();
            params.cloneUrl = detailsDTO.clone_url;
            if (branch != null)
                params.branch = branch;
            else
                params.branch = "origin/" + detailsDTO.default_branch;
            params.name = name;
            params.category = "GitHub";
            params.iconUri = avatarUri;
            if (detailsDTO.html_url != null) {
                params.helpUri = createHelpUri(repo, detailsDTO.html_url);
            }
            return (Template) new GitCloneTemplate(params);
        });
    }).collect(toPromise(promiseFactory));
}
Also used : Parameters(aQute.bnd.header.Parameters) PromiseCollectors.toPromise(aQute.lib.promise.PromiseCollectors.toPromise) Constants(org.osgi.framework.Constants) Reporter(aQute.service.reporter.Reporter) Deactivate(org.osgi.service.component.annotations.Deactivate) Base64(aQute.lib.base64.Base64) Template(org.bndtools.templating.Template) Executors(java.util.concurrent.Executors) Promise(org.osgi.util.promise.Promise) Objects(java.util.Objects) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TemplateLoader(org.bndtools.templating.TemplateLoader) List(java.util.List) Component(org.osgi.service.component.annotations.Component) Attrs(aQute.bnd.header.Attrs) PromiseFactory(org.osgi.util.promise.PromiseFactory) Activate(org.osgi.service.component.annotations.Activate) ReferencePolicyOption(org.osgi.service.component.annotations.ReferencePolicyOption) URI(java.net.URI) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) ExecutorService(java.util.concurrent.ExecutorService) Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) URI(java.net.URI)

Example 8 with Reporter

use of aQute.service.reporter.Reporter in project felix by apache.

the class AbstractBaselinePlugin method execute.

protected void execute(Object context) throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().info("Skipping Baseline execution");
        return;
    }
    if (!supportedProjectTypes.contains(project.getArtifact().getType())) {
        getLog().info("Skipping Baseline (project type " + project.getArtifact().getType() + " not supported)");
        return;
    }
    // get the bundles that have to be compared
    final Jar currentBundle = getCurrentBundle();
    if (currentBundle == null) {
        getLog().info("Not generating Baseline report as there is no bundle generated by the project");
        return;
    }
    final Artifact previousArtifact = getPreviousArtifact();
    final Jar previousBundle;
    if (previousArtifact != null) {
        previousBundle = openJar(previousArtifact.getFile());
    } else {
        previousBundle = null;
    }
    if (previousBundle == null) {
        getLog().info("Not generating Baseline report as there is no previous version of the library to compare against");
        return;
    }
    // preparing the filters
    final Instructions packageFilters;
    if (filters == null || filters.length == 0) {
        packageFilters = new Instructions();
    } else {
        packageFilters = new Instructions(Arrays.asList(filters));
    }
    String generationDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'").format(new Date());
    final Reporter reporter = new Processor();
    final Info[] infos;
    try {
        final Set<Info> infoSet = new Baseline(reporter, new DiffPluginImpl()).baseline(currentBundle, previousBundle, packageFilters);
        infos = infoSet.toArray(new Info[infoSet.size()]);
        Arrays.sort(infos, new InfoComparator());
    } catch (final Exception e) {
        throw new MojoExecutionException("Impossible to calculate the baseline", e);
    } finally {
        closeJars(currentBundle, previousBundle);
    }
    try {
        // go!
        context = this.init(context);
        startBaseline(context, generationDate, project.getArtifactId(), project.getVersion(), previousArtifact.getVersion());
        for (final Info info : infos) {
            DiffMessage diffMessage = null;
            if (info.suggestedVersion != null) {
                if (info.newerVersion.compareTo(info.suggestedVersion) > 0) {
                    diffMessage = new DiffMessage("Excessive version increase", DiffMessage.Type.warning);
                    reporter.warning("%s: %s; detected %s, suggested %s", info.packageName, diffMessage, info.newerVersion, info.suggestedVersion);
                } else if (info.newerVersion.compareTo(info.suggestedVersion) < 0) {
                    diffMessage = new DiffMessage("Version increase required", DiffMessage.Type.error);
                    reporter.error("%s: %s; detected %s, suggested %s", info.packageName, diffMessage, info.newerVersion, info.suggestedVersion);
                }
            }
            switch(info.packageDiff.getDelta()) {
                case UNCHANGED:
                    if (info.newerVersion.compareTo(info.suggestedVersion) != 0) {
                        diffMessage = new DiffMessage("Version has been increased but analysis detected no changes", DiffMessage.Type.warning);
                        reporter.warning("%s: %s; detected %s, suggested %s", info.packageName, diffMessage, info.newerVersion, info.suggestedVersion);
                    }
                    break;
                case REMOVED:
                    diffMessage = new DiffMessage("Package removed", DiffMessage.Type.info);
                    reporter.trace("%s: %s ", info.packageName, diffMessage);
                    break;
                case CHANGED:
                case MICRO:
                case MINOR:
                case MAJOR:
                case ADDED:
                default:
                    // ok
                    break;
            }
            startPackage(context, info.mismatch, info.packageName, getShortDelta(info.packageDiff.getDelta()), StringUtils.lowerCase(String.valueOf(info.packageDiff.getDelta())), info.newerVersion, info.olderVersion, info.suggestedVersion, diffMessage, info.attributes);
            if (Delta.REMOVED != info.packageDiff.getDelta()) {
                doPackageDiff(context, info.packageDiff);
            }
            endPackage(context);
        }
        endBaseline(context);
    } finally {
        this.close(context);
    }
    // check if it has to fail if some error has been detected
    boolean fail = false;
    if (!reporter.isOk()) {
        for (String errorMessage : reporter.getErrors()) {
            getLog().error(errorMessage);
        }
        if (failOnError) {
            fail = true;
        }
    }
    if (!reporter.getWarnings().isEmpty()) {
        for (String warningMessage : reporter.getWarnings()) {
            getLog().warn(warningMessage);
        }
        if (failOnWarning) {
            fail = true;
        }
    }
    getLog().info(String.format("Baseline analysis complete, %s error(s), %s warning(s)", reporter.getErrors().size(), reporter.getWarnings().size()));
    if (fail) {
        throw new MojoFailureException("Baseline failed, see generated report");
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Reporter(aQute.service.reporter.Reporter) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Instructions(aQute.bnd.osgi.Instructions) Info(aQute.bnd.differ.Baseline.Info) Baseline(aQute.bnd.differ.Baseline) Artifact(org.apache.maven.artifact.Artifact) Date(java.util.Date) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) OverConstrainedVersionException(org.apache.maven.artifact.versioning.OverConstrainedVersionException) ArtifactMetadataRetrievalException(org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException) DiffPluginImpl(aQute.bnd.differ.DiffPluginImpl) Jar(aQute.bnd.osgi.Jar) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Reporter (aQute.service.reporter.Reporter)8 ReporterAdapter (aQute.libg.reporter.ReporterAdapter)3 Baseline (aQute.bnd.differ.Baseline)2 DiffPluginImpl (aQute.bnd.differ.DiffPluginImpl)2 Jar (aQute.bnd.osgi.Jar)2 Processor (aQute.bnd.osgi.Processor)2 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)2 CommandLine (aQute.lib.getopt.CommandLine)2 PromiseCollectors.toPromise (aQute.lib.promise.PromiseCollectors.toPromise)2 Sed (aQute.libg.sed.Sed)2 File (java.io.File)2 Method (java.lang.reflect.Method)2 Collections (java.util.Collections)2 List (java.util.List)2 Objects (java.util.Objects)2 ExecutorService (java.util.concurrent.ExecutorService)2 Executors (java.util.concurrent.Executors)2 Template (org.bndtools.templating.Template)2 TemplateLoader (org.bndtools.templating.TemplateLoader)2 Constants (org.osgi.framework.Constants)2