This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 232917
Collapse All | Expand All

(-)maven/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.maven/2
2
OpenIDE-Module: org.netbeans.modules.maven/2
3
OpenIDE-Module-Specification-Version: 2.84
3
OpenIDE-Module-Specification-Version: 2.85
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/maven/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/maven/Bundle.properties
5
OpenIDE-Module-Layer: org/netbeans/modules/maven/layer.xml
5
OpenIDE-Module-Layer: org/netbeans/modules/maven/layer.xml
6
AutoUpdate-Show-In-Client: false
6
AutoUpdate-Show-In-Client: false
(-)maven/nbproject/project.xml (-1 / +1 lines)
Lines 86-92 Link Here
86
                    <compile-dependency/>
86
                    <compile-dependency/>
87
                    <run-dependency>
87
                    <run-dependency>
88
                        <release-version>1</release-version>
88
                        <release-version>1</release-version>
89
                        <specification-version>1.35</specification-version>
89
                        <specification-version>1.49</specification-version>
90
                    </run-dependency>
90
                    </run-dependency>
91
                </dependency>
91
                </dependency>
92
                <dependency>
92
                <dependency>
(-)maven/src/org/netbeans/modules/maven/queries/MavenSourceJavadocAttacher.java (-49 / +78 lines)
Lines 42-53 Link Here
42
import java.io.IOException;
42
import java.io.IOException;
43
import java.net.URL;
43
import java.net.URL;
44
import java.util.ArrayList;
44
import java.util.ArrayList;
45
import java.util.Collections;
45
import java.util.List;
46
import java.util.List;
47
import java.util.concurrent.Callable;
48
import java.util.logging.Level;
49
import java.util.logging.Logger;
46
import org.apache.maven.artifact.Artifact;
50
import org.apache.maven.artifact.Artifact;
47
import org.apache.maven.artifact.repository.ArtifactRepository;
51
import org.apache.maven.artifact.repository.ArtifactRepository;
48
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
52
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
49
import org.netbeans.api.annotations.common.NonNull;
53
import org.netbeans.api.annotations.common.NonNull;
50
import org.netbeans.api.java.queries.SourceJavadocAttacher.AttachmentListener;
51
import org.netbeans.api.progress.aggregate.AggregateProgressFactory;
54
import org.netbeans.api.progress.aggregate.AggregateProgressFactory;
52
import org.netbeans.api.progress.aggregate.AggregateProgressHandle;
55
import org.netbeans.api.progress.aggregate.AggregateProgressHandle;
53
import org.netbeans.api.progress.aggregate.ProgressContributor;
56
import org.netbeans.api.progress.aggregate.ProgressContributor;
Lines 60-90 Link Here
60
import org.netbeans.spi.java.queries.SourceJavadocAttacherImplementation;
63
import org.netbeans.spi.java.queries.SourceJavadocAttacherImplementation;
61
import org.openide.awt.StatusDisplayer;
64
import org.openide.awt.StatusDisplayer;
62
import org.openide.filesystems.FileUtil;
65
import org.openide.filesystems.FileUtil;
66
import org.openide.util.Exceptions;
63
import org.openide.util.NbBundle.Messages;
67
import org.openide.util.NbBundle.Messages;
64
import org.openide.util.RequestProcessor;
68
import org.openide.util.RequestProcessor;
69
import org.openide.util.Utilities;
65
import org.openide.util.lookup.ServiceProvider;
70
import org.openide.util.lookup.ServiceProvider;
66
71
67
@ServiceProvider(service=SourceJavadocAttacherImplementation.class, position=200)
72
@ServiceProvider(service=SourceJavadocAttacherImplementation.Definer.class)
68
public class MavenSourceJavadocAttacher implements SourceJavadocAttacherImplementation {
73
public class MavenSourceJavadocAttacher implements SourceJavadocAttacherImplementation.Definer {
74
    private static final Logger LOG = Logger.getLogger(MavenSourceJavadocAttacher.class.getName());
69
75
70
    private static final RequestProcessor RP = new RequestProcessor(MavenSourceJavadocAttacher.class.getName(), 5);
71
72
    @Override public boolean attachSources(@NonNull URL root, @NonNull AttachmentListener listener) throws IOException {
73
        return attach(root, listener, false);
74
    }
75
76
    @Override public boolean attachJavadoc(@NonNull URL root, @NonNull AttachmentListener listener) throws IOException {
77
        return attach(root, listener, true);
78
    }
79
80
    @Messages({"# {0} - artifact ID", "attaching=Attaching {0}", 
76
    @Messages({"# {0} - artifact ID", "attaching=Attaching {0}", 
81
        "LBL_DOWNLOAD_REPO=Downloading source jar from known Maven repositories for local repository file.",
77
        "LBL_DOWNLOAD_REPO=Downloading source jar from known Maven repositories for local repository file.",
82
        "LBL_DOWNLOAD_SHA1=Downloading source jar from known Maven repositories for jar with SHA1 match in Maven repository indexes."
78
        "LBL_DOWNLOAD_SHA1=Downloading source jar from known Maven repositories for jar with SHA1 match in Maven repository indexes."
83
    })
79
    })
84
    private boolean attach(@NonNull final URL root, @NonNull final AttachmentListener listener, final boolean javadoc) throws IOException {
80
    private List<? extends URL> attach(@NonNull final URL root, @NonNull Callable<Boolean> cancel, final boolean javadoc) throws Exception {
85
        final File file = FileUtil.archiveOrDirForURL(root);
81
        final File file = FileUtil.archiveOrDirForURL(root);
86
        if (file == null) {
82
        if (file == null) {
87
            return false;
83
            return Collections.emptyList();
88
        }
84
        }
89
        String[] coordinates = MavenFileOwnerQueryImpl.findCoordinates(file);
85
        String[] coordinates = MavenFileOwnerQueryImpl.findCoordinates(file);
90
        final boolean byHash = coordinates == null;
86
        final boolean byHash = coordinates == null;
Lines 92-103 Link Here
92
        // without the indexes present locally, we return fast but nothing, only the next invokation after indexing finish is accurate..
88
        // without the indexes present locally, we return fast but nothing, only the next invokation after indexing finish is accurate..
93
        NBVersionInfo defined = null;
89
        NBVersionInfo defined = null;
94
        StatusDisplayer.Message message = null;
90
        StatusDisplayer.Message message = null;
91
        if (Boolean.TRUE.equals(cancel.call())) {
92
            return Collections.emptyList();
93
        }
95
        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
94
        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
96
            //TODO classifier?
95
            //TODO classifier?
97
            defined = new NBVersionInfo(null, coordinates[0], coordinates[1], coordinates[2], null, null, null, null, null);
96
            defined = new NBVersionInfo(null, coordinates[0], coordinates[1], coordinates[2], null, null, null, null, null);
98
            message = StatusDisplayer.getDefault().setStatusText(Bundle.LBL_DOWNLOAD_REPO(), StatusDisplayer.IMPORTANCE_ERROR_HIGHLIGHT);
97
            message = StatusDisplayer.getDefault().setStatusText(Bundle.LBL_DOWNLOAD_REPO(), StatusDisplayer.IMPORTANCE_ERROR_HIGHLIGHT);
99
        } else if (file.isFile()) {
98
        } else if (file.isFile()) {
100
            List<NBVersionInfo> candidates = RepositoryQueries.findBySHA1Result(file, null).getResults();
99
            RepositoryQueries.Result<NBVersionInfo> res = RepositoryQueries.findBySHA1Result(file, null);
100
            List<NBVersionInfo> candidates = res.getResults();
101
            for (NBVersionInfo nbvi : candidates) {
101
            for (NBVersionInfo nbvi : candidates) {
102
                if (javadoc ? nbvi.isJavadocExists() : nbvi.isSourcesExists()) {
102
                if (javadoc ? nbvi.isJavadocExists() : nbvi.isSourcesExists()) {
103
                    defined = nbvi;
103
                    defined = nbvi;
Lines 105-125 Link Here
105
                    break;
105
                    break;
106
                }
106
                }
107
            }
107
            }
108
        } else {
108
            if (defined == null && res.isPartial()) {
109
            return false;
109
                //TODO should we wait?
110
        }
110
        }
111
        final NBVersionInfo _defined;
112
        if (defined != null) {
113
            _defined = defined;
114
        } else {
115
            return false;
116
        }
111
        }
117
        RP.post(new Runnable() {
112
        
118
            @Override public void run() {
113
        if (defined == null) {
119
                boolean attached = false;
114
            return Collections.emptyList();
120
                try {
115
        }
116
        if (Boolean.TRUE.equals(cancel.call())) {
117
            return Collections.emptyList();
118
        }
119
        
120
121
                    MavenEmbedder online = EmbedderFactory.getOnlineEmbedder();
121
                    MavenEmbedder online = EmbedderFactory.getOnlineEmbedder();
122
                    Artifact art = online.createArtifactWithClassifier(_defined.getGroupId(), _defined.getArtifactId(), _defined.getVersion(), "jar", javadoc ? "javadoc" : "sources");
122
        Artifact art = online.createArtifactWithClassifier(defined.getGroupId(), defined.getArtifactId(), defined.getVersion(), "jar", javadoc ? "javadoc" : "sources");
123
        if (Boolean.TRUE.equals(cancel.call())) {
124
            return Collections.emptyList();
125
        }        
126
        
123
                    AggregateProgressHandle hndl = AggregateProgressFactory.createHandle(Bundle.attaching(art.getId()),
127
                    AggregateProgressHandle hndl = AggregateProgressFactory.createHandle(Bundle.attaching(art.getId()),
124
                        new ProgressContributor[] {AggregateProgressFactory.createProgressContributor("attach")},
128
                        new ProgressContributor[] {AggregateProgressFactory.createProgressContributor("attach")},
125
                        ProgressTransferListener.cancellable(), null);
129
                        ProgressTransferListener.cancellable(), null);
Lines 131-146 Link Here
131
                        online.resolve(art, repos, online.getLocalRepository());
135
                        online.resolve(art, repos, online.getLocalRepository());
132
                        File result = art.getFile();
136
                        File result = art.getFile();
133
                        if (result.isFile()) {
137
                        if (result.isFile()) {
134
                            attached = true;
138
                return Collections.singletonList(Utilities.toURI(result).toURL());
135
                            if (byHash) {
136
                                SourceJavadocByHash.register(root, new File[] {result}, javadoc);
137
                            }
138
                        } else {
139
                        } else {
140
                if (Boolean.TRUE.equals(cancel.call())) {
141
                    return Collections.emptyList();
142
                } 
139
                            if (file.isFile()) {
143
                            if (file.isFile()) {
140
                                List<RepositoryForBinaryQueryImpl.Coordinates> coordinates = RepositoryForBinaryQueryImpl.getShadedCoordinates(result);
144
                    List<RepositoryForBinaryQueryImpl.Coordinates> coordinates2 = RepositoryForBinaryQueryImpl.getShadedCoordinates(result);
141
                                List<File> res = new ArrayList<File>();
145
                    List<URL> res = new ArrayList<URL>();
142
                                if (coordinates != null) {
146
                    if (coordinates2 != null) {
143
                                    for (RepositoryForBinaryQueryImpl.Coordinates coordinate : coordinates) {
147
                        for (RepositoryForBinaryQueryImpl.Coordinates coordinate : coordinates2) {
148
                            if (Boolean.TRUE.equals(cancel.call())) {
149
                                return Collections.emptyList();
150
                            }                             
144
                                        Artifact sources = EmbedderFactory.getOnlineEmbedder().createArtifactWithClassifier(
151
                                        Artifact sources = EmbedderFactory.getOnlineEmbedder().createArtifactWithClassifier(
145
                                                     coordinate.groupId,
152
                                                     coordinate.groupId,
146
                                                     coordinate.artifactId,
153
                                                     coordinate.artifactId,
Lines 149-162 Link Here
149
                                                     javadoc ? "javadoc" : "sources"); //NOI18N
156
                                                     javadoc ? "javadoc" : "sources"); //NOI18N
150
                                        online.resolve(sources, repos, online.getLocalRepository());
157
                                        online.resolve(sources, repos, online.getLocalRepository());
151
                                        if (sources.getFile() != null && sources.getFile().isFile()) {
158
                                        if (sources.getFile() != null && sources.getFile().isFile()) {
152
                                            res.add(sources.getFile());
159
                                res.add(Utilities.toURI(sources.getFile()).toURL());
153
                                        }
160
                                        }
154
                                    }
161
                                    }
155
                                    attached = true;
162
                        if (!res.isEmpty()) {
156
                                    if (byHash) {
163
                            return res;
157
                                        SourceJavadocByHash.register(root, res.toArray(new File[0]), javadoc);
158
                                    } else {
159
                                        //we have a problem here, there is noone listening on these source jars being downloaded.
160
                                    }                                    
164
                                    }                                    
161
                                }
165
                                }
162
                            }
166
                            }
Lines 172-186 Link Here
172
                        hndl.finish();
176
                        hndl.finish();
173
                        ProgressTransferListener.clearAggregateHandle();
177
                        ProgressTransferListener.clearAggregateHandle();
174
                    }
178
                    }
175
                } finally {
179
        return Collections.emptyList();
176
                    if (attached) {
177
                        listener.attachmentSucceeded();
178
                    } else {
179
                        listener.attachmentFailed();
180
                    }
180
                    }
181
182
    @Override
183
    public String getDisplayName() {
184
        return "Maven";
181
                }
185
                }
186
187
    @Override
188
    public String getDescription() {
189
        return "Lookup javadoc/sources in know Maven repositories";
182
            }
190
            }
183
        });
191
184
        return true;
192
    @Override
193
    public List<? extends URL> getSources(URL root, Callable<Boolean> cancel) {
194
        try {
195
            return attach(root, cancel, false);
196
        } catch (IOException io) {
197
            LOG.log(Level.INFO, "IO error while retrieving the source for " + root, io);
198
        } catch (Exception ex) {
199
            Exceptions.printStackTrace(ex);
185
    }
200
    }
201
        return Collections.emptyList();
186
}
202
}
203
204
    @Override
205
    public List<? extends URL> getJavadoc(URL root, Callable<Boolean> cancel) {
206
        try {
207
            return attach(root, cancel, true);
208
        } catch (IOException io) {
209
            LOG.log(Level.INFO, "IO error while retrieving the javadoc for " + root, io);
210
        } catch (Exception ex) {
211
            Exceptions.printStackTrace(ex);
212
        }
213
        return Collections.emptyList();
214
    }
215
}

Return to bug 232917