Package org.apache.ivy.core.module.descriptor

Examples of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor


     * @see <a href="https://issues.apache.org/jira/browse/IVY-1207">IVY-1207</a>
     * @throws Exception
     */
    public void testTransitiveAttributeNotWrittenForTransitiveConfs() throws Exception {
        // Given a ModuleDescriptor with a transitive configuration
        DefaultModuleDescriptor md = new DefaultModuleDescriptor(new ModuleRevisionId(new ModuleId(
                "myorg", "myname"), "1.0"), "integration", new Date());
        Configuration conf = new Configuration("conf", Visibility.PUBLIC, "desc", null, true, null);
        md.addConfiguration(conf);

        // When the ModuleDescriptor is written
        XmlModuleDescriptorWriter.write(md, LICENSE, dest);

        // Then the transitive attribute must NOT be written
View Full Code Here


            }
        }

        public void setResource(Resource res) {
            this.res = res; // used for log and date only
            md = new DefaultModuleDescriptor(parser, res);
            md.setLastModified(ResourceHelper.getLastModifiedOrDefault(res));
        }
View Full Code Here

        File ivyfile;
        if (line.hasOption("dependency")) {
            String[] dep = line.getOptionValues("dependency");
            ivyfile = File.createTempFile("ivy", ".xml");
            ivyfile.deleteOnExit();
            DefaultModuleDescriptor md = DefaultModuleDescriptor
                    .newDefaultInstance(ModuleRevisionId.newInstance(dep[0], dep[1] + "-caller",
                        "working"));
            DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md,
                    ModuleRevisionId.newInstance(dep[0], dep[1], dep[2]), false, false, true);
            for (int i = 0; i < confs.length; i++) {
                dd.addDependencyConfiguration("default", confs[i]);
            }
            md.addDependency(dd);
            XmlModuleDescriptorWriter.write(md, ivyfile);
            confs = new String[] {"default"};
        } else {
            ivyfile = new File(settings.substitute(line.getOptionValue("ivy", "ivy.xml")));
            if (!ivyfile.exists()) {
                error("ivy file not found: " + ivyfile);
            } else if (ivyfile.isDirectory()) {
                error("ivy file is not a file: " + ivyfile);
            }
        }

        if (line.hasOption("useOrigin")) {
            ivy.getSettings().useDeprecatedUseOrigin();
        }
        ResolveOptions resolveOptions = new ResolveOptions()
                .setConfs(confs)
                .setValidate(validate)
                .setResolveMode(line.getOptionValue("mode"))
                .setArtifactFilter(
                    FilterHelper.getArtifactTypeFilter(line.getOptionValues("types")));
        if (line.hasOption("notransitive")) {
            resolveOptions.setTransitive(false);
        }
        if (line.hasOption("refresh")) {
            resolveOptions.setRefresh(true);
        }
        ResolveReport report = ivy.resolve(ivyfile.toURI().toURL(), resolveOptions);
        if (report.hasError()) {
            System.exit(1);
        }
        ModuleDescriptor md = report.getModuleDescriptor();

        if (confs.length == 1 && "*".equals(confs[0])) {
            confs = md.getConfigurationsNames();
        }
        if (line.hasOption("retrieve")) {
            String retrievePattern = settings.substitute(line.getOptionValue("retrieve"));
            if (retrievePattern.indexOf("[") == -1) {
                retrievePattern = retrievePattern + "/lib/[conf]/[artifact].[ext]";
            }
            String ivyPattern = settings.substitute(line.getOptionValue("ivypattern"));
            ivy.retrieve(
                md.getModuleRevisionId(),
                retrievePattern,
                new RetrieveOptions()
                        .setConfs(confs)
                        .setSync(line.hasOption("sync"))
                        .setUseOrigin(line.hasOption("useOrigin"))
                        .setDestIvyPattern(ivyPattern)
                        .setArtifactFilter(
                            FilterHelper.getArtifactTypeFilter(line.getOptionValues("types")))
                        .setMakeSymlinks(line.hasOption("symlink"))
                        .setMakeSymlinksInMass(line.hasOption("symlinkmass")));
        }
        if (line.hasOption("cachepath")) {
            outputCachePath(ivy, cache, md, confs,
                line.getOptionValue("cachepath", "ivycachepath.txt"));
        }

        if (line.hasOption("revision")) {
            ivy.deliver(
                md.getResolvedModuleRevisionId(),
                settings.substitute(line.getOptionValue("revision")),
                settings.substitute(line.getOptionValue("deliverto", "ivy-[revision].xml")),
                DeliverOptions.newInstance(settings)
                        .setStatus(settings.substitute(line.getOptionValue("status", "release")))
                        .setValidate(validate));
            if (line.hasOption("publish")) {
                ivy.publish(
                    md.getResolvedModuleRevisionId(),
                    Collections.singleton(settings.substitute(line.getOptionValue("publishpattern",
                        "distrib/[type]s/[artifact]-[revision].[ext]"))),
                    line.getOptionValue("publish"),
                    new PublishOptions()
                            .setPubrevision(settings.substitute(line.getOptionValue("revision")))
View Full Code Here

        out.println("\t\tpublication=\"" + DateUtil.format(md.getResolvedPublicationDate()) + "\"");
        if (md.isDefault()) {
            out.println("\t\tdefault=\"true\"");
        }
        if (md instanceof DefaultModuleDescriptor) {
            DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md;
            if (dmd.getNamespace() != null && !dmd.getNamespace().getName().equals("system")) {
                out.println("\t\tnamespace=\"" + XMLHelper.escape(dmd.getNamespace().getName())
                        + "\"");
            }
        }
        if (!md.getExtraAttributes().isEmpty()) {
            printExtraAttributes(md, out, "\t\t");
View Full Code Here

     * @throws ProfileNotFoundException
     */
    public static DefaultModuleDescriptor toModuleDescriptor(ModuleDescriptorParser parser,
            URI baseUri, BundleInfo bundle, ExecutionEnvironmentProfileProvider profileProvider)
            throws ProfileNotFoundException {
        DefaultModuleDescriptor md = new DefaultModuleDescriptor(parser, null);
        md.addExtraAttributeNamespace("o", Ivy.getIvyHomeURL() + "osgi");
        ModuleRevisionId mrid = asMrid(BundleInfo.BUNDLE_TYPE, bundle.getSymbolicName(),
            bundle.getVersion());
        md.setResolvedPublicationDate(new Date());
        md.setModuleRevisionId(mrid);

        md.addConfiguration(CONF_DEFAULT);
        md.addConfiguration(CONF_OPTIONAL);
        md.addConfiguration(CONF_TRANSITIVE_OPTIONAL);

        Set<String> exportedPkgNames = new HashSet<String>(bundle.getExports().size());
        for (ExportPackage exportPackage : bundle.getExports()) {
            md.getExtraInfo().put(EXTRA_INFO_EXPORT_PREFIX + exportPackage.getName(),
                exportPackage.getVersion().toString());
            exportedPkgNames.add(exportPackage.getName());
            String[] confDependencies = new String[exportPackage.getUses().size() + 1];
            int i = 0;
            for (String use : exportPackage.getUses()) {
                confDependencies[i++] = CONF_USE_PREFIX + use;
            }
            confDependencies[i] = CONF_NAME_DEFAULT;
            md.addConfiguration(new Configuration(CONF_USE_PREFIX + exportPackage.getName(),
                    Visibility.PUBLIC, "Exported package " + exportPackage.getName(),
                    confDependencies, true, null));
        }

        requirementAsDependency(md, bundle, exportedPkgNames);

        if (baseUri != null) {
            for (BundleArtifact bundleArtifact : bundle.getArtifacts()) {
                String type = "jar";
                String ext = "jar";
                String packaging = null;
                if (bundle.hasInnerClasspath()) {
                    packaging = "zip";
                }
                if ("packed".equals(bundleArtifact.getFormat())) {
                    ext = "jar.pack.gz";
                    if (packaging != null) {
                        packaging += ",pack200";
                    } else {
                        packaging = "pack200";
                    }
                }
                if (bundleArtifact.isSource()) {
                    type = "source";
                }
                URI uri = bundleArtifact.getUri();
                if (uri != null) {
                    DefaultArtifact artifact = buildArtifact(mrid, baseUri, uri, type, ext,
                        packaging);
                    md.addArtifact(CONF_NAME_DEFAULT, artifact);
                }
            }
        }

        if (profileProvider != null) {
            for (String env : bundle.getExecutionEnvironments()) {
                ExecutionEnvironmentProfile profile = profileProvider.getProfile(env);
                if (profile == null) {
                    throw new ProfileNotFoundException("Execution environment profile " + env
                            + " not found");
                }
                for (String pkg : profile.getPkgNames()) {
                    ArtifactId id = new ArtifactId(ModuleId.newInstance(BundleInfo.PACKAGE_TYPE,
                        pkg), PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION,
                            PatternMatcher.ANY_EXPRESSION);
                    DefaultExcludeRule rule = new DefaultExcludeRule(id,
                            ExactOrRegexpPatternMatcher.INSTANCE, null);
                    String[] confs = md.getConfigurationsNames();
                    for (int i = 0; i < confs.length; i++) {
                        rule.addConfiguration(confs[i]);
                    }
                    md.addExcludeRule(rule);
                }
            }
        }

        return md;
View Full Code Here

                            + ". Available options are " + getAllowedLogOptions());
                }

                ModuleRevisionId mrid = ModuleRevisionId.newInstance("", "",
                    Ivy.getWorkingRevision());
                DefaultModuleDescriptor md = DefaultModuleDescriptor.newBasicInstance(mrid, null);

                Iterator itDeps = dependencies.iterator();
                while (itDeps.hasNext()) {
                    IvyDependency dep = (IvyDependency) itDeps.next();
                    DependencyDescriptor dd = dep.asDependencyDescriptor(md, "default", settings);
                    md.addDependency(dd);
                }

                Iterator itExcludes = excludes.iterator();
                while (itExcludes.hasNext()) {
                    IvyExclude exclude = (IvyExclude) itExcludes.next();
                    DefaultExcludeRule rule = exclude.asRule(settings);
                    rule.addConfiguration("default");
                    md.addExcludeRule(rule);
                }

                Iterator itConflicts = conflicts.iterator();
                while (itConflicts.hasNext()) {
                    IvyConflict conflict = (IvyConflict) itConflicts.next();
                    conflict.addConflict(md, settings);
                }

                report = ivy
                        .resolve(md, getResolveOptions(ivy, new String[] {"default"}, settings));
            } else if (isInline()) {
                if (organisation == null) {
                    throw new BuildException("'organisation' is required when using inline mode");
                }
                if (module == null) {
                    throw new BuildException("'module' is required when using inline mode");
                }
                if (file != null) {
                    throw new BuildException("'file' not allowed when using inline mode");
                }
                if (!getAllowedLogOptions().contains(log)) {
                    throw new BuildException("invalid option for 'log': " + log
                            + ". Available options are " + getAllowedLogOptions());
                }
                for (int i = 0; i < confs.length; i++) {
                    if ("*".equals(confs[i])) {
                        confs[i] = "*(public)";
                    }
                }
                if (revision == null) {
                    revision = "latest.integration";
                }
                report = ivy.resolve(
                    ModuleRevisionId.newInstance(organisation, module, branch, revision),
                    getResolveOptions(ivy, confs, settings), changing);

            } else {
                if (organisation != null) {
                    throw new BuildException(
                            "'organisation' not allowed when not using 'org' attribute");
                }
                if (module != null) {
                    throw new BuildException("'module' not allowed when not using 'org' attribute");
                }
                if (file == null) {
                    file = getProject().resolveFile(getProperty(settings, "ivy.dep.file"));
                }
                report = ivy.resolve(file.toURI().toURL(), getResolveOptions(ivy, confs, settings));
            }
            if (report.hasError()) {
                if (failureProperty != null) {
                    getProject().setProperty(failureProperty, "true");
                }
                if (isHaltonfailure()) {
                    throw new BuildException("resolve failed - see output for details");
                }
            }
            setResolved(report, resolveId, isKeep());
            confs = report.getConfigurations();

            if (isKeep()) {
                ModuleDescriptor md = report.getModuleDescriptor();
                // put resolved infos in ant properties and ivy variables
                // putting them in ivy variables is important to be able to change from one resolve
                // call to the other
                String mdOrg = md.getModuleRevisionId().getOrganisation();
                String mdName = md.getModuleRevisionId().getName();
                String mdRev = md.getResolvedModuleRevisionId().getRevision();
                getProject().setProperty("ivy.organisation", mdOrg);
                settings.setVariable("ivy.organisation", mdOrg);
                getProject().setProperty("ivy.module", mdName);
                settings.setVariable("ivy.module", mdName);
                getProject().setProperty("ivy.revision", mdRev);
                settings.setVariable("ivy.revision", mdRev);
                for (int i = 0; i < md.getInheritedDescriptors().length; i++) {
                    ExtendsDescriptor parent = md.getInheritedDescriptors()[i];
                    String parentOrg = parent.getResolvedParentRevisionId().getOrganisation();
                    String parentModule = parent.getResolvedParentRevisionId().getName();
                    String parentRevision = parent.getResolvedParentRevisionId().getRevision();
                    String parentBranch = parent.getResolvedParentRevisionId().getBranch();
                    getProject().setProperty("ivy.parent[" + i + "].organisation", parentOrg);
                    settings.setVariable("ivy.parent[" + i + "].organisation", parentOrg);
                    getProject().setProperty("ivy.parent[" + i + "].module", parentModule);
                    settings.setVariable("ivy.parent[" + i + "].module", parentModule);
                    getProject().setProperty("ivy.parent[" + i + "].revision", parentRevision);
                    settings.setVariable("ivy.parent[" + i + "].revision", parentRevision);
                    if (parentBranch != null) {
                        getProject().setProperty("ivy.parent[" + i + "].branch", parentBranch);
                        settings.setVariable("ivy.parent[" + i + "].branch", parentBranch);
                    }
                }
                getProject().setProperty("ivy.parents.count",
                    String.valueOf(md.getInheritedDescriptors().length));
                settings.setVariable("ivy.parents.count",
                    String.valueOf(md.getInheritedDescriptors().length));

                Boolean hasChanged = null;
                if (getCheckIfChanged()) {
                    hasChanged = Boolean.valueOf(report.hasChanged());
                    getProject().setProperty("ivy.deps.changed", hasChanged.toString());
View Full Code Here

    public void doExecute() throws BuildException {
        prepareAndCheck();

        ModuleDescriptor originalModuleDescriptor = getResolvedReport().getModuleDescriptor();
        // clone module descriptor
        DefaultModuleDescriptor latestModuleDescriptor = new DefaultModuleDescriptor(
                originalModuleDescriptor.getModuleRevisionId(),
                originalModuleDescriptor.getStatus(), originalModuleDescriptor.getPublicationDate());
        // copy configurations
        for (int i = 0; i < originalModuleDescriptor.getConfigurations().length; i++) {
            Configuration configuration = originalModuleDescriptor.getConfigurations()[i];
            latestModuleDescriptor.addConfiguration(configuration);
        }
        // clone dependency and add new one with the requested revisionToCheck
        for (int i = 0; i < originalModuleDescriptor.getDependencies().length; i++) {
            DependencyDescriptor dependencyDescriptor = originalModuleDescriptor.getDependencies()[i];
            ModuleRevisionId upToDateMrid = ModuleRevisionId.newInstance(
                dependencyDescriptor.getDependencyRevisionId(), revisionToCheck);
            latestModuleDescriptor.addDependency(dependencyDescriptor.clone(upToDateMrid));
        }

        // resolve
        ResolveOptions resolveOptions = new ResolveOptions();
        resolveOptions.setDownload(isDownload());
View Full Code Here

     * Resolves the module identified by the given mrid with its dependencies if transitive is set
     * to true.
     */
    public ResolveReport resolve(final ModuleRevisionId mrid, ResolveOptions options,
            boolean changing) throws ParseException, IOException {
        DefaultModuleDescriptor md;
        ResolveOptions optionsToUse = new ResolveOptions(options);

        if (options.useSpecialConfs()) {
            // create new resolve options because this is a different resolve than the real resolve
            // (which will be a resolve of a newCallerInstance module)
View Full Code Here

    public ResolvedModuleRevision findModule(ModuleRevisionId id, ResolveOptions options) {
        DependencyResolver r = settings.getResolver(id);
        if (r == null) {
            throw new IllegalStateException("no resolver found for " + id.getModuleId());
        }
        DefaultModuleDescriptor md = DefaultModuleDescriptor.newCallerInstance(id,
            new String[] {"*"}, false, false);

        if (options.getResolveId() == null) {
            options.setResolveId(ResolveOptions.getDefaultResolveId(md));
        }
View Full Code Here

            final boolean isdefault) {
        final MockResolver r = new MockResolver();
        r.setName(name);
        r.setSettings(settings);
        if (findRevision) {
            DefaultModuleDescriptor md = new DefaultModuleDescriptor(mrid, "integration",
                    publicationDate, isdefault);
            r.rmr = new ResolvedModuleRevision(r, r, md, new MetadataArtifactDownloadReport(
                    md.getMetadataArtifact()));
        }
        return r;
    }
View Full Code Here

TOP

Related Classes of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.