1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php 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 com.android.ide.eclipse.adt.internal.build; 18 19 import org.eclipse.core.resources.IFile; 20 21 import java.util.ArrayList; 22 import java.util.Collections; 23 import java.util.List; 24 25 /** 26 * Data for Android-specific source files. It contains a list of output files and a list 27 * of dependencies. 28 * The source file itself is a implied dependency and is not meant to be in the dependency list. 29 */ 30 public class SourceFileData { 31 32 private final IFile mSourceFile; 33 private final List<IFile> mOutputFiles = new ArrayList<IFile>(); 34 private final List<IFile> mDependencyFiles = new ArrayList<IFile>(); 35 SourceFileData(IFile sourceFile)36 public SourceFileData(IFile sourceFile) { 37 this(sourceFile, null, null); 38 } 39 SourceFileData(IFile sourceFile, List<IFile> outputFiles, List<IFile> dependencyFiles)40 SourceFileData(IFile sourceFile, 41 List<IFile> outputFiles, List<IFile> dependencyFiles) { 42 mSourceFile = sourceFile; 43 if (outputFiles != null) { 44 mOutputFiles.addAll(outputFiles); 45 } 46 if (dependencyFiles != null) { 47 mDependencyFiles.addAll(dependencyFiles); 48 } 49 } 50 SourceFileData(IFile sourceFile, IFile outputFile)51 SourceFileData(IFile sourceFile, IFile outputFile) { 52 mSourceFile = sourceFile; 53 if (outputFile != null) { 54 mOutputFiles.add(outputFile); 55 } 56 } 57 58 /** 59 * Returns the source file as an {@link IFile} 60 */ getSourceFile()61 public IFile getSourceFile() { 62 return mSourceFile; 63 } 64 65 /** 66 * Returns whether the given file is a dependency for this source file. 67 * <p/>Note that the source file itself is not tested against. Therefore if 68 * {@code file.equals(getSourceFile()} returns {@code true}, this method will return 69 * {@code false}. 70 * @param file the file to check against 71 * @return true if the given file is a dependency for this source file. 72 */ dependsOn(IFile file)73 public boolean dependsOn(IFile file) { 74 return mDependencyFiles.contains(file); 75 } 76 77 /** 78 * Returns whether the given file is an ouput of this source file. 79 * @param file the file to test. 80 * @return true if the file is an output file. 81 */ generated(IFile file)82 public boolean generated(IFile file) { 83 return mOutputFiles.contains(file); 84 } 85 setOutputFiles(List<IFile> outputFiles)86 void setOutputFiles(List<IFile> outputFiles) { 87 mOutputFiles.clear(); 88 if (outputFiles != null) { 89 mOutputFiles.addAll(outputFiles); 90 } 91 } 92 setOutputFile(IFile outputFile)93 void setOutputFile(IFile outputFile) { 94 mOutputFiles.clear(); 95 if (outputFile != null) { 96 mOutputFiles.add(outputFile); 97 } 98 } 99 setDependencyFiles(List<IFile> depFiles)100 void setDependencyFiles(List<IFile> depFiles) { 101 mDependencyFiles.clear(); 102 if (depFiles != null) { 103 mDependencyFiles.addAll(depFiles); 104 } 105 } 106 getDependencyFiles()107 public List<IFile> getDependencyFiles() { 108 return mDependencyFiles; 109 } 110 111 /** 112 * Shortcut access to the first output file. This is useful for generator that only output 113 * one file. 114 */ getOutput()115 public IFile getOutput() { 116 if (mOutputFiles.size() > 0) { 117 return mOutputFiles.get(0); 118 } 119 120 return null; 121 } 122 getOutputFiles()123 public List<IFile> getOutputFiles() { 124 return Collections.unmodifiableList(mOutputFiles); 125 } 126 127 @Override toString()128 public String toString() { 129 return "NonJavaFileBundle [mSourceFile=" + mSourceFile + ", mGeneratedFiles=" 130 + mOutputFiles + ", mDependencies=" + mDependencyFiles + "]"; 131 } 132 } 133