Skip to content

Commit ea17c2a

Browse files
geetikabatrarawagner
authored andcommitted
returning IFile instead of set
1 parent 5f4a1bb commit ea17c2a

6 files changed

Lines changed: 22 additions & 27 deletions

File tree

plugins/com.redhat.fabric8analytics.lsp.eclipse.core/src/com/redhat/fabric8analytics/lsp/eclipse/core/RecommenderAPIProvider.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,10 @@
1111

1212
package com.redhat.fabric8analytics.lsp.eclipse.core;
1313

14-
import java.io.BufferedReader;
14+
1515
import java.io.File;
16-
import java.io.FileNotFoundException;
17-
import java.io.FileReader;
1816
import java.io.IOException;
19-
import java.io.InputStream;
2017
import java.util.Map;
21-
import java.util.Set;
22-
2318
import org.apache.http.HttpEntity;
2419
import org.apache.http.HttpResponse;
2520
import org.apache.http.HttpStatus;
@@ -32,7 +27,6 @@
3227
import org.apache.http.impl.client.HttpClients;
3328
import org.apache.http.util.EntityUtils;
3429
import org.eclipse.core.resources.IFile;
35-
import org.eclipse.core.runtime.CoreException;
3630
import org.eclipse.core.runtime.IPath;
3731
import org.json.JSONException;
3832
import org.json.JSONObject;
@@ -75,7 +69,7 @@ public RecommenderAPIProvider(AnalyticsAuthData analyticsAuthData) {
7569
* @param pomFiles
7670
* @return jobID
7771
*/
78-
public String requestAnalyses(Map<String, String> files, Set<IFile> license) throws RecommenderAPIException {
72+
public String requestAnalyses(Map<String, String> files, IFile license) throws RecommenderAPIException {
7973

8074
checkFiles(files);// check if this is none
8175
HttpPost post = new HttpPost(
@@ -90,8 +84,8 @@ public String requestAnalyses(Map<String, String> files, Set<IFile> license) thr
9084
builder.addPart("manifest[]", new PomContentBody(fileObject.getValue())).addTextBody("filePath[]",
9185
fileObject.getKey());
9286
}
93-
if(!license.isEmpty()) {
94-
IPath licenseFile = license.iterator().next().getLocation();
87+
if(license!=null) {
88+
IPath licenseFile = license.getLocation();
9589

9690
FileBody licenseBody = new FileBody(new File(licenseFile.toString()));
9791
builder.addPart("license[]", licenseBody);

plugins/com.redhat.fabric8analytics.lsp.eclipse.core/src/com/redhat/fabric8analytics/lsp/eclipse/core/job/SendToFabric8AnalysisJob.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public class SendToFabric8AnalysisJob extends Job {
3434
private String jobID;
3535
private Set<IFile> pomFiles;
3636
private RecommenderAPIProvider provider;
37-
private Set<IFile> license;
37+
private IFile license;
3838

39-
public SendToFabric8AnalysisJob(RecommenderAPIProvider provider, Set<IFile> pomFiles, Set<IFile> license) {
39+
public SendToFabric8AnalysisJob(RecommenderAPIProvider provider, Set<IFile> pomFiles, IFile license) {
4040
super("Send poms to fabric8-analysis");
4141
this.pomFiles = pomFiles;
4242
this.provider = provider;

plugins/com.redhat.fabric8analytics.lsp.eclipse.ui/src/com/redhat/fabric8analytics/lsp/eclipse/ui/EditorComposite.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void done(IJobChangeEvent event) {
8585
AnalyticsAuthData analyticsAuthData = getAuthDataJob.getAuthData();
8686
if(analyticsAuthData != null) {
8787
RecommenderAPIProvider provider = new RecommenderAPIProvider(analyticsAuthData);
88-
new AnalysesJobHandler(provider, Collections.singleton(currentPomFile), Collections.EMPTY_SET, EditorComposite.this).analyze();
88+
new AnalysesJobHandler(provider, Collections.singleton(currentPomFile), null , EditorComposite.this).analyze();
8989
}
9090
}
9191
});

plugins/com.redhat.fabric8analytics.lsp.eclipse.ui/src/com/redhat/fabric8analytics/lsp/eclipse/ui/ExitHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ExitHandler extends AbstractHandler {
4040
@Override
4141
public Object execute(ExecutionEvent event) throws ExecutionException {
4242
final Set<IFile> pomFiles;
43-
final Set<IFile> license;
43+
final IFile license;
4444
try {
4545
pomFiles = WorkspaceFilesFinder.getInstance().findPOMs();
4646
license = WorkspaceFilesFinder.getInstance().findLicense();

plugins/com.redhat.fabric8analytics.lsp.eclipse.ui/src/com/redhat/fabric8analytics/lsp/eclipse/ui/internal/AnalysesJobHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public class AnalysesJobHandler {
4141

4242
private EditorComposite editorComposite;
4343

44-
private Set<IFile> license;
44+
private IFile license;
4545

46-
public AnalysesJobHandler(RecommenderAPIProvider provider, Set<IFile> pomFiles, Set<IFile> license, EditorComposite editorComposite) {
46+
public AnalysesJobHandler(RecommenderAPIProvider provider, Set<IFile> pomFiles, IFile license, EditorComposite editorComposite) {
4747
this.provider = provider;
4848
this.pomFiles = pomFiles;
4949
this.editorComposite = editorComposite;

plugins/com.redhat.fabric8analytics.lsp.eclipse.ui/src/com/redhat/fabric8analytics/lsp/eclipse/ui/internal/WorkspaceFilesFinder.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ public Set<IFile> getCurrentPom() throws CoreException
133133
* @return
134134
* @throws CoreException
135135
*/
136-
public Set<IFile> findLicense() throws CoreException {
136+
public IFile findLicense() throws CoreException {
137137
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
138138
if (window == null) {
139-
return Collections.emptySet();
139+
return null;
140140
}
141141

142142
IStructuredSelection selection = (IStructuredSelection) window.getSelectionService().getSelection();
143143
if (selection == null) {
144-
return Collections.emptySet();
144+
return null;
145145
}
146146
return findLicense(selection);
147147
}
@@ -152,7 +152,7 @@ public Set<IFile> findLicense() throws CoreException {
152152
* @return
153153
* @throws CoreException
154154
*/
155-
public Set<IFile> findLicense(IStructuredSelection selection) throws CoreException {
155+
public IFile findLicense(IStructuredSelection selection) throws CoreException {
156156
Set<IFile> files = new HashSet<IFile>();
157157
if(selection instanceof IStructuredSelection) {
158158
IStructuredSelection structurredSelection = (IStructuredSelection)selection;
@@ -164,42 +164,43 @@ public Set<IFile> findLicense(IStructuredSelection selection) throws CoreExcepti
164164
// selectedProject = (IProject) firstSeleciton;
165165
for (Object o : selection.toList()) {
166166
if (o instanceof IAdaptable) {
167-
findLicense(files, (IAdaptable) o);
167+
return findLicense((IAdaptable) o);
168168
}
169169
}
170170

171-
return files;
171+
return null;
172172
}
173173

174174
}
175-
return files;
175+
return null;
176176
}
177177
/**
178178
* Finds the license file in the the project.
179179
* @param adaptable
180180
* @return
181181
* @throws CoreException
182182
*/
183-
private void findLicense(Set<IFile> files, IAdaptable adaptable) throws CoreException {
183+
private IFile findLicense(IAdaptable adaptable) throws CoreException {
184184

185185
IContainer container = (IContainer) adaptable.getAdapter(IContainer.class);
186186
if (container == null || !container.isAccessible()) {
187-
return;
187+
return null;
188188
}
189189
for (IResource member : container.members()) {
190190
if (member instanceof IFile && member.getName().toLowerCase().equals("license")) {
191191
IFile file = (IFile) member.getAdapter(IFile.class);
192192
if (file != null) {
193193
if (file.isAccessible()) {
194-
files.add(file);
194+
return file;
195195
} else {
196-
return;
196+
return null;
197197
}
198198
}
199199

200200
}
201201

202202
}
203+
return null;
203204

204205

205206
}

0 commit comments

Comments
 (0)