Search in sources :

Example 1 with PatternMatcher

use of org.apache.ivy.plugins.matcher.PatternMatcher in project ant-ivy by apache.

the class DefaultRepositoryCacheManager method getChangingMatcher.

private Matcher getChangingMatcher(CacheMetadataOptions options) {
    String changingPattern = options.getChangingPattern() != null ? options.getChangingPattern() : this.changingPattern;
    if (changingPattern == null) {
        return NoMatcher.INSTANCE;
    }
    String changingMatcherName = options.getChangingMatcherName() != null ? options.getChangingMatcherName() : this.changingMatcherName;
    PatternMatcher matcher = settings.getMatcher(changingMatcherName);
    if (matcher == null) {
        throw new IllegalStateException("unknown matcher '" + changingMatcherName + "'. It is set as changing matcher in " + this);
    }
    return matcher.getMatcher(changingPattern);
}
Also used : ExactPatternMatcher(org.apache.ivy.plugins.matcher.ExactPatternMatcher) PatternMatcher(org.apache.ivy.plugins.matcher.PatternMatcher)

Example 2 with PatternMatcher

use of org.apache.ivy.plugins.matcher.PatternMatcher in project ant-ivy by apache.

the class InstallEngine method install.

public ResolveReport install(ModuleRevisionId mrid, String from, String to, InstallOptions options) throws IOException {
    DependencyResolver fromResolver = settings.getResolver(from);
    DependencyResolver toResolver = settings.getResolver(to);
    if (fromResolver == null) {
        throw new IllegalArgumentException("unknown resolver " + from + ". Available resolvers are: " + settings.getResolverNames());
    }
    if (toResolver == null) {
        throw new IllegalArgumentException("unknown resolver " + to + ". Available resolvers are: " + settings.getResolverNames());
    }
    PatternMatcher matcher = settings.getMatcher(options.getMatcherName());
    if (matcher == null) {
        throw new IllegalArgumentException("unknown matcher " + options.getMatcherName() + ". Available matchers are: " + settings.getMatcherNames());
    }
    // build module file declaring the dependency
    Message.info(":: installing " + mrid + " ::");
    DependencyResolver oldDictator = resolveEngine.getDictatorResolver();
    boolean log = settings.logNotConvertedExclusionRule();
    try {
        settings.setLogNotConvertedExclusionRule(true);
        resolveEngine.setDictatorResolver(fromResolver);
        DefaultModuleDescriptor md = new DefaultModuleDescriptor(ModuleRevisionId.newInstance("apache", "ivy-install", "1.0"), settings.getStatusManager().getDefaultStatus(), new Date());
        String resolveId = ResolveOptions.getDefaultResolveId(md);
        md.addConfiguration(new Configuration("default"));
        md.addConflictManager(new ModuleId(ExactPatternMatcher.ANY_EXPRESSION, ExactPatternMatcher.ANY_EXPRESSION), ExactPatternMatcher.INSTANCE, new NoConflictManager());
        for (String dc : options.getConfs()) {
            final String depConf = dc.trim();
            if (MatcherHelper.isExact(matcher, mrid)) {
                DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, mrid, false, false, options.isTransitive());
                dd.addDependencyConfiguration("default", depConf);
                md.addDependency(dd);
            } else {
                for (ModuleRevisionId imrid : searchEngine.listModules(fromResolver, mrid, matcher)) {
                    Message.info("\tfound " + imrid + " to install: adding to the list");
                    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, imrid, false, false, options.isTransitive());
                    dd.addDependencyConfiguration("default", depConf);
                    md.addDependency(dd);
                }
            }
        }
        // resolve using appropriate resolver
        ResolveReport report = new ResolveReport(md, resolveId);
        Message.info(":: resolving dependencies ::");
        ResolveOptions resolveOptions = new ResolveOptions().setResolveId(resolveId).setConfs(new String[] { "default" }).setValidate(options.isValidate());
        IvyNode[] dependencies = resolveEngine.getDependencies(md, resolveOptions, report);
        report.setDependencies(Arrays.asList(dependencies), options.getArtifactFilter());
        Message.info(":: downloading artifacts to cache ::");
        resolveEngine.downloadArtifacts(report, options.getArtifactFilter(), new DownloadOptions());
        // now that everything is in cache, we can publish all these modules
        Message.info(":: installing in " + to + " ::");
        for (IvyNode dependency : dependencies) {
            ModuleDescriptor depmd = dependency.getDescriptor();
            if (depmd != null) {
                ModuleRevisionId depMrid = depmd.getModuleRevisionId();
                Message.verbose("installing " + depMrid);
                boolean successfullyPublished = false;
                try {
                    toResolver.beginPublishTransaction(depMrid, options.isOverwrite());
                    // publish artifacts
                    for (ArtifactDownloadReport artifact : report.getArtifactsReports(depMrid)) {
                        if (artifact.getLocalFile() != null) {
                            toResolver.publish(artifact.getArtifact(), artifact.getLocalFile(), options.isOverwrite());
                        }
                    }
                    // publish metadata
                    MetadataArtifactDownloadReport artifactDownloadReport = dependency.getModuleRevision().getReport();
                    File localIvyFile = artifactDownloadReport.getLocalFile();
                    toResolver.publish(depmd.getMetadataArtifact(), localIvyFile, options.isOverwrite());
                    if (options.isInstallOriginalMetadata()) {
                        if (artifactDownloadReport.getArtifactOrigin() != null && artifactDownloadReport.getArtifactOrigin().isExists() && !ArtifactOrigin.isUnknown(artifactDownloadReport.getArtifactOrigin()) && artifactDownloadReport.getArtifactOrigin().getArtifact() != null && artifactDownloadReport.getArtifactOrigin().getArtifact().getType().endsWith(".original") && !artifactDownloadReport.getArtifactOrigin().getArtifact().getType().equals(depmd.getMetadataArtifact().getType() + ".original")) {
                            // publish original metadata artifact, too, as it has a different
                            // type
                            toResolver.publish(artifactDownloadReport.getArtifactOrigin().getArtifact(), artifactDownloadReport.getOriginalLocalFile(), options.isOverwrite());
                        }
                    }
                    // end module publish
                    toResolver.commitPublishTransaction();
                    successfullyPublished = true;
                } finally {
                    if (!successfullyPublished) {
                        toResolver.abortPublishTransaction();
                    }
                }
            }
        }
        Message.info(":: install resolution report ::");
        // output report
        resolveEngine.outputReport(report, settings.getResolutionCacheManager(), resolveOptions);
        return report;
    } finally {
        // IVY-834: log the problems if there were any...
        Message.sumupProblems();
        resolveEngine.setDictatorResolver(oldDictator);
        settings.setLogNotConvertedExclusionRule(log);
    }
}
Also used : MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) Date(java.util.Date) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) ModuleId(org.apache.ivy.core.module.id.ModuleId) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) NoConflictManager(org.apache.ivy.plugins.conflict.NoConflictManager) ResolveReport(org.apache.ivy.core.report.ResolveReport) DownloadOptions(org.apache.ivy.core.resolve.DownloadOptions) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ExactPatternMatcher(org.apache.ivy.plugins.matcher.ExactPatternMatcher) PatternMatcher(org.apache.ivy.plugins.matcher.PatternMatcher) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) File(java.io.File) IvyNode(org.apache.ivy.core.resolve.IvyNode)

Example 3 with PatternMatcher

use of org.apache.ivy.plugins.matcher.PatternMatcher in project ant-ivy by apache.

the class SearchEngine method findModuleRevisionIds.

public Collection<ModuleRevisionId> findModuleRevisionIds(DependencyResolver resolver, ModuleRevisionId pattern, PatternMatcher matcher) {
    Collection<ModuleRevisionId> mrids = new ArrayList<>();
    String resolverName = resolver.getName();
    Message.verbose("looking for modules matching " + pattern + " using " + matcher.getName());
    Namespace fromNamespace = null;
    if (resolver instanceof AbstractResolver) {
        fromNamespace = resolver.getNamespace();
    }
    Collection<ModuleEntry> modules = new ArrayList<>();
    OrganisationEntry[] orgs = resolver.listOrganisations();
    if (orgs == null || orgs.length == 0) {
        // hack for resolvers which are not able to list organisation, we try to see if the
        // asked organisation is not an exact one:
        String org = pattern.getOrganisation();
        if (fromNamespace != null) {
            org = NameSpaceHelper.transform(pattern.getModuleId(), fromNamespace.getFromSystemTransformer()).getOrganisation();
        }
        modules.addAll(Arrays.asList(resolver.listModules(new OrganisationEntry(resolver, org))));
    } else {
        Matcher orgMatcher = matcher.getMatcher(pattern.getOrganisation());
        for (OrganisationEntry oe : orgs) {
            String org = oe.getOrganisation();
            String systemOrg = (fromNamespace == null) ? org : NameSpaceHelper.transformOrganisation(org, fromNamespace.getToSystemTransformer());
            if (orgMatcher.matches(systemOrg)) {
                modules.addAll(Arrays.asList(resolver.listModules(new OrganisationEntry(resolver, org))));
            }
        }
    }
    Message.debug("found " + modules.size() + " modules for " + pattern.getOrganisation() + " on " + resolverName);
    boolean foundModule = false;
    for (ModuleEntry mEntry : modules) {
        ModuleId foundMid = new ModuleId(mEntry.getOrganisation(), mEntry.getModule());
        ModuleId systemMid = foundMid;
        if (fromNamespace != null) {
            systemMid = NameSpaceHelper.transform(foundMid, fromNamespace.getToSystemTransformer());
        }
        if (MatcherHelper.matches(matcher, pattern.getModuleId(), systemMid)) {
            // The module corresponds to the searched module pattern
            foundModule = true;
            RevisionEntry[] rEntries = resolver.listRevisions(mEntry);
            Message.debug("found " + rEntries.length + " revisions for [" + mEntry.getOrganisation() + ", " + mEntry.getModule() + "] on " + resolverName);
            boolean foundRevision = false;
            for (RevisionEntry rEntry : rEntries) {
                ModuleRevisionId foundMrid = ModuleRevisionId.newInstance(mEntry.getOrganisation(), mEntry.getModule(), rEntry.getRevision());
                ModuleRevisionId systemMrid = foundMrid;
                if (fromNamespace != null) {
                    systemMrid = fromNamespace.getToSystemTransformer().transform(foundMrid);
                }
                if (MatcherHelper.matches(matcher, pattern, systemMrid)) {
                    // We have a matching module revision
                    foundRevision = true;
                    mrids.add(systemMrid);
                }
            }
            if (!foundRevision) {
                Message.debug("no revision found matching " + pattern + " in [" + mEntry.getOrganisation() + "," + mEntry.getModule() + "] using " + resolverName);
            }
        }
    }
    if (!foundModule) {
        Message.debug("no module found matching " + pattern + " using " + resolverName);
    }
    return mrids;
}
Also used : Matcher(org.apache.ivy.plugins.matcher.Matcher) PatternMatcher(org.apache.ivy.plugins.matcher.PatternMatcher) ArrayList(java.util.ArrayList) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) Namespace(org.apache.ivy.plugins.namespace.Namespace) ModuleId(org.apache.ivy.core.module.id.ModuleId) AbstractResolver(org.apache.ivy.plugins.resolver.AbstractResolver)

Example 4 with PatternMatcher

use of org.apache.ivy.plugins.matcher.PatternMatcher in project ant-ivy by apache.

the class Match method getPatternMatcher.

public Matcher getPatternMatcher(ModuleRevisionId askedMrid) {
    String revision = askedMrid.getRevision();
    List<String> args = split(getArgs());
    List<String> argValues = getRevisionArgs(revision);
    if (args.size() != argValues.size()) {
        return new NoMatchMatcher();
    }
    Map<String, String> variables = new HashMap<>();
    for (String arg : args) {
        variables.put(arg, argValues.get(args.indexOf(arg)));
    }
    String pattern = getPattern();
    pattern = IvyPatternHelper.substituteVariables(pattern, variables);
    PatternMatcher pMatcher = IvyContext.getContext().getSettings().getMatcher(matcher);
    return pMatcher.getMatcher(pattern);
}
Also used : HashMap(java.util.HashMap) PatternMatcher(org.apache.ivy.plugins.matcher.PatternMatcher)

Example 5 with PatternMatcher

use of org.apache.ivy.plugins.matcher.PatternMatcher in project ant-ivy by apache.

the class IvyBuildNumber method doExecute.

public void doExecute() throws BuildException {
    if (organisation == null) {
        throw new BuildException("no organisation provided for ivy buildnumber task");
    }
    if (module == null) {
        throw new BuildException("no module name provided for ivy buildnumber task");
    }
    if (prefix == null) {
        throw new BuildException("null prefix not allowed");
    }
    Ivy ivy = getIvyInstance();
    IvySettings settings = ivy.getSettings();
    if (branch == null) {
        branch = settings.getDefaultBranch(new ModuleId(organisation, module));
    }
    if (isNullOrEmpty(revision)) {
        revision = "latest.integration";
    } else if (!revision.endsWith("+")) {
        revision += "+";
    }
    if (!prefix.endsWith(".") && !prefix.isEmpty()) {
        prefix += ".";
    }
    SearchEngine searcher = new SearchEngine(settings);
    PatternMatcher patternMatcher = new PatternMatcher() {

        private PatternMatcher exact = new ExactPatternMatcher();

        private PatternMatcher regexp = new ExactOrRegexpPatternMatcher();

        public Matcher getMatcher(String expression) {
            if (expression.equals(organisation) || expression.equals(module) || expression.equals(branch)) {
                return exact.getMatcher(expression);
            } else {
                return regexp.getMatcher(expression);
            }
        }

        public String getName() {
            return "buildnumber-matcher";
        }
    };
    String revisionPattern = ".*";
    if (revision.endsWith("+")) {
        revisionPattern = Pattern.quote(revision.substring(0, revision.length() - 1)) + ".*";
    }
    ModuleRevisionId mrid = ModuleRevisionId.newInstance(organisation, module, branch, revisionPattern);
    ModuleRevisionId[] revisions;
    if (resolver == null) {
        revisions = searcher.listModules(mrid, patternMatcher);
    } else {
        DependencyResolver depResolver = settings.getResolver(resolver);
        if (depResolver == null) {
            throw new BuildException("Unknown resolver: " + resolver);
        }
        revisions = searcher.listModules(depResolver, mrid, patternMatcher);
    }
    List<ArtifactInfo> infos = new ArrayList<>(revisions.length);
    for (ModuleRevisionId rev : revisions) {
        infos.add(new ResolvedModuleRevisionArtifactInfo(rev));
    }
    VersionMatcher matcher = settings.getVersionMatcher();
    LatestStrategy latestStrategy = settings.getLatestStrategy("latest-revision");
    List<ArtifactInfo> sorted = latestStrategy.sort(infos.toArray(new ArtifactInfo[revisions.length]));
    ModuleRevisionId askedMrid = ModuleRevisionId.newInstance(organisation, module, branch, revision);
    String foundRevision = null;
    ListIterator<ArtifactInfo> iter = sorted.listIterator(sorted.size());
    while (iter.hasPrevious()) {
        ResolvedModuleRevisionArtifactInfo info = (ResolvedModuleRevisionArtifactInfo) iter.previous();
        if (!matcher.accept(askedMrid, info.rmr)) {
            continue;
        }
        if (matcher.needModuleDescriptor(askedMrid, info.rmr)) {
            ResolvedModuleRevision rmr = ivy.findModule(info.rmr);
            if (matcher.accept(askedMrid, rmr.getDescriptor())) {
                foundRevision = info.rmr.getRevision();
            }
        } else {
            foundRevision = info.rmr.getRevision();
        }
        if (foundRevision != null) {
            break;
        }
    }
    NewRevision newRevision = computeNewRevision(foundRevision);
    setProperty("revision", newRevision.getRevision());
    setProperty("new.revision", newRevision.getNewRevision());
    setProperty("build.number", newRevision.getBuildNumber());
    setProperty("new.build.number", newRevision.getNewBuildNumber());
}
Also used : ExactPatternMatcher(org.apache.ivy.plugins.matcher.ExactPatternMatcher) ArrayList(java.util.ArrayList) IvySettings(org.apache.ivy.core.settings.IvySettings) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) Ivy(org.apache.ivy.Ivy) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) ModuleId(org.apache.ivy.core.module.id.ModuleId) ExactOrRegexpPatternMatcher(org.apache.ivy.plugins.matcher.ExactOrRegexpPatternMatcher) SearchEngine(org.apache.ivy.core.search.SearchEngine) ArtifactInfo(org.apache.ivy.plugins.latest.ArtifactInfo) VersionMatcher(org.apache.ivy.plugins.version.VersionMatcher) LatestStrategy(org.apache.ivy.plugins.latest.LatestStrategy) BuildException(org.apache.tools.ant.BuildException) ExactPatternMatcher(org.apache.ivy.plugins.matcher.ExactPatternMatcher) ExactOrRegexpPatternMatcher(org.apache.ivy.plugins.matcher.ExactOrRegexpPatternMatcher) PatternMatcher(org.apache.ivy.plugins.matcher.PatternMatcher)

Aggregations

PatternMatcher (org.apache.ivy.plugins.matcher.PatternMatcher)6 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)4 ModuleId (org.apache.ivy.core.module.id.ModuleId)3 ExactPatternMatcher (org.apache.ivy.plugins.matcher.ExactPatternMatcher)3 DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)3 ArrayList (java.util.ArrayList)2 Ivy (org.apache.ivy.Ivy)2 SearchEngine (org.apache.ivy.core.search.SearchEngine)2 IvySettings (org.apache.ivy.core.settings.IvySettings)2 BuildException (org.apache.tools.ant.BuildException)2 File (java.io.File)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Configuration (org.apache.ivy.core.module.descriptor.Configuration)1 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)1 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)1 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)1 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)1 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)1 ResolveReport (org.apache.ivy.core.report.ResolveReport)1