1 19 20 package org.netbeans.modules.java.source.parsing; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.ArrayList ; 25 import java.util.Collection ; 26 import java.util.Collections ; 27 import java.util.Comparator ; 28 import java.util.Iterator ; 29 import java.util.LinkedList ; 30 import java.util.List ; 31 import javax.tools.JavaFileObject; 32 import org.netbeans.api.java.classpath.ClassPath; 33 import org.netbeans.modules.java.source.TestUtil; 34 import org.netbeans.modules.java.preprocessorbridge.spi.JavaFileFilterImplementation; 35 import org.netbeans.modules.java.source.util.Factory; 36 37 44 class GoldenArchive implements Archive { 45 46 private File rootFolder; 47 private int rootLength; 48 49 51 63 public String getFilesDiff( String folderName, Archive archive ) throws IOException { 64 return TestUtil.collectionDiff( getFiles( folderName, null, null), archive.getFiles( folderName, null, null) ); 65 } 66 67 69 public GoldenArchive( File rootFolder ) { 70 if ( !rootFolder.isDirectory() ) { 71 throw new IllegalArgumentException ( "Root folder has to be a directory." ); 72 } 73 if ( !rootFolder.canRead() ) { 74 throw new IllegalArgumentException ( "Root folder has to be readable." ); 75 } 76 77 this.rootFolder = rootFolder; 78 this.rootLength = rootFolder.getPath().length(); 79 } 80 81 82 public Iterable <JavaFileObject> getFiles( String folderName, ClassPath.Entry e, JavaFileFilterImplementation filter ) { 83 84 File folder = new File ( rootFolder, folderName ); 85 86 if ( !folder.exists() ) { 87 return null; 88 } 89 90 File [] files = folder.listFiles(); 91 List <JavaFileObject> entries = new ArrayList <JavaFileObject>(); 92 93 for( File f : files ) { 94 if ( !f.isDirectory() ) { 95 entries.add( FileObjects.fileFileObject (f, rootFolder, null)); 96 } 97 } 98 99 Collections.sort( entries, new Comparator <JavaFileObject> () { 100 public int compare (JavaFileObject o1, JavaFileObject o2) { 101 return o1.toUri().toString().compareTo(o2.toUri().toString()); 102 } 103 }); 104 105 return entries; 106 } 107 108 public void clear () { 109 } 110 111 public void add (String pkg, String name) { 112 113 } 114 115 public void delete (String pkg, String name) { 116 117 } 118 119 120 122 124 private void storeFolders( Collection <File > dest, File folder, boolean isRoot ) { 125 126 File files[] = folder.listFiles(); 127 128 boolean hasFiles = false; 129 for (File f : files) { 130 if ( f.isDirectory() ) { 131 storeFolders( dest, f, false ); 132 } 133 else { 134 hasFiles = true; 135 } 136 } 137 138 if ( hasFiles && !isRoot ) { 139 dest.add( folder ); 140 } 141 142 } 143 144 146 private void storeFiles( Collection <File > dest, File folder ) { 147 148 File files[] = folder.listFiles(); 149 150 for ( File f : files) { 151 if ( f.isDirectory() ) { 152 storeFiles( dest, f ); 153 } 154 else { 155 dest.add( f ); 156 } 157 } 158 } 159 160 161 } | Popular Tags |