public Collection publish()

in src/java/org/apache/ivy/core/publish/PublishEngine.java [84:180]


    public Collection<Artifact> publish(ModuleRevisionId mrid,
            Collection<String> srcArtifactPattern, String resolverName, PublishOptions options)
            throws IOException {
        Message.info(":: publishing :: " + mrid.getModuleId());
        Message.verbose("\tvalidate = " + options.isValidate());
        long start = System.currentTimeMillis();

        options.setSrcIvyPattern(settings.substitute(options.getSrcIvyPattern()));
        if (options.getPubBranch() == null) {
            options.setPubbranch(mrid.getBranch());
        }
        if (options.getPubrevision() == null) {
            options.setPubrevision(mrid.getRevision());
        }
        ModuleRevisionId pubmrid = ModuleRevisionId.newInstance(mrid, options.getPubBranch(),
            options.getPubrevision());

        // let's find the resolved module descriptor
        ModuleDescriptor md = null;
        if (options.getSrcIvyPattern() != null) {
            File ivyFile = settings.resolveFile(IvyPatternHelper.substitute(
                options.getSrcIvyPattern(), DefaultArtifact.newIvyArtifact(pubmrid, new Date())));
            if (!ivyFile.exists()) {
                throw new IllegalArgumentException("ivy file to publish not found for " + mrid
                        + ": call deliver before (" + ivyFile + ")");
            }

            URL ivyFileURL = ivyFile.toURI().toURL();
            try {
                md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyFileURL,
                    false);

                if (options.isUpdate()) {
                    File tmp = File.createTempFile("ivy", ".xml");
                    tmp.deleteOnExit();

                    String[] confs = replaceWildcards(options.getConfs(), md);
                    Set<String> confsToRemove = new HashSet<>(Arrays.asList(md
                            .getConfigurationsNames()));
                    confsToRemove.removeAll(Arrays.asList(confs));

                    try {
                        XmlModuleDescriptorUpdater.update(
                            ivyFileURL,
                            tmp,
                            new UpdateOptions()
                                    .setSettings(settings)
                                    .setStatus(options.getStatus() == null ? md.getStatus()
                                            : options.getStatus())
                                    .setRevision(options.getPubrevision())
                                    .setBranch(options.getPubBranch())
                                    .setPubdate(options.getPubdate() == null ? new Date()
                                            : options.getPubdate())
                                    .setMerge(options.isMerge())
                                    .setMergedDescriptor(md)
                                    .setConfsToExclude(
                                        confsToRemove.toArray(new String[confsToRemove.size()])));
                        ivyFile = tmp;
                        // we parse the new file to get updated module descriptor
                        md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
                            ivyFile.toURI().toURL(), false);
                        options.setSrcIvyPattern(ivyFile.getAbsolutePath());
                    } catch (SAXException e) {
                        throw new IllegalStateException("bad ivy file for " + mrid + ": " + ivyFile
                                + ": " + e);
                    }
                } else if (!options.getPubrevision().equals(md.getModuleRevisionId().getRevision())) {
                    throw new IllegalArgumentException("cannot publish " + ivyFile + " as "
                            + options.getPubrevision()
                            + ": bad revision found in ivy file (Revision: "
                            + md.getModuleRevisionId().getRevision()
                            + "). Use forcedeliver or update.");
                }
            } catch (ParseException e) {
                throw new IllegalStateException("bad ivy file for " + mrid + ": " + ivyFile + ": "
                        + e);
            }
        } else {
            ResolutionCacheManager cacheManager = settings.getResolutionCacheManager();
            try {
                md = cacheManager.getResolvedModuleDescriptor(mrid);
            } catch (ParseException e) {
                throw new IllegalStateException("bad ivy file in cache for " + mrid + ": " + e);
            }
            md.setResolvedModuleRevisionId(pubmrid);
        }

        DependencyResolver resolver = settings.getResolver(resolverName);
        if (resolver == null) {
            throw new IllegalArgumentException("unknown resolver " + resolverName);
        }

        // collect all declared artifacts of this module
        Collection<Artifact> missing = publish(md, srcArtifactPattern, resolver, options);
        Message.verbose("\tpublish done (" + (System.currentTimeMillis() - start) + "ms)");
        return missing;
    }