• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package vogar;
18 
19 import java.io.File;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Set;
25 
26 /**
27  * Stores and presents information about jars the user may have forgotten to include.
28  */
29 public final class JarSuggestions {
30     private final Set<File> allSuggestedJars = new HashSet<File>();
31 
getAllSuggestedJars()32     public Set<File> getAllSuggestedJars() {
33         return allSuggestedJars;
34     }
35 
addSuggestions(JarSuggestions jarSuggestions)36     public void addSuggestions(JarSuggestions jarSuggestions) {
37         allSuggestedJars.addAll(jarSuggestions.getAllSuggestedJars());
38     }
39 
addSuggestionsFromOutcome(Outcome outcome, ClassFileIndex classFileIndex, Classpath classpath)40     public void addSuggestionsFromOutcome(Outcome outcome, ClassFileIndex classFileIndex,
41             Classpath classpath) {
42         Result result = outcome.getResult();
43         if (result != Result.COMPILE_FAILED && result != Result.EXEC_FAILED) {
44             return;
45         }
46         Set<File> suggestedJars = classFileIndex.suggestClasspaths(outcome.getOutput());
47         // don't suggest adding a jar that's already on the classpath
48         suggestedJars.removeAll(classpath.getElements());
49 
50         allSuggestedJars.addAll(suggestedJars);
51     }
52 
getStringList()53     public List<String> getStringList() {
54         List<String> jarStringList = new ArrayList<String>();
55         for (File jar : allSuggestedJars) {
56             jarStringList.add(jar.getPath());
57         }
58         Collections.sort(jarStringList);
59         return jarStringList;
60     }
61 }
62