Java Code Examples for org.apache.ivy.core.module.descriptor.ModuleDescriptor#getModuleRevisionId()

The following examples show how to use org.apache.ivy.core.module.descriptor.ModuleDescriptor#getModuleRevisionId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IvyInternalPublisher.java    From jeka with Apache License 2.0 6 votes vote down vote up
private Path createIvyFile(ModuleDescriptor moduleDescriptor) {
    try {
        final ModuleRevisionId mrId = moduleDescriptor.getModuleRevisionId();
        final Path file;
        if (this.descriptorOutputDir != null) {
            file = this.descriptorOutputDir.resolve("published-of-" + mrId.getOrganisation()
            + "-" + mrId.getName() + "-" + mrId.getRevision() + ".xml");
        } else {
            file = JkUtilsPath.createTempFile("published-of-", ".xml");
        }
        moduleDescriptor.toIvyFile(file.toFile());
        return file;
    } catch (final IOException | ParseException e) {
        throw new RuntimeException(e);
    }

}
 
Example 2
Source File: XmlModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Explain how to inherit metadata related to info element
 *
 * @param parent
 *            a given parent module descriptor
 */
protected void mergeInfo(ModuleDescriptor parent) {
    ModuleRevisionId parentMrid = parent.getModuleRevisionId();

    DefaultModuleDescriptor descriptor = getMd();
    ModuleRevisionId currentMrid = descriptor.getModuleRevisionId();

    ModuleRevisionId mergedMrid = ModuleRevisionId.newInstance(
        mergeValue(parentMrid.getOrganisation(), currentMrid.getOrganisation()),
        currentMrid.getName(),
        mergeValue(parentMrid.getBranch(), currentMrid.getBranch()),
        mergeRevisionValue(parentMrid.getRevision(), currentMrid.getRevision()),
        mergeValues(parentMrid.getQualifiedExtraAttributes(),
            currentMrid.getQualifiedExtraAttributes()));

    descriptor.setModuleRevisionId(mergedMrid);
    descriptor.setResolvedModuleRevisionId(mergedMrid);

    descriptor.setStatus(mergeValue(parent.getStatus(), descriptor.getStatus()));
    if (descriptor.getNamespace() == null && parent instanceof DefaultModuleDescriptor) {
        Namespace parentNamespace = ((DefaultModuleDescriptor) parent).getNamespace();
        descriptor.setNamespace(parentNamespace);
    }

    descriptor.getExtraInfos().addAll(parent.getExtraInfos());
}
 
Example 3
Source File: IvyPublisherForMaven.java    From jeka with Apache License 2.0 5 votes vote down vote up
private Path makePom(ModuleDescriptor moduleDescriptor, JkMavenPublication publication) {
    final ModuleRevisionId ivyModuleRevisionId = moduleDescriptor.getModuleRevisionId();
    final String artifactName = ivyModuleRevisionId.getName();
    final Path pomXml;
    if (this.descriptorOutputDir != null) {
        pomXml = Paths.get(targetDir()).resolve("published-pom-" + ivyModuleRevisionId.getOrganisation()
        + "-" + artifactName + "-" + ivyModuleRevisionId.getRevision() + ".xml");
    } else {
        pomXml = JkUtilsPath.createTempFile("published-pom-", ".xml");
    }
    final String packaging = JkUtilsString.substringAfterLast(publication.getArtifactLocator()
            .getMainArtifactPath().getFileName().toString(), ".");
    final PomWriterOptions pomWriterOptions = new PomWriterOptions();
    pomWriterOptions.setMapping(new ScopeMapping());
    pomWriterOptions.setArtifactPackaging(packaging);
    Path fileToDelete = null;
    if (publication.getPomMetadata() != null) {
        final Path template = JkPomTemplateGenerator.generateTemplate(publication.getPomMetadata());
        pomWriterOptions.setTemplate(template.toFile());
        fileToDelete = template;
    }
    try {
        PomModuleDescriptorWriter.write(moduleDescriptor, pomXml.toFile(), pomWriterOptions);
        if (fileToDelete != null) {
            Files.deleteIfExists(fileToDelete);
        }
        return pomXml;
    } catch (final IOException e) {
        throw JkUtilsThrowable.unchecked(e);
    }
}
 
Example 4
Source File: AbstractOSGiResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private MDResolvedResource buildResolvedCapabilityMd(DependencyDescriptor dd,
        ModuleDescriptor md) {
    String org = dd.getDependencyRevisionId().getOrganisation();
    String name = dd.getDependencyRevisionId().getName();
    String rev = md.getExtraInfoContentByTagName(BundleInfoAdapter.EXTRA_INFO_EXPORT_PREFIX
            + name);
    ModuleRevisionId capabilityRev = ModuleRevisionId.newInstance(org, name, rev,
        Collections.singletonMap(CAPABILITY_EXTRA_ATTR, md.getModuleRevisionId().toString()));

    DefaultModuleDescriptor capabilityMd = new DefaultModuleDescriptor(capabilityRev,
            getSettings().getStatusManager().getDefaultStatus(), new Date());

    String useConf = BundleInfoAdapter.CONF_USE_PREFIX + dd.getDependencyRevisionId().getName();

    capabilityMd.addConfiguration(BundleInfoAdapter.CONF_DEFAULT);
    capabilityMd.addConfiguration(BundleInfoAdapter.CONF_OPTIONAL);
    capabilityMd.addConfiguration(BundleInfoAdapter.CONF_TRANSITIVE_OPTIONAL);
    capabilityMd.addConfiguration(new Configuration(useConf));

    DefaultDependencyDescriptor capabilityDD = new DefaultDependencyDescriptor(
            md.getModuleRevisionId(), false);
    capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_DEFAULT,
        BundleInfoAdapter.CONF_NAME_DEFAULT);
    capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_OPTIONAL,
        BundleInfoAdapter.CONF_NAME_OPTIONAL);
    capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_TRANSITIVE_OPTIONAL,
        BundleInfoAdapter.CONF_NAME_TRANSITIVE_OPTIONAL);
    capabilityDD.addDependencyConfiguration(useConf, useConf);
    capabilityMd.addDependency(capabilityDD);

    MetadataArtifactDownloadReport report = new MetadataArtifactDownloadReport(null);
    report.setDownloadStatus(DownloadStatus.NO);
    report.setSearched(true);
    ResolvedModuleRevision rmr = new ResolvedModuleRevision(this, this, capabilityMd, report);
    return new MDResolvedResource(null, capabilityMd.getRevision(), rmr);
}
 
Example 5
Source File: PomModuleDescriptorWriter.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private static void setModuleVariables(ModuleDescriptor md, IvyVariableContainer variables,
        PomWriterOptions options) {
    ModuleRevisionId mrid = md.getModuleRevisionId();
    variables.setVariable("ivy.pom.groupId", mrid.getOrganisation(), true);

    String artifactId = options.getArtifactName();
    if (artifactId == null) {
        artifactId = mrid.getName();
    }

    String packaging = options.getArtifactPackaging();
    if (packaging == null) {
        // find artifact to determine the packaging
        Artifact artifact = findArtifact(md, artifactId);
        if (artifact == null) {
            // no suitable artifact found, default to 'pom'
            packaging = "pom";
        } else {
            packaging = artifact.getType();
        }
    }

    variables.setVariable("ivy.pom.artifactId", artifactId, true);
    variables.setVariable("ivy.pom.packaging", packaging, true);
    if (mrid.getRevision() != null) {
        variables.setVariable("ivy.pom.version", mrid.getRevision(), true);
    }
    if (options.getDescription() != null) {
        variables.setVariable("ivy.pom.description", options.getDescription(), true);
    } else if (!isNullOrEmpty(md.getDescription())) {
        variables.setVariable("ivy.pom.description", md.getDescription(), true);
    }
    if (md.getHomePage() != null) {
        variables.setVariable("ivy.pom.url", md.getHomePage(), true);
    }
}
 
Example 6
Source File: XmlModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Describes how to merge configurations elements
 *
 * @param parent
 *            the module descriptor
 */
protected void mergeConfigurations(ModuleDescriptor parent) {
    ModuleRevisionId sourceMrid = parent.getModuleRevisionId();
    for (Configuration configuration : parent.getConfigurations()) {
        Message.debug("Merging configuration with: " + configuration.getName());
        // copy configuration from parent descriptor
        getMd().addConfiguration(new Configuration(configuration, sourceMrid));
    }

    if (parent instanceof DefaultModuleDescriptor) {
        setDefaultConfMapping(((DefaultModuleDescriptor) parent).getDefaultConfMapping());
        setDefaultConf(((DefaultModuleDescriptor) parent).getDefaultConf());
        getMd().setMappingOverride(((DefaultModuleDescriptor) parent).isMappingOverride());
    }
}
 
Example 7
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testRetrieveReport() throws Exception {
    // mod1.1 depends on mod1.2
    ResolveReport report = ivy.resolve(new File(
            "test/repositories/1/org20/mod20.1/ivys/ivy-1.2.xml").toURI().toURL(),
        getResolveOptions(new String[] {"*"}));
    assertNotNull(report);
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);

    ModuleRevisionId mrid = md.getModuleRevisionId();
    RetrieveOptions options = getRetrieveOptions();
    options.setConfs(new String[] {"A"});
    Map<ArtifactDownloadReport, Set<String>> artifactsToCopy = ivy.getRetrieveEngine()
            .determineArtifactsToCopy(mrid,
                "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]", options);
    assertEquals(2, artifactsToCopy.size());

    options.setConfs(new String[] {"B"});
    artifactsToCopy = ivy.getRetrieveEngine().determineArtifactsToCopy(mrid,
        "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]", options);
    assertEquals(2, artifactsToCopy.size());

    options.setConfs(new String[] {"A", "B"});
    artifactsToCopy = ivy.getRetrieveEngine().determineArtifactsToCopy(mrid,
        "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]", options);
    assertEquals(3, artifactsToCopy.size());
}
 
Example 8
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNamespaces() throws Exception {
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-namespaces.xml"), true);
    assertNotNull(md);
    ModuleRevisionId mrid = md.getModuleRevisionId();
    assertEquals("myorg", mrid.getOrganisation());
    assertEquals("mymodule", mrid.getName());
    assertEquals("myval", mrid.getExtraAttribute("e:myextra"));
    assertEquals(Collections.singletonMap("e:myextra", "myval"),
        mrid.getQualifiedExtraAttributes());
    assertEquals("myval", mrid.getExtraAttribute("myextra"));
    assertEquals(Collections.singletonMap("myextra", "myval"), mrid.getExtraAttributes());
    assertEquals("http://ant.apache.org/ivy/extra", md.getExtraAttributesNamespaces().get("e"));
}
 
Example 9
Source File: IvyDependencyUpdateChecker.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
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 (Configuration configuration : originalModuleDescriptor.getConfigurations()) {
        latestModuleDescriptor.addConfiguration(configuration);
    }
    // clone dependency and add new one with the requested revisionToCheck
    for (DependencyDescriptor dependencyDescriptor : originalModuleDescriptor.getDependencies()) {
        ModuleRevisionId upToDateMrid = ModuleRevisionId.newInstance(
            dependencyDescriptor.getDependencyRevisionId(), revisionToCheck);
        latestModuleDescriptor.addDependency(dependencyDescriptor.clone(upToDateMrid));
    }

    // resolve
    ResolveOptions resolveOptions = new ResolveOptions();
    resolveOptions.setDownload(isDownload());
    resolveOptions.setLog(getLog());
    resolveOptions.setConfs(splitToArray(getConf()));
    resolveOptions.setCheckIfChanged(checkIfChanged);

    ResolveReport latestReport;
    try {
        latestReport = getIvyInstance().getResolveEngine().resolve(latestModuleDescriptor,
            resolveOptions);

        displayDependencyUpdates(getResolvedReport(), latestReport);
        if (showTransitive) {
            displayNewDependencyOnLatest(getResolvedReport(), latestReport);
            displayMissingDependencyOnLatest(getResolvedReport(), latestReport);
        }

    } catch (ParseException | IOException e) {
        throw new BuildException("impossible to resolve dependencies:\n\t" + e, e);
    }

}
 
Example 10
Source File: IvyNode.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public IvyNode(ResolveData data, ModuleDescriptor md) {
    id = md.getModuleRevisionId();
    this.md = md;
    root = this;
    init(data);
}
 
Example 11
Source File: PomModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private void addSourcesAndJavadocArtifactsIfPresent(PomModuleDescriptorBuilder mdBuilder,
        ParserSettings ivySettings) {
    if (mdBuilder.getMainArtifact() == null) {
        // no main artifact in pom, we don't need to search for meta artifacts
        return;
    }

    boolean sourcesLookup = !"false"
            .equals(ivySettings.getVariable("ivy.maven.lookup.sources"));
    boolean javadocLookup = !"false"
            .equals(ivySettings.getVariable("ivy.maven.lookup.javadoc"));
    if (!sourcesLookup && !javadocLookup) {
        Message.debug("Sources and javadocs lookup disabled");
        return;
    }

    ModuleDescriptor md = mdBuilder.getModuleDescriptor();
    ModuleRevisionId mrid = md.getModuleRevisionId();
    DependencyResolver resolver = ivySettings.getResolver(mrid);

    if (resolver == null) {
        Message.debug(
            "no resolver found for " + mrid + ": no source or javadoc artifact lookup");
    } else {
        ArtifactOrigin mainArtifact = resolver.locate(mdBuilder.getMainArtifact());

        if (!ArtifactOrigin.isUnknown(mainArtifact)) {
            String mainArtifactLocation = mainArtifact.getLocation();

            if (sourcesLookup) {
                ArtifactOrigin sourceArtifact = resolver.locate(mdBuilder.getSourceArtifact());
                if (!ArtifactOrigin.isUnknown(sourceArtifact)
                        && !sourceArtifact.getLocation().equals(mainArtifactLocation)) {
                    Message.debug("source artifact found for " + mrid);
                    mdBuilder.addSourceArtifact();
                } else {
                    // it seems that sometimes the 'src' classifier is used instead of 'sources'
                    // Cfr. IVY-1138
                    ArtifactOrigin srcArtifact = resolver.locate(mdBuilder.getSrcArtifact());
                    if (!ArtifactOrigin.isUnknown(srcArtifact)
                            && !srcArtifact.getLocation().equals(mainArtifactLocation)) {
                        Message.debug("source artifact found for " + mrid);
                        mdBuilder.addSrcArtifact();
                    } else {
                        Message.debug("no source artifact found for " + mrid);
                    }
                }
            } else {
                Message.debug("sources lookup disabled");
            }

            if (javadocLookup) {
                ArtifactOrigin javadocArtifact = resolver
                        .locate(mdBuilder.getJavadocArtifact());
                if (!ArtifactOrigin.isUnknown(javadocArtifact)
                        && !javadocArtifact.getLocation().equals(mainArtifactLocation)) {
                    Message.debug("javadoc artifact found for " + mrid);
                    mdBuilder.addJavadocArtifact();
                } else {
                    Message.debug("no javadoc artifact found for " + mrid);
                }
            } else {
                Message.debug("javadocs lookup disabled");
            }
        }
    }
}
 
Example 12
Source File: XmlModuleDescriptorUpdater.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private void infoStarted(Attributes attributes) {

            String module = substitute(settings, attributes.getValue("module"));
            String rev = null;
            String branch = null;
            String status = null;
            String namespace = null;
            Map<String, String> extraAttributes = null;

            if (options.isMerge()) {
                // get attributes from merged descriptor, ignoring raw XML
                ModuleDescriptor merged = options.getMergedDescriptor();
                ModuleRevisionId mergedMrid = merged.getModuleRevisionId();
                organisation = mergedMrid.getOrganisation();
                branch = mergedMrid.getBranch();
                rev = mergedMrid.getRevision();
                status = merged.getStatus();

                // TODO: should namespace be added to ModuleDescriptor interface, so we don't
                // have to do this kind of check?
                if (merged instanceof DefaultModuleDescriptor) {
                    Namespace ns = ((DefaultModuleDescriptor) merged).getNamespace();
                    if (ns != null) {
                        namespace = ns.getName();
                    }
                }
                if (namespace == null) {
                    namespace = attributes.getValue("namespace");
                }

                extraAttributes = merged.getQualifiedExtraAttributes();
            } else {
                // get attributes from raw XML, performing property substitution
                organisation = substitute(settings, attributes.getValue("organisation"));
                rev = substitute(settings, attributes.getValue("revision"));
                branch = substitute(settings, attributes.getValue("branch"));
                status = substitute(settings, attributes.getValue("status"));
                namespace = substitute(settings, attributes.getValue("namespace"));
                extraAttributes = new LinkedHashMap<>(attributes.getLength());
                for (int i = 0; i < attributes.getLength(); i++) {
                    String qname = attributes.getQName(i);
                    if (!STD_ATTS.contains(qname)) {
                        extraAttributes.put(qname, substitute(settings, attributes.getValue(i)));
                    }
                }
            }

            // apply override values provided in options
            if (revision != null) {
                rev = revision;
            }
            if (options.getBranch() != null) {
                branch = options.getBranch();
            }
            if (this.status != null) {
                status = this.status;
            }

            // if necessary translate mrid using optional namespace argument
            ModuleRevisionId localMid = ModuleRevisionId.newInstance(organisation, module, branch,
                rev, ExtendableItemHelper.getExtraAttributes(settings, attributes,
                            Arrays.asList("organisation", "module", "revision", "status",
                                    "publication", "namespace")));
            ModuleRevisionId systemMid = (ns == null) ? localMid : ns.getToSystemTransformer()
                    .transform(localMid);

            write("<info");
            if (organisation != null) {
                write(" organisation=\"" + XMLHelper.escape(systemMid.getOrganisation()) + "\"");
            }
            write(" module=\"" + XMLHelper.escape(systemMid.getName()) + "\"");
            if (branch != null) {
                write(" branch=\"" + XMLHelper.escape(systemMid.getBranch()) + "\"");
            }
            if (systemMid.getRevision() != null) {
                write(" revision=\"" + XMLHelper.escape(systemMid.getRevision()) + "\"");
            }
            write(" status=\"" + XMLHelper.escape(status) + "\"");
            if (pubdate != null) {
                write(" publication=\"" + DateUtil.format(pubdate) + "\"");
            } else if (attributes.getValue("publication") != null) {
                write(" publication=\"" + substitute(settings, attributes.getValue("publication"))
                        + "\"");
            }
            if (namespace != null) {
                write(" namespace=\"" + namespace + "\"");
            }

            for (Map.Entry<String, String> extra : extraAttributes.entrySet()) {
                write(" " + extra.getKey() + "=\"" + extra.getValue() + "\"");
            }
        }
 
Example 13
Source File: AbstractWorkspaceResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
protected WorkspaceModuleDescriptor createWorkspaceMd(ModuleDescriptor md) {
    DefaultWorkspaceModuleDescriptor newMd = new DefaultWorkspaceModuleDescriptor(
            md.getModuleRevisionId(), "release", null, true);
    newMd.addConfiguration(new Configuration(ModuleDescriptor.DEFAULT_CONFIGURATION));
    newMd.setLastModified(System.currentTimeMillis());

    newMd.setDescription(md.getDescription());
    newMd.setHomePage(md.getHomePage());
    newMd.setLastModified(md.getLastModified());
    newMd.setPublicationDate(md.getPublicationDate());
    newMd.setResolvedPublicationDate(md.getResolvedPublicationDate());
    newMd.setStatus(md.getStatus());

    Configuration[] allConfs = md.getConfigurations();
    for (Artifact af : createWorkspaceArtifacts(md)) {
        if (allConfs.length == 0) {
            newMd.addArtifact(ModuleDescriptor.DEFAULT_CONFIGURATION, af);
        } else {
            for (Configuration conf : allConfs) {
                newMd.addConfiguration(conf);
                newMd.addArtifact(conf.getName(), af);
            }
        }
    }

    for (DependencyDescriptor dependency : md.getDependencies()) {
        newMd.addDependency(dependency);
    }

    for (ExcludeRule excludeRule : md.getAllExcludeRules()) {
        newMd.addExcludeRule(excludeRule);
    }

    newMd.getExtraInfos().addAll(md.getExtraInfos());

    for (License license : md.getLicenses()) {
        newMd.addLicense(license);
    }

    return newMd;
}