Lines 48-58
Link Here
|
48 |
import org.netbeans.api.java.platform.Specification; |
48 |
import org.netbeans.api.java.platform.Specification; |
49 |
import org.netbeans.api.project.Project; |
49 |
import org.netbeans.api.project.Project; |
50 |
import org.netbeans.api.project.ProjectManager; |
50 |
import org.netbeans.api.project.ProjectManager; |
51 |
import org.netbeans.lib.profiler.ProfilerLogger; |
|
|
52 |
import org.netbeans.lib.profiler.client.ClientUtils; |
51 |
import org.netbeans.lib.profiler.client.ClientUtils; |
53 |
import org.netbeans.lib.profiler.client.ClientUtils.SourceCodeSelection; |
52 |
import org.netbeans.lib.profiler.client.ClientUtils.SourceCodeSelection; |
54 |
import org.netbeans.lib.profiler.common.SessionSettings; |
53 |
import org.netbeans.lib.profiler.common.SessionSettings; |
55 |
import org.netbeans.lib.profiler.common.filters.SimpleFilter; |
|
|
56 |
import org.netbeans.lib.profiler.common.integration.IntegrationUtils; |
54 |
import org.netbeans.lib.profiler.common.integration.IntegrationUtils; |
57 |
import org.netbeans.lib.profiler.global.CommonConstants; |
55 |
import org.netbeans.lib.profiler.global.CommonConstants; |
58 |
import org.netbeans.lib.profiler.marker.MethodMarker; |
56 |
import org.netbeans.lib.profiler.marker.MethodMarker; |
Lines 75-99
Link Here
|
75 |
import org.openide.DialogDescriptor; |
73 |
import org.openide.DialogDescriptor; |
76 |
import org.openide.ErrorManager; |
74 |
import org.openide.ErrorManager; |
77 |
import org.openide.NotifyDescriptor; |
75 |
import org.openide.NotifyDescriptor; |
78 |
import org.openide.filesystems.FileLock; |
|
|
79 |
import org.openide.filesystems.FileObject; |
76 |
import org.openide.filesystems.FileObject; |
80 |
import org.openide.filesystems.FileUtil; |
77 |
import org.openide.filesystems.FileUtil; |
81 |
import org.openide.modules.InstalledFileLocator; |
78 |
import org.openide.modules.InstalledFileLocator; |
82 |
import org.openide.util.NbBundle; |
79 |
import org.openide.util.NbBundle; |
83 |
import org.openide.util.WeakListeners; |
80 |
import org.openide.util.WeakListeners; |
84 |
import org.openide.xml.XMLUtil; |
|
|
85 |
import org.w3c.dom.Document; |
81 |
import org.w3c.dom.Document; |
86 |
import org.w3c.dom.Element; |
82 |
import org.w3c.dom.Element; |
87 |
import java.beans.PropertyChangeEvent; |
83 |
import java.beans.PropertyChangeEvent; |
88 |
import java.beans.PropertyChangeListener; |
84 |
import java.beans.PropertyChangeListener; |
89 |
import java.io.*; |
85 |
import java.io.*; |
90 |
import java.text.MessageFormat; |
|
|
91 |
import java.util.Arrays; |
92 |
import java.util.Collection; |
86 |
import java.util.Collection; |
93 |
import java.util.HashSet; |
|
|
94 |
import java.util.Map; |
87 |
import java.util.Map; |
95 |
import java.util.Properties; |
88 |
import java.util.Properties; |
96 |
import java.util.Set; |
|
|
97 |
import javax.swing.JComponent; |
89 |
import javax.swing.JComponent; |
98 |
import javax.swing.event.ChangeListener; |
90 |
import javax.swing.event.ChangeListener; |
99 |
import org.netbeans.api.project.ProjectUtils; |
91 |
import org.netbeans.api.project.ProjectUtils; |
Lines 350-356
Link Here
|
350 |
final FileObject profiledClass) { |
342 |
final FileObject profiledClass) { |
351 |
switch (type) { |
343 |
switch (type) { |
352 |
case TARGET_PROFILE: |
344 |
case TARGET_PROFILE: |
353 |
return "profile-j2ee"; // NOI18N |
345 |
return "profile"; // NOI18N |
354 |
case TARGET_PROFILE_TEST: |
346 |
case TARGET_PROFILE_TEST: |
355 |
return null; // not currently supported // "profile-test"; // NOI18N |
347 |
return null; // not currently supported // "profile-test"; // NOI18N |
356 |
case TARGET_PROFILE_TEST_SINGLE: |
348 |
case TARGET_PROFILE_TEST_SINGLE: |
Lines 500-648
Link Here
|
500 |
} |
492 |
} |
501 |
} |
493 |
} |
502 |
|
494 |
|
503 |
public boolean checkProjectIsModifiedForProfiler(final Project project) { |
|
|
504 |
if (ProjectUtilities.isProfilerIntegrated(project)) { |
505 |
return true; // already modified by this version, nothing more to do |
506 |
} |
507 |
|
508 |
String projectName = ProjectUtils.getInformation(project).getDisplayName(); |
509 |
String caption = MessageFormat.format(MODIFY_BUILDSCRIPT_CAPTION, new Object[] { projectName }); |
510 |
String message = MessageFormat.format(MODIFY_BUILDSCRIPT_MSG, new Object[] { projectName, "build-before-profiler.xml" }); // NOI18N |
511 |
if (ProfilerDialogs.notify(new NotifyDescriptor(message, caption, NotifyDescriptor.OK_CANCEL_OPTION, |
512 |
NotifyDescriptor.INFORMATION_MESSAGE, new Object[] { NotifyDescriptor.OK_OPTION, |
513 |
NotifyDescriptor.CANCEL_OPTION }, NotifyDescriptor.OK_OPTION)) != NotifyDescriptor.OK_OPTION) { |
514 |
return false; // cancelled by the user |
515 |
} |
516 |
|
517 |
// not yet modified for profiler => create profiler-build-impl & modify build.xml and project.xml |
518 |
final Element profilerFragment = XMLUtil.createDocument("ignore", null, null, null) |
519 |
.createElementNS(ProjectUtilities.PROFILER_NAME_SPACE, "data"); // NOI18N |
520 |
profilerFragment.setAttribute(PROFILE_VERSION_ATTRIBUTE, VERSION_NUMBER); // NOI18N |
521 |
|
522 |
ProjectUtils.getAuxiliaryConfiguration(project).putConfigurationFragment(profilerFragment, false); |
523 |
|
524 |
try { |
525 |
ProjectManager.getDefault().saveProject(project); |
526 |
} catch (IOException e1) { |
527 |
err.notify(e1); |
528 |
ProfilerLogger.log(e1); |
529 |
|
530 |
return false; |
531 |
} |
532 |
|
533 |
// we are going to regenerate the build script in one of 3 cases: |
534 |
// 1. it has not been generated yet |
535 |
// 2. the profiler version has been changed (see above) |
536 |
// 3. the stylesheet changed (usually should be caught by 2.) |
537 |
final GeneratedFilesHelper gfh = new GeneratedFilesHelper(project.getProjectDirectory()); |
538 |
int flags = gfh.getBuildScriptState("nbproject/profiler-build-impl.xml", |
539 |
J2EEProjectTypeProfiler.class.getResource("profiler-build-impl.xsl")); // NOI18N |
540 |
|
541 |
if (((flags & GeneratedFilesHelper.FLAG_MISSING) != 0) || ((flags & GeneratedFilesHelper.FLAG_OLD_STYLESHEET) != 0)) { |
542 |
try { |
543 |
if ((flags & GeneratedFilesHelper.FLAG_MODIFIED) != 0) { |
544 |
if (ProfilerDialogs.notify(new NotifyDescriptor.Confirmation(MessageFormat.format(REGENERATE_BUILDSCRIPT_MSG, |
545 |
new Object[] { |
546 |
"profiler-build-impl.xml" |
547 |
}), // NOI18N |
548 |
NotifyDescriptor.OK_CANCEL_OPTION)) != NotifyDescriptor.OK_OPTION) { |
549 |
return false; |
550 |
} |
551 |
} |
552 |
|
553 |
gfh.generateBuildScriptFromStylesheet("nbproject/profiler-build-impl.xml", |
554 |
J2EEProjectTypeProfiler.class.getResource("profiler-build-impl.xsl")); // NOI18N |
555 |
} catch (IOException e1) { |
556 |
err.notify(ErrorManager.WARNING, e1); |
557 |
|
558 |
return false; |
559 |
} |
560 |
} |
561 |
|
562 |
final String buildScript = ProjectUtilities.getProjectBuildScript(project); |
563 |
|
564 |
if (buildScript == null) { |
565 |
ProfilerDialogs.notify(new NotifyDescriptor.Message(MessageFormat.format(CANNOT_FIND_BUILDSCRIPT_MSG, |
566 |
new Object[] { "build.xml" }), // NOI18N |
567 |
NotifyDescriptor.ERROR_MESSAGE)); |
568 |
|
569 |
return false; |
570 |
} |
571 |
|
572 |
if (!ProjectUtilities.backupBuildScript(project)) { |
573 |
if (ProfilerDialogs.notify(new NotifyDescriptor.Confirmation(CANNOT_BACKUP_BUILDSCRIPT_MSG, |
574 |
NotifyDescriptor.OK_CANCEL_OPTION, |
575 |
NotifyDescriptor.WARNING_MESSAGE)) != NotifyDescriptor.OK_OPTION) { |
576 |
return false; // cancelled by the user |
577 |
} |
578 |
} |
579 |
|
580 |
final StringBuffer newDataBuffer = new StringBuffer(buildScript.length() + 200); |
581 |
final int importIndex = buildScript.indexOf(STANDARD_IMPORT_STRING); |
582 |
|
583 |
if (importIndex == -1) { |
584 |
// notify the user that the build script cannot be modified, and he should perform the change himself |
585 |
ProfilerDialogs.notify(new NotifyDescriptor.Message(MessageFormat.format(MODIFY_BUILDSCRIPT_MANUALLY_MSG, |
586 |
new Object[] { |
587 |
"build.xml", |
588 |
"<import file=\"nbproject/profiler-build-impl.xml\"/>" |
589 |
}), // NOI18N |
590 |
NotifyDescriptor.WARNING_MESSAGE)); |
591 |
|
592 |
return false; |
593 |
} |
594 |
|
595 |
String indent = ""; // NOI18N |
596 |
int idx = importIndex - 1; |
597 |
|
598 |
while (idx >= 0) { |
599 |
if (buildScript.charAt(idx) == ' ') { |
600 |
indent = " " + indent; // NOI18N |
601 |
} else if (buildScript.charAt(idx) == '\t') { |
602 |
indent = "\t" + indent; // NOI18N |
603 |
} else { |
604 |
break; |
605 |
} |
606 |
|
607 |
idx--; |
608 |
} |
609 |
|
610 |
newDataBuffer.append(buildScript.substring(0, importIndex + STANDARD_IMPORT_STRING.length() + 1)); |
611 |
newDataBuffer.append("\n"); // NOI18N |
612 |
newDataBuffer.append(indent); |
613 |
newDataBuffer.append(PROFILER_IMPORT_STRING); |
614 |
newDataBuffer.append(buildScript.substring(importIndex + STANDARD_IMPORT_STRING.length() + 1)); |
615 |
|
616 |
final FileObject buildFile = getProjectBuildScript(project); |
617 |
FileLock lock = null; |
618 |
OutputStreamWriter writer = null; |
619 |
|
620 |
try { |
621 |
lock = buildFile.lock(); |
622 |
writer = new OutputStreamWriter(buildFile.getOutputStream(lock), "UTF-8"); // NOI18N // According to Issue 65557, build.xml uses UTF-8, not default encoding! |
623 |
writer.write(newDataBuffer.toString()); |
624 |
} catch (FileNotFoundException e1) { |
625 |
err.notify(e1); |
626 |
ProfilerLogger.log(e1); |
627 |
} catch (IOException e1) { |
628 |
err.notify(e1); |
629 |
ProfilerLogger.log(e1); |
630 |
} finally { |
631 |
if (lock != null) { |
632 |
lock.releaseLock(); |
633 |
} |
634 |
|
635 |
if (writer != null) { |
636 |
try { |
637 |
writer.close(); |
638 |
} catch (IOException ex) { |
639 |
} |
640 |
} |
641 |
} |
642 |
|
643 |
return true; |
644 |
} |
645 |
|
646 |
public void configurePropertiesForProfiling(final Properties props, final Project project, final FileObject profiledClassFile) { |
495 |
public void configurePropertiesForProfiling(final Properties props, final Project project, final FileObject profiledClassFile) { |
647 |
initAntPlatform(project, props); |
496 |
initAntPlatform(project, props); |
648 |
// set forceRestart |
497 |
// set forceRestart |