예제 #1
0
  @Override
  public Package resolveParentPackage(final Package pkg) {
    final Set<String> packageNames = new HashSet<String>();

    final org.uberfire.java.nio.file.Path nioProjectRootPath =
        Paths.convert(pkg.getProjectRootPath());
    packageNames.addAll(
        getPackageNames(
            nioProjectRootPath,
            Paths.convert(pkg.getPackageMainSrcPath()).getParent(),
            true,
            false,
            false));

    // Construct Package objects for each package name
    for (String packagePathSuffix : packageNames) {
      for (String src : sourcePaths) {
        if (packagePathSuffix == null) {
          return null;
        }
        final org.uberfire.java.nio.file.Path nioPackagePath =
            nioProjectRootPath.resolve(src).resolve(packagePathSuffix);
        if (Files.exists(nioPackagePath)) {
          return resolvePackage(Paths.convert(nioPackagePath));
        }
      }
    }

    return null;
  }
예제 #2
0
  @Override
  public Set<Package> resolvePackages(final Package pkg) {
    final Set<Package> packages = new HashSet<Package>();
    final Set<String> packageNames = new HashSet<String>();
    if (pkg == null) {
      return packages;
    }

    // Build a set of all package names across /src/main/java, /src/main/resources, /src/test/java
    // and /src/test/resources paths
    // It is possible (if the project was not created within the workbench that some packages only
    // exist in certain paths)

    final Path projectRoot = pkg.getProjectRootPath();
    final org.uberfire.java.nio.file.Path nioProjectRootPath = Paths.convert(projectRoot);

    for (String src : sourcePaths) {
      final org.uberfire.java.nio.file.Path nioPackageRootSrcPath =
          nioProjectRootPath.resolve(src).resolve(resolvePkgName(pkg.getCaption()));
      packageNames.addAll(
          getPackageNames(nioProjectRootPath, nioPackageRootSrcPath, false, true, false));
    }

    // Construct Package objects for each package name
    final java.util.Set<String> resolvedPackages = new java.util.HashSet<String>();
    for (String packagePathSuffix : packageNames) {
      for (String src : sourcePaths) {
        final org.uberfire.java.nio.file.Path nioPackagePath =
            nioProjectRootPath.resolve(src).resolve(packagePathSuffix);
        if (Files.exists(nioPackagePath) && !resolvedPackages.contains(packagePathSuffix)) {
          packages.add(resolvePackage(Paths.convert(nioPackagePath)));
          resolvedPackages.add(packagePathSuffix);
        }
      }
    }

    return packages;
  }