PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/netbeans-7.3/maven/src/org/netbeans/modules/maven/classpath/MavenSourcesImpl.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 655 lines | 508 code | 60 blank | 87 comment | 135 complexity | f353817697c92a6138a5c1574fd34a8e MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common
  11. * Development and Distribution License("CDDL") (collectively, the
  12. * "License"). You may not use this file except in compliance with the
  13. * License. You can obtain a copy of the License at
  14. * http://www.netbeans.org/cddl-gplv2.html
  15. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. * specific language governing permissions and limitations under the
  17. * License. When distributing the software, include this License Header
  18. * Notice in each file and include the License file at
  19. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. * particular file as subject to the "Classpath" exception as provided
  21. * by Oracle in the GPL Version 2 section of the License file that
  22. * accompanied this code. If applicable, add the following below the
  23. * License Header, with the fields enclosed by brackets [] replaced by
  24. * your own identifying information:
  25. * "Portions Copyrighted [year] [name of copyright owner]"
  26. *
  27. * If you wish your version of this file to be governed by only the CDDL
  28. * or only the GPL Version 2, indicate your decision by adding
  29. * "[Contributor] elects to include this software in this distribution
  30. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  31. * single choice of license, a recipient has the option to distribute
  32. * your version of this file under either the CDDL, the GPL Version 2 or
  33. * to extend the choice of license to its licensees as provided above.
  34. * However, if you add GPL Version 2 code and therefore, elected the GPL
  35. * Version 2 license, then the option applies only if the new code is
  36. * made subject to such option by the copyright holder.
  37. *
  38. * Contributor(s):
  39. *
  40. * Portions Copyrighted 2008 Sun Microsystems, Inc.
  41. */
  42. package org.netbeans.modules.maven.classpath;
  43. import java.awt.Image;
  44. import org.netbeans.modules.maven.api.FileUtilities;
  45. import java.beans.PropertyChangeEvent;
  46. import java.beans.PropertyChangeListener;
  47. import java.beans.PropertyChangeSupport;
  48. import java.io.File;
  49. import java.io.IOException;
  50. import java.net.URI;
  51. import java.util.ArrayList;
  52. import java.util.Arrays;
  53. import java.util.HashSet;
  54. import java.util.List;
  55. import java.util.Map;
  56. import java.util.Set;
  57. import java.util.TreeMap;
  58. import java.util.logging.Level;
  59. import java.util.logging.Logger;
  60. import javax.swing.Icon;
  61. import javax.swing.event.ChangeListener;
  62. import org.apache.maven.model.Resource;
  63. import org.apache.maven.project.MavenProject;
  64. import org.netbeans.api.annotations.common.NullAllowed;
  65. import org.netbeans.modules.maven.api.NbMavenProject;
  66. import org.netbeans.api.java.project.JavaProjectConstants;
  67. import org.netbeans.api.project.FileOwnerQuery;
  68. import org.netbeans.api.project.Project;
  69. import org.netbeans.api.project.ProjectManager;
  70. import org.netbeans.api.project.ProjectUtils;
  71. import org.netbeans.api.project.SourceGroup;
  72. import org.netbeans.api.project.Sources;
  73. import org.netbeans.api.queries.SharabilityQuery;
  74. import org.netbeans.modules.maven.NbMavenProjectImpl;
  75. import org.netbeans.modules.maven.spi.nodes.NodeUtils;
  76. import org.netbeans.spi.project.SourceGroupModifierImplementation;
  77. import org.netbeans.spi.project.support.GenericSources;
  78. import org.openide.filesystems.FileObject;
  79. import org.openide.filesystems.FileUtil;
  80. import org.openide.util.ChangeSupport;
  81. import org.openide.util.Exceptions;
  82. import org.openide.util.ImageUtilities;
  83. import static org.netbeans.modules.maven.classpath.Bundle.*;
  84. import org.netbeans.spi.project.ProjectServiceProvider;
  85. import org.openide.util.NbBundle.Messages;
  86. import org.openide.util.Utilities;
  87. /**
  88. * Implementation of Sources interface for maven projects.
  89. * generic and java are necessary for proper workings of the project, the rest is custom thing..
  90. * IMHO at least..
  91. * @author Milos Kleint
  92. */
  93. @ProjectServiceProvider(service={Sources.class, SourceGroupModifierImplementation.class}, projectType="org-netbeans-modules-maven")
  94. public class MavenSourcesImpl implements Sources, SourceGroupModifierImplementation {
  95. public static final String TYPE_OTHER = "Resources"; //NOI18N
  96. public static final String TYPE_TEST_OTHER = "TestResources"; //NOI18N
  97. public static final String TYPE_GEN_SOURCES = "GeneratedSources"; //NOI18N
  98. public static final String NAME_PROJECTROOT = "ProjectRoot"; //NOI18N
  99. public static final String NAME_XDOCS = "XDocs"; //NOI18N
  100. public static final String NAME_SOURCE = "1SourceRoot"; //NOI18N
  101. public static final String NAME_TESTSOURCE = "2TestSourceRoot"; //NOI18N
  102. public static final String NAME_GENERATED_SOURCE = "6GeneratedSourceRoot"; //NOI18N
  103. public static final String NAME_GENERATED_TEST_SOURCE = "7GeneratedSourceRoot"; //NOI18N
  104. private final Project proj;
  105. private final ChangeSupport cs = new ChangeSupport(this);
  106. private final PropertyChangeListener pcl = new PropertyChangeListener() {
  107. public @Override void propertyChange(PropertyChangeEvent event) {
  108. checkChanges(true, true);
  109. }
  110. };
  111. private Map<String, SourceGroup> javaGroup;
  112. private Map<File, SourceGroup> genSrcGroup;
  113. private Map<File, OtherGroup> otherMainGroups;
  114. private Map<File, OtherGroup> otherTestGroups;
  115. private final Object lock = new Object();
  116. public MavenSourcesImpl(Project proj) {
  117. this.proj = proj;
  118. javaGroup = new TreeMap<String, SourceGroup>();
  119. genSrcGroup = new TreeMap<File, SourceGroup>();
  120. otherMainGroups = new TreeMap<File, OtherGroup>();
  121. otherTestGroups = new TreeMap<File, OtherGroup>();
  122. }
  123. private NbMavenProjectImpl project() {
  124. return proj.getLookup().lookup(NbMavenProjectImpl.class);
  125. }
  126. @Messages({
  127. "SG_Sources=Source Packages",
  128. "SG_Test_Sources=Test Packages"
  129. })
  130. private void checkChanges(boolean fireChanges, boolean checkAlsoNonJavaStuff) {
  131. boolean changed = false;
  132. synchronized (lock) {
  133. NbMavenProjectImpl project = project();
  134. MavenProject mp = project.getOriginalMavenProject();
  135. NbMavenProject watcher = project.getProjectWatcher();
  136. File folder = FileUtilities.convertStringToFile(mp.getBuild().getSourceDirectory());
  137. //QualitasCorpus.class: Created due to compilation errors
  138. //changed = changed | checkSourceGroupCache(folder, NAME_SOURCE, SG_Sources(), javaGroup, watcher);
  139. folder = FileUtilities.convertStringToFile(mp.getBuild().getTestSourceDirectory());
  140. //QualitasCorpus.class: Created due to compilation errors
  141. //changed = changed | checkSourceGroupCache(folder, NAME_TESTSOURCE, SG_Test_Sources(), javaGroup, watcher);
  142. changed = changed | checkGeneratedGroupsCache();
  143. if (checkAlsoNonJavaStuff) {
  144. changed = changed | checkOtherGroupsCache(project.getOtherRoots(false), false);
  145. changed = changed | checkOtherGroupsCache(project.getOtherRoots(true), true);
  146. }
  147. }
  148. if (changed) {
  149. if (fireChanges) {
  150. cs.fireChange();
  151. }
  152. }
  153. }
  154. public @Override void addChangeListener(ChangeListener changeListener) {
  155. if (!cs.hasListeners()) {
  156. NbMavenProject.addPropertyChangeListener(project(), pcl);
  157. }
  158. cs.addChangeListener(changeListener);
  159. }
  160. public @Override void removeChangeListener(ChangeListener changeListener) {
  161. cs.removeChangeListener(changeListener);
  162. if (!cs.hasListeners()) {
  163. NbMavenProject.removePropertyChangeListener(project(), pcl);
  164. }
  165. }
  166. public @Override SourceGroup[] getSourceGroups(String str) {
  167. if (Sources.TYPE_GENERIC.equals(str)) {
  168. return new SourceGroup[] { GenericSources.group(proj, proj.getProjectDirectory(), NAME_PROJECTROOT,
  169. ProjectUtils.getInformation(proj).getDisplayName(), null, null) };
  170. }
  171. if (JavaProjectConstants.SOURCES_TYPE_JAVA.equals(str)) {
  172. List<SourceGroup> toReturn = new ArrayList<SourceGroup>();
  173. synchronized (lock) {
  174. // don't fire event at all..
  175. checkChanges(false, false);
  176. toReturn.addAll(javaGroup.values());
  177. }
  178. SourceGroup[] grp = new SourceGroup[toReturn.size()];
  179. grp = toReturn.toArray(grp);
  180. return grp;
  181. }
  182. if (TYPE_GEN_SOURCES.equals(str)) {
  183. List<SourceGroup> toReturn = new ArrayList<SourceGroup>();
  184. synchronized (lock) {
  185. checkGeneratedGroupsCache();
  186. toReturn.addAll(genSrcGroup.values());
  187. }
  188. SourceGroup[] grp = new SourceGroup[toReturn.size()];
  189. grp = toReturn.toArray(grp);
  190. return grp;
  191. }
  192. if (TYPE_OTHER.equals(str) || TYPE_TEST_OTHER.equals(str)) {
  193. // TODO not all these are probably resources.. maybe need to split in 2 groups..
  194. boolean test = TYPE_TEST_OTHER.equals(str);
  195. List<SourceGroup> toReturn = new ArrayList<SourceGroup>();
  196. File[] roots = project().getOtherRoots(test);
  197. synchronized (lock) {
  198. // don't fire event synchronously..
  199. checkOtherGroupsCache(roots, test);
  200. if (test && !otherTestGroups.isEmpty()) {
  201. toReturn.addAll(otherTestGroups.values());
  202. } else if (!test && !otherMainGroups.isEmpty()) {
  203. toReturn.addAll(otherMainGroups.values());
  204. }
  205. }
  206. SourceGroup[] grp = new SourceGroup[toReturn.size()];
  207. grp = toReturn.toArray(grp);
  208. return grp;
  209. }
  210. if (JavaProjectConstants.SOURCES_TYPE_RESOURCES.equals(str)) {
  211. return getOrCreateResourceSourceGroup(false, false);
  212. }
  213. // logger.warn("unknown source type=" + str);
  214. return new SourceGroup[0];
  215. }
  216. @Messages("SG_Project_Resources=Project Resources")
  217. private SourceGroup[] getOrCreateResourceSourceGroup(boolean test, boolean create) {
  218. URI[] uris = project().getResources(test);
  219. if (uris.length > 0) {
  220. List<URI> virtuals = new ArrayList<URI>();
  221. List<SourceGroup> existing = new ArrayList<SourceGroup>();
  222. for (URI u : uris) {
  223. FileObject fo = FileUtilities.convertURItoFileObject(u);
  224. if (fo == null) {
  225. virtuals.add(u);
  226. } else if (fo.isFolder()) {
  227. existing.add(GenericSources.group(proj, fo, "resources", //NOI18N
  228. SG_Project_Resources(), null, null));
  229. }
  230. }
  231. if (create && existing.isEmpty()) {
  232. File root = Utilities.toFile(virtuals.get(0));
  233. try {
  234. FileObject fo = FileUtil.createFolder(root);
  235. existing.add(GenericSources.group(proj, fo, "resources", //NOI18N
  236. SG_Project_Resources(), null, null));
  237. } catch (IOException ex) {
  238. Exceptions.printStackTrace(ex);
  239. }
  240. }
  241. //TODO we should probably add includes/excludes to source groups.
  242. return existing.toArray(new SourceGroup[0]);
  243. } else {
  244. //TODO add <Resources> element to pom??
  245. }
  246. return new SourceGroup[0];
  247. }
  248. //QualitasCorpus.class: Created due to compilation errors
  249. private String SG_Project_Resources() {
  250. // TODO Auto-generated method stub
  251. return null;
  252. }
  253. /**
  254. * consult the SourceGroup cache, return true if anything changed..
  255. */
  256. private boolean checkSourceGroupCache(@NullAllowed File rootF, String name, String displayName, Map<String, SourceGroup> groups, NbMavenProject watcher) {
  257. FileObject root;
  258. if (rootF != null) {
  259. watcher.addWatchedPath(Utilities.toURI(rootF));
  260. root = FileUtil.toFileObject(rootF);
  261. } else {
  262. root = null;
  263. }
  264. SourceGroup group = groups.get(name);
  265. if ((root == null || root.isData()) && group != null) {
  266. groups.remove(name);
  267. return true;
  268. }
  269. if (root == null || root.isData()) {
  270. return false;
  271. }
  272. boolean changed = false;
  273. if (group == null) {
  274. group = GenericSources.group(proj, root, name, displayName, null, null);
  275. groups.put(name, group);
  276. changed = true;
  277. } else {
  278. if (!group.getRootFolder().equals(root)) {
  279. group = GenericSources.group(proj, root, name, displayName, null, null);
  280. groups.put(name, group);
  281. changed = true;
  282. }
  283. }
  284. return changed;
  285. }
  286. private boolean checkGeneratedGroupsCache() {
  287. boolean changed = false;
  288. List<File> checked = new ArrayList<File>();
  289. for (boolean test : new boolean[] {false, true}) {
  290. for (URI u : project().getGeneratedSourceRoots(test)) {
  291. File file = FileUtil.normalizeFile(Utilities.toFile(u));
  292. FileObject folder = FileUtil.toFileObject(file);
  293. changed |= checkGeneratedGroupCache(folder, file, file.getName(), test);
  294. checked.add(file);
  295. }
  296. }
  297. Set<File> currs = new HashSet<File>();
  298. currs.addAll(genSrcGroup.keySet());
  299. for (File curr : currs) {
  300. if (!checked.contains(curr)) {
  301. genSrcGroup.remove(curr);
  302. changed = true;
  303. }
  304. }
  305. return changed;
  306. }
  307. /**
  308. * consult the SourceGroup cache, return true if anything changed..
  309. */
  310. @Messages({
  311. "# {0} - name suffix", "SG_Generated_Sources=Generated Sources ({0})",
  312. "# {0} - name suffix", "SG_Generated_Test_Sources=Generated Test Sources ({0})"
  313. })
  314. private boolean checkGeneratedGroupCache(FileObject root, File rootFile, String nameSuffix, boolean test) {
  315. SourceGroup group = genSrcGroup.get(rootFile);
  316. if ((root == null || root.isData()) && group != null) {
  317. genSrcGroup.remove(rootFile);
  318. return true;
  319. }
  320. if (root == null || root.isData()) {
  321. return false;
  322. }
  323. boolean changed = false;
  324. String name = (test ? NAME_GENERATED_TEST_SOURCE : NAME_GENERATED_SOURCE) + nameSuffix;
  325. String displayName = (String) (test ? SG_Generated_Test_Sources(nameSuffix) : SG_Generated_Sources(nameSuffix));
  326. if (group == null) {
  327. group = new GeneratedGroup(project(), root, name, displayName);
  328. genSrcGroup.put(rootFile, group);
  329. changed = true;
  330. } else {
  331. if (!group.getRootFolder().isValid() || !group.getRootFolder().equals(root)) {
  332. group = new GeneratedGroup(project(), root, name, displayName);
  333. genSrcGroup.put(rootFile, group);
  334. changed = true;
  335. }
  336. }
  337. return changed;
  338. }
  339. //QualitasCorpus.class: Created due to compilation errors
  340. private Object SG_Generated_Test_Sources(String nameSuffix) {
  341. // TODO Auto-generated method stub
  342. return null;
  343. }
  344. private Object SG_Generated_Sources(String nameSuffix) {
  345. // TODO Auto-generated method stub
  346. return null;
  347. }
  348. private boolean checkOtherGroupsCache(File[] roots, boolean test) {
  349. boolean ch = false;
  350. Set<File> toRemove = new HashSet<File>(test ? otherTestGroups.keySet() : otherMainGroups.keySet());
  351. toRemove.removeAll(Arrays.asList(roots));
  352. URI[] res = project().getResources(test);
  353. Set<File> resources = new HashSet<File>();
  354. for (URI ur : res) {
  355. resources.add(Utilities.toFile(ur));
  356. }
  357. for (File f : roots) {
  358. ch = ch | checkOtherGroup(f, resources, test);
  359. }
  360. for (File f : toRemove) {
  361. //now this shall remove the nonexisting ones and even mark the change..
  362. ch = ch | checkOtherGroup(f, resources, test);
  363. }
  364. return ch;
  365. }
  366. private boolean checkOtherGroup(File rootFile, Set<File> resourceRoots, boolean test) {
  367. FileObject root = FileUtil.toFileObject(rootFile);
  368. if (root != null && !root.isFolder()) {
  369. root = null;
  370. }
  371. Map<File, OtherGroup> map = test ? otherTestGroups : otherMainGroups;
  372. OtherGroup grp = map.get(rootFile);
  373. boolean isResourceNow = resourceRoots.contains(rootFile);
  374. boolean wasResourceBefore = grp != null && grp.getResource() != null;
  375. if ((root == null && grp != null) || (root != null && grp != null && wasResourceBefore && !isResourceNow)) {
  376. map.remove(rootFile);
  377. return true;
  378. }
  379. if (root == null) {
  380. return false;
  381. }
  382. boolean changed = false;
  383. if (grp == null || !grp.getRootFolder().isValid() || !grp.getRootFolder().equals(root) ||
  384. isResourceNow != wasResourceBefore) {
  385. grp = new OtherGroup(project(), root, "Resource" + (test ? "Test":"Main") + root.getNameExt(), root.getName(), test); //NOI18N
  386. map.put(rootFile, grp);
  387. changed = true;
  388. }
  389. return changed;
  390. }
  391. public @Override SourceGroup createSourceGroup(String type, String hint) {
  392. assert type != null;
  393. MavenProject mp = project().getOriginalMavenProject();
  394. File folder = null;
  395. if (JavaProjectConstants.SOURCES_TYPE_RESOURCES.equals(type)) {
  396. boolean main = JavaProjectConstants.SOURCES_HINT_MAIN.equals(hint);
  397. SourceGroup[] grps = getOrCreateResourceSourceGroup(!main, true);
  398. if (grps.length > 0) {
  399. return grps[0];
  400. }
  401. return null;
  402. }
  403. if (JavaProjectConstants.SOURCES_TYPE_JAVA.equals(type)) {
  404. if (JavaProjectConstants.SOURCES_HINT_MAIN.equals(hint)) {
  405. folder = FileUtilities.convertStringToFile(mp.getBuild().getSourceDirectory());
  406. }
  407. if (JavaProjectConstants.SOURCES_HINT_TEST.equals(hint)) {
  408. folder = FileUtilities.convertStringToFile(mp.getBuild().getTestSourceDirectory());
  409. }
  410. }
  411. if (folder != null) {
  412. FileObject fo;
  413. try {
  414. fo = FileUtil.createFolder(folder);
  415. } catch (IOException x) { // XXX not allowed to rethrow
  416. Logger.getLogger(MavenSourcesImpl.class.getName()).log(Level.INFO, null, x);
  417. return null;
  418. }
  419. SourceGroup[] grps = getSourceGroups(type);
  420. for (SourceGroup sg : grps) {
  421. if (fo.equals(sg.getRootFolder())) {
  422. return sg;
  423. }
  424. }
  425. //shall we somehow report it?
  426. }
  427. return null;
  428. }
  429. public @Override boolean canCreateSourceGroup(String type, String hint) {
  430. return (JavaProjectConstants.SOURCES_TYPE_RESOURCES.equals(type) ||
  431. JavaProjectConstants.SOURCES_TYPE_JAVA.equals(type))
  432. && (JavaProjectConstants.SOURCES_HINT_MAIN.equals(hint) ||
  433. JavaProjectConstants.SOURCES_HINT_TEST.equals(hint));
  434. }
  435. public static final class OtherGroup implements SourceGroup {
  436. private final FileObject rootFolder;
  437. private File rootFile;
  438. private final String name;
  439. private final String displayName;
  440. private final Icon icon;
  441. private final Icon openedIcon;
  442. private NbMavenProjectImpl project;
  443. private Resource resource;
  444. private PropertyChangeSupport support = new PropertyChangeSupport(this);
  445. @Messages("SG_Root_not_defined=<Root not defined>")
  446. OtherGroup(NbMavenProjectImpl p, FileObject rootFold, String nm, String displayNm, boolean test) {
  447. project = p;
  448. rootFolder = rootFold;
  449. rootFile = FileUtil.toFile(rootFolder);
  450. resource = checkResource(rootFold,
  451. test ? project.getOriginalMavenProject().getTestResources() :
  452. project.getOriginalMavenProject().getResources());
  453. if (resource != null) {
  454. Image badge = ImageUtilities.loadImage("org/netbeans/modules/maven/others-badge.png", true); //NOI18N
  455. // ImageUtilities.addToolTipToImage(badge, "Resource root as defined in POM.");
  456. icon = ImageUtilities.image2Icon(ImageUtilities.mergeImages(NodeUtils.getTreeFolderIcon(false), badge, 8, 8));
  457. openedIcon = ImageUtilities.image2Icon(ImageUtilities.mergeImages(NodeUtils.getTreeFolderIcon(true), badge, 8, 8));
  458. name = FileUtilities.relativizeFile(FileUtil.toFile(project.getProjectDirectory()), FileUtilities.convertStringToFile(resource.getDirectory()));
  459. displayName = name;
  460. } else {
  461. icon = ImageUtilities.image2Icon(NodeUtils.getTreeFolderIcon(false));
  462. openedIcon = ImageUtilities.image2Icon(NodeUtils.getTreeFolderIcon(true));
  463. name = nm;
  464. displayName = displayNm != null ? displayNm : SG_Root_not_defined();
  465. }
  466. }
  467. //QualitasCorpus.class: Created due to compilation errors
  468. private String SG_Root_not_defined() {
  469. // TODO Auto-generated method stub
  470. return null;
  471. }
  472. public @Override FileObject getRootFolder() {
  473. return rootFolder;
  474. }
  475. public File getRootFolderFile() {
  476. return rootFile;
  477. }
  478. public Resource getResource() {
  479. return resource;
  480. }
  481. public @Override String getName() {
  482. return name;
  483. }
  484. public @Override String getDisplayName() {
  485. if (resource != null && resource.getTargetPath() != null) {
  486. return displayName + " -> " + resource.getTargetPath();
  487. }
  488. return displayName;
  489. }
  490. public @Override Icon getIcon(boolean opened) {
  491. return opened ? icon : openedIcon;
  492. }
  493. public @Override boolean contains(FileObject file) {
  494. if (file != rootFolder && !FileUtil.isParentOf(rootFolder, file)) {
  495. return false;
  496. }
  497. if (project != null) {
  498. if (file.isFolder() && file != project.getProjectDirectory() && ProjectManager.getDefault().isProject(file)) {
  499. // #67450: avoid actually loading the nested project.
  500. return false;
  501. }
  502. if (FileOwnerQuery.getOwner(file) != project) {
  503. return false;
  504. }
  505. }
  506. File f = FileUtil.toFile(file);
  507. if (f != null) {
  508. // MIXED, UNKNOWN, and SHARABLE -> include it
  509. return SharabilityQuery.getSharability(f) != SharabilityQuery.NOT_SHARABLE;
  510. } else {
  511. // Not on disk, include it.
  512. return true;
  513. }
  514. }
  515. public @Override void addPropertyChangeListener(PropertyChangeListener l) {
  516. support.addPropertyChangeListener(l);
  517. }
  518. public @Override void removePropertyChangeListener(PropertyChangeListener l) {
  519. support.removePropertyChangeListener(l);
  520. }
  521. private Resource checkResource(FileObject rootFold, List<Resource> list) {
  522. for (Resource elem : list) {
  523. String dir = elem.getDirectory();
  524. if (dir == null) { // #203635
  525. continue;
  526. }
  527. URI uri = FileUtilities.getDirURI(project.getProjectDirectory(), dir);
  528. FileObject fo = FileUtilities.convertURItoFileObject(uri);
  529. if (fo != null && fo.equals(rootFold)) {
  530. return elem;
  531. }
  532. }
  533. return null;
  534. }
  535. }
  536. /**
  537. * MEVENIDE-536 - cannot use default implementation of SourceGroup because it
  538. * won't include non-shareable folders..
  539. */
  540. public static final class GeneratedGroup implements SourceGroup {
  541. private final FileObject rootFolder;
  542. private final String name;
  543. private final String displayName;
  544. private final Icon icon = null;
  545. private final Icon openedIcon = null;
  546. private NbMavenProjectImpl project;
  547. GeneratedGroup(NbMavenProjectImpl p, FileObject rootFold, String nm, String displayNm/*,
  548. Icon icn, Icon opened*/) {
  549. project = p;
  550. rootFolder = rootFold;
  551. name = nm;
  552. displayName = displayNm != null ? displayNm : SG_Root_not_defined();
  553. // icon = icn;
  554. // openedIcon = opened;
  555. }
  556. //QualitasCorpus.class: Created due to compilation errors
  557. private String SG_Root_not_defined() {
  558. // TODO Auto-generated method stub
  559. return null;
  560. }
  561. public @Override FileObject getRootFolder() {
  562. return rootFolder;
  563. }
  564. public @Override String getName() {
  565. return name;
  566. }
  567. public @Override String getDisplayName() {
  568. return displayName;
  569. }
  570. public @Override Icon getIcon(boolean opened) {
  571. return opened ? icon : openedIcon;
  572. }
  573. public @Override boolean contains(FileObject file) {
  574. if (file != rootFolder && !FileUtil.isParentOf(rootFolder, file)) {
  575. return false;
  576. }
  577. if (project != null) {
  578. if (file.isFolder() && file != project.getProjectDirectory() && ProjectManager.getDefault().isProject(file)) {
  579. // #67450: avoid actually loading the nested project.
  580. return false;
  581. }
  582. if (FileOwnerQuery.getOwner(file) != project) {
  583. return false;
  584. }
  585. }
  586. return true;
  587. }
  588. public @Override void addPropertyChangeListener(PropertyChangeListener l) {
  589. // XXX should react to ProjectInformation changes
  590. }
  591. public @Override void removePropertyChangeListener(PropertyChangeListener l) {
  592. // XXX
  593. }
  594. }
  595. }