# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /Users/mkleint/src/core-main-backup # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: maven/manifest.mf --- maven/manifest.mf +++ maven/manifest.mf @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.maven/2 -OpenIDE-Module-Specification-Version: 2.84 +OpenIDE-Module-Specification-Version: 2.85 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/maven/Bundle.properties OpenIDE-Module-Layer: org/netbeans/modules/maven/layer.xml AutoUpdate-Show-In-Client: false Index: maven/nbproject/project.xml --- maven/nbproject/project.xml +++ maven/nbproject/project.xml @@ -86,7 +86,7 @@ 1 - 1.35 + 1.49 Index: maven/src/org/netbeans/modules/maven/queries/MavenSourceJavadocAttacher.java --- maven/src/org/netbeans/modules/maven/queries/MavenSourceJavadocAttacher.java +++ maven/src/org/netbeans/modules/maven/queries/MavenSourceJavadocAttacher.java @@ -42,12 +42,15 @@ import java.io.IOException; import java.net.URL; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.concurrent.Callable; +import java.util.logging.Level; +import java.util.logging.Logger; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException; import org.netbeans.api.annotations.common.NonNull; -import org.netbeans.api.java.queries.SourceJavadocAttacher.AttachmentListener; import org.netbeans.api.progress.aggregate.AggregateProgressFactory; import org.netbeans.api.progress.aggregate.AggregateProgressHandle; import org.netbeans.api.progress.aggregate.ProgressContributor; @@ -60,31 +63,24 @@ import org.netbeans.spi.java.queries.SourceJavadocAttacherImplementation; import org.openide.awt.StatusDisplayer; import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; import org.openide.util.NbBundle.Messages; import org.openide.util.RequestProcessor; +import org.openide.util.Utilities; import org.openide.util.lookup.ServiceProvider; -@ServiceProvider(service=SourceJavadocAttacherImplementation.class, position=200) -public class MavenSourceJavadocAttacher implements SourceJavadocAttacherImplementation { +@ServiceProvider(service=SourceJavadocAttacherImplementation.Definer.class) +public class MavenSourceJavadocAttacher implements SourceJavadocAttacherImplementation.Definer { + private static final Logger LOG = Logger.getLogger(MavenSourceJavadocAttacher.class.getName()); - private static final RequestProcessor RP = new RequestProcessor(MavenSourceJavadocAttacher.class.getName(), 5); - - @Override public boolean attachSources(@NonNull URL root, @NonNull AttachmentListener listener) throws IOException { - return attach(root, listener, false); - } - - @Override public boolean attachJavadoc(@NonNull URL root, @NonNull AttachmentListener listener) throws IOException { - return attach(root, listener, true); - } - @Messages({"# {0} - artifact ID", "attaching=Attaching {0}", "LBL_DOWNLOAD_REPO=Downloading source jar from known Maven repositories for local repository file.", "LBL_DOWNLOAD_SHA1=Downloading source jar from known Maven repositories for jar with SHA1 match in Maven repository indexes." }) - private boolean attach(@NonNull final URL root, @NonNull final AttachmentListener listener, final boolean javadoc) throws IOException { + private List attach(@NonNull final URL root, @NonNull Callable cancel, final boolean javadoc) throws Exception { final File file = FileUtil.archiveOrDirForURL(root); if (file == null) { - return false; + return Collections.emptyList(); } String[] coordinates = MavenFileOwnerQueryImpl.findCoordinates(file); final boolean byHash = coordinates == null; @@ -92,12 +88,16 @@ // without the indexes present locally, we return fast but nothing, only the next invokation after indexing finish is accurate.. NBVersionInfo defined = null; StatusDisplayer.Message message = null; + if (Boolean.TRUE.equals(cancel.call())) { + return Collections.emptyList(); + } if (!byHash) { //from local repository, known coordinates and we always return a maven SFBQ.Result for it, no reason to let people choose a jar via the default SJAI //TODO classifier? defined = new NBVersionInfo(null, coordinates[0], coordinates[1], coordinates[2], null, null, null, null, null); message = StatusDisplayer.getDefault().setStatusText(Bundle.LBL_DOWNLOAD_REPO(), StatusDisplayer.IMPORTANCE_ERROR_HIGHLIGHT); } else if (file.isFile()) { - List candidates = RepositoryQueries.findBySHA1Result(file, null).getResults(); + RepositoryQueries.Result res = RepositoryQueries.findBySHA1Result(file, null); + List candidates = res.getResults(); for (NBVersionInfo nbvi : candidates) { if (javadoc ? nbvi.isJavadocExists() : nbvi.isSourcesExists()) { defined = nbvi; @@ -105,21 +105,25 @@ break; } } - } else { - return false; + if (defined == null && res.isPartial()) { + //TODO should we wait? } - final NBVersionInfo _defined; - if (defined != null) { - _defined = defined; - } else { - return false; } - RP.post(new Runnable() { - @Override public void run() { - boolean attached = false; - try { + + if (defined == null) { + return Collections.emptyList(); + } + if (Boolean.TRUE.equals(cancel.call())) { + return Collections.emptyList(); + } + + MavenEmbedder online = EmbedderFactory.getOnlineEmbedder(); - Artifact art = online.createArtifactWithClassifier(_defined.getGroupId(), _defined.getArtifactId(), _defined.getVersion(), "jar", javadoc ? "javadoc" : "sources"); + Artifact art = online.createArtifactWithClassifier(defined.getGroupId(), defined.getArtifactId(), defined.getVersion(), "jar", javadoc ? "javadoc" : "sources"); + if (Boolean.TRUE.equals(cancel.call())) { + return Collections.emptyList(); + } + AggregateProgressHandle hndl = AggregateProgressFactory.createHandle(Bundle.attaching(art.getId()), new ProgressContributor[] {AggregateProgressFactory.createProgressContributor("attach")}, ProgressTransferListener.cancellable(), null); @@ -131,16 +135,19 @@ online.resolve(art, repos, online.getLocalRepository()); File result = art.getFile(); if (result.isFile()) { - attached = true; - if (byHash) { - SourceJavadocByHash.register(root, new File[] {result}, javadoc); - } + return Collections.singletonList(Utilities.toURI(result).toURL()); } else { + if (Boolean.TRUE.equals(cancel.call())) { + return Collections.emptyList(); + } if (file.isFile()) { - List coordinates = RepositoryForBinaryQueryImpl.getShadedCoordinates(result); - List res = new ArrayList(); - if (coordinates != null) { - for (RepositoryForBinaryQueryImpl.Coordinates coordinate : coordinates) { + List coordinates2 = RepositoryForBinaryQueryImpl.getShadedCoordinates(result); + List res = new ArrayList(); + if (coordinates2 != null) { + for (RepositoryForBinaryQueryImpl.Coordinates coordinate : coordinates2) { + if (Boolean.TRUE.equals(cancel.call())) { + return Collections.emptyList(); + } Artifact sources = EmbedderFactory.getOnlineEmbedder().createArtifactWithClassifier( coordinate.groupId, coordinate.artifactId, @@ -149,14 +156,11 @@ javadoc ? "javadoc" : "sources"); //NOI18N online.resolve(sources, repos, online.getLocalRepository()); if (sources.getFile() != null && sources.getFile().isFile()) { - res.add(sources.getFile()); + res.add(Utilities.toURI(sources.getFile()).toURL()); } } - attached = true; - if (byHash) { - SourceJavadocByHash.register(root, res.toArray(new File[0]), javadoc); - } else { - //we have a problem here, there is noone listening on these source jars being downloaded. + if (!res.isEmpty()) { + return res; } } } @@ -172,15 +176,40 @@ hndl.finish(); ProgressTransferListener.clearAggregateHandle(); } - } finally { - if (attached) { - listener.attachmentSucceeded(); - } else { - listener.attachmentFailed(); + return Collections.emptyList(); } + + @Override + public String getDisplayName() { + return "Maven"; } + + @Override + public String getDescription() { + return "Lookup javadoc/sources in know Maven repositories"; } - }); - return true; + + @Override + public List getSources(URL root, Callable cancel) { + try { + return attach(root, cancel, false); + } catch (IOException io) { + LOG.log(Level.INFO, "IO error while retrieving the source for " + root, io); + } catch (Exception ex) { + Exceptions.printStackTrace(ex); } + return Collections.emptyList(); } + + @Override + public List getJavadoc(URL root, Callable cancel) { + try { + return attach(root, cancel, true); + } catch (IOException io) { + LOG.log(Level.INFO, "IO error while retrieving the javadoc for " + root, io); + } catch (Exception ex) { + Exceptions.printStackTrace(ex); + } + return Collections.emptyList(); + } +}