diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchScopeTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchScopeTests.java index deb70fd..52af315 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchScopeTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchScopeTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 @@ -1025,7 +1025,7 @@ // Index the output location as it is a library for the project IndexManager indexManager = JavaModelManager.getIndexManager(); - indexManager.indexLibrary(new Path("/P1/bin"), project.getProject()); + indexManager.indexLibrary(new Path("/P1/bin"), project.getProject(), null); waitUntilIndexesReady(); // Search for all types diff --git a/org.eclipse.jdt.core/META-INF/MANIFEST.MF b/org.eclipse.jdt.core/META-INF/MANIFEST.MF index bb3c0af..354c648 100644 --- a/org.eclipse.jdt.core/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.core/META-INF/MANIFEST.MF @@ -17,6 +17,7 @@ org.eclipse.jdt.core.jdom, org.eclipse.jdt.core.search, org.eclipse.jdt.core.util, + org.eclipse.jdt.core.index, org.eclipse.jdt.internal.codeassist;x-internal:=true, org.eclipse.jdt.internal.codeassist.complete;x-internal:=true, org.eclipse.jdt.internal.codeassist.impl;x-internal:=true, diff --git a/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/internal/antadapter/messages.properties b/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/internal/antadapter/messages.properties index df61656..9cb9be2 100644 --- a/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/internal/antadapter/messages.properties +++ b/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/internal/antadapter/messages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2006 IBM Corporation and others. +# Copyright (c) 2000, 2011 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 @@ -19,3 +19,7 @@ checkDebugAttributes.property.argument.cannot.be.null=The property argument cannot be null checkDebugAttributes.ioexception.occured=IOException occurred while reading checkDebugAttributes.file.argument.must.be.a.classfile.or.a.jarfile=The file argument must be a .class or a .jar file + +buildJarIndex.jarFile.cannot.be.null=The jar file argument cannot be null +buildJarIndex.indexFile.cannot.be.null=The index file argument cannot be null +buildJarIndex.ioexception.occured=IOException - {0} diff --git a/org.eclipse.jdt.core/build.properties b/org.eclipse.jdt.core/build.properties index ff520f9..8e3f678 100644 --- a/org.eclipse.jdt.core/build.properties +++ b/org.eclipse.jdt.core/build.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2010 IBM Corporation and others. +# Copyright (c) 2000, 2011 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 @@ -24,7 +24,8 @@ org.eclipse.jdt.core.jdom.*,\ org.eclipse.jdt.core.dom.*,\ org.eclipse.jdt.core.dom.rewrite.*,\ - org.eclipse.jdt.core.search.* + org.eclipse.jdt.core.search.*,\ + org.eclipse.jdt.core.index.* source.. = batch/,\ codeassist/,\ compiler/,\ diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IClasspathAttribute.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IClasspathAttribute.java index d90ab15..220f397 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IClasspathAttribute.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IClasspathAttribute.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2011 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 @@ -58,6 +58,16 @@ * @since 3.1 */ String JAVADOC_LOCATION_ATTRIBUTE_NAME = "javadoc_location"; //$NON-NLS-1$ + + /** + * Constant for the name of the index location attribute. + * + *
The value for this attribute has to be the string representation of a URL. + * It should point to an existing index file in a folder or a jar.
+ * + * @since 3.8 + */ + String INDEX_LOCATION_ATTRIBUTE_NAME = "index_location"; //$NON-NLS-1$ /** * Constant for the name of the optional attribute. The possible values diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaElementDelta.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaElementDelta.java index bc17b09..b52c5ef 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaElementDelta.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaElementDelta.java @@ -57,6 +57,12 @@ *null
if this package fragment root's binary archive
+ * has no corresponding index file, or if this package fragment root
+ * is not a binary archive
+ * @exception JavaModelException if this operation fails
+ *
+ * @since 3.8
+ */
+ URL getIndexPath() throws JavaModelException;
+ /**
* Returns this package fragment root's kind encoded as an integer.
* A package fragment root can contain source files (i.e. files with one
* of the {@link JavaCore#getJavaLikeExtensions() Java-like extensions},
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathChange.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathChange.java
index b96cd44..df8fbfa 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathChange.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathChange.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.jdt.internal.core;
+import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -362,12 +363,15 @@
}
// check source attachment
+ // TODO SATYAM: Understand this
IPath newSourcePath = newResolvedClasspath[index].getSourceAttachmentPath();
int sourceAttachmentFlags = getSourceAttachmentDeltaFlag(this.oldResolvedClasspath[i].getSourceAttachmentPath(), newSourcePath);
IPath oldRootPath = this.oldResolvedClasspath[i].getSourceAttachmentRootPath();
IPath newRootPath = newResolvedClasspath[index].getSourceAttachmentRootPath();
int sourceAttachmentRootFlags = getSourceAttachmentDeltaFlag(oldRootPath, newRootPath);
- int flags = sourceAttachmentFlags | sourceAttachmentRootFlags;
+ URL newIndexPath = ((ClasspathEntry)newResolvedClasspath[index]).getLibraryIndexLocation();
+ int indexFlags = getIndexDeltaFlag(((ClasspathEntry)this.oldResolvedClasspath[i]).getLibraryIndexLocation(), newIndexPath);
+ int flags = sourceAttachmentFlags | sourceAttachmentRootFlags | indexFlags;
if (flags != 0) {
addClasspathDeltas(delta, this.project.computePackageFragmentRoots(this.oldResolvedClasspath[i]), flags);
} else {
@@ -432,6 +436,25 @@
}
return result;
+ }
+
+ /*
+ * TODO SATYAM: Put a comment
+ */
+ private int getIndexDeltaFlag(URL oldPath, URL newPath) {
+ if (oldPath == null) {
+ if (newPath != null) {
+ return IJavaElementDelta.F_INDEXATTACHED;
+ } else {
+ return 0;
+ }
+ } else if (newPath == null) {
+ return IJavaElementDelta.F_INDEXDETACHED;
+ } else if (!oldPath.equals(newPath)) {
+ return IJavaElementDelta.F_INDEXATTACHED | IJavaElementDelta.F_INDEXDETACHED;
+ } else {
+ return 0;
+ }
}
/*
@@ -511,7 +534,7 @@
for (int i = 0; i < newLength; i++) {
int index = classpathContains(this.oldResolvedClasspath, newResolvedClasspath[i]);
- if (index == -1) {
+ if (index == -1 || newResolvedClasspath[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
// remote projects are not indexed in this project
if (newResolvedClasspath[i].getEntryKind() == IClasspathEntry.CPE_PROJECT){
continue;
@@ -524,14 +547,23 @@
boolean pathHasChanged = true;
IPath newPath = newResolvedClasspath[i].getPath();
for (int j = 0; j < oldLength; j++) {
+ //TODO SATYAM: Isn't index == j?
IClasspathEntry oldEntry = this.oldResolvedClasspath[j];
if (oldEntry.getPath().equals(newPath)) {
- pathHasChanged = false;
+ URL oldurl = ((ClasspathEntry)oldEntry).getLibraryIndexLocation();
+ URL newurl = ((ClasspathEntry)newResolvedClasspath[i]).getLibraryIndexLocation();
+ if (oldurl == null && newurl == null) {
+ pathHasChanged = false;
+ } else if (oldurl != null && newurl != null) {
+ pathHasChanged = !(newurl.equals(oldurl));
+ } else if (oldurl != null) {
+ indexManager.removeIndex(newPath);
+ }
break;
}
}
if (pathHasChanged) {
- indexManager.indexLibrary(newPath, this.project.getProject());
+ indexManager.indexLibrary(newPath, this.project.getProject(),((ClasspathEntry)newResolvedClasspath[i]).getLibraryIndexLocation());
}
break;
case IClasspathEntry.CPE_SOURCE:
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java
index d8086ff..567ec4a 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java
@@ -16,6 +16,8 @@
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -2164,4 +2166,31 @@
}
return JavaModelStatus.VERIFIED_OK;
}
+
+ /*
+ * This function computes the URL of the index location for this classpath entry.
+ * It returns null if the URL is invalid.
+ */
+ public URL getLibraryIndexLocation() {
+ switch(getEntryKind()) {
+ case IClasspathEntry.CPE_LIBRARY :
+ case IClasspathEntry.CPE_VARIABLE :
+ break;
+ default :
+ return null;
+ }
+
+ for (int i= 0; i < this.extraAttributes.length; i++) {
+ IClasspathAttribute attrib= this.extraAttributes[i];
+ if (IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) {
+ String value = attrib.getValue();
+ try {
+ return new URL(value);
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+ }
+ return null;
+ }
}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessingState.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessingState.java
index 6f94386..f93b992 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessingState.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessingState.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 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
@@ -18,6 +18,7 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.net.URL;
import java.util.*;
import org.eclipse.core.resources.*;
@@ -75,6 +76,9 @@
/* A table from IPath (a source attachment path from a classpath entry) to IPath (a root path) */
public HashMap sourceAttachments = new HashMap();
+ /* TODO SATYAM: Is this necessary?*/
+ public HashMap indexMap = new HashMap();
+
/* A table from IJavaProject to IJavaProject[] (the list of direct dependent of the key) */
public HashMap projectDependencies = new HashMap();
@@ -262,6 +266,7 @@
this.otherRoots = rootInfos[1];
this.sourceAttachments = rootInfos[2];
this.projectDependencies = rootInfos[3];
+ this.indexMap = rootInfos[4];
this.rootsAreStale = false;
}
}
@@ -274,6 +279,7 @@
this.otherRoots = rootInfos[1];
this.sourceAttachments = rootInfos[2];
this.projectDependencies = rootInfos[3];
+ this.indexMap = rootInfos[4];
this.rootsAreStale = false;
}
}
@@ -283,6 +289,7 @@
HashMap newOtherRoots = new HashMap();
HashMap newSourceAttachments = new HashMap();
HashMap newProjectDependencies = new HashMap();
+ HashMap newIndexes = new HashMap();
IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
IJavaProject[] projects;
@@ -354,9 +361,15 @@
if (sourceAttachmentPath != null) {
newSourceAttachments.put(sourceAttachmentPath, path);
}
+
+ //TODO SATYAM: Do we need something like this?
+ URL url = ((ClasspathEntry)entry).getLibraryIndexLocation();
+ if (url != null) {
+ newIndexes.put(url, path);
+ }
}
}
- return new HashMap[] {newRoots, newOtherRoots, newSourceAttachments, newProjectDependencies};
+ return new HashMap[] {newRoots, newOtherRoots, newSourceAttachments, newProjectDependencies, newIndexes};
}
public synchronized ClasspathValidation[] removeClasspathValidations() {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java
index f7a0c1c..2c65200 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java
@@ -590,6 +590,38 @@
}
}
}
+ private void checkIndexChange(IResourceDelta delta, IResource res) {
+ IPath rootPath = (IPath)this.state.indexMap.get(externalPath(res));
+ if (rootPath != null) {
+ RootInfo rootInfo = rootInfo(rootPath, delta.getKind());
+ if (rootInfo != null) {
+ IJavaProject projectOfRoot = rootInfo.project;
+ IPackageFragmentRoot root = null;
+ try {
+ // close the root so that source attachment cache is flushed
+ root = projectOfRoot.findPackageFragmentRoot(rootPath);
+ if (root != null) {
+ root.close();
+ }
+ } catch (JavaModelException e) {
+ // root doesn't exist: ignore
+ }
+ if (root == null) return;
+ switch (delta.getKind()) {
+ case IResourceDelta.ADDED:
+ currentDelta().indexAttached(root);
+ break;
+ case IResourceDelta.CHANGED:
+ currentDelta().indexDetached(root);
+ currentDelta().indexAttached(root);
+ break;
+ case IResourceDelta.REMOVED:
+ currentDelta().indexDetached(root);
+ break;
+ }
+ }
+ }
+ }
/*
* Closes the given element, which removes it from the cache of open elements.
*/
@@ -996,7 +1028,7 @@
// first remove the index so that it is forced to be re-indexed
this.manager.indexManager.removeIndex(entryPath);
// then index the jar
- this.manager.indexManager.indexLibrary(entryPath, project.getProject());
+ this.manager.indexManager.indexLibrary(entryPath, project.getProject(), ((ClasspathEntry)entries[j]).getLibraryIndexLocation());
} else {
externalArchivesStatus.put(entryPath, EXTERNAL_JAR_UNCHANGED);
}
@@ -1008,7 +1040,7 @@
this.state.getExternalLibTimeStamps().put(entryPath, new Long(newTimeStamp));
// index the new jar
this.manager.indexManager.removeIndex(entryPath);
- this.manager.indexManager.indexLibrary(entryPath, project.getProject());
+ this.manager.indexManager.indexLibrary(entryPath, project.getProject(), ((ClasspathEntry)entries[j]).getLibraryIndexLocation());
}
}
} else { // internal JAR
@@ -2239,6 +2271,7 @@
// check source attachment change
checkSourceAttachmentChange(child, childRes);
+ checkIndexChange(child, childRes);
// find out whether the child is a package fragment root of the current project
IPath childPath = externalPath(childRes);
@@ -2628,13 +2661,13 @@
switch (delta.getKind()) {
case IResourceDelta.ADDED:
// index the new jar
- indexManager.indexLibrary(jarPath, root.getJavaProject().getProject());
+ indexManager.indexLibrary(jarPath, root.getJavaProject().getProject(), root.getIndexPath() );
break;
case IResourceDelta.CHANGED:
// first remove the index so that it is forced to be re-indexed
indexManager.removeIndex(jarPath);
// then index the jar
- indexManager.indexLibrary(jarPath, root.getJavaProject().getProject());
+ indexManager.indexLibrary(jarPath, root.getJavaProject().getProject(), root.getIndexPath());
break;
case IResourceDelta.REMOVED:
// the jar was physically removed: remove the index
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElementDelta.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElementDelta.java
index ee0d715..e55c951 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElementDelta.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElementDelta.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 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
@@ -569,6 +569,29 @@
detachedDelta.changed(F_SOURCEDETACHED);
insertDeltaTree(element, detachedDelta);
}
+
+/**
+ * Creates the nested deltas resulting from a change operation.
+ * Convenience method for creating change deltas.
+ * The constructor should be used to create the root delta
+ * and then a change operation should call this method.
+ */
+public void indexAttached(IJavaElement element) {
+ JavaElementDelta attachedDelta = new JavaElementDelta(element);
+ attachedDelta.changed(F_INDEXATTACHED);
+ insertDeltaTree(element, attachedDelta);
+}
+/**
+ * Creates the nested deltas resulting from a change operation.
+ * Convenience method for creating change deltas.
+ * The constructor should be used to create the root delta
+ * and then a change operation should call this method.
+ */
+public void indexDetached(IJavaElement element) {
+ JavaElementDelta detachedDelta = new JavaElementDelta(element);
+ detachedDelta.changed(F_INDEXDETACHED);
+ insertDeltaTree(element, detachedDelta);
+}
/**
* Returns a string representation of this delta's
* structure suitable for debug purposes.
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java
index cdead40..6b7eb77 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java
@@ -180,6 +180,8 @@
* Map from a package fragment root's path to a source attachment property (source path + ATTACHMENT_PROPERTY_DELIMITER + source root path)
*/
public Map rootPathToAttachments = new Hashtable();
+ //TODO SATYAM: Is this necessary
+ public Map rootPathToIndexes = new Hashtable();
public final static String CP_VARIABLE_PREFERENCES_PREFIX = JavaCore.PLUGIN_ID+".classpathVariable."; //$NON-NLS-1$
public final static String CP_CONTAINER_PREFERENCES_PREFIX = JavaCore.PLUGIN_ID+".classpathContainer."; //$NON-NLS-1$
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java
index 9fb59c6..6aa31bd 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.jdt.internal.core;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Map;
@@ -807,4 +808,19 @@
}
}
+public URL getIndexPath() {
+ try {
+ if (getKind() != K_BINARY) return null;
+
+ IClasspathEntry entry = ((JavaProject) getParent()).getClasspathEntryFor(getPath());
+ URL indexPath;
+ if (entry != null && (indexPath = ((ClasspathEntry)entry).getLibraryIndexLocation()) != null)
+ return indexPath;
+
+ } catch (JavaModelException e) {
+ // ignore exception
+ }
+ return null;
+}
+
}
diff --git a/org.eclipse.jdt.core/plugin.xml b/org.eclipse.jdt.core/plugin.xml
index 3784256..5d69788 100644
--- a/org.eclipse.jdt.core/plugin.xml
+++ b/org.eclipse.jdt.core/plugin.xml
@@ -1,7 +1,7 @@
@@ -196,6 +201,17 @@
+
+
++ * On MacOS, when invoked using the Eclipse executable, the "user.dir" property is set to the folder in which the + * eclipse.ini file is located. This makes it harder to use relative paths to point to the files to be formatted or the + * configuration file to use to set the code formatter's options. + *
+ * + * + * @since 3.8 + * @noinstantiate This class is not intended to be instantiated by clients. + * @noextend This class is not intended to be subclassed by clients. + */ +public class JavaIndexerApplication implements IApplication { + + private final static class Messages extends NLS { + private static final String MESSAGES_NAME = "org.eclipse.jdt.core.index.messages";//$NON-NLS-1$ + + public static String CommandLineProcessing; + public static String CommandLineUsage; + public static String CommandLineOnlyOutputError; + public static String CommandLineOnlyOneJarError; + public static String CommandLineJarNotSpecified; + public static String CommandLineIndexFileNotSpecified; + public static String CaughtException; + public static String CommandLineJarFileNotExist; + + static { + NLS.initializeMessages(MESSAGES_NAME, Messages.class); + } + + public static String bind(String message) { + return bind(message, null); + } + + public static String bind(String message, Object binding) { + return bind(message, new Object[] { binding }); + } + + public static String bind(String message, Object binding1, Object binding2) { + return bind(message, new Object[] { binding1, binding2 }); + } + + public static String bind(String message, Object[] bindings) { + return MessageFormat.format(message, bindings); + } + } + + private String jarToIndex; + private String indexFile; + private boolean verbose = false; + private static final String PDE_LAUNCH = "-pdelaunch"; //$NON-NLS-1$ + private static final String ARG_HELP = "-help"; //$NON-NLS-1$ + private static final String ARG_VERBOSE = "-verbose"; //$NON-NLS-1$ + private static final String ARG_OUTPUT = "-output"; //$NON-NLS-1$ + + private void displayHelp() { + System.out.println(Messages.bind(Messages.CommandLineUsage)); + } + + private void displayError(String message) { + System.err.println(message); + System.out.println(); + displayHelp(); + } + + private boolean processCommandLine(String[] argsArray) { + ArrayList args = new ArrayList(); + for (int i = 0, max = argsArray.length; i < max; i++) { + args.add(argsArray[i]); + } + int index = 0; + final int argCount = argsArray.length; + + loop: while (index < argCount) { + String currentArg = argsArray[index++]; + if (PDE_LAUNCH.equals(currentArg)) { + continue loop; + } else if (ARG_HELP.equals(currentArg)) { + displayHelp(); + return false; + } else if (ARG_VERBOSE.equals(currentArg)) { + this.verbose = true; + continue loop; + } else if (ARG_OUTPUT.equals(currentArg)) { + if (this.indexFile != null || index == argCount) { + displayError(Messages.bind(Messages.CommandLineOnlyOutputError)); + return false; + } + this.indexFile = argsArray[index++]; + } else { + if (this.jarToIndex != null) { + displayError(Messages.bind(Messages.CommandLineOnlyOneJarError)); + return false; + } + this.jarToIndex = currentArg; + } + } + return true; + } + + public Object start(IApplicationContext context) throws Exception { + boolean execute = processCommandLine((String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS)); + if (execute) { + if (this.jarToIndex != null && this.indexFile != null) { + File f = new File(this.jarToIndex); + if (!f.exists()) { + System.out.println(Messages.bind(Messages.CommandLineJarFileNotExist, this.jarToIndex)); + } + if (this.verbose) { + System.out.println(Messages.bind(Messages.CommandLineProcessing, this.jarToIndex, this.indexFile)); + } + try { + JavaIndexer.generateIndexForJar(this.jarToIndex, this.indexFile); + } catch (IOException e) { + System.out.println(Messages.bind(Messages.CaughtException, "IOException", e.getLocalizedMessage())); //$NON-NLS-1$ + } + } else if (this.jarToIndex == null) { + System.out.println(Messages.bind(Messages.CommandLineJarNotSpecified)); + } else if (this.indexFile == null) { + System.out.println(Messages.bind(Messages.CommandLineIndexFileNotSpecified)); + } + } + return IApplication.EXIT_OK; + } + + public void stop() { + // do nothing + } + +} diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/core/index/messages.properties b/org.eclipse.jdt.core/search/org/eclipse/jdt/core/index/messages.properties new file mode 100644 index 0000000..704b29f --- /dev/null +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/core/index/messages.properties @@ -0,0 +1,28 @@ +############################################################################### +# Copyright (c) 2000, 2006 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 +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +CommandLineUsage=Usage: eclipse -application org.eclipse.jdt.core.JavaCodeGenerateIndex [ OPTIONS ] -output