Search in sources :

Example 1 with Glob

use of aQute.libg.glob.Glob in project bnd by bndtools.

the class Analyzer method getJarsFromName.

public List<Jar> getJarsFromName(String name, String from) {
    Jar j = super.getJarFromName(name, from);
    if (j != null)
        return Collections.singletonList(j);
    Glob g = new Glob(name);
    List<Jar> result = new ArrayList<>();
    for (Iterator<Jar> cp = getClasspath().iterator(); cp.hasNext(); ) {
        Jar entry = cp.next();
        if (entry.getSource() == null)
            continue;
        if (g.matcher(entry.getSource().getName()).matches()) {
            result.add(entry);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Glob(aQute.libg.glob.Glob)

Example 2 with Glob

use of aQute.libg.glob.Glob in project bnd by bndtools.

the class bnd method _find.

public void _find(FindOptions options) throws Exception {
    List<File> files = new ArrayList<File>();
    List<String> args = options._arguments();
    if (args.size() == 0) {
        Project p = getProject();
        if (p == null) {
            error("This is not a project directory and you have specified no jar files ...");
            return;
        }
        File output = p.getOutput();
        if (output.exists()) {
            files.add(output);
        }
        for (Container c : p.getBuildpath()) {
            files.add(c.getFile());
        }
    } else {
        for (String f : args) {
            File file = getFile(f);
            files.add(file);
        }
    }
    for (File f : files) {
        logger.debug("find {}", f);
        try (Jar jar = new Jar(f)) {
            Manifest m = jar.getManifest();
            if (m != null) {
                Domain domain = Domain.domain(m);
                if (options.exports() != null) {
                    Parameters ep = domain.getExportPackage();
                    for (Glob g : options.exports()) {
                        for (Entry<String, Attrs> exp : ep.entrySet()) {
                            if (g.matcher(exp.getKey()).matches()) {
                                String v = exp.getValue().get(VERSION_ATTRIBUTE);
                                if (v == null)
                                    v = "0";
                                out.printf(">%s: %s-%s%n", f.getPath(), exp.getKey(), v);
                            }
                        }
                    }
                }
                if (options.imports() != null) {
                    Parameters ip = domain.getImportPackage();
                    for (Glob g : options.imports()) {
                        for (Entry<String, Attrs> imp : ip.entrySet()) {
                            if (g.matcher(imp.getKey()).matches()) {
                                String v = imp.getValue().get(VERSION_ATTRIBUTE);
                                if (v == null)
                                    v = "0";
                                out.printf("<%s: %s-%s%n", f.getPath(), imp.getKey(), v);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) ArrayList(java.util.ArrayList) Attrs(aQute.bnd.header.Attrs) Manifest(java.util.jar.Manifest) PomFromManifest(aQute.bnd.maven.PomFromManifest) Project(aQute.bnd.build.Project) Container(aQute.bnd.build.Container) Glob(aQute.libg.glob.Glob) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 3 with Glob

use of aQute.libg.glob.Glob in project bnd by bndtools.

the class WorkspaceRepository method list.

public List<String> list(String pattern) throws Exception {
    List<String> names = new ArrayList<String>();
    Collection<Project> projects = workspace.getAllProjects();
    for (Project project : projects) {
        for (String bsn : project.getBsns()) {
            if (pattern != null) {
                Glob glob = new Glob(pattern);
                Matcher matcher = glob.matcher(bsn);
                if (matcher.matches()) {
                    if (!names.contains(bsn)) {
                        names.add(bsn);
                    }
                }
            } else {
                if (!names.contains(bsn)) {
                    names.add(bsn);
                }
            }
        }
    }
    return names;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Glob(aQute.libg.glob.Glob)

Example 4 with Glob

use of aQute.libg.glob.Glob in project bnd by bndtools.

the class BridgeRepository method list.

public List<String> list(String pattern) throws Exception {
    List<String> bsns = new ArrayList<>();
    if (pattern == null || pattern.equals("*") || pattern.equals("")) {
        bsns.addAll(index.keySet());
    } else {
        String[] split = pattern.split("\\s+");
        Glob[] globs = new Glob[split.length];
        for (int i = 0; i < split.length; i++) {
            globs[i] = new Glob(split[i]);
        }
        outer: for (String bsn : index.keySet()) {
            for (Glob g : globs) {
                if (g.matcher(bsn).find()) {
                    bsns.add(bsn);
                    continue outer;
                }
            }
        }
    }
    return bsns;
}
Also used : ArrayList(java.util.ArrayList) Glob(aQute.libg.glob.Glob)

Example 5 with Glob

use of aQute.libg.glob.Glob in project bnd by bndtools.

the class ConnectionSettings method createProxyHandler.

/**
	 * Create Proxy Handler from ProxyDTO
	 */
public static ProxyHandler createProxyHandler(final ProxyDTO proxyDTO) {
    return new ProxyHandler() {

        Glob[] globs;

        private ProxySetup proxySetup;

        @Override
        public ProxySetup forURL(URL url) throws Exception {
            switch(proxyDTO.protocol) {
                case DIRECT:
                    break;
                case HTTP:
                    String scheme = url.getProtocol();
                    if (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https")) {
                    // ok
                    } else
                        return null;
                    break;
                case SOCKS:
                    break;
                default:
                    break;
            }
            String host = url.getHost();
            if (host != null) {
                if (isNonProxyHost(host))
                    return null;
            }
            if (proxySetup == null) {
                proxySetup = new ProxySetup();
                if (proxyDTO.username != null && proxyDTO.password != null)
                    proxySetup.authentication = new PasswordAuthentication(proxyDTO.username, proxyDTO.password.toCharArray());
                SocketAddress socketAddress;
                if (proxyDTO.host != null)
                    socketAddress = new InetSocketAddress(proxyDTO.host, proxyDTO.port);
                else
                    socketAddress = new InetSocketAddress(proxyDTO.port);
                proxySetup.proxy = new Proxy(proxyDTO.protocol, socketAddress);
            }
            return proxySetup;
        }

        public boolean isNonProxyHost(String host) {
            Glob[] globs = getNonProxyHosts(proxyDTO);
            for (Glob glob : globs) {
                if (glob.matcher(host).matches())
                    return true;
            }
            return false;
        }

        public Glob[] getNonProxyHosts(final ProxyDTO proxyDTO) {
            // not synchronized because conflicts only do some double work
            if (globs == null) {
                if (proxyDTO.nonProxyHosts == null)
                    globs = new Glob[0];
                else {
                    String[] parts = proxyDTO.nonProxyHosts.split("\\s*\\|\\s*");
                    globs = new Glob[parts.length];
                    for (int i = 0; i < parts.length; i++) globs[i] = new Glob(parts[i]);
                }
            }
            return globs;
        }
    };
}
Also used : ProxyHandler(aQute.bnd.service.url.ProxyHandler) InetSocketAddress(java.net.InetSocketAddress) URL(java.net.URL) Proxy(java.net.Proxy) Glob(aQute.libg.glob.Glob) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) PasswordAuthentication(java.net.PasswordAuthentication)

Aggregations

Glob (aQute.libg.glob.Glob)22 ArrayList (java.util.ArrayList)11 File (java.io.File)7 Parameters (aQute.bnd.header.Parameters)3 Description (aQute.lib.getopt.Description)3 IOException (java.io.IOException)3 Project (aQute.bnd.build.Project)2 Attrs (aQute.bnd.header.Attrs)2 Domain (aQute.bnd.osgi.Domain)2 Jar (aQute.bnd.osgi.Jar)2 CommandData (aQute.jpm.lib.CommandData)2 Service (aQute.jpm.lib.Service)2 ServiceData (aQute.jpm.lib.ServiceData)2 ExtList (aQute.lib.collections.ExtList)2 InputStream (java.io.InputStream)2 SocketException (java.net.SocketException)2 URL (java.net.URL)2 Matcher (java.util.regex.Matcher)2 Container (aQute.bnd.build.Container)1 PomFromManifest (aQute.bnd.maven.PomFromManifest)1