Ejemplo n.º 1
0
  private String getPackagePathSuffix(
      final org.uberfire.java.nio.file.Path nioProjectRootPath,
      final org.uberfire.java.nio.file.Path nioPackagePath) {
    final org.uberfire.java.nio.file.Path nioMainSrcPath =
        nioProjectRootPath.resolve(MAIN_SRC_PATH);
    final org.uberfire.java.nio.file.Path nioTestSrcPath =
        nioProjectRootPath.resolve(TEST_SRC_PATH);
    final org.uberfire.java.nio.file.Path nioMainResourcesPath =
        nioProjectRootPath.resolve(MAIN_RESOURCES_PATH);
    final org.uberfire.java.nio.file.Path nioTestResourcesPath =
        nioProjectRootPath.resolve(TEST_RESOURCES_PATH);

    String packageName = null;
    org.uberfire.java.nio.file.Path packagePath = null;
    if (nioPackagePath.startsWith(nioMainSrcPath)) {
      packagePath = nioMainSrcPath.relativize(nioPackagePath);
      packageName = packagePath.toString();
    } else if (nioPackagePath.startsWith(nioTestSrcPath)) {
      packagePath = nioTestSrcPath.relativize(nioPackagePath);
      packageName = packagePath.toString();
    } else if (nioPackagePath.startsWith(nioMainResourcesPath)) {
      packagePath = nioMainResourcesPath.relativize(nioPackagePath);
      packageName = packagePath.toString();
    } else if (nioPackagePath.startsWith(nioTestResourcesPath)) {
      packagePath = nioTestResourcesPath.relativize(nioPackagePath);
      packageName = packagePath.toString();
    }

    return packageName;
  }
Ejemplo n.º 2
0
  private Package makePackage(final Project project, final Path resource) {
    final Path projectRoot = project.getRootPath();
    final org.uberfire.java.nio.file.Path nioProjectRoot = Paths.convert(projectRoot);
    final org.uberfire.java.nio.file.Path nioMainSrcPath = nioProjectRoot.resolve(MAIN_SRC_PATH);
    final org.uberfire.java.nio.file.Path nioTestSrcPath = nioProjectRoot.resolve(TEST_SRC_PATH);
    final org.uberfire.java.nio.file.Path nioMainResourcesPath =
        nioProjectRoot.resolve(MAIN_RESOURCES_PATH);
    final org.uberfire.java.nio.file.Path nioTestResourcesPath =
        nioProjectRoot.resolve(TEST_RESOURCES_PATH);

    org.uberfire.java.nio.file.Path nioResource = Paths.convert(resource);

    if (Files.isRegularFile(nioResource)) {
      nioResource = nioResource.getParent();
    }

    String packageName = null;
    org.uberfire.java.nio.file.Path packagePath = null;
    if (nioResource.startsWith(nioMainSrcPath)) {
      packagePath = nioMainSrcPath.relativize(nioResource);
      packageName = packagePath.toString().replaceAll("/", ".");
    } else if (nioResource.startsWith(nioTestSrcPath)) {
      packagePath = nioTestSrcPath.relativize(nioResource);
      packageName = packagePath.toString().replaceAll("/", ".");
    } else if (nioResource.startsWith(nioMainResourcesPath)) {
      packagePath = nioMainResourcesPath.relativize(nioResource);
      packageName = packagePath.toString().replaceAll("/", ".");
    } else if (nioResource.startsWith(nioTestResourcesPath)) {
      packagePath = nioTestResourcesPath.relativize(nioResource);
      packageName = packagePath.toString().replaceAll("/", ".");
    }

    // Resource was not inside a package
    if (packageName == null) {
      return null;
    }

    final Path mainSrcPath = Paths.convert(nioMainSrcPath.resolve(packagePath));
    final Path testSrcPath = Paths.convert(nioTestSrcPath.resolve(packagePath));
    final Path mainResourcesPath = Paths.convert(nioMainResourcesPath.resolve(packagePath));
    final Path testResourcesPath = Paths.convert(nioTestResourcesPath.resolve(packagePath));

    final String displayName = getPackageDisplayName(packageName);

    final Package pkg =
        new Package(
            project.getRootPath(),
            mainSrcPath,
            testSrcPath,
            mainResourcesPath,
            testResourcesPath,
            packageName,
            displayName,
            getPackageRelativeCaption(displayName, resource.getFileName()));
    return pkg;
  }
  private List<String> loadWorkItemImages(final Path resourcePath) {
    final Path projectRoot = projectService.resolveProject(resourcePath).getRootPath();
    final org.uberfire.java.nio.file.Path nioProjectPath = Paths.convert(projectRoot);
    final org.uberfire.java.nio.file.Path nioResourceParent =
        Paths.convert(resourcePath).getParent();

    final Collection<org.uberfire.java.nio.file.Path> imagePaths =
        fileDiscoveryService.discoverFiles(nioProjectPath, imageFilter, true);
    final List<String> images = new ArrayList<String>();
    for (org.uberfire.java.nio.file.Path imagePath : imagePaths) {
      final org.uberfire.java.nio.file.Path relativePath = nioResourceParent.relativize(imagePath);
      images.add(relativePath.toString());
    }
    return images;
  }