1 19 20 package org.netbeans.modules.j2ee.ejbjarproject.ui.logicalview.libraries; 21 22 23 import java.awt.Dialog ; 24 import java.awt.Image ; 25 import java.awt.event.ActionEvent ; 26 import java.beans.BeanInfo ; 27 import java.beans.PropertyChangeEvent ; 28 import java.beans.PropertyChangeListener ; 29 import java.io.IOException ; 30 import java.io.File ; 31 import java.net.MalformedURLException ; 32 import java.net.URI ; 33 import java.net.URL ; 34 import java.text.MessageFormat ; 35 import java.util.ArrayList ; 36 import java.util.Arrays ; 37 import java.util.Collection ; 38 import java.util.Collections ; 39 import java.util.HashSet ; 40 import java.util.Iterator ; 41 import java.util.LinkedList ; 42 import java.util.List ; 43 import java.util.Set ; 44 import javax.swing.AbstractAction ; 45 import javax.swing.Action ; 46 import javax.swing.Icon ; 47 import javax.swing.ImageIcon ; 48 import javax.swing.JButton ; 49 import javax.swing.JFileChooser ; 50 import javax.swing.filechooser.FileFilter ; 51 import org.openide.DialogDescriptor; 52 import org.openide.DialogDisplayer; 53 import org.openide.ErrorManager; 54 import org.openide.filesystems.FileObject; 55 import org.openide.filesystems.FileUtil; 56 import org.openide.filesystems.Repository; 57 import org.openide.filesystems.URLMapper; 58 import org.openide.loaders.DataFolder; 59 import org.openide.nodes.AbstractNode; 60 import org.openide.nodes.Children; 61 import org.openide.nodes.Node; 62 import org.openide.util.NbBundle; 63 import org.openide.util.RequestProcessor; 64 import org.openide.util.Utilities; 65 import org.openide.windows.WindowManager; 66 import org.netbeans.api.project.FileOwnerQuery; 67 import org.netbeans.api.project.SourceGroup; 68 import org.netbeans.api.project.Project; 69 import org.netbeans.api.project.ant.AntArtifact; 70 import org.netbeans.api.project.libraries.Library; 71 import org.netbeans.api.project.libraries.LibraryManager; 72 import org.netbeans.api.java.classpath.ClassPath; 73 import org.netbeans.api.java.project.JavaProjectConstants; 74 import org.netbeans.spi.project.support.ant.AntProjectHelper; 75 import org.netbeans.spi.project.support.ant.EditableProperties; 76 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 77 import org.netbeans.spi.project.support.ant.PropertyUtils; 78 import org.netbeans.spi.project.support.ant.ReferenceHelper; 79 import org.netbeans.spi.java.project.support.ui.PackageView; 80 import org.netbeans.modules.j2ee.ejbjarproject.ui.FoldersListSettings; 81 import org.netbeans.modules.j2ee.ejbjarproject.UpdateHelper; 82 import org.netbeans.modules.j2ee.ejbjarproject.classpath.EjbJarProjectClassPathExtender; 83 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.AntArtifactChooser; 84 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarClassPathUi; 85 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; 86 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.LibrariesChooser; 87 import org.openide.util.lookup.Lookups; 88 89 90 91 92 93 97 public final class LibrariesNode extends AbstractNode { 98 99 private static final Image ICON_BADGE = Utilities.loadImage("org/netbeans/modules/j2ee/ejbjarproject/ui/resources/libraries-badge.png"); static final RequestProcessor rp = new RequestProcessor (); 101 private static Icon folderIconCache; 102 private static Icon openedFolderIconCache; 103 104 private final String displayName; 105 private final Action [] librariesNodeActions; 106 107 121 public LibrariesNode (String displayName, Project project, PropertyEvaluator eval, UpdateHelper helper, ReferenceHelper refHelper, 122 String classPathProperty, String [] classPathIgnoreRef, String platformProperty, String j2eePlatformProperty, 123 Action [] librariesNodeActions, String includedLibrariesElement) { 124 super (new LibrariesChildren (eval, helper, refHelper, classPathProperty, classPathIgnoreRef, platformProperty, j2eePlatformProperty, includedLibrariesElement), Lookups.singleton(project)); 125 this.displayName = displayName; 126 this.librariesNodeActions = librariesNodeActions; 127 } 128 129 public String getDisplayName () { 130 return this.displayName; 131 } 132 133 public String getName () { 134 return this.getDisplayName(); 135 } 136 137 public Image getIcon( int type ) { 138 return computeIcon( false, type ); 139 } 140 141 public Image getOpenedIcon( int type ) { 142 return computeIcon( true, type ); 143 } 144 145 public Action [] getActions(boolean context) { 146 return this.librariesNodeActions; 147 } 148 149 public boolean canCopy() { 150 return false; 151 } 152 153 public static Action createAddProjectAction (Project p, String classPathId, String includedLibrariesElement) { 155 return new AddProjectAction (p, classPathId, includedLibrariesElement); 156 } 157 158 public static Action createAddLibraryAction (Project p, AntProjectHelper helper, String classPathId, String includedLibrariesElement) { 159 return new AddLibraryAction (p, helper, classPathId, includedLibrariesElement); 160 } 161 162 public static Action createAddFolderAction (Project p, String classPathId, String includedLibrariesElement) { 163 return new AddFolderAction (p, classPathId, includedLibrariesElement); 164 } 165 166 171 static synchronized Icon getFolderIcon (boolean opened) { 172 if (openedFolderIconCache == null) { 173 Node n = DataFolder.findFolder(Repository.getDefault().getDefaultFileSystem().getRoot()).getNodeDelegate(); 174 openedFolderIconCache = new ImageIcon (n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16)); 175 folderIconCache = new ImageIcon (n.getIcon(BeanInfo.ICON_COLOR_16x16)); 176 } 177 if (opened) { 178 return openedFolderIconCache; 179 } 180 else { 181 return folderIconCache; 182 } 183 } 184 185 private Image computeIcon( boolean opened, int type ) { 186 Icon icon = getFolderIcon(opened); 187 Image image = Utilities.mergeImages(Utilities.icon2Image(icon), ICON_BADGE, 7, 7 ); 188 return image; 189 } 190 191 private static class LibrariesChildren extends Children.Keys implements PropertyChangeListener { 193 194 195 198 private static final String LIBRARY_PREFIX = "${libs."; 200 203 private static final String ANT_ARTIFACT_PREFIX = "${reference."; 207 private static final String FILE_REF_PREFIX = "${file.reference."; 211 private static final String REF_PREFIX = "${"; 213 private static final String LIBRARIES_ICON = "org/netbeans/modules/j2ee/ejbjarproject/ui/resources/libraries.gif"; private static final String ARCHIVE_ICON = "org/netbeans/modules/j2ee/ejbjarproject/ui/resources/jar.gif"; 216 private final PropertyEvaluator eval; 217 private final UpdateHelper helper; 218 private final ReferenceHelper refHelper; 219 private final String classPathProperty; 220 private final String platformProperty; 221 private final String j2eePlatformProperty; 222 private final Set classPathIgnoreRef; 223 private final String includedLibrariesElement; 224 225 private ClassPath fsListener; 229 230 231 LibrariesChildren (PropertyEvaluator eval, UpdateHelper helper, ReferenceHelper refHelper, 232 String classPathProperty, String [] classPathIgnoreRef, String platformProperty, String j2eePlatformProperty, 233 String includedLibrariesElement) { 234 this.eval = eval; 235 this.helper = helper; 236 this.refHelper = refHelper; 237 this.classPathProperty = classPathProperty; 238 this.classPathIgnoreRef = new HashSet (Arrays.asList(classPathIgnoreRef)); 239 this.platformProperty = platformProperty; 240 this.j2eePlatformProperty = j2eePlatformProperty; 241 this.includedLibrariesElement = includedLibrariesElement; 242 } 243 244 public void propertyChange(PropertyChangeEvent evt) { 245 String propName = evt.getPropertyName(); 246 if (classPathProperty.equals(propName) || ClassPath.PROP_ROOTS.equals(propName)) { 247 synchronized (this) { 248 if (fsListener!=null) { 249 fsListener.removePropertyChangeListener (this); 250 } 251 } 252 rp.post (new Runnable () { 253 public void run () { 254 setKeys(getKeys()); 255 } 256 }); 257 } 258 } 259 260 protected void addNotify() { 261 this.eval.addPropertyChangeListener (this); 262 this.setKeys(getKeys ()); 263 } 264 265 protected void removeNotify() { 266 this.eval.removePropertyChangeListener(this); 267 synchronized (this) { 268 if (fsListener!=null) { 269 fsListener.removePropertyChangeListener (this); 270 fsListener = null; 271 } 272 } 273 this.setKeys(Collections.EMPTY_SET); 274 } 275 276 protected Node[] createNodes(Object obj) { 277 Node[] result = null; 278 if (obj instanceof Key) { 279 Key key = (Key) obj; 280 switch (key.getType()) { 281 case Key.TYPE_PLATFORM: 282 result = new Node[] {PlatformNode.create(eval, platformProperty)}; 283 break; 284 case Key.TYPE_J2EE_PLATFORM: 285 Project project = FileOwnerQuery.getOwner(helper.getAntProjectHelper().getProjectDirectory()); 286 result = new Node[] {J2eePlatformNode.create(project, eval, j2eePlatformProperty)}; 287 break; 288 case Key.TYPE_PROJECT: 289 result = new Node[] {new ProjectNode(key.getProject(), key.getArtifactLocation(), helper, eval, refHelper, key.getClassPathId(), 290 key.getEntryId(), includedLibrariesElement)}; 291 break; 292 case Key.TYPE_LIBRARY: 293 result = new Node[] {ActionFilterNode.create(PackageView.createPackageView(key.getSourceGroup()), 294 helper, eval, refHelper, key.getClassPathId(), key.getEntryId(), includedLibrariesElement)}; 295 break; 296 } 297 } 298 if (result == null) { 299 assert false : "Unknown key type"; result = new Node[0]; 301 } 302 return result; 303 } 304 305 private List getKeys () { 306 EditableProperties projectSharedProps = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 307 EditableProperties projectPrivateProps = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 308 EditableProperties privateProps = PropertyUtils.getGlobalProperties(); 309 List rootsList = new ArrayList (); 310 List result = getKeys (projectSharedProps, projectPrivateProps, privateProps, classPathProperty, rootsList); 311 FileObject projectDir = helper.getAntProjectHelper().getProjectDirectory(); 313 if (platformProperty!=null && projectDir !=null && projectDir.isValid() && !projectDir.isVirtual()) { 314 result.add (new Key()); 315 } 316 if (j2eePlatformProperty != null) { 317 result.add(new Key(true)); 318 } 319 ClassPath cp = org.netbeans.spi.java.classpath.support.ClassPathSupport.createClassPath ((URL [])rootsList.toArray(new URL [rootsList.size()])); 322 cp.addPropertyChangeListener (this); 323 cp.getRoots(); 324 synchronized (this) { 325 fsListener = cp; 326 } 327 return result; 328 } 329 330 private List getKeys (EditableProperties projectSharedProps, EditableProperties projectPrivateProps, 331 EditableProperties privateProps, String currentClassPath, List rootsList) { 332 List result = new ArrayList (); 333 String raw = projectSharedProps.getProperty (currentClassPath); 334 if (raw == null) { 335 raw = projectPrivateProps.getProperty(currentClassPath); 336 } 337 if (raw == null) { 338 raw = privateProps.getProperty(currentClassPath); 339 } 340 if (raw == null) { 341 return result; 342 } 343 List pe = new ArrayList (Arrays.asList(PropertyUtils.tokenizePath( raw ))); 344 while (pe.size()>0){ 345 String prop = (String ) pe.remove(0); 346 String propName = EjbJarProjectProperties.getAntPropertyName (prop); 347 if (classPathIgnoreRef.contains(propName)) { 348 continue; 349 } 350 else if (prop.startsWith( LIBRARY_PREFIX )) { 351 String eval = prop.substring( LIBRARY_PREFIX.length(), prop.lastIndexOf('.') ); Library lib = LibraryManager.getDefault().getLibrary (eval); 354 if (lib != null) { 355 List roots = lib.getContent("classpath"); Icon libIcon = new ImageIcon (Utilities.loadImage(LIBRARIES_ICON)); 357 for (Iterator it = roots.iterator(); it.hasNext();) { 358 URL rootUrl = (URL ) it.next(); 359 rootsList.add (rootUrl); 360 FileObject root = URLMapper.findFileObject (rootUrl); 361 if (root != null) { 362 String displayName; 363 if ("jar".equals(rootUrl.getProtocol())) { FileObject file = FileUtil.getArchiveFile (root); 365 displayName = file.getNameExt(); 366 } 367 else { 368 File file = FileUtil.toFile (root); 369 if (file != null) { 370 displayName = file.getAbsolutePath(); 371 } 372 else { 373 displayName = root.getNameExt(); 374 } 375 } 376 displayName = MessageFormat.format ( 377 NbBundle.getMessage (LibrariesNode.class,"TXT_LibraryPartFormat"), 378 new Object [] {lib.getDisplayName(), displayName}); 379 SourceGroup sg = new LibrariesSourceGroup (root, displayName, libIcon, libIcon); 380 result.add (new Key(sg,currentClassPath, propName)); 381 } 382 } 383 } 384 } 386 else if (prop.startsWith(ANT_ARTIFACT_PREFIX)) { 387 Object [] ref = refHelper.findArtifactAndLocation(prop); 389 if (ref[0] != null && ref[1] != null) { 390 AntArtifact artifact = (AntArtifact)ref[0]; 391 URI uri = (URI )ref[1]; 392 result.add(new Key(artifact, uri, currentClassPath, propName)); 393 } 394 } 395 else if (prop.startsWith(FILE_REF_PREFIX)) { 396 String evaluatedRef = eval.getProperty(propName); 398 if (evaluatedRef != null) { 399 File file = helper.getAntProjectHelper().resolveFile(evaluatedRef); 400 SourceGroup sg = createFileSourceGroup(file,rootsList); 401 if (sg !=null) { 402 result.add (new Key(sg,currentClassPath, propName)); 403 } 404 } 405 } 406 else if (prop.startsWith(REF_PREFIX)) { 407 result.addAll(getKeys(projectSharedProps, projectPrivateProps, privateProps,propName, rootsList)); 409 } 410 else { 411 File file = helper.getAntProjectHelper().resolveFile(prop); 413 SourceGroup sg = createFileSourceGroup(file,rootsList); 414 if (sg !=null) { 415 result.add ( new Key(sg,currentClassPath, propName)); 416 } 417 } 418 } 419 return result; 420 } 421 422 private static SourceGroup createFileSourceGroup (File file, List rootsList) { 423 Icon icon; 424 Icon openedIcon; 425 String displayName; 426 try { 427 URL url = file.toURI().toURL(); 428 if (FileUtil.isArchiveFile(url)) { 429 url = FileUtil.getArchiveRoot(url); 430 icon = openedIcon = new ImageIcon (Utilities.loadImage(ARCHIVE_ICON)); 431 displayName = file.getName(); 432 } 433 else { 434 String sURL = url.toExternalForm(); 435 if (!sURL.endsWith("/")) { url = new URL (sURL+"/"); } 438 icon = getFolderIcon (false); 439 openedIcon = getFolderIcon (true); 440 displayName = file.getAbsolutePath(); 441 } 442 rootsList.add (url); 443 FileObject root = URLMapper.findFileObject (url); 444 if (root != null) { 445 return new LibrariesSourceGroup (root,displayName,icon,openedIcon); 446 } 447 } catch (MalformedURLException e) { 448 ErrorManager.getDefault().notify(e); 449 } 450 return null; 451 } 452 } 453 454 private static class Key { 455 static final int TYPE_PLATFORM = 0; 456 static final int TYPE_LIBRARY = 1; 457 static final int TYPE_PROJECT = 2; 458 static final int TYPE_J2EE_PLATFORM = 3; 459 460 private int type; 461 private String classPathId; 462 private String entryId; 463 private SourceGroup sg; 464 private AntArtifact antArtifact; 465 private URI uri; 466 467 Key () { 468 this(false); 469 } 470 471 Key (boolean j2ee) { 472 this.type = j2ee ? TYPE_J2EE_PLATFORM : TYPE_PLATFORM; 473 } 474 475 Key (SourceGroup sg, String classPathId, String entryId) { 476 this.type = TYPE_LIBRARY; 477 this.sg = sg; 478 this.classPathId = classPathId; 479 this.entryId = entryId; 480 } 481 482 Key (AntArtifact a, URI uri, String classPathId, String entryId) { 483 this.type = TYPE_PROJECT; 484 this.antArtifact = a; 485 this.uri = uri; 486 this.classPathId = classPathId; 487 this.entryId = entryId; 488 } 489 490 public int getType () { 491 return this.type; 492 } 493 494 public String getClassPathId () { 495 return this.classPathId; 496 } 497 498 public String getEntryId () { 499 return this.entryId; 500 } 501 502 public SourceGroup getSourceGroup () { 503 return this.sg; 504 } 505 506 public AntArtifact getProject() { 507 return this.antArtifact; 508 } 509 510 public URI getArtifactLocation() { 511 return this.uri; 512 } 513 514 public int hashCode() { 515 int hashCode = this.type<<16; 516 switch (this.type) { 517 case TYPE_LIBRARY: 518 hashCode ^= this.sg == null ? 0 : this.sg.hashCode(); 519 break; 520 case TYPE_PROJECT: 521 hashCode ^= this.antArtifact == null ? 0 : this.antArtifact.hashCode(); 522 break; 523 } 524 return hashCode; 525 } 526 527 public boolean equals(Object obj) { 528 if (!(obj instanceof Key)) { 529 return false; 530 } 531 Key other = (Key) obj; 532 if (other.type != type) { 533 return false; 534 } 535 switch (type) { 536 case TYPE_LIBRARY: 537 return (this.sg == null ? other.sg == null : this.sg.equals(other.sg)) && 538 (this.classPathId == null ? other.classPathId == null : this.classPathId.equals (other.classPathId)) && 539 (this.entryId == null ? other.entryId == null : this.entryId.equals (other.entryId)); 540 case TYPE_PROJECT: 541 return (this.antArtifact == null ? other.antArtifact == null : this.antArtifact.equals(other.antArtifact)) && 542 (this.classPathId == null ? other.classPathId == null : this.classPathId.equals (other.classPathId)) && 543 (this.entryId == null ? other.entryId == null : this.entryId.equals (other.entryId)); 544 case TYPE_PLATFORM: 545 case TYPE_J2EE_PLATFORM: 546 return true; 547 default: 548 throw new IllegalStateException (); 549 } 550 } 551 } 552 553 private static class AddProjectAction extends AbstractAction { 554 555 private final Project project; 556 private final String classPathId; 557 private final String includedLibrariesElement; 558 559 public AddProjectAction (Project project, String classPathId, String includedLibrariesElement) { 560 super( NbBundle.getMessage( LibrariesNode.class, "LBL_AddProject_Action" ) ); 561 this.project = project; 562 this.classPathId = classPathId; 563 this.includedLibrariesElement = includedLibrariesElement; 564 } 565 566 public void actionPerformed(ActionEvent e) { 567 AntArtifactChooser.ArtifactItem artifactItems[] = AntArtifactChooser.showDialog(JavaProjectConstants.ARTIFACT_TYPE_JAR, project, null); 568 if ( artifactItems != null ) { 569 addArtifacts( artifactItems ); 570 } 571 } 572 573 private void addArtifacts (AntArtifactChooser.ArtifactItem[] artifactItems) { 574 EjbJarProjectClassPathExtender cpExtender = (EjbJarProjectClassPathExtender) project.getLookup().lookup(EjbJarProjectClassPathExtender.class); 575 if (cpExtender != null) { 576 try { 577 cpExtender.addAntArtifacts(classPathId, artifactItems, includedLibrariesElement ); 578 } catch (IOException ioe) { 579 ErrorManager.getDefault().notify(ioe); 580 } 581 } 582 else { 583 ErrorManager.getDefault().log ("EjbJarProjectClassPathExtender not found in the project lookup of project: "+project.getProjectDirectory().getPath()); } 585 } 586 } 587 588 private static class AddLibraryAction extends AbstractAction { 589 590 private final Project project; 591 private final AntProjectHelper helper; 592 private final String classPathId; 593 private final String includedLibrariesElement; 594 595 public AddLibraryAction (Project project, AntProjectHelper helper, String classPathId, String includedLibrariesElement) { 596 super( NbBundle.getMessage( LibrariesNode.class, "LBL_AddLibrary_Action" ) ); 597 this.project = project; 598 this.helper = helper; 599 this.classPathId = classPathId; 600 this.includedLibrariesElement = includedLibrariesElement; 601 } 602 603 public void actionPerformed(ActionEvent e) { 604 Object [] options = new Object [] { 605 new JButton (NbBundle.getMessage (EjbJarClassPathUi.class,"LBL_AddLibrary")), 606 DialogDescriptor.CANCEL_OPTION 607 }; 608 ((JButton )options[0]).setEnabled(false); 609 ((JButton )options[0]).getAccessibleContext().setAccessibleDescription (NbBundle.getMessage (EjbJarClassPathUi.class,"AD_AddLibrary")); 610 LibrariesChooser panel = new LibrariesChooser ((JButton )options[0], Collections.EMPTY_SET); 612 DialogDescriptor desc = new DialogDescriptor(panel,NbBundle.getMessage( EjbJarClassPathUi.class, "LBL_CustomizeCompile_Classpath_AddLibrary" ), 613 true, options, options[0], DialogDescriptor.DEFAULT_ALIGN,null,null); 614 Dialog dlg = DialogDisplayer.getDefault().createDialog(desc); 615 dlg.setVisible(true); 616 if (desc.getValue() == options[0]) { 617 addLibraries(panel.getSelectedLibraries()); 618 } 619 dlg.dispose(); 620 } 621 622 private void addLibraries (Library[] libraries) { 623 EjbJarProjectClassPathExtender cpExtender = (EjbJarProjectClassPathExtender) project.getLookup().lookup(EjbJarProjectClassPathExtender.class); 624 if (cpExtender != null) { 625 try { 626 cpExtender.addLibraries(classPathId, libraries, includedLibrariesElement); 627 } catch (IOException ioe) { 628 ErrorManager.getDefault().notify(ioe); 629 } 630 } 631 else { 632 ErrorManager.getDefault().log ("EjbJarProjectClassPathExtender not found in the project lookup of project: "+project.getProjectDirectory().getPath()); } 634 } 635 } 636 637 private static class AddFolderAction extends AbstractAction { 638 639 private final Project project; 640 private final String classPathId; 641 private final String includedLibrariesElement; 642 643 public AddFolderAction (Project project, String classPathId, String includedLibrariesElement) { 644 super( NbBundle.getMessage( LibrariesNode.class, "LBL_AddFolder_Action" ) ); 645 this.project = project; 646 this.classPathId = classPathId; 647 this.includedLibrariesElement = includedLibrariesElement; 648 } 649 650 public void actionPerformed(ActionEvent e) { 651 JFileChooser chooser = new JFileChooser (); 652 FileUtil.preventFileChooserSymlinkTraversal(chooser, null); 653 chooser.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES ); 654 chooser.setMultiSelectionEnabled( true ); 655 chooser.setDialogTitle( NbBundle.getMessage( LibrariesNode.class, "LBL_AddJar_DialogTitle" ) ); FileFilter fileFilter = new SimpleFileFilter ( 657 NbBundle.getMessage( LibrariesNode.class, "LBL_ZipJarFolderFilter" ), new String [] {"ZIP","JAR"} ); chooser.setAcceptAllFileFilterUsed( false ); 661 chooser.setFileFilter(fileFilter); 662 File curDir = FoldersListSettings.getDefault().getLastUsedClassPathFolder(); 663 chooser.setCurrentDirectory (curDir); 664 int option = chooser.showOpenDialog( WindowManager.getDefault().getMainWindow() ); 665 if ( option == JFileChooser.APPROVE_OPTION ) { 666 File files[] = chooser.getSelectedFiles(); 667 addJarFiles( files, fileFilter ); 668 curDir = FileUtil.normalizeFile(chooser.getCurrentDirectory()); 669 FoldersListSettings.getDefault().setLastUsedClassPathFolder(curDir); 670 } 671 } 672 673 private void addJarFiles (File [] files, FileFilter fileFilter) { 674 EjbJarProjectClassPathExtender cpExtender = (EjbJarProjectClassPathExtender) project.getLookup().lookup(EjbJarProjectClassPathExtender.class); 675 if (cpExtender != null) { 676 List fileObjects = new LinkedList (); 677 for (int i = 0; i < files.length; i++) { 678 if (fileFilter.accept(files[i])) { 679 FileObject fo = FileUtil.toFileObject (files[i]); 680 assert fo != null : files[i]; 681 fileObjects.add(fo); 682 } 683 } 684 try { 685 FileObject[] fileObjectArray = new FileObject[fileObjects.size()]; 686 fileObjects.toArray(fileObjectArray); 687 cpExtender.addArchiveFiles(classPathId, fileObjectArray, includedLibrariesElement); 688 } catch (IOException ioe) { 689 ErrorManager.getDefault().notify(ioe); 690 } 691 } 692 else { 693 ErrorManager.getDefault().log ("EjbJarProjectClassPathExtender not found in the project lookup of project: "+project.getProjectDirectory().getPath()); } 695 } 696 697 } 698 699 private static class SimpleFileFilter extends FileFilter { 700 701 private String description; 702 private Collection extensions; 703 704 705 public SimpleFileFilter (String description, String [] extensions) { 706 this.description = description; 707 this.extensions = Arrays.asList(extensions); 708 } 709 710 public boolean accept(File f) { 711 if (f.isDirectory()) 712 return true; 713 try { 714 return FileUtil.isArchiveFile(f.toURI().toURL()); 715 } catch (MalformedURLException mue) { 716 ErrorManager.getDefault().notify(mue); 717 return false; 718 } 719 } 720 721 public String getDescription() { 722 return this.description; 723 } 724 } 725 } 726 727 728 | Popular Tags |