Example usage for java.lang Package getPackages

List of usage examples for java.lang Package getPackages

Introduction

In this page you can find the example usage for java.lang Package getPackages.

Prototype

@CallerSensitive
public static Package[] getPackages() 

Source Link

Document

Returns all of the Package s defined by the caller's class loader and its ancestors.

Usage

From source file:Main.java

public static void main(String args[]) {
    Package[] pack = Package.getPackages();
    for (int i = 0; i < pack.length; i++) {
        System.out.println(pack[i].isAnnotationPresent(Deprecated.class));
    }//from   ww w. j  av a2  s . c  o  m
}

From source file:Main.java

public static void main(String[] args) {

    // get all the packages
    Package[] pack = Package.getPackages();

    for (int i = 0; i < pack.length; i++) {
        System.out.println(pack[i]);
    }//ww w.j  a  v a2 s .c  o  m
}

From source file:MainClass.java

public static void main(String args[]) {
    Package pkgs[];//from   w ww. j  av  a  2  s . com

    pkgs = Package.getPackages();

    for (int i = 0; i < pkgs.length; i++)
        System.out.println(pkgs[i].getName() + " " + pkgs[i].getImplementationTitle() + " "
                + pkgs[i].getImplementationVendor() + " " + pkgs[i].getImplementationVersion());

}

From source file:com.ineunet.knife.mgt.ActivatorHelper.java

static int getBundleSize() {
    int size = 0;
    Package[] pkgs = Package.getPackages();
    for (Package pkg : pkgs) {
        String name = pkg.getName();
        if (name.endsWith(".internal")) {
            if (name.contains(".knife.")) {
                size++;/*from   www.  j av  a2s.  c o m*/
            } else if ("com.sun.naming.internal".equals(name)) {
                continue;
            } else {
                try {
                    Class<?> cls = ClassLocator.loadClass(name + ".Activator");
                    BundleActivator c = cls.getAnnotation(BundleActivator.class);
                    if (c != null) {
                        size++;
                    }
                } catch (ClassNotFoundException e) {
                    // other package has the same name '*.internal', ignore
                    continue;
                }
            }
        }
    }
    return size;
}

From source file:net.bafeimao.umbrella.servers.world.test.MiscTests.java

@Test
public void test1() {
    Package pkg = Package.getPackage("net");
    Package.getPackages();
    System.out.println(pkg);
}

From source file:eu.gentech.osgi.packagescanner.utils.PackageNameValidatorTest.java

@Test
public void testClasspath() {
    final Package[] packages = Package.getPackages();
    for (final Package pkg : packages) {
        Assert.assertTrue(PackageNameValidator.isValid(pkg.getName()));
    }//from  ww w .  j  a v  a  2s  .com
}

From source file:de.interactive_instruments.ShapeChange.Model.EA.EADocument.java

public void executeCommonInitializationProcedure() throws ShapeChangeAbortException {

    // determine if specific packages should not be loaded
    this.excludedPackageNames = options.getExcludedPackages();

    /** Cache classes and packages */
    // First set up initial evaluation tasks of packages consisting
    // of the models in the repository
    class EvalTask {
        PackageInfoEA fatherPI;//from w  w  w  .ja  v  a  2s.  c o m
        org.sparx.Package eaPackage;

        EvalTask(PackageInfoEA fpi, org.sparx.Package p) {
            fatherPI = fpi;
            eaPackage = p;
        }
    }

    StatusBoard.getStatusBoard().statusChanged(STATUS_EADOCUMENT_READMODEL);

    LinkedList<EvalTask> evalp = new LinkedList<EvalTask>();
    Collection<org.sparx.Package> model = repository.GetModels();
    for (org.sparx.Package p : model) {

        // Check if this model and all its contents shall be excluded
        String name = p.GetName();
        if (excludedPackageNames != null && excludedPackageNames.contains(name)) {
            // stop processing this model and continue with the next
            continue;
        }

        evalp.addLast(new EvalTask(null, p));
    }

    // Now remove tasks from the list, adding further tasks as we proceed
    // until we have no more tasks to evaluate
    while (evalp.size() > 0) {
        // Remove next evaluation task
        EvalTask et = evalp.removeFirst();
        org.sparx.Package pack = et.eaPackage;
        PackageInfoEA fpi = et.fatherPI;

        // Check if this package and all its contents shall be excluded from
        // the model
        String name = pack.GetName();
        if (excludedPackageNames != null && excludedPackageNames.contains(name)) {
            // stop processing this package and continue with the next
            continue;
        }

        // Add to package cache. The PackageInfo Ctor does the necessary
        // parent/child linkage of packages
        Element packelmt = pack.GetElement();
        PackageInfoEA pi = new PackageInfoEA(this, fpi, pack, packelmt);
        fPackageById.put(pi.id(), pi);
        if (packelmt != null)
            this.fPackageByElmtId.put(new Integer(packelmt.GetElementID()).toString(), pi);
        // Now pick all classes and add these to their to caches.
        for (org.sparx.Element elmt : pack.GetElements()) {
            String type = elmt.GetType();
            if (!type.equals("DataType") && !type.equals("Class") && !type.equals("Interface")
                    && !type.equals("Enumeration"))
                continue;
            ClassInfoEA ci = new ClassInfoEA(this, pi, elmt);
            fClassById.put(ci.id(), ci);
            // TODO What's happening to identical class names? How is this
            // supposed to be handled? Open issue.While classifier names
            // have to be
            // unique per app schema only, it is a legacy from Rational Rose
            // that it is expected that classifier names are unique in the
            // whole
            // model. The correct solution would be to add namespace
            // qualifiers.
            fClassByName.put(ci.name(), ci);
        }
        // Add next level packages for further evaluation
        for (org.sparx.Package pnxt : pack.GetPackages()) {
            evalp.addLast(new EvalTask(pi, pnxt));
        }
    }

    StatusBoard.getStatusBoard().statusChanged(STATUS_EADOCUMENT_ESTABLISHCLASSES);

    /**
     * Now that all classes are collected, in a second go establish class
     * derivation hierarchy and all other associations between classes.
     */
    for (ClassInfoEA ci : fClassById.values()) {

        // Generalization - class derivation hierarchy
        ci.establishClassDerivationHierarchy();
        // Other associations where the class is source or target
        ci.establishAssociations();
    }

    String checkingConstraints = options.parameter("checkingConstraints");
    if (checkingConstraints == null || !checkingConstraints.toLowerCase().trim().equals("disabled")) {
        StatusBoard.getStatusBoard().statusChanged(STATUS_EADOCUMENT_READCONSTARINTS);

        // TODO The following may be removed when constraints have been
        // tested.
        /** In a third go collect all constraints */
        for (ClassInfoEA ci : fClassById.values()) {
            ci.constraints();
            SortedMap<StructuredNumber, PropertyInfo> props = ci.properties();
            for (PropertyInfo pi : props.values())
                pi.constraints();
        }
    }

    /**
     * Loop over all schemas (i.e packages with a target namespace) and
     * store the schema location, so that it can be added in import
     * statements
     */
    SortedSet<PackageInfo> schemas = schemas("");
    for (Iterator<PackageInfo> i = schemas.iterator(); i.hasNext();) {
        PackageInfo pi = i.next();
        options.addSchemaLocation(pi.targetNamespace(), pi.xsdDocument());
    }

    // ==============================
    // load diagrams if so requested
    String loadDiagrams = options.parameter("loadDiagrams");

    if (loadDiagrams != null && loadDiagrams.equalsIgnoreCase("true")) {

        java.io.File tmpDir = options.imageTmpDir();

        if (tmpDir.exists()) {

            // probably content from previous run, delete the content of the directory
            try {
                FileUtils.deleteDirectory(tmpDir);
            } catch (IOException e) {
                result.addWarning(null, 34, tmpDir.getAbsolutePath());
            }

            if (!tmpDir.exists()) {
                try {
                    FileUtils.forceMkdir(tmpDir);
                } catch (IOException e) {
                    result.addWarning(null, 32, tmpDir.getAbsolutePath());
                }
            }
        }

        AtomicInteger imgIdCounter = new AtomicInteger(0);

        SortedSet<? extends PackageInfo> selectedSchema = this.selectedSchemas();

        for (PackageInfo pi : selectedSchema) {

            if (pi == null) {
                continue;
            }

            // Only process schemas in a namespace and name that matches a
            // user-selected pattern
            if (options.skipSchema(null, pi))
                continue;

            saveDiagrams(imgIdCounter, "img", tmpDir, escapeFileName(tmpDir.getName()), pi);
        }
    }

}

From source file:mitm.application.djigzo.DjigzoConfigurator.java

private static void logAllPackages() {
    List<Package> packages = Arrays.asList(Package.getPackages());

    Comparator<Package> packageComparator = new Comparator<Package>() {
        @Override/*from w w  w .j  a  v a 2 s .  c  om*/
        public int compare(Package package1, Package package2) {
            return package1.getName().compareTo(package2.getName());
        }
    };

    Collections.sort(packages, packageComparator);

    StrBuilder sb = new StrBuilder(1024);

    sb.appendNewLine();

    for (Package pack : packages) {
        sb.append("Package: ").append(pack.getName()).appendSeparator("; ");
        sb.append("Title: ").append(pack.getImplementationTitle()).appendSeparator("; ");
        sb.append("Version: ").append(pack.getImplementationVersion());
        sb.appendNewLine();
    }

    logger.info(sb.toString());
}

From source file:py.una.pol.karaku.configuration.KarakuWSClientConfiguration.java

private Jaxb2Marshaller getJaxb2Marshaller() {

    if (!isEnabled()) {
        return null;
    }//from w  w w  . j a  va2  s . c  om
    Pattern pattern = Pattern
            .compile(properties.get(KARAKU_WS_CLIENT_PACKAGES_TO_SCAN, DEFAULT_PACKAGES_TO_SCAN_EXPRESSION));

    Package[] packages = Package.getPackages();
    List<String> packagesFound = new ArrayList<String>();
    for (Package pa : packages) {
        Matcher matcher = pattern.matcher(pa.getName());
        if (matcher.matches()) {
            log.trace("Found a package to add to the marshaller: " + pa.getName());
            packagesFound.add(pa.getName());
        }
    }

    addSpecificPackages(packagesFound);

    return instanciateMarshaller(packagesFound);
}

From source file:org.omnaest.utils.reflection.ReflectionUtils.java

/**
 * Returns a {@link Map} of all {@link Package}s annotated with at least one of the given package level {@link Annotation}s
 * including the {@link Annotation} instances related to each {@link Package}. <br>
 * <br>/*from  w w  w.  j  ava 2 s.c  o m*/
 * If no {@link Annotation} is specified an empty {@link Map} is returned.
 * 
 * @see #annotatedPackageSet(Class...)
 * @param packageAnnotationTypes
 * @return
 */
public static <A extends Annotation> Map<Package, Set<A>> annotatedPackageToAnnotationSetMap(
        Class<? extends A>... packageAnnotationTypes) {
    final Set<Package> scannedPackageSet = SetUtils.valueOf(Package.getPackages());
    return annotatedPackageToAnnotationSetMap(scannedPackageSet, packageAnnotationTypes);
}