Creates a PackageDescriptor for the named package using the
specified ClassLoader to load the PackageInfo or Package.
540412
public PackageDescriptor createPackageDescriptor(String packageName,
                                                     ClassLoader classLoader) {
        return PackageDescriptor.forName(packageName, classLoader);
    }
219303
public ClassLoader findBundleClassLoader(String packageName, String versionRange)
    {
    	ClassLoader classLoader = this.getClassLoaderFromBundle(null, packageName, versionRange);

        if (classLoader == null) {
            Object resource = this.deployThisResource(packageName, versionRange, false);
            if (resource != null)
            	classLoader = this.getClassLoaderFromBundle(resource, packageName, versionRange);
        }

        return classLoader;    	
    }
277490
private StringBuilder makeNewPackageName(final StringBuilder packageName, final File dir) {
		if (packageName.length() == 0) {
			return new StringBuilder(dir.getName());
		} else {
			return new StringBuilder(packageName).append(PATH_SEPARATOR).append(dir.getName());
		}
	}
423318
public void addPackageDescr(PackageDescr descr) {
        try {

            PackageDescrVisitor ruleFlattener = new PackageDescrVisitor( result.getVerifierData(),
                                                                         jars );

            ruleFlattener.visitPackageDescr( descr );

        } catch ( Throwable t ) {
            t.printStackTrace();
        }
    }
757235
public PackageDocImpl getPackageDoc(PackageSymbol pack) {
        PackageDocImpl result = packageMap.get(pack);
        if (result != null) return result;
        result = new PackageDocImpl(this, pack);
        packageMap.put(pack, result);
        return result;
    }
697834
protected Class findClassInternal(String name)
        throws ClassNotFoundException {

        if (!validate(name))
            throw new ClassNotFoundException(name);

        String tempPath = name.replace('.', '/');
        String classPath = tempPath + ".class";

        ResourceEntry entry = null;

        entry = findResourceInternal(name, classPath);

        if (entry == null)
            throw new ClassNotFoundException(name);

        Class clazz = entry.loadedClass;
        if (clazz != null)
            return clazz;

        synchronized (this) {
            if (entry.binaryContent == null && entry.loadedClass == null)
                throw new ClassNotFoundException(name);

            // Looking up the package
            String packageName = null;
            int pos = name.lastIndexOf('.');
            if (pos != -1)
                packageName = name.substring(0, pos);
        
            Package pkg = null;
        
            if (packageName != null) {
                pkg = getPackage(packageName);
                // Define the package (if null)
                if (pkg == null) {
                    try {
                        if (entry.manifest == null) {
                            definePackage(packageName, null, null, null, null,
                                    null, null, null);
                        } else {
                            definePackage(packageName, entry.manifest,
                                    entry.codeBase);
                        }
                    } catch (IllegalArgumentException e) {
                        // Ignore: normal error due to dual definition of package
                    }
                    pkg = getPackage(packageName);
                }
            }
    
            if (securityManager != null) {

                // Checking sealing
                if (pkg != null) {
                    boolean sealCheck = true;
                    if (pkg.isSealed()) {
                        sealCheck = pkg.isSealed(entry.codeBase);
                    } else {
                        sealCheck = (entry.manifest == null)
                            || !isPackageSealed(packageName, entry.manifest);
                    }
                    if (!sealCheck)
                        throw new SecurityException
                            ("Sealing violation loading " + name + " : Package "
                             + packageName + " is sealed.");
                }
    
            }

            if (entry.loadedClass == null) {
                clazz = defineClass(name, entry.binaryContent, 0,
                        entry.binaryContent.length, 
                        new CodeSource(entry.codeBase, entry.certificates));
                entry.loadedClass = clazz;
                entry.binaryContent = null;
                entry.source = null;
                entry.codeBase = null;
                entry.manifest = null;
                entry.certificates = null;
            } else {
                clazz = entry.loadedClass;
            }
        }
        
        return clazz;

    }
1151416
@SuppressWarnings("unchecked")
    public static <T> Set<Class<T>> loadClasses(String packageName, Class<T> baseClassOrInterface)
    {
        Set<Class<T>> result = new HashSet<>();

        try
        {
            Set<String> classNames = getClassNamesFromPackage(packageName);
            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            for (String className : classNames)
            {
                try
                {
                    Class< ? > clazz = classLoader.loadClass(packageName + "." + className);
                    if (!Modifier.isAbstract(clazz.getModifiers()) && baseClassOrInterface.isAssignableFrom(clazz))
                    {
                        result.add((Class<T>) clazz);
                    }
                }
                catch (Throwable e)
                {
                    logger.error(e, e);
                }

            }
            logger.info("Loaded " + result.size());
        }
        catch (Exception e)
        {
            logger.error(e, e);
        }

        return result;
    }
191049
public void loadPackage() {
		if (isLoaded)
			return;
		isLoaded = true;

		URL url = getClass().getResource(packageFilename);
		if (url == null) {
			throw new RuntimeException("Missing serialized package: " + packageFilename);
		}
		URI uri = URI.createURI(url.toString());
		Resource resource = new EcoreResourceFactoryImpl().createResource(uri);
		try {
			resource.load(null);
		} catch (IOException exception) {
			throw new WrappedException(exception);
		}
		initializeFromLoadedEPackage(this, (EPackage) resource.getContents().get(0));
		createResource(eNS_URI);
	}
321125
public ClasspathScanDescriptorProvider scanPackage(final String packageName, final boolean recursive,
            final ClassLoader classLoader) {
        return scanPackage(packageName, recursive, classLoader, true);
    }
972612
public static RepositoryPackage fromPackagist(String name) throws Exception {
		
		PackagistDownloader downloader = new PackagistDownloader();
		return downloader.loadPackage(name);
	}
1349996
protected void packageDef(AST packageDef) {
        List<AnnotationNode> annotations = new ArrayList<AnnotationNode>();
        AST node = packageDef.getFirstChild();
        if (isType(ANNOTATIONS, node)) {
            processAnnotations(annotations, node);
            node = node.getNextSibling();
        }
        String name = qualifiedName(node);
        // TODO should we check package node doesn't already exist? conflict?
        PackageNode packageNode = setPackage(name, annotations);
        configureAST(packageNode, packageDef);
    }
883549
private static void initFromPackageInfo(PackageDescriptor pd,
                                            Class<?> packageInfoClass) 
    throws Exception {


        pd.setExists(true);

        Class<?>[] ca = new Class[0];
        Object[] oa = new Object[0];

        pd.setSpecificationTitle(
            (String) (packageInfoClass.getMethod("getSpecificationTitle", 
                                                 ca)).invoke(null, oa));

        pd.setSpecificationVersion(
            (String) (packageInfoClass.getMethod("getSpecificationVersion", 
                                                 ca)).invoke(null, oa));

        pd.setSpecificationVendor(
            (String) (packageInfoClass.getMethod("getSpecificationVendor", 
                                                 ca)).invoke(null, oa));

        pd.setImplementationTitle(
            (String) (packageInfoClass.getMethod("getImplementationTitle", 
                                                 ca)).invoke(null, oa));

        pd.setImplementationVersion(
            (String) (packageInfoClass.getMethod("getImplementationVersion", 
                                                 ca)).invoke(null, oa));

        pd.setImplementationVendor(
            (String) (packageInfoClass.getMethod("getImplementationVendor", 
                                                 ca)).invoke(null, oa));

        pd.setBaseDirectory(
            (String) (packageInfoClass.getMethod("getBaseDirectory", 
                                                 ca)).invoke(null, oa));

        pd.setRepository(
            (String) (packageInfoClass.getMethod("getRepository", 
                                                 ca)).invoke(null, oa));

        pd.setUsername(
            (String) (packageInfoClass.getMethod("getUsername", 
                                                 ca)).invoke(null, oa));

        pd.setBuildMachine(
            (String) (packageInfoClass.getMethod("getBuildMachine", 
                                                 ca)).invoke(null, oa));

        pd.setGroup(
            (String) (packageInfoClass.getMethod("getGroup", 
                                                 ca)).invoke(null, oa));

        pd.setProject(
            (String) (packageInfoClass.getMethod("getProject", 
                                                 ca)).invoke(null, oa));

        pd.setBuildLocation(
            (String) (packageInfoClass.getMethod("getBuildLocation", 
                                                 ca)).invoke(null, oa));

        pd.setProduct(
            (String) (packageInfoClass.getMethod("getProduct", 
                                                 ca)).invoke(null, oa));

        pd.setProductVersion(
            (String) (packageInfoClass.getMethod("getProductVersion", 
                                                 ca)).invoke(null, oa));

        pd.setBuildNumber(
            (String) (packageInfoClass.getMethod("getBuildNumber", 
                                                 ca)).invoke(null, oa));

        pd.setBuildDate(
            (Date) (packageInfoClass.getMethod("getBuildDate", 
                                               ca)).invoke(null, oa));


    }
294089
public Class<?> loadClassFrom(String name, AbstractClassLoader first) throws ClassNotFoundException {
		// try on the system one
		try { return AppClassLoader.class.getClassLoader().loadClass(name); }
		catch (ClassNotFoundException e) { /* not found. */ }
		Class<?> c = null;
		// check it is not loaded on one of the library
		for (int i = 0; i < libs.size(); i++) {
    		AbstractClassLoader cl = libs.get(i);
    		c = cl.isLoaded(name);
    		if (c != null) return c;
    	}
    	// try with the first one
    	if (first != null) {
    		try {
    			c = first.loadClassInLibrary(name);
    			if (c != null) return c;
    		} catch (FileNotFoundException e) {
    			// not found
    		} catch (IOException e) {
    			throw new ClassNotFoundException(e.getMessage());
    		}
    	}
    	// then, try on other libraries
    	for (int i = 0; i < libs.size(); i++) {
    		AbstractClassLoader cl = libs.get(i);
    		if (cl == first) continue;
    		try {
    			c = cl.loadClassInLibrary(name);
    			if (c != null) return c;
    		} catch (FileNotFoundException e) {
    			// not found
    		} catch (IOException e) {
    			throw new ClassNotFoundException(e.getMessage());
    		}
    	}
		StringBuilder msg = new StringBuilder(512);
		msg.append("Class not found: ").append(name);
		msg.append("\r\nFrom class loader: ").append(first);
		msg.append("\r\nlibraries currently registered:");
		for (int i = 0; i < libs.size(); i++)
			msg.append("\r\n - ").append(libs.get(i).toString());
		throw new ClassNotFoundException(msg.toString());
	}

	/** Load a resource. */
	@SuppressWarnings("resource")
	public IO.Readable getResourceIO(String name, byte priority) {
		if (name.length() == 0) return null;
		if (name.charAt(0) == '/') name = name.substring(1);
		IO.Readable io = null;
    	for (int i = 0; i < libs.size(); i++) {
    		AbstractClassLoader cl = libs.get(i);
   			try { io = cl.open(name, priority); }
   			catch (IOException e) { /* ignore */ }
    		if (io != null) return io;
    	}
       	// then try on the core one
        InputStream in = AppClassLoader.class.getClassLoader().getResourceAsStream(name);
        if (in == null) return null;
        return new IOFromInputStream(in, name, Threading.getUnmanagedTaskManager(), priority);
	}
1134218
protected ClassLoader getClassLoader() {
        ClassLoader loader = null;
        Package pkg = PackageCache.getProcessPackage(getProcessId());
        if (pkg != null) {
            loader = pkg.getCloudClassLoader();
        }
        if (loader == null) {
            loader = getClass().getClassLoader();
        }
        return loader;
    }
291979
private void findPluginsForDescriptor(final CommandLinePluginDescriptor<?> pluginDescriptor)
    {
        final ClassFinder classFinder = new ClassFinder();
        pluginDescriptor.getPackageNames().forEach(
                pkg -> classFinder.find(pkg, pluginDescriptor.getPluginBaseClass()));
        final Set<Class<?>> pluginClasses = classFinder.getClasses();

        for (Class<?> c : pluginClasses) {
            if (pluginDescriptor.includePluginClass(c)) {
                try {
                    final Object plugin = pluginDescriptor.createInstanceForPlugin(c);
                    createArgumentDefinitions(plugin, pluginDescriptor);
                } catch (InstantiationException | IllegalAccessException e) {
                    throw new CommandLineException.CommandLineParserInternalException("Problem making an instance of plugin " + c +
                            " Do check that the class has a non-arg constructor", e);
                }
            }
        }
    }
804140
public CacheConfigurationBuilder<K, V> withClassLoader(ClassLoader classLoader) {
    CacheConfigurationBuilder<K, V> otherBuilder = new CacheConfigurationBuilder<>(this);
    otherBuilder.classLoader = classLoader;
    return otherBuilder;
  }
760538
public static String packageNameOf(Class<?> clazz) {
        String name = clazz.getName();
        int pos = name.lastIndexOf('.');
        E.unexpectedIf(pos < 0, "Class does not have package: " + name);
        return name.substring(0, pos);
    }