Search in sources :

Example 1 with DictionaryPropertyResolver

use of org.ops4j.util.property.DictionaryPropertyResolver in project fabric8 by jboss-fuse.

the class Activator method updated.

public void updated(Dictionary<String, ?> config) {
    PropertyResolver propertyResolver;
    if (config == null) {
        propertyResolver = new PropertyResolver() {

            @Override
            public String get(String propertyName) {
                return m_bundleContext.getProperty(propertyName);
            }
        };
    } else {
        propertyResolver = new DictionaryPropertyResolver(config);
    }
    MavenConfiguration mavenConfig = new MavenConfigurationImpl(propertyResolver, PID);
    MavenResolver resolver = new AetherBasedResolver(mavenConfig);
    MavenResolver oldResolver = m_resolver.getAndSet(resolver);
    ServiceRegistration<MavenResolver> registration = m_bundleContext.registerService(MavenResolver.class, resolver, null);
    registration = m_resolverReg.getAndSet(registration);
    if (registration != null) {
        registration.unregister();
    }
    if (oldResolver != null) {
        try {
            oldResolver.close();
        } catch (IOException e) {
        // Ignore
        }
    }
}
Also used : MavenConfiguration(io.fabric8.maven.util.MavenConfiguration) MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) MavenResolver(io.fabric8.maven.MavenResolver) DictionaryPropertyResolver(org.ops4j.util.property.DictionaryPropertyResolver) IOException(java.io.IOException) PropertyResolver(org.ops4j.util.property.PropertyResolver) DictionaryPropertyResolver(org.ops4j.util.property.DictionaryPropertyResolver)

Example 2 with DictionaryPropertyResolver

use of org.ops4j.util.property.DictionaryPropertyResolver in project fabric8 by jboss-fuse.

the class MavenResolvers method createMavenResolver.

public static MavenResolver createMavenResolver(Mirror mirror, Dictionary<String, String> properties, String pid, RepositorySystem repositorySystem) {
    PropertiesPropertyResolver syspropsResolver = new PropertiesPropertyResolver(System.getProperties());
    DictionaryPropertyResolver propertyResolver = new DictionaryPropertyResolver(properties, syspropsResolver);
    MavenConfigurationImpl config = new MavenConfigurationImpl(propertyResolver, pid);
    return new AetherBasedResolver(config, mirror, repositorySystem);
}
Also used : MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) PropertiesPropertyResolver(org.ops4j.util.property.PropertiesPropertyResolver) DictionaryPropertyResolver(org.ops4j.util.property.DictionaryPropertyResolver) AetherBasedResolver(io.fabric8.maven.url.internal.AetherBasedResolver)

Example 3 with DictionaryPropertyResolver

use of org.ops4j.util.property.DictionaryPropertyResolver in project fabric8 by jboss-fuse.

the class MavenProxyServletSupportTest method createResolver.

private MavenResolver createResolver(String localRepo, List<String> remoteRepos, String proxyProtocol, String proxyHost, int proxyPort, String proxyUsername, String proxyPassword, String proxyNonProxyHosts) {
    Hashtable<String, String> props = new Hashtable<>();
    props.put("localRepository", localRepo);
    if (remoteRepos != null) {
        props.put("repositories", join(remoteRepos, ","));
    }
    MavenConfigurationImpl config = new MavenConfigurationImpl(new DictionaryPropertyResolver(props), null);
    if (proxyProtocol != null) {
        Proxy proxy = new Proxy();
        proxy.setProtocol(proxyProtocol);
        proxy.setHost(proxyHost);
        proxy.setPort(proxyPort);
        proxy.setUsername(proxyUsername);
        proxy.setPassword(proxyPassword);
        proxy.setNonProxyHosts(proxyNonProxyHosts);
        config.getSettings().addProxy(proxy);
    }
    return new AetherBasedResolver(config);
}
Also used : MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) Proxy(org.apache.maven.settings.Proxy) Hashtable(java.util.Hashtable) DictionaryPropertyResolver(org.ops4j.util.property.DictionaryPropertyResolver) AetherBasedResolver(io.fabric8.maven.url.internal.AetherBasedResolver)

Example 4 with DictionaryPropertyResolver

use of org.ops4j.util.property.DictionaryPropertyResolver in project fabric8 by jboss-fuse.

the class ProfileWatcherImpl method retrieveMavenConfiguration.

protected MavenConfiguration retrieveMavenConfiguration() {
    MavenConfiguration mavenConfiguration = null;
    try {
        Configuration configuration = configurationAdmin.get().getConfiguration("org.ops4j.pax.url.mvn");
        if (configuration != null) {
            Dictionary dictonary = configuration.getProperties();
            if (dictonary != null) {
                DictionaryPropertyResolver resolver = new DictionaryPropertyResolver(dictonary);
                mavenConfiguration = new MavenConfigurationImpl(resolver, "org.ops4j.pax.url.mvn");
            }
        }
    } catch (IOException e) {
        LOG.error("Error retrieving maven configuration", e);
    }
    return mavenConfiguration;
}
Also used : MavenConfiguration(io.fabric8.maven.util.MavenConfiguration) Dictionary(java.util.Dictionary) MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) Configuration(org.osgi.service.cm.Configuration) MavenConfiguration(io.fabric8.maven.util.MavenConfiguration) DictionaryPropertyResolver(org.ops4j.util.property.DictionaryPropertyResolver) IOException(java.io.IOException)

Example 5 with DictionaryPropertyResolver

use of org.ops4j.util.property.DictionaryPropertyResolver in project karaf by apache.

the class FeaturesProcessingSerializer method read.

/**
 * Reads {@link FeaturesProcessing features processing model} from input stream
 * @param stream
 * @param versions additional properties to resolve placeholders in features processing XML
 * @return
 */
public FeaturesProcessing read(InputStream stream, Properties versions) throws Exception {
    Unmarshaller unmarshaller = FEATURES_PROCESSING_CONTEXT.createUnmarshaller();
    UnmarshallerHandler handler = unmarshaller.getUnmarshallerHandler();
    // BundleContextPropertyResolver gives access to e.g., ${karaf.base}
    final PropertyResolver resolver = bundleContext == null ? new DictionaryPropertyResolver(versions) : new DictionaryPropertyResolver(versions, new BundleContextPropertyResolver(bundleContext));
    // indirect unmarshaling with property resolution inside XML attribute values and CDATA
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    XMLReader xmlReader = spf.newSAXParser().getXMLReader();
    xmlReader.setContentHandler(new ResolvingContentHandler(new Properties() {

        @Override
        public String getProperty(String key) {
            return resolver.get(key);
        }

        @Override
        public String getProperty(String key, String defaultValue) {
            String value = resolver.get(key);
            return value == null ? defaultValue : value;
        }
    }, handler));
    xmlReader.parse(new InputSource(stream));
    return (FeaturesProcessing) handler.getResult();
}
Also used : BundleContextPropertyResolver(org.ops4j.pax.swissbox.property.BundleContextPropertyResolver) InputSource(org.xml.sax.InputSource) UnmarshallerHandler(javax.xml.bind.UnmarshallerHandler) DictionaryPropertyResolver(org.ops4j.util.property.DictionaryPropertyResolver) Unmarshaller(javax.xml.bind.Unmarshaller) DictionaryPropertyResolver(org.ops4j.util.property.DictionaryPropertyResolver) PropertyResolver(org.ops4j.util.property.PropertyResolver) BundleContextPropertyResolver(org.ops4j.pax.swissbox.property.BundleContextPropertyResolver) Properties(java.util.Properties) XMLReader(org.xml.sax.XMLReader) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

DictionaryPropertyResolver (org.ops4j.util.property.DictionaryPropertyResolver)5 MavenConfigurationImpl (io.fabric8.maven.util.MavenConfigurationImpl)4 AetherBasedResolver (io.fabric8.maven.url.internal.AetherBasedResolver)2 MavenConfiguration (io.fabric8.maven.util.MavenConfiguration)2 IOException (java.io.IOException)2 PropertyResolver (org.ops4j.util.property.PropertyResolver)2 MavenResolver (io.fabric8.maven.MavenResolver)1 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 Properties (java.util.Properties)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 UnmarshallerHandler (javax.xml.bind.UnmarshallerHandler)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 FeaturesProcessing (org.apache.karaf.features.internal.model.processing.FeaturesProcessing)1 Proxy (org.apache.maven.settings.Proxy)1 BundleContextPropertyResolver (org.ops4j.pax.swissbox.property.BundleContextPropertyResolver)1 PropertiesPropertyResolver (org.ops4j.util.property.PropertiesPropertyResolver)1 Configuration (org.osgi.service.cm.Configuration)1 InputSource (org.xml.sax.InputSource)1 XMLReader (org.xml.sax.XMLReader)1