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 17package vogar; 18 19import java.io.File; 20import java.util.ArrayList; 21import java.util.Collections; 22import java.util.HashSet; 23import java.util.List; 24import java.util.Set; 25 26/** 27 * Stores and presents information about jars the user may have forgotten to include. 28 */ 29public final class JarSuggestions { 30 private final Set<File> allSuggestedJars = new HashSet<File>(); 31 32 public Set<File> getAllSuggestedJars() { 33 return allSuggestedJars; 34 } 35 36 public void addSuggestions(JarSuggestions jarSuggestions) { 37 allSuggestedJars.addAll(jarSuggestions.getAllSuggestedJars()); 38 } 39 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 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