org.apache.ivy.plugins.parser.ModuleDescriptorParser Java Examples

The following examples show how to use org.apache.ivy.plugins.parser.ModuleDescriptorParser. 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: ResolveEngine.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Resolve dependencies of a module described by an ivy file.
 *
 * @param ivySource URL
 * @param options ResolveOptions
 * @return ResolveReport
 * @throws ParseException if something goes wrong
 * @throws IOException if something goes wrong
 */
public ResolveReport resolve(URL ivySource, ResolveOptions options) throws ParseException,
        IOException {
    URLResource res = new URLResource(ivySource);
    ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(res);
    Message.verbose("using " + parser + " to parse " + ivySource);
    ModuleDescriptor md = parser.parseDescriptor(settings, ivySource, options.isValidate());
    String revision = options.getRevision();
    if (revision == null && md.getResolvedModuleRevisionId().getRevision() == null) {
        revision = Ivy.getWorkingRevision();
    }
    if (revision != null) {
        md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(md.getModuleRevisionId(),
            revision));
    }

    return resolve(md, options);
}
 
Example #2
Source File: AbstractRepositoryCacheManager.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected ModuleDescriptor parseModuleDescriptor(DependencyResolver resolver, Artifact moduleArtifact, CacheMetadataOptions options, File artifactFile, Resource resource) throws ParseException {
    ModuleRevisionId moduleRevisionId = moduleArtifact.getId().getModuleRevisionId();
    try {
        IvySettings ivySettings = IvyContextualiser.getIvyContext().getSettings();
        ParserSettings parserSettings = new LegacyResolverParserSettings(ivySettings, resolver, moduleRevisionId);
        ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(resource);
        return parser.parseDescriptor(parserSettings, new URL(artifactFile.toURI().toASCIIString()), resource, options.isValidate());
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
Example #3
Source File: AbstractRepositoryCacheManager.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected ModuleDescriptor parseModuleDescriptor(DependencyResolver resolver, Artifact moduleArtifact, CacheMetadataOptions options, File artifactFile, Resource resource) throws ParseException {
    ModuleRevisionId moduleRevisionId = moduleArtifact.getId().getModuleRevisionId();
    try {
        IvySettings ivySettings = IvyContextualiser.getIvyContext().getSettings();
        ParserSettings parserSettings = new LegacyResolverParserSettings(ivySettings, resolver, moduleRevisionId);
        ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(resource);
        return parser.parseDescriptor(parserSettings, new URL(artifactFile.toURI().toASCIIString()), resource, options.isValidate());
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
Example #4
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void cacheModuleDescriptor(ModuleDescriptor systemMd, ModuleRevisionId systemMrid,
        ResolvedResource ivyRef, ResolvedModuleRevision rmr) {
    RepositoryCacheManager cacheManager = getRepositoryCacheManager();

    final ModuleDescriptorParser parser = systemMd.getParser();

    // the metadata artifact which was used to cache the original metadata file
    Artifact requestedMetadataArtifact = (ivyRef == null) ? systemMd.getMetadataArtifact()
            : parser.getMetadataArtifact(
                    ModuleRevisionId.newInstance(systemMrid, systemMd.getRevision()),
            ivyRef.getResource());

    cacheManager.originalToCachedModuleDescriptor(this, ivyRef, requestedMetadataArtifact, rmr,
        new ModuleDescriptorWriter() {
            public void write(ResolvedResource originalMdResource, ModuleDescriptor md,
                    File src, File dest) throws IOException, ParseException {
                if (originalMdResource == null) {
                    // a basic ivy file is written containing default data
                    XmlModuleDescriptorWriter.write(md, dest);
                } else {
                    // copy and update ivy file from source to cache
                    parser.toIvyFile(new FileInputStream(src),
                        originalMdResource.getResource(), dest, md);
                    long repLastModified = originalMdResource.getLastModified();
                    if (repLastModified > 0) {
                        dest.setLastModified(repLastModified);
                    }
                }
            }
        });
}
 
Example #5
Source File: PomModuleDescriptorBuilder.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public PomModuleDescriptorBuilder(ModuleDescriptorParser parser, Resource res,
        ParserSettings ivySettings) {
    ivyModuleDescriptor = new PomModuleDescriptor(parser, res);
    ivyModuleDescriptor.setResolvedPublicationDate(new Date(res.getLastModified()));
    for (Configuration m2conf : MAVEN2_CONFIGURATIONS) {
        ivyModuleDescriptor.addConfiguration(m2conf);
    }
    ivyModuleDescriptor.setMappingOverride(true);
    ivyModuleDescriptor.addExtraAttributeNamespace("m", IVY_XML_MAVEN_NAMESPACE_URI);
    parserSettings = ivySettings;
}
 
Example #6
Source File: DefaultRepositoryCacheManager.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private ModuleDescriptor getStaledMd(ModuleDescriptorParser mdParser,
        CacheMetadataOptions options, File ivyFile, ParserSettings parserSettings)
        throws ParseException, IOException {
    ModuleDescriptorMemoryCache cache = getMemoryCache();
    ModuleDescriptorProvider mdProvider = new MyModuleDescriptorProvider(mdParser,
            parserSettings);
    return cache.getStale(ivyFile, settings, options.isValidate(), mdProvider);
}
 
Example #7
Source File: RepositoryResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Override
protected ResolvedResource findResourceUsingPattern(ModuleRevisionId mrid, String pattern,
        Artifact artifact, ResourceMDParser rmdparser, Date date) {
    String name = getName();
    VersionMatcher versionMatcher = getSettings().getVersionMatcher();
    try {
        if (!versionMatcher.isDynamic(mrid) || isAlwaysCheckExactRevision()) {
            String resourceName = IvyPatternHelper.substitute(pattern, mrid, artifact);
            Message.debug("\t trying " + resourceName);
            logAttempt(resourceName);
            Resource res = repository.getResource(resourceName);
            boolean reachable = res.exists();
            if (reachable) {
                String revision;
                if (pattern.contains(IvyPatternHelper.REVISION_KEY)) {
                    revision = mrid.getRevision();
                } else {
                    if ("ivy".equals(artifact.getType()) || "pom".equals(artifact.getType())) {
                        // we can't determine the revision from the pattern, get it
                        // from the module descriptor itself
                        File temp = File.createTempFile("ivy", artifact.getExt());
                        temp.deleteOnExit();
                        repository.get(res.getName(), temp);
                        ModuleDescriptorParser parser = ModuleDescriptorParserRegistry
                                .getInstance().getParser(res);
                        ModuleDescriptor md = parser.parseDescriptor(getParserSettings(), temp
                                .toURI().toURL(), res, false);
                        revision = md.getRevision();
                        if (isNullOrEmpty(revision)) {
                            revision = "working@" + name;
                        }
                    } else {
                        revision = "working@" + name;
                    }
                }
                return new ResolvedResource(res, revision);
            } else if (versionMatcher.isDynamic(mrid)) {
                return findDynamicResourceUsingPattern(rmdparser, mrid, pattern, artifact, date);
            } else {
                Message.debug("\t" + name + ": resource not reachable for " + mrid + ": res="
                        + res);
                return null;
            }
        } else {
            return findDynamicResourceUsingPattern(rmdparser, mrid, pattern, artifact, date);
        }
    } catch (IOException | ParseException ex) {
        throw new RuntimeException(name + ": unable to get resource for " + mrid + ": res="
                + IvyPatternHelper.substitute(pattern, mrid, artifact) + ": " + ex, ex);
    }
}
 
Example #8
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public ResolvedModuleRevision parse(final ResolvedResource mdRef, DependencyDescriptor dd,
        ResolveData data) throws ParseException {

    DependencyDescriptor nsDd = dd;
    dd = toSystem(nsDd);

    ModuleRevisionId mrid = dd.getDependencyRevisionId();
    ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(
        mdRef.getResource());
    if (parser == null) {
        Message.warn("no module descriptor parser available for " + mdRef.getResource());
        return null;
    }
    Message.verbose("\t" + getName() + ": found md file for " + mrid);
    Message.verbose("\t\t=> " + mdRef);
    Message.debug("\tparser = " + parser);

    ModuleRevisionId resolvedMrid = mrid;

    // first check if this dependency has not yet been resolved
    if (getSettings().getVersionMatcher().isDynamic(mrid)) {
        resolvedMrid = ModuleRevisionId.newInstance(mrid, mdRef.getRevision());
        IvyNode node = data.getNode(resolvedMrid);
        if (node != null && node.getModuleRevision() != null) {
            // this revision has already be resolved : return it
            if (node.getDescriptor() == null || !node.getDescriptor().isDefault()) {
                Message.verbose("\t" + getName() + ": revision already resolved: "
                        + resolvedMrid);
                node.getModuleRevision().getReport().setSearched(true);
                return node.getModuleRevision();
            }
            Message.verbose("\t" + getName() + ": found already resolved revision: "
                    + resolvedMrid
                    + ": but it's a default one, maybe we can find a better one");
        }
    }

    Artifact moduleArtifact = parser.getMetadataArtifact(resolvedMrid, mdRef.getResource());
    return getRepositoryCacheManager().cacheModuleDescriptor(this, mdRef, dd, moduleArtifact,
        downloader, getCacheOptions(data));
}
 
Example #9
Source File: XmlModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public Parser(ModuleDescriptorParser parser, ParserSettings ivySettings) {
    super(parser);
    settings = ivySettings;
}
 
Example #10
Source File: PomModuleDescriptorBuilder.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public PomModuleDescriptor(ModuleDescriptorParser parser, Resource res) {
    super(parser, res);
}
 
Example #11
Source File: IvySettings.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public synchronized void addConfigured(ModuleDescriptorParser parser) {
    ModuleDescriptorParserRegistry.getInstance().addParser(parser);
}
 
Example #12
Source File: DefaultRepositoryCacheManager.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private ModuleDescriptor getMdFromCache(ModuleDescriptorParser mdParser,
        CacheMetadataOptions options, File ivyFile) throws ParseException, IOException {
    ModuleDescriptorMemoryCache cache = getMemoryCache();
    ModuleDescriptorProvider mdProvider = new MyModuleDescriptorProvider(mdParser, settings);
    return cache.get(ivyFile, settings, options.isValidate(), mdProvider);
}
 
Example #13
Source File: DefaultRepositoryCacheManager.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public MyModuleDescriptorProvider(ModuleDescriptorParser mdParser, ParserSettings settings) {
    this.mdParser = mdParser;
    this.settings = settings;
}
 
Example #14
Source File: DefaultWorkspaceModuleDescriptor.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public DefaultWorkspaceModuleDescriptor(ModuleDescriptorParser parser, Resource res) {
    super(parser, res);
}
 
Example #15
Source File: DefaultModuleDescriptor.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public ModuleDescriptorParser getParser() {
    return parser;
}
 
Example #16
Source File: BundleInfoAdapter.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
/**
 * @param parser ModuleDescriptorParser
 * @param baseUri
 *            uri to help build the absolute url if the bundle info has a relative uri.
 * @param bundle BundleInfo
 * @param manifest Manifest
 * @param profileProvider ExecutionEnvironmentProfileProvider
 * @return DefaultModuleDescriptor ditto
 * @throws ProfileNotFoundException if descriptor is not found
 */
public static DefaultModuleDescriptor toModuleDescriptor(ModuleDescriptorParser parser,
        URI baseUri, BundleInfo bundle, Manifest manifest,
        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<>(bundle.getExports().size());
    for (ExportPackage exportPackage : bundle.getExports()) {
        md.getExtraInfos().add(
            new ExtraInfoHolder(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(),
                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() && !bundleArtifact.isSource()) {
                packaging = "bundle";
            }
            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);
                for (String conf : md.getConfigurationsNames()) {
                    rule.addConfiguration(conf);
                }
                md.addExcludeRule(rule);
            }
        }
    }

    if (manifest != null) {
        for (Map.Entry<Object, Object> entries : manifest.getMainAttributes().entrySet()) {
            md.addExtraInfo(new ExtraInfoHolder(entries.getKey().toString(), entries.getValue()
                    .toString()));
        }
    }

    return md;
}
 
Example #17
Source File: BundleInfoAdapter.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public static DefaultModuleDescriptor toModuleDescriptor(ModuleDescriptorParser parser,
        URI baseUri, BundleInfo bundle, ExecutionEnvironmentProfileProvider profileProvider) {
    return toModuleDescriptor(parser, baseUri, bundle, null, profileProvider);
}
 
Example #18
Source File: DefaultRepositoryCacheManager.java    From ant-ivy with Apache License 2.0 2 votes vote down vote up
/**
 * Choose write module descriptor parser for a given moduleDescriptor
 *
 * @param moduleDescriptorFile
 *            a given module descriptor
 * @return ModuleDescriptorParser
 */
protected ModuleDescriptorParser getModuleDescriptorParser(File moduleDescriptorFile) {
    return XmlModuleDescriptorParser.getInstance();
}
 
Example #19
Source File: DefaultResolutionCacheManager.java    From ant-ivy with Apache License 2.0 2 votes vote down vote up
/**
 * Choose write module descriptor parser for a given moduleDescriptor
 *
 * @param moduleDescriptorFile
 *            a given module descriptor
 * @return ModuleDescriptorParser
 */
protected ModuleDescriptorParser getModuleDescriptorParser(File moduleDescriptorFile) {
    return XmlModuleDescriptorParser.getInstance();
}
 
Example #20
Source File: ModuleDescriptor.java    From ant-ivy with Apache License 2.0 2 votes vote down vote up
/**
 * @return the ModuleDescriptorParser used to parse this module descriptor, null is no parser was used.
 */
ModuleDescriptorParser getParser();
 
Example #21
Source File: DefaultModuleDescriptor.java    From ant-ivy with Apache License 2.0 2 votes vote down vote up
/**
 * IMPORTANT : at least call setModuleRevisionId and setResolvedPublicationDate with instances
 * created by this constructor !
 *
 * @param parser ModuleDescriptorParser
 * @param res Resource
 */
public DefaultModuleDescriptor(ModuleDescriptorParser parser, Resource res) {
    this.parser = parser;
    resource = res;
}