diff options
Diffstat (limited to 'bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/search/indexing/SourceIndexer.java')
-rw-r--r-- | bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/search/indexing/SourceIndexer.java | 67 |
1 files changed, 62 insertions, 5 deletions
diff --git a/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/search/indexing/SourceIndexer.java b/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/search/indexing/SourceIndexer.java index dedc317d..25b3c0eb 100644 --- a/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/search/indexing/SourceIndexer.java +++ b/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/search/indexing/SourceIndexer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,18 +11,30 @@ *******************************************************************************/ package org.eclipse.wst.jsdt.internal.core.search.indexing; +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; + import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.wst.jsdt.core.JavaScriptCore; import org.eclipse.wst.jsdt.core.search.SearchDocument; +import org.eclipse.wst.jsdt.core.search.SearchEngine; +import org.eclipse.wst.jsdt.core.search.SearchParticipant; import org.eclipse.wst.jsdt.internal.compiler.SourceElementParser; import org.eclipse.wst.jsdt.internal.compiler.util.SuffixConstants; +import org.eclipse.wst.jsdt.internal.compiler.util.Util; import org.eclipse.wst.jsdt.internal.core.BasicCompilationUnit; import org.eclipse.wst.jsdt.internal.core.JavaModelManager; +import org.eclipse.wst.jsdt.internal.core.Logger; +import org.eclipse.wst.jsdt.internal.core.index.Index; import org.eclipse.wst.jsdt.internal.core.search.JavaSearchDocument; -import org.eclipse.wst.jsdt.internal.core.search.processing.JobManager; import org.eclipse.wst.jsdt.internal.oaametadata.LibraryAPIs; import org.eclipse.wst.jsdt.internal.oaametadata.MetadataReader; import org.eclipse.wst.jsdt.internal.oaametadata.MetadataSourceElementNotifier; @@ -79,9 +91,7 @@ public class SourceIndexer extends AbstractIndexer implements SuffixConstants { try { parser.parseCompilationUnit(compilationUnit, true/*full parse*/); } catch (Exception e) { - if (JobManager.VERBOSE) { - e.printStackTrace(); - } + Logger.logException("Error while indexing document", e); } } public void indexMetadata() { @@ -112,5 +122,52 @@ public class SourceIndexer extends AbstractIndexer implements SuffixConstants { new MetadataSourceElementNotifier(apis,requestor).notifyRequestor(); } + public void indexArchive() { + /* + * index the individual documents in the archive into the single index + * file for the archive's path + */ + IPath jarPath = new Path(this.document.getPath()); + + File file = new File(jarPath.toOSString()); + if (file.isFile()) { + IndexManager indexManager = JavaModelManager.getJavaModelManager().getIndexManager(); + Index index = indexManager.getIndexForUpdate(jarPath, false /*don't reuse index file*/, true /*create if none*/); + SearchParticipant participant = SearchEngine.getDefaultSearchParticipant(); + ZipFile zip = null; + try { + zip = new ZipFile(file); + for (Enumeration e = zip.entries(); e.hasMoreElements();) { + // iterate each entry to index it + ZipEntry ze = (ZipEntry) e.nextElement(); + if (Util.isClassFileName(ze.getName())) { + final byte[] classFileBytes = org.eclipse.wst.jsdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip); + JavaSearchDocument entryDocument = new JavaSearchDocument(ze, jarPath, ByteBuffer.wrap(classFileBytes).asCharBuffer().array(), participant); + indexManager.indexDocument(entryDocument, participant, index, jarPath); + } + } + indexManager.saveIndex(index); + } + catch (ZipException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + finally { + if (zip != null) { + try { + zip.close(); + } + catch (IOException e) { + } + if(index != null) { + } + } + } + } + } } |