Author: fbricon
Date: 2012-10-04 10:35:44 -0400 (Thu, 04 Oct 2012)
New Revision: 44298
Modified:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/identification/ArtifactIdentifier.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/FileIdentificationManager.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/MavenPropertiesIdentifier.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusIndexIdentifier.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusRepositoryIdentifier.java
Log:
JBIDE-12529 add monitor to identify method
Modified:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/identification/ArtifactIdentifier.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/identification/ArtifactIdentifier.java 2012-10-04
14:34:33 UTC (rev 44297)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/identification/ArtifactIdentifier.java 2012-10-04
14:35:44 UTC (rev 44298)
@@ -13,10 +13,14 @@
import java.io.File;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.m2e.core.embedder.ArtifactKey;
public interface ArtifactIdentifier {
+ @Deprecated
ArtifactKey identify(File file) throws CoreException;
+ ArtifactKey identify(File file, IProgressMonitor monitor) throws CoreException;
+
}
\ No newline at end of file
Modified:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/FileIdentificationManager.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/FileIdentificationManager.java 2012-10-04
14:34:33 UTC (rev 44297)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/FileIdentificationManager.java 2012-10-04
14:35:44 UTC (rev 44298)
@@ -84,7 +84,7 @@
if (monitor.isCanceled()) {
return null;
}
- artifactKey = identifier.identify(file);
+ artifactKey = identifier.identify(file, monitor);
if (artifactKey != null) {
//long stop = System.currentTimeMillis();
//System.err.println(file.getName() + " identified as " + artifactKey +
" in " + (stop-start) + " ms");
Modified:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/MavenPropertiesIdentifier.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/MavenPropertiesIdentifier.java 2012-10-04
14:34:33 UTC (rev 44297)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/MavenPropertiesIdentifier.java 2012-10-04
14:35:44 UTC (rev 44298)
@@ -19,6 +19,8 @@
import java.util.zip.ZipFile;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.m2e.core.embedder.ArtifactKey;
public class MavenPropertiesIdentifier extends AbstractArtifactIdentifier {
@@ -28,9 +30,20 @@
}
public ArtifactKey identify(File file) throws CoreException {
+ return identify(file, null);
+ }
+
+ public ArtifactKey identify(File file, IProgressMonitor monitor) throws CoreException {
+ if (monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+ if (monitor.isCanceled()) {
+ return null;
+ }
ZipFile jar = null;
try {
jar = new ZipFile(file);
+ monitor.setTaskName("Checking for maven properties in " + file.getName());
return getArtifactFromMetaInf(jar);
} catch (ZipException e) {
e.printStackTrace();
Modified:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusIndexIdentifier.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusIndexIdentifier.java 2012-10-04
14:34:33 UTC (rev 44297)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusIndexIdentifier.java 2012-10-04
14:35:44 UTC (rev 44298)
@@ -15,6 +15,8 @@
import java.util.List;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.internal.index.IIndex;
@@ -36,10 +38,21 @@
}
public ArtifactKey identify(File file) throws CoreException {
+ return identify(file, null);
+ }
+
+ public ArtifactKey identify(File file, IProgressMonitor monitor) throws CoreException {
+ if (monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
IndexManager indexManager = MavenPlugin.getIndexManager();
IIndex index = indexManager.getAllIndexes();
IndexedArtifactFile info = null;
try {
+ if (monitor.isCanceled()) {
+ return null;
+ }
+ monitor.setTaskName("Checking global m2e Nexus index for "+file.getName());
info = index.identify(file);
} catch (Throwable e) {
// ignore
@@ -57,6 +70,10 @@
NexusIndex nexusIndex = nexusIndexManager.getIndex(repository);
if (nexusIndex != null) {
try {
+ if (monitor.isCanceled()) {
+ return null;
+ }
+ monitor.setTaskName("Checking Nexus index of '"+ repository.getId() +
"' repository for "+file.getName());
info = nexusIndex.identify(file);
} catch (Throwable t) {
// ignore
@@ -70,7 +87,6 @@
}
}
}
- //System.err.println(getName() + " could not identify "+file);
return artifact;
}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusRepositoryIdentifier.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusRepositoryIdentifier.java 2012-10-04
14:34:33 UTC (rev 44297)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusRepositoryIdentifier.java 2012-10-04
14:35:44 UTC (rev 44298)
@@ -16,12 +16,16 @@
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.net.UnknownHostException;
+import java.util.LinkedHashSet;
import java.util.Set;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.jboss.tools.maven.core.MavenCoreActivator;
import org.jboss.tools.maven.core.repositories.NexusRepository;
@@ -36,10 +40,20 @@
}
public ArtifactKey identify(File file) throws CoreException {
- return getArtifactFromRemoteNexusRepository(file);
+ return getArtifactFromRemoteNexusRepository(file, null);
}
- private ArtifactKey getArtifactFromRemoteNexusRepository(File file) {
+ public ArtifactKey identify(File file, IProgressMonitor monitor) throws CoreException {
+ return getArtifactFromRemoteNexusRepository(file, monitor);
+ }
+
+ private ArtifactKey getArtifactFromRemoteNexusRepository(File file, IProgressMonitor
monitor) {
+ if (monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+ if (monitor.isCanceled()) {
+ return null;
+ }
String sha1;
try {
sha1 = getSHA1(file);
@@ -47,38 +61,25 @@
return null;
}
RemoteRepositoryManager repoManager =
MavenCoreActivator.getDefault().getRepositoryManager();
- Set<NexusRepository> nexusRepositories = repoManager .getNexusRepositories();
+ Set<NexusRepository> nexusRepositories = new
LinkedHashSet<NexusRepository>(repoManager.getNexusRepositories());
for (NexusRepository repository : nexusRepositories) {
+ if (monitor.isCanceled()) {
+ return null;
+ }
if (!repository.isEnabled()) {
continue;
}
+ monitor.setTaskName("Querying "+repository.getUrl() + " for
"+file.getName());
+
try {
ArtifactKey key =
searchArtifactFromRemoteNexusRepository(repository.getSearchUrl(sha1));
if (key != null) {
- /*
- Searching for sources here makes no sense here :
- ex : guice.jar (from seam 2.3) is found in jboss nexus via a SHA1 search but
subsequent search
- of its sources on this repo returns null => guice.jar can never be identified in
that case!
- Source resolution / Missing sources should be dealt upstream from here
-
- String searchSourcesUrl = repository.getSearchUrl(key.getArtifactId(),
- key.getGroupId(),
- key.getVersion(),
- getSourcesClassifier(key.getClassifier()));
-
- ArtifactKey resolvedKey =
searchArtifactFromRemoteNexusRepository(searchSourcesUrl);
-
- if (resolvedKey != null) {
- return key;
- }
- */
return key;
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
- //System.err.println(getName()+ "Couldn't find match for SHA1="+sha1);
return null;
}
@@ -96,6 +97,8 @@
if (object instanceof SearchResponse) {
return extractArtifactKey((SearchResponse)object);
}
+ } catch (UnknownHostException uhe) {
+ System.err.println("NexusRepositoryIdentifier can't connect to remote
repository :"+ uhe.getMessage());
} catch (Exception e) {
e.printStackTrace();
} finally {
Show replies by date