Lines 38-50
Link Here
|
38 |
*/ |
38 |
*/ |
39 |
package org.netbeans.modules.maven.output; |
39 |
package org.netbeans.modules.maven.output; |
40 |
|
40 |
|
|
|
41 |
import java.awt.event.ActionEvent; |
41 |
import java.io.BufferedReader; |
42 |
import java.io.BufferedReader; |
42 |
import java.io.File; |
43 |
import java.io.File; |
43 |
import java.io.IOException; |
44 |
import java.io.IOException; |
44 |
import java.io.InputStreamReader; |
45 |
import java.io.InputStreamReader; |
|
|
46 |
import java.net.MalformedURLException; |
47 |
import java.net.URL; |
48 |
import java.util.Collections; |
49 |
import java.util.HashSet; |
50 |
import java.util.List; |
51 |
import java.util.Set; |
45 |
import java.util.logging.Logger; |
52 |
import java.util.logging.Logger; |
46 |
import java.util.regex.Matcher; |
53 |
import java.util.regex.Matcher; |
47 |
import java.util.regex.Pattern; |
54 |
import java.util.regex.Pattern; |
|
|
55 |
import javax.swing.AbstractAction; |
56 |
import javax.swing.Action; |
48 |
import org.netbeans.modules.maven.NbMavenProjectImpl; |
57 |
import org.netbeans.modules.maven.NbMavenProjectImpl; |
49 |
import org.netbeans.modules.maven.api.output.OutputProcessor; |
58 |
import org.netbeans.modules.maven.api.output.OutputProcessor; |
50 |
import org.netbeans.modules.maven.api.output.OutputUtils; |
59 |
import org.netbeans.modules.maven.api.output.OutputUtils; |
Lines 52-61
Link Here
|
52 |
import org.netbeans.api.java.classpath.ClassPath; |
61 |
import org.netbeans.api.java.classpath.ClassPath; |
53 |
import org.netbeans.api.project.FileOwnerQuery; |
62 |
import org.netbeans.api.project.FileOwnerQuery; |
54 |
import org.netbeans.api.project.Project; |
63 |
import org.netbeans.api.project.Project; |
|
|
64 |
import org.netbeans.modules.maven.api.ModelUtils; |
65 |
import org.netbeans.modules.maven.api.NbMavenProject; |
66 |
import org.netbeans.modules.maven.api.problem.ProblemReport; |
67 |
import org.netbeans.modules.maven.api.problem.ProblemReporter; |
68 |
import org.netbeans.modules.maven.indexer.api.RepositoryInfo; |
69 |
import org.netbeans.modules.maven.indexer.api.RepositoryPreferences; |
70 |
import org.netbeans.modules.maven.model.ModelOperation; |
71 |
import org.netbeans.modules.maven.model.pom.Dependency; |
72 |
import org.netbeans.modules.maven.model.pom.POMModel; |
55 |
import org.openide.ErrorManager; |
73 |
import org.openide.ErrorManager; |
56 |
import org.openide.awt.StatusDisplayer; |
74 |
import org.openide.awt.StatusDisplayer; |
57 |
import org.openide.filesystems.FileObject; |
75 |
import org.openide.filesystems.FileObject; |
58 |
import org.openide.filesystems.FileUtil; |
76 |
import org.openide.filesystems.FileUtil; |
|
|
77 |
import org.openide.util.Exceptions; |
59 |
import org.openide.util.NbBundle; |
78 |
import org.openide.util.NbBundle; |
60 |
import org.openide.util.RequestProcessor; |
79 |
import org.openide.util.RequestProcessor; |
61 |
import org.openide.windows.IOProvider; |
80 |
import org.openide.windows.IOProvider; |
Lines 159-164
Link Here
|
159 |
private String testname; |
178 |
private String testname; |
160 |
private String outputDir; |
179 |
private String outputDir; |
161 |
private Pattern testNamePattern = Pattern.compile(".*\\((.*)\\).*<<< (?:FAILURE)?(?:ERROR)?!\\s*"); //NOI18N |
180 |
private Pattern testNamePattern = Pattern.compile(".*\\((.*)\\).*<<< (?:FAILURE)?(?:ERROR)?!\\s*"); //NOI18N |
|
|
181 |
private Pattern ejbContainerPattern = Pattern.compile("java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/ejb/embeddable/EJBContainer[\\s]*"); // NOI18N |
162 |
|
182 |
|
163 |
public TestOutputListener(String test, String outDir) { |
183 |
public TestOutputListener(String test, String outDir) { |
164 |
testname = test; |
184 |
testname = test; |
Lines 227-239
Link Here
|
227 |
try { |
247 |
try { |
228 |
reader = new BufferedReader(new InputStreamReader(fo.getInputStream())); |
248 |
reader = new BufferedReader(new InputStreamReader(fo.getInputStream())); |
229 |
ClassPath classPath = null; |
249 |
ClassPath classPath = null; |
|
|
250 |
Project project = null; |
230 |
while ((line = reader.readLine()) != null) { |
251 |
while ((line = reader.readLine()) != null) { |
|
|
252 |
Matcher ejb = ejbContainerPattern.matcher(line); |
253 |
if (ejb.matches()) { |
254 |
if (project != null) { |
255 |
ProblemReporter report = project.getLookup().lookup(ProblemReporter.class); |
256 |
ProblemReport rep = new ProblemReport(ProblemReport.SEVERITY_HIGH, |
257 |
"Missing Embeddable EJB Container", |
258 |
"Description...", |
259 |
//NbBundle.getMessage(POHImpl.class, "MSG_AppServer", tit), |
260 |
new ResolveEjbContainerAction(project)); |
261 |
report.addReport(rep); |
262 |
} |
263 |
} |
231 |
Matcher m = testNamePattern.matcher(line); |
264 |
Matcher m = testNamePattern.matcher(line); |
232 |
if (m.matches()) { |
265 |
if (m.matches()) { |
233 |
String testClassName = m.group(1).replace('.', File.separatorChar) + ".java"; //NOI18N |
266 |
String testClassName = m.group(1).replace('.', File.separatorChar) + ".java"; //NOI18N |
234 |
File testClassFile = new File(testDir, testClassName); |
267 |
File testClassFile = new File(testDir, testClassName); |
235 |
FileObject testFileObject = FileUtil.toFileObject(testClassFile); |
268 |
FileObject testFileObject = FileUtil.toFileObject(testClassFile); |
236 |
classPath = ClassPath.getClassPath(testFileObject, ClassPath.EXECUTE); |
269 |
classPath = ClassPath.getClassPath(testFileObject, ClassPath.EXECUTE); |
|
|
270 |
project = FileOwnerQuery.getOwner(testFileObject); |
237 |
} |
271 |
} |
238 |
if (classPath != null) { |
272 |
if (classPath != null) { |
239 |
OutputListener list = OutputUtils.matchStackTraceLine(line, classPath); |
273 |
OutputListener list = OutputUtils.matchStackTraceLine(line, classPath); |
Lines 262-265
Link Here
|
262 |
}); |
296 |
}); |
263 |
} |
297 |
} |
264 |
} |
298 |
} |
|
|
299 |
|
300 |
private static class ResolveEjbContainerAction extends AbstractAction { |
301 |
private Project prj; |
302 |
private NbMavenProjectImpl mavenPrj; |
303 |
private ResolveEjbContainerAction(Project project) { |
304 |
prj = project; |
305 |
mavenPrj = prj.getLookup().lookup(NbMavenProjectImpl.class); |
306 |
putValue(Action.NAME, "Add Embeddable EJB Container");//NbBundle.getMessage(TestOutputListenerProvider.class, "TXT_Add_Server")); |
307 |
} |
308 |
|
309 |
public void actionPerformed(ActionEvent e) { |
310 |
try { |
311 |
boolean added = addPomToTestScope(new URL("http://download.java.net/maven/glassfish/org/glassfish/extras/glassfish-embedded-all/3.0/glassfish-embedded-all-3.0.pom")); |
312 |
} catch (MalformedURLException ex) { |
313 |
Exceptions.printStackTrace(ex); |
314 |
} |
315 |
} |
316 |
|
317 |
private boolean addPomToTestScope(final URL pomUrl) { |
318 |
final Boolean[] added = new Boolean[1]; |
319 |
ModelOperation<POMModel> operation = new ModelOperation<POMModel>() { |
320 |
@Override |
321 |
public void performOperation(POMModel model) { |
322 |
added[0] = checkAndAddPom(pomUrl, model, "test", null, null); |
323 |
} |
324 |
}; |
325 |
FileObject pom = mavenPrj.getProjectDirectory().getFileObject("pom.xml");//NOI18N |
326 |
org.netbeans.modules.maven.model.Utilities.performPOMModelOperations(pom, Collections.singletonList(operation)); |
327 |
//TODO is the manual reload necessary if pom.xml file is being saved? |
328 |
// NbMavenProject.fireMavenProjectReload(project); |
329 |
if (added[0]) { |
330 |
mavenPrj.getLookup().lookup(NbMavenProject.class).triggerDependencyDownload(); |
331 |
} |
332 |
return added[0]; |
333 |
} |
334 |
|
335 |
private boolean checkAndAddPom(URL pom, POMModel model, String scope, String repoId, String repoName) { |
336 |
URL[] repos = getRepoURLs(); |
337 |
String[] result = checkLibrary(pom, repos); |
338 |
if (result != null) { |
339 |
//set dependency |
340 |
Dependency dep = ModelUtils.checkModelDependency(model, result[2], result[3], true); |
341 |
dep.setVersion(result[4]); |
342 |
if (scope != null) { |
343 |
dep.setScope(scope); |
344 |
} |
345 |
if (result.length == 6) { |
346 |
dep.setClassifier(result[5]); |
347 |
} |
348 |
//set repository |
349 |
org.netbeans.modules.maven.model.pom.Repository reposit = ModelUtils.addModelRepository( |
350 |
mavenPrj.getOriginalMavenProject(), model, result[1]); |
351 |
if (reposit != null) { |
352 |
if (repoId == null) { |
353 |
repoId = result[1]; |
354 |
} |
355 |
reposit.setId(repoId); |
356 |
reposit.setLayout(result[0]); |
357 |
reposit.setName(repoName); //NOI18N - content coming into the pom.xml file |
358 |
} |
359 |
return true; |
360 |
} else { |
361 |
return false; |
362 |
} |
363 |
} |
364 |
} |
365 |
|
366 |
private static URL[] getRepoURLs() { |
367 |
Set<URL> urls = new HashSet<URL>(); |
368 |
List<RepositoryInfo> ris = RepositoryPreferences.getInstance().getRepositoryInfos(); |
369 |
for (RepositoryInfo ri : ris) { |
370 |
if (ri.getRepositoryUrl() != null) { |
371 |
try { |
372 |
urls.add(new URL(ri.getRepositoryUrl())); |
373 |
} catch (MalformedURLException ex) { |
374 |
//ignore |
375 |
} |
376 |
} |
377 |
} |
378 |
// these urls are essential (together with central) for correct |
379 |
// resolution of maven pom urls in libraries |
380 |
try { |
381 |
urls.add(new URL("http://repo1.maven.org/maven2")); //NOI18N |
382 |
urls.add(new URL("http://download.java.net/maven/2"));//NOI18N |
383 |
urls.add(new URL("http://download.java.net/maven/1"));//NOI18N |
384 |
urls.add(new URL("http://download.java.net/maven/glassfish"));//NOI18N |
385 |
} catch (MalformedURLException ex) { |
386 |
Exceptions.printStackTrace(ex); |
387 |
} |
388 |
return urls.toArray(new URL[0]); |
389 |
} |
390 |
|
391 |
static Pattern DEFAULT = Pattern.compile("(.+)[/]{1}(.+)[/]{1}(.+)[/]{1}(.+)\\.pom"); //NOI18N |
392 |
static Pattern LEGACY = Pattern.compile("(.+)[/]{1}poms[/]{1}([a-zA-Z0-9_]+[a-zA-Z\\-_]+)[\\-]{1}([0-9]{1}.+)\\.pom"); //NOI18N |
393 |
|
394 |
/** |
395 |
* @returns [0] type - default/legacy |
396 |
* [1] repo root |
397 |
* [2] groupId |
398 |
* [3] artifactId |
399 |
* [4] version |
400 |
* [5] classifier (optional, not part of path, but url's ref) |
401 |
*/ |
402 |
|
403 |
static String[] checkLibrary(URL pom, URL[] knownRepos) { |
404 |
String path = pom.getPath(); |
405 |
Matcher match = LEGACY.matcher(path); |
406 |
boolean def = false; |
407 |
if (!match.matches()) { |
408 |
match = DEFAULT.matcher(path); |
409 |
def = true; |
410 |
} |
411 |
if (match.matches()) { |
412 |
String[] toRet; |
413 |
if (pom.getRef() != null) { |
414 |
toRet = new String[6]; |
415 |
toRet[5] = pom.getRef(); |
416 |
} else { |
417 |
toRet = new String[5]; |
418 |
} |
419 |
toRet[0] = def ? "default" : "legacy"; //NOI18N |
420 |
toRet[1] = pom.getProtocol() + "://" + pom.getHost() + (pom.getPort() != -1 ? (":" + pom.getPort()) : ""); //NOI18N |
421 |
toRet[2] = match.group(1); |
422 |
toRet[3] = match.group(2); |
423 |
toRet[4] = match.group(3); |
424 |
for (URL repo : knownRepos) { |
425 |
String root = repo.getProtocol() + "://" + repo.getHost() + (repo.getPort() != -1 ? (":" + repo.getPort()) : ""); //NOI18N |
426 |
if (root.equals(toRet[1]) && toRet[2].startsWith(repo.getPath())) { |
427 |
toRet[1] = toRet[1] + repo.getPath(); |
428 |
toRet[2] = toRet[2].substring(repo.getPath().length()); |
429 |
break; |
430 |
} |
431 |
} |
432 |
if (toRet[2].startsWith("/")) { //NOI18N |
433 |
toRet[2] = toRet[2].substring(1); |
434 |
} |
435 |
//sort of hack, these 2 are the most probable root paths. |
436 |
if (toRet[2].startsWith("maven/")) {//NOI18N |
437 |
toRet[1] = toRet[1] + "/maven";//NOI18N |
438 |
toRet[2] = toRet[2].substring("maven/".length());//NOI18N |
439 |
} |
440 |
if (toRet[2].startsWith("maven2/")) {//NOI18N |
441 |
toRet[1] = toRet[1] + "/maven2";//NOI18N |
442 |
toRet[2] = toRet[2].substring("maven2/".length());//NOI18N |
443 |
} |
444 |
if (toRet[2].startsWith("mirror/eclipse/rt/eclipselink/maven.repo/")) {//NOI18N |
445 |
toRet[1] = toRet[1] + "/mirror/eclipse/rt/eclipselink/maven.repo";//NOI18N |
446 |
toRet[2] = toRet[2].substring("mirror/eclipse/rt/eclipselink/maven.repo/".length());//NOI18N |
447 |
} |
448 |
toRet[2] = toRet[2].replace('/', '.'); //NOI18N |
449 |
return toRet; |
450 |
} |
451 |
return null; |
452 |
} |
453 |
|
265 |
} |
454 |
} |