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;
  }
Ejemplo n.º 3
0
  @Override
  public boolean isKModule(final Path resource) {
    try {
      // Null resource paths cannot resolve to a Project
      if (resource == null) {
        return false;
      }

      // Check if path equals kmodule.xml
      final Project project = resolveProject(resource);
      // It's possible that the Incremental Build attempts to act on a Project file before the
      // project has been fully created.
      // This should be a short-term issue that will be resolved when saving a project batches
      // pom.xml, kmodule.xml and project.imports
      // etc into a single git-batch. At present they are saved individually leading to multiple
      // Incremental Build requests.
      if (project == null) {
        return false;
      }

      final org.uberfire.java.nio.file.Path path = Paths.convert(resource).normalize();
      final org.uberfire.java.nio.file.Path kmoduleFilePath =
          Paths.convert(project.getKModuleXMLPath());
      return path.startsWith(kmoduleFilePath);

    } catch (Exception e) {
      throw ExceptionUtilities.handleException(e);
    }
  }