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

The following examples show how to use org.apache.ivy.plugins.parser.ParserSettings. 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: ModuleDescriptorMemoryCache.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
ModuleDescriptor getFromCache(File ivyFile, ParserSettings ivySettings, boolean validated) {
    if (maxSize <= 0) {
        // cache is disabled
        return null;
    }
    synchronized (valueMap) {
        CacheEntry entry = valueMap.get(ivyFile);
        if (entry != null) {
            if (entry.isStale(ivyFile, validated, ivySettings)) {
                Message.debug("Entry is found in the ModuleDescriptorCache but entry should be "
                        + "reevaluated : " + ivyFile);
                valueMap.remove(ivyFile);
                return null;
            } else {
                // Move the entry at the end of the list
                valueMap.remove(ivyFile);
                valueMap.put(ivyFile, entry);
                Message.debug("Entry is found in the ModuleDescriptorCache : " + ivyFile);
                return entry.md;
            }
        } else {
            Message.debug("No entry is found in the ModuleDescriptorCache : " + ivyFile);
            return null;
        }
    }
}
 
Example #2
Source File: DefaultResolutionCacheManager.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public ModuleDescriptor getResolvedModuleDescriptor(ModuleRevisionId mrid)
        throws ParseException, IOException {
    File ivyFile = getResolvedIvyFileInCache(mrid);
    if (!ivyFile.exists()) {
        throw new IllegalStateException("Ivy file not found in cache for " + mrid + "!");
    }

    Properties paths = new Properties();

    File parentsFile = getResolvedIvyPropertiesInCache(ModuleRevisionId.newInstance(mrid,
        mrid.getRevision() + "-parents"));
    if (parentsFile.exists()) {
        FileInputStream in = new FileInputStream(parentsFile);
        paths.load(in);
        in.close();
    }

    ParserSettings pSettings = new CacheParserSettings(settings, paths);

    URL ivyFileURL = ivyFile.toURI().toURL();
    return getModuleDescriptorParser(ivyFile).parseDescriptor(pSettings, ivyFileURL, false);
}
 
Example #3
Source File: ModuleDescriptorMemoryCache.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public ModuleDescriptor get(File ivyFile, ParserSettings ivySettings, boolean validated,
        ModuleDescriptorProvider mdProvider) throws ParseException, IOException {

    ModuleDescriptor descriptor = getFromCache(ivyFile, ivySettings, validated);
    if (descriptor == null) {
        descriptor = getStale(ivyFile, ivySettings, validated, mdProvider);
    }
    return descriptor;
}
 
Example #4
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 #5
Source File: ParserSettingsMonitor.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the newSettings is compatible with the original settings that has been monitored.
 * Only the info that was actually used is compared.
 */
public boolean hasChanged(ParserSettings newSettings) {
    for (Map.Entry<String, String> entry : substitutes.entrySet()) {
        String key = entry.getKey();
        if (!entry.getValue().equals(newSettings.substitute(key))) {
            Message.debug("settings variable has changed for : " + key);
            return true;
        }
    }
    return false;
}
 
Example #6
Source File: PomModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void addTo(PomModuleDescriptorBuilder mdBuilder, PomDependencyMgt dep,
        ParserSettings ivySettings) throws ParseException, IOException {
    if ("import".equals(dep.getScope())) {
        // In Maven, "import" scope semantics are equivalent to getting (only) the
        // dependency management section of the imported module, into the current
        // module, so that those "managed dependency versions" are usable/applicable
        // in the current module's dependencies
        ModuleRevisionId importModRevID = ModuleRevisionId.newInstance(dep.getGroupId(),
                dep.getArtifactId(), dep.getVersion());
        ResolvedModuleRevision importModule = parseOtherPom(ivySettings, importModRevID, false);
        if (importModule == null) {
            throw new IOException("Impossible to import module for "
                    + mdBuilder.getModuleDescriptor().getResource().getName() + ". Import="
                    + importModRevID);
        }
        ModuleDescriptor importDescr = importModule.getDescriptor();

        // add dependency management info from imported module
        for (PomDependencyMgt importedDepMgt : getDependencyManagements(importDescr)) {
            mdBuilder.addDependencyMgt(new DefaultPomDependencyMgt(importedDepMgt.getGroupId(),
                    importedDepMgt.getArtifactId(), importedDepMgt.getVersion(),
                    importedDepMgt.getScope(), importedDepMgt.getExcludedModules()));
        }
    } else {
        mdBuilder.addDependencyMgt(dep);
    }

}
 
Example #7
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 #8
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 #9
Source File: XmlModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/** Used for test purpose */
ModuleDescriptor parseDescriptor(ParserSettings ivySettings, InputStream descriptor,
        Resource res, boolean validate) throws ParseException {
    Parser parser = newParser(ivySettings);
    parser.setValidate(validate);
    parser.setResource(res);
    parser.setInput(descriptor);
    parser.parse();
    return parser.getModuleDescriptor();
}
 
Example #10
Source File: ModuleDescriptorMemoryCache.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Get the module descriptor from the mdProvider and store it into the cache.
 */
public ModuleDescriptor getStale(File ivyFile, ParserSettings ivySettings, boolean validated,
        ModuleDescriptorProvider mdProvider) throws ParseException, IOException {
    ParserSettingsMonitor settingsMonitor = new ParserSettingsMonitor(ivySettings);
    ModuleDescriptor descriptor = mdProvider.provideModule(
        settingsMonitor.getMonitoredSettings(), ivyFile, validated);
    putInCache(ivyFile, settingsMonitor, validated, descriptor);
    return descriptor;
}
 
Example #11
Source File: ExtendableItemHelper.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public static void fillExtraAttributes(ParserSettings settings, DefaultExtendableItem item,
        Attributes attributes, List<String> ignoredAttNames) {
    Map<String, String> att = getExtraAttributes(settings, attributes, ignoredAttNames);
    for (Map.Entry<String, String> entry : att.entrySet()) {
        item.setExtraAttribute(entry.getKey(), entry.getValue());
    }
}
 
Example #12
Source File: ExtendableItemHelper.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Extract from the XML attribute the extra Ivy ones
 *
 * @param settings ParserSettings
 * @param attributes Attributes
 * @param ignoredAttNames
 *            the XML attributes names which are not extra but Ivy core ones
 * @return Map&lt;String,String&gt;
 */
public static Map<String, String> getExtraAttributes(ParserSettings settings,
        Attributes attributes, List<String> ignoredAttNames) {
    Map<String, String> ret = new HashMap<>();
    for (int i = 0; i < attributes.getLength(); i++) {
        if (!ignoredAttNames.contains(attributes.getQName(i))) {
            ret.put(attributes.getQName(i), settings.substitute(attributes.getValue(i)));
        }
    }
    return ret;
}
 
Example #13
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 #14
Source File: ModuleDescriptorMemoryCacheTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public ModuleDescriptor provideModule(ParserSettings ivySettings, File descriptorFile,
        boolean validate) {
    if (ivySettings != null) {
        ivySettings.substitute("${val}");
    }
    called = true;
    return result;
}
 
Example #15
Source File: XmlModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
protected ParserSettings getSettings() {
    return settings;
}
 
Example #16
Source File: ModuleDescriptorProvider.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
ModuleDescriptor provideModule(ParserSettings ivySettings, File descriptorFile,
boolean validate) throws ParseException, IOException;
 
Example #17
Source File: UpdateOptions.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public ParserSettings getSettings() {
    return settings;
}
 
Example #18
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 #19
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 #20
Source File: UpdateOptions.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public UpdateOptions setSettings(ParserSettings settings) {
    this.settings = settings;
    return this;
}
 
Example #21
Source File: XmlModuleDescriptorUpdater.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private String substitute(ParserSettings ivy, String value) {
    String result = (ivy == null) ? value : ivy.substitute(value);
    return XMLHelper.escape(result);
}
 
Example #22
Source File: AbstractResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public ParserSettings getParserSettings() {
    return new ResolverParserSettings();
}
 
Example #23
Source File: PomModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public ModuleDescriptor parseDescriptor(ParserSettings ivySettings, URL descriptorURL,
        boolean validate) throws ParseException, IOException {
    URLResource resource = new URLResource(descriptorURL);
    return parseDescriptor(ivySettings, descriptorURL, resource, validate);
}
 
Example #24
Source File: ParserSettingsMonitor.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public ParserSettingsMonitor(ParserSettings settings) {
    this.delegatedSettings = settings;
    this.substitutes = new HashMap<>();
}
 
Example #25
Source File: DefaultRepositoryCacheManager.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public ModuleDescriptor provideModule(ParserSettings ivySettings, File descriptorURL,
        boolean validate) throws ParseException, IOException {
    return mdParser.parseDescriptor(settings, descriptorURL.toURI().toURL(), validate);
}
 
Example #26
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 #27
Source File: ModuleDescriptorMemoryCache.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
boolean isStale(File ivyFile, boolean validated, ParserSettings newParserSettings) {
    return (validated && !this.validated)
            || md.getLastModified() != ivyFile.lastModified()
            || parserSettingsMonitor.hasChanged(newParserSettings);
}
 
Example #28
Source File: DefaultResolutionCacheManager.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public CacheParserSettings(ParserSettings delegate, Map<Object, Object> parentPaths) {
    this.delegate = delegate;
    this.parentPaths = parentPaths;
}
 
Example #29
Source File: ExtendableItemHelper.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Deprecated
public static void fillExtraAttributes(ParserSettings settings, DefaultExtendableItem item,
                                       Attributes attributes, String[] ignoredAttNames) {
    fillExtraAttributes(settings, item, attributes, Arrays.asList(ignoredAttNames));
}
 
Example #30
Source File: ExtendableItemHelper.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Deprecated
public static Map<String, String> getExtraAttributes(ParserSettings settings,
                                                     Attributes attributes, String[] ignoredAttNames) {
    return getExtraAttributes(settings, attributes, Arrays.asList(ignoredAttNames));
}