Package java.util

Examples of java.util.SortedSet


        }
    }

    public SortedSet getLoadedArtifacts(Artifact query) {
        List values = (List) artifactsByArtifact.get(query.getArtifactId());
        SortedSet results = new TreeSet();
        if (values != null) {
            for (int i = 0; i < values.size(); i++) {
                Artifact test = (Artifact) values.get(i);
                if(query.matches(test)) {
                    results.add(test);
                }
            }
        }
        return results;
    }
View Full Code Here


        return working;
    }

    private Artifact resolveVersion(Collection parentConfigurations, Artifact working) {
        SortedSet existingArtifacts;
        if (artifactManager != null) {
            existingArtifacts = artifactManager.getLoadedArtifacts(working);
        } else {
            existingArtifacts = new TreeSet();
        }

        // if we have exactly one artifact loaded use its' version
        if (existingArtifacts.size() == 1) {
            return (Artifact) existingArtifacts.first();
        }

        //see if there is an explicit resolution for this artifact.
        Artifact resolved = (Artifact) explicitResolution.get(working);
        if (resolved != null) {
            return resolved;
        }
        //see if there is an entry for the whole groupId.
        Artifact groupId = new Artifact(working.getGroupId(), "", (Version)null, "");
        resolved = (Artifact) explicitResolution.get(groupId);
        if (resolved != null) {
            return new Artifact(working.getGroupId(), working.getArtifactId(), resolved.getVersion(), working.getType());
        }


        // if we have no existing loaded artifacts grab the highest version from the repository
        if (existingArtifacts.size() == 0) {
            SortedSet list = new TreeSet();
            for (Iterator iterator = repositories.iterator(); iterator.hasNext();) {
                ListableRepository repository = (ListableRepository) iterator.next();
                list.addAll(repository.list(working));
            }

            if (list.isEmpty()) {
                return null;
            }
            return (Artifact) list.last();
        }

        // more than one version of the artifact was loaded...

        // if one of parents already loaded the artifact, use that version
View Full Code Here

        Set artifacts2 = new HashSet();
        Artifact private2 = new Artifact("private2", "artifact", "1", "jar");
        artifacts2.add(private2);
        artifactManager.loadArtifacts(loader2, artifacts2);

        SortedSet loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("private1", "artifact", (Version)null, "jar"));
        assertEquals(Collections.singleton(private1), loadedArtifacts);

        loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("loaderGroup", "loaderArtifact1", (Version)null, "car"));
        assertEquals(Collections.singleton(loader1), loadedArtifacts);
View Full Code Here

        Set artifacts = new HashSet();
        artifacts.add(version1);
        artifacts.add(version2);

        SortedSet loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("version", "version", (Version)null, "jar"));
        assertEquals(artifacts, loadedArtifacts);

        artifactManager.unloadAllArtifacts(loader1);
        loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("version", "version", (Version)null, "jar"));
        assertEquals(Collections.singleton(version2), loadedArtifacts);
View Full Code Here

        artifactManager.loadArtifacts(loader1, Collections.singleton(artifact));

        Artifact loader2 = new Artifact("loaderGroup", "loaderArtifact2", "1", "car");
        artifactManager.loadArtifacts(loader2, Collections.singleton(artifact));

        SortedSet loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("dupe", "dupe", (Version)null, "jar"));
        assertEquals(Collections.singleton(artifact), loadedArtifacts);

        artifactManager.unloadAllArtifacts(loader1);

        loadedArtifacts = artifactManager.getLoadedArtifacts(new Artifact("dupe", "dupe", (Version)null, "jar"));
View Full Code Here

     *
     * @return A Map with key type String (plugin name) and value type Artifact
     *         (config ID of the plugin).
     */
    public Map getInstalledPlugins() {
        SortedSet artifacts = writeableRepo.list();

        Map plugins = new HashMap();
        for (Iterator i = artifacts.iterator(); i.hasNext();) {
            Artifact configId = (Artifact) i.next();
            File dir = writeableRepo.getLocation(configId);
            if(dir.isDirectory()) {
                File meta = new File(dir, "META-INF");
                if(!meta.isDirectory() || !meta.canRead()) {
View Full Code Here

            path = new File(path, query.getArtifactId());
            if(!path.canRead() || !path.isDirectory()) {
                return new TreeSet();
            }

            SortedSet artifacts = new TreeSet();

            File[] versionDirs = path.listFiles();
            for (int i = 0; i < versionDirs.length; i++) {
                File versionDir = versionDirs[i];
                if (versionDir.canRead() && versionDir.isDirectory()) {
                    String version = versionDir.getName();
                    if(query.getVersion() != null && !query.getVersion().toString().equals(version)) {
                        continue;
                    }
                    // Assumes that artifactId is set
                    final String filePrefix = query.getArtifactId() + "-" + version + ".";
                    File[] list = versionDir.listFiles(new FilenameFilter() {
                        public boolean accept(File dir, String name) {
                            return name.startsWith(filePrefix);
                        }
                    });
                    for (int j = 0; j < list.length; j++) {
                        File file = list[j];
                        String end = file.getName().substring(filePrefix.length());
                        if(query.getType() != null && !query.getType().equals(end)) {
                            continue;
                        }
                        if(end.indexOf('.') < 0) {
                            artifacts.add(new Artifact(query.getGroupId(), query.getArtifactId(), version, end));
                        }
                    }
                }
            }
            return artifacts;
View Full Code Here

            return listInternal(query.getArtifactId(), query.getType(), query.getVersion() == null ? null : query.getVersion().toString());
        }
    }

    private SortedSet listInternal(String artifactMatch, String typeMatch, String versionMatch) {
        SortedSet artifacts = new TreeSet();
        File[] groupIds = rootFile.listFiles();
        for (int i = 0; i < groupIds.length; i++) {
            File groupId = groupIds[i];
            if (groupId.canRead() && groupId.isDirectory()) {
                File[] versionDirs = groupId.listFiles();
                for (int j = 0; j < versionDirs.length; j++) {
                    File versionDir = versionDirs[j];
                    if (versionDir.canRead() && versionDir.isDirectory()) {
                        artifacts.addAll(getArtifacts(null, versionDir, artifactMatch, typeMatch, versionMatch));
                    }
                }
            }
        }
        return artifacts;
View Full Code Here

        File file = null;
       
        for (Repository arepository : repositories) {
            if (arepository instanceof ListableRepository) {
                ListableRepository repository = (ListableRepository) arepository;
                SortedSet artifactSet = repository.list(artifactQuery);
                // if we have exactly one artifact found
                if (artifactSet.size() == 1) {
                    file = repository.getLocation((Artifact) artifactSet.first());
                    return file.getAbsoluteFile();
                } else if (artifactSet.size() > 1) {// if we have more than 1 artifacts found use the latest one.
                    file = repository.getLocation((Artifact) artifactSet.last());
                    return file.getAbsoluteFile();
                }
            }
        }
       
View Full Code Here

               }
            }

            if ( keySet == null ) {
               // Fall back to a Collection scan
               SortedSet set = new TreeSet();
               RecordSet rs = context.getFiler().getRecordSet();
               while ( rs.hasMoreRecords() )
                  set.add(rs.getNextKey());
               keySet = (Key[])set.toArray(EmptyKeys);
            }

            return new ResultSet(context, pr, keySet, query);
         }
         catch ( Exception e ) {
View Full Code Here

TOP

Related Classes of java.util.SortedSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.