Search in sources :

Example 1 with SearchEngine

use of org.apache.ivy.core.search.SearchEngine in project ant-ivy by apache.

the class RepositoryManagementEngineTest method setUp.

@Before
public void setUp() {
    fixture = new TestFixture();
    IvySettings settings = fixture.getSettings();
    repository = new RepositoryManagementEngine(settings, new SearchEngine(settings), new ResolveEngine(settings, new EventManager(), new SortEngine(settings)));
}
Also used : ResolveEngine(org.apache.ivy.core.resolve.ResolveEngine) SortEngine(org.apache.ivy.core.sort.SortEngine) SearchEngine(org.apache.ivy.core.search.SearchEngine) EventManager(org.apache.ivy.core.event.EventManager) IvySettings(org.apache.ivy.core.settings.IvySettings) TestFixture(org.apache.ivy.TestFixture) Before(org.junit.Before)

Example 2 with SearchEngine

use of org.apache.ivy.core.search.SearchEngine 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)

Example 3 with SearchEngine

use of org.apache.ivy.core.search.SearchEngine in project ant-ivy by apache.

the class IvyListModules method doExecute.

public void doExecute() throws BuildException {
    if (organisation == null) {
        throw new BuildException("no organisation provided for ivy listmodules task");
    }
    if (module == null) {
        throw new BuildException("no module name provided for ivy listmodules task");
    }
    if (revision == null) {
        throw new BuildException("no revision provided for ivy listmodules task");
    }
    if (property == null) {
        throw new BuildException("no property provided for ivy listmodules task");
    }
    if (value == null) {
        throw new BuildException("no value provided for ivy listmodules task");
    }
    Ivy ivy = getIvyInstance();
    IvySettings settings = ivy.getSettings();
    SearchEngine searcher = new SearchEngine(settings);
    PatternMatcher patternMatcher = settings.getMatcher(matcher);
    ModuleRevisionId[] mrids;
    if (resolver == null) {
        mrids = searcher.listModules(ModuleRevisionId.newInstance(organisation, module, branch, revision), patternMatcher);
    } else {
        DependencyResolver depResolver = settings.getResolver(resolver);
        if (depResolver == null) {
            throw new BuildException("Unknown resolver: " + resolver);
        }
        mrids = searcher.listModules(depResolver, ModuleRevisionId.newInstance(organisation, module, branch, revision), patternMatcher);
    }
    for (ModuleRevisionId mrid : mrids) {
        String name = IvyPatternHelper.substitute(settings.substitute(property), mrid);
        String value = IvyPatternHelper.substitute(settings.substitute(this.value), mrid);
        getProject().setProperty(name, value);
    }
}
Also used : SearchEngine(org.apache.ivy.core.search.SearchEngine) IvySettings(org.apache.ivy.core.settings.IvySettings) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) BuildException(org.apache.tools.ant.BuildException) Ivy(org.apache.ivy.Ivy) PatternMatcher(org.apache.ivy.plugins.matcher.PatternMatcher) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 4 with SearchEngine

use of org.apache.ivy.core.search.SearchEngine in project ant-ivy by apache.

the class Ivy method bind.

/**
 * This method is used to bind this Ivy instance to required dependencies, i.e. instance of
 * settings, engines, and so on.
 * <p>
 * After this call Ivy is still not configured, which means that the settings object is still
 * empty.
 * </p>
 */
public void bind() {
    pushContext();
    try {
        if (settings == null) {
            settings = new IvySettings();
        }
        if (eventManager == null) {
            eventManager = new EventManager();
        }
        if (sortEngine == null) {
            sortEngine = new SortEngine(settings);
        }
        if (searchEngine == null) {
            searchEngine = new SearchEngine(settings);
        }
        if (resolveEngine == null) {
            resolveEngine = new ResolveEngine(settings, eventManager, sortEngine);
        }
        if (retrieveEngine == null) {
            retrieveEngine = new RetrieveEngine(settings, eventManager);
        }
        if (deliverEngine == null) {
            deliverEngine = new DeliverEngine(settings);
        }
        if (publishEngine == null) {
            publishEngine = new PublishEngine(settings, eventManager);
        }
        if (installEngine == null) {
            installEngine = new InstallEngine(settings, searchEngine, resolveEngine);
        }
        if (repositoryEngine == null) {
            repositoryEngine = new RepositoryManagementEngine(settings, searchEngine, resolveEngine);
        }
        eventManager.addTransferListener(new TransferListener() {

            public void transferProgress(TransferEvent evt) {
                ResolveData resolve;
                switch(evt.getEventType()) {
                    case TransferEvent.TRANSFER_PROGRESS:
                        resolve = IvyContext.getContext().getResolveData();
                        if (resolve == null || !LogOptions.LOG_QUIET.equals(resolve.getOptions().getLog())) {
                            Message.progress();
                        }
                        break;
                    case TransferEvent.TRANSFER_COMPLETED:
                        resolve = IvyContext.getContext().getResolveData();
                        if (resolve == null || !LogOptions.LOG_QUIET.equals(resolve.getOptions().getLog())) {
                            Message.endProgress(" (" + (evt.getTotalLength() / KILO) + "kB)");
                        }
                        break;
                    default:
                        break;
                }
            }
        });
        bound = true;
    } finally {
        popContext();
    }
}
Also used : TransferListener(org.apache.ivy.plugins.repository.TransferListener) EventManager(org.apache.ivy.core.event.EventManager) DeliverEngine(org.apache.ivy.core.deliver.DeliverEngine) TransferEvent(org.apache.ivy.plugins.repository.TransferEvent) IvySettings(org.apache.ivy.core.settings.IvySettings) ResolveEngine(org.apache.ivy.core.resolve.ResolveEngine) RetrieveEngine(org.apache.ivy.core.retrieve.RetrieveEngine) RepositoryManagementEngine(org.apache.ivy.core.repository.RepositoryManagementEngine) SortEngine(org.apache.ivy.core.sort.SortEngine) ResolveData(org.apache.ivy.core.resolve.ResolveData) SearchEngine(org.apache.ivy.core.search.SearchEngine) PublishEngine(org.apache.ivy.core.publish.PublishEngine) InstallEngine(org.apache.ivy.core.install.InstallEngine)

Aggregations

SearchEngine (org.apache.ivy.core.search.SearchEngine)4 IvySettings (org.apache.ivy.core.settings.IvySettings)4 Ivy (org.apache.ivy.Ivy)2 EventManager (org.apache.ivy.core.event.EventManager)2 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)2 ResolveEngine (org.apache.ivy.core.resolve.ResolveEngine)2 SortEngine (org.apache.ivy.core.sort.SortEngine)2 PatternMatcher (org.apache.ivy.plugins.matcher.PatternMatcher)2 DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)2 BuildException (org.apache.tools.ant.BuildException)2 ArrayList (java.util.ArrayList)1 TestFixture (org.apache.ivy.TestFixture)1 DeliverEngine (org.apache.ivy.core.deliver.DeliverEngine)1 InstallEngine (org.apache.ivy.core.install.InstallEngine)1 ModuleId (org.apache.ivy.core.module.id.ModuleId)1 PublishEngine (org.apache.ivy.core.publish.PublishEngine)1 RepositoryManagementEngine (org.apache.ivy.core.repository.RepositoryManagementEngine)1 ResolveData (org.apache.ivy.core.resolve.ResolveData)1 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)1 RetrieveEngine (org.apache.ivy.core.retrieve.RetrieveEngine)1