001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.gsfret.source.usages;
043:
044: import java.io.File;
045: import java.io.IOException;
046: import java.io.InputStream;
047: import java.net.URL;
048: import java.util.HashMap;
049: import java.util.HashSet;
050: import java.util.List;
051: import java.util.Map;
052: import java.util.Set;
053: import java.util.concurrent.atomic.AtomicBoolean;
054: import org.netbeans.api.progress.ProgressHandle;
055: import org.netbeans.modules.gsfret.source.util.LowMemoryEvent;
056: import org.netbeans.modules.gsfret.source.util.LowMemoryListener;
057:
058: /**
059: * This file is originally from Retouche, the Java Support
060: * infrastructure in NetBeans. I have modified the file as little
061: * as possible to make merging Retouche fixes back as simple as
062: * possible.
063: *
064: *
065: * @author Petr Hrebejk, Tomas Zezula
066: */
067: public class BinaryAnalyser implements LowMemoryListener {
068:
069: public void lowMemory(LowMemoryEvent event) {
070: // throw new UnsupportedOperationException("Not supported yet.");
071: }
072: //
073: // static final String OBJECT = Object.class.getName();
074: //
075: // private final Index index;
076: // private final Map<String,List<String>> refs = new HashMap<String,List<String>>();
077: // private final Set<String> toDelete = new HashSet<String> ();
078: // private final AtomicBoolean lowMemory;
079: // private boolean cacheCleared;
080: //
081: // public BinaryAnalyser (Index index) {
082: // assert index != null;
083: // this.index = index;
084: // this.lowMemory = new AtomicBoolean (false);
085: // }
086: //
087: // /** Analyses a classpath root.
088: // * @param URL the classpath root, either a folder or an archive file.
089: // *
090: // */
091: // public final void analyse (final URL root, final ProgressHandle handle) throws IOException, IllegalArgumentException {
092: //// assert root != null;
093: //// ClassIndexManager.getDefault().writeLock(new ClassIndexManager.ExceptionAction<Void> () {
094: //// public Void run () throws IOException {
095: //// LowMemoryNotifier.getDefault().addLowMemoryListener (BinaryAnalyser.this);
096: //// try {
097: //// if (root.isDirectory()) { //NOI18N
098: //// String path = root.getAbsolutePath ();
099: //// if (path.charAt(path.length()-1) != File.separatorChar) {
100: //// path = path + File.separatorChar;
101: //// }
102: //// cacheCleared = false;
103: //// analyseFolder(root, path);
104: //// }
105: //// else {
106: //// if (root.exists() && root.canRead()) {
107: //// if (!isUpToDate(null,root.lastModified())) {
108: //// index.clear();
109: //// if (handle != null) { //Tests don't provide handle
110: //// handle.setDisplayName (NbBundle.getMessage(RepositoryUpdater.class,"MSG_Analyzing",root.getAbsolutePath()));
111: //// }
112: //// final ZipFile zipFile = new ZipFile(root);
113: //// try {
114: //// analyseArchive( zipFile );
115: //// }
116: //// finally {
117: //// zipFile.close();
118: //// }
119: //// }
120: //// }
121: //// }
122: //// } finally {
123: //// LowMemoryNotifier.getDefault().removeLowMemoryListener(BinaryAnalyser.this);
124: //// }
125: //// store();
126: //// return null;
127: //// }});
128: // }
129: //
130: // /** Analyses a folder
131: // * @param folder to analyze
132: // * @param rootURL the url of root, it would be nicer to pass an URL type,
133: // * but the {@link URL#toExternalForm} from some strange reason does not cache result,
134: // * the String type is faster.
135: // */
136: // private void analyseFolder (final File folder, final String rootPath) throws IOException {
137: //// if (folder.exists() && folder.canRead()) {
138: //// File[] children = folder.listFiles();
139: //// for (File file : children) {
140: //// if (file.isDirectory()) {
141: //// analyseFolder(file, rootPath);
142: //// }
143: //// else if (this.accepts(file.getName())) {
144: //// String filePath = file.getAbsolutePath();
145: //// long fileMTime = file.lastModified();
146: //// int dotIndex = filePath.lastIndexOf('.');
147: //// int slashIndex = filePath.lastIndexOf('/');
148: //// int endPos;
149: //// if (dotIndex>slashIndex) {
150: //// endPos = dotIndex;
151: //// }
152: //// else {
153: //// endPos = filePath.length();
154: //// }
155: //// String relativePath = FileObjects.convertFolder2Package (filePath.substring(rootPath.length(), endPos));
156: //// if (!isUpToDate (relativePath, fileMTime)) {
157: //// if (!cacheCleared) {
158: //// this.index.clear();
159: //// cacheCleared = true;
160: //// }
161: //// InputStream in = new BufferedInputStream (new FileInputStream (file));
162: //// analyse (in);
163: //// if (this.lowMemory.getAndSet(false)) {
164: //// this.store();
165: //// }
166: //// }
167: //// }
168: //// }
169: //// }
170: // }
171: //
172: // public void lowMemory (final LowMemoryEvent event) {
173: // this.lowMemory.set(true);
174: // }
175: //
176: // // Implementation of StreamAnalyser ----------------------------------------
177: //
178: // private boolean accepts(String name) {
179: // int index = name.lastIndexOf('.');
180: // if (index == -1 || (index+1) == name.length()) {
181: // return false;
182: // }
183: // return "CLASS".equalsIgnoreCase(name.substring(index+1)); // NOI18N
184: // }
185: //
186: // //Cleans up usages of deleted class
187: // private final void delete (final String className) throws IOException {
188: // assert className != null;
189: // if (!this.index.isValid(false)) {
190: // return;
191: // }
192: // this.toDelete.add(className);
193: // }
194: //
195: // private void analyse (InputStream inputStream ) throws IOException {
196: //// throw new RuntimeException("Not yet implemented");
197: // }
198: //
199: //
200: // private final boolean isUpToDate(String resourceName, long resourceMTime) throws IOException {
201: // return this.index.isUpToDate(resourceName, resourceMTime);
202: // }
203: }
|