Пример #1
0
 @Test
 public void testCreateTopLevelPackage() throws Exception {
   initializeJavaProject();
   DirectoryResource root = getProject().getProjectRoot();
   Resource<?> srcMainJavaDirectory = root.getChild("/src/main/java");
   assertNotNull(srcMainJavaDirectory.reify(DirectoryResource.class));
   Resource<?> testDirectory = srcMainJavaDirectory.getChild("com/test");
   assertNotNull(testDirectory.reify(DirectoryResource.class));
 }
Пример #2
0
  @Override
  public Resource<?> getCurrentResource() {
    Resource<?> result = this.projectContext.getCurrentResource();
    if (result == null) {
      result = this.resourceFactory.getResourceFrom(Files.getWorkingDirectory());
      environment.setProperty("CWD", result.getFullyQualifiedName());
    }

    return result;
  }
Пример #3
0
  @Override
  public Resource<?> getChild(String name) {
    List<Resource<?>> chidren = listResources();

    for (Resource<?> child : chidren) {
      if (child.getName().trim().equals(name)) return child;
    }

    return null;
  }
Пример #4
0
 @Override
 public List<String> getWebPaths(final Resource<?> r) {
   if (r != null) {
     WebResourceFacet web = project.getFacet(WebResourceFacet.class);
     List<DirectoryResource> webRootDirectories = web.getWebRootDirectories();
     for (DirectoryResource d : webRootDirectories) {
       if (r.getFullyQualifiedName().startsWith(d.getFullyQualifiedName())) {
         String path = r.getFullyQualifiedName().substring(d.getFullyQualifiedName().length());
         return getWebPaths(path);
       }
     }
   }
   return new ArrayList<String>();
 }
  @Command(value = "new-element", help = "Create a new WebElement in the current class")
  public void newElement(
      @Option(required = true, name = "named", help = "the element name") String name,
      @Option(required = true, name = "findby", help = "the locator name") FindByType findBy,
      @Option(required = true, name = "value", help = "the locator value") String value,
      @Option(required = false, name = "fragmentClass", help = "the Page Fragment class")
          Resource<?> fragmentClass,
      final PipeOut out)
      throws Exception {
    final JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);

    JavaClass javaClass = getJavaClass();

    if (javaClass.hasField(name)) {
      throw new IllegalStateException("Class already has a field named [" + name + "]");
    }

    Field<JavaClass> field = javaClass.addField();
    field.setName(name).setPrivate();
    if (fragmentClass != null) {

      JavaClass javaFragment =
          JavaParser.parse(JavaClass.class, fragmentClass.getResourceInputStream());
      if (javaFragment == null) {
        throw new IllegalStateException(
            "Class notfound in test resources [" + fragmentClass.getFullyQualifiedName() + "]");
      }
      field.setType(javaFragment.getQualifiedName());
    } else {
      field.setType("org.openqa.selenium.WebElement");
    }
    Annotation<JavaClass> annotation =
        field.addAnnotation("org.jboss.arquillian.graphene.enricher.findby.FindBy");
    annotation.setStringValue(findBy.name(), value);
    javaClass
        .addMethod()
        .setReturnType(field.getTypeInspector().toString())
        .setName("get" + Strings.capitalize(name))
        .setPublic()
        .setBody("return this." + name + ";");

    java.saveTestJavaSource(javaClass);

    shell.println("Created element  [" + field.getName() + "]");
  }
Пример #6
0
  @Override
  public List<String> getWebPaths(Resource<?> r) {
    List<String> results = new ArrayList<String>();

    if (r != null) {
      WebResourceFacet web = project.getFacet(WebResourceFacet.class);
      List<DirectoryResource> webRootDirectories = web.getWebRootDirectories();
      for (DirectoryResource d : webRootDirectories) {
        if (r.getFullyQualifiedName().startsWith(d.getFullyQualifiedName())) {
          String path = r.getFullyQualifiedName().substring(d.getFullyQualifiedName().length());

          for (String p : getWebPaths(path)) {
            if (!results.contains(p)) results.add(p);
          }
          break;
        }
      }
    }
    return results;
  }
Пример #7
0
  @Override
  public Resource<?> getResourceForWebPath(String path) {
    if (path != null) {
      WebResourceFacet web = project.getFacet(WebResourceFacet.class);
      List<DirectoryResource> webRootDirectories = web.getWebRootDirectories();

      boolean matches = false;
      for (String mapping : getEffectiveFacesServletMappings()) {
        Matcher matcher = ServletUtil.mappingToRegex(mapping).matcher(path);
        if (matcher.matches()) {
          path = matcher.group(1);
          matches = true;
          break;
        }
      }

      while (path.startsWith("/")) {
        path = path.substring(1);
      }

      if (!matches) {
        return null;
      }

      List<String> strings = Arrays.asList(path.split("/"));
      for (DirectoryResource d : webRootDirectories) {
        Queue<String> queue = new LinkedList<String>();
        queue.addAll(strings);

        Resource<?> temp = d;
        while (queue.size() > 1) {
          Resource<?> child = temp.getChild(queue.remove());
          if ((child != null) && child.exists()) {
            temp = child;
          } else {
            break;
          }

          if (queue.isEmpty()) {
            return child;
          }
        }

        if (temp != null) {
          String name = queue.remove();
          for (String suffix : getFacesSuffixes()) {
            Resource<?> child = null;
            if (name.endsWith(suffix)) {
              child = temp.getChild(name);
            } else {
              child = temp.getChild(name + suffix);
            }
            if ((child != null) && child.exists()) {
              return child;
            }
          }
        }
      }
    }
    return null;
  }
Пример #8
0
  @Command("set-parent")
  public void setParent(
      @Option(
              name = "parentId",
              description =
                  "dependency identifier of parent, ex: \"org.jboss.forge:forge-parent:1.0.0\"",
              required = false)
          final Dependency gav,
      @Option(
              name = "parentRelativePath",
              description =
                  "relative location from the current project to the parent project root folder",
              type = PromptType.FILE_PATH,
              required = false)
          final String relativePath,
      @Option(
              name = "parentProjectRoot",
              description = "absolute location of a project to use as this project's direct parent",
              required = false)
          final Resource<?> path,
      final PipeOut out) {
    MavenCoreFacet mvn = project.getFacet(MavenCoreFacet.class);
    Parent parent = null;
    if (gav != null) {
      Assert.notNull(
          gav.getArtifactId(), "ArtifactId must not be null [" + gav.toCoordinates() + "]");
      Assert.notNull(gav.getGroupId(), "GroupId must not be null [" + gav.toCoordinates() + "]");
      Assert.notNull(gav.getVersion(), "Version must not be null [" + gav.toCoordinates() + "]");

      parent = new Parent();
      parent.setArtifactId(gav.getArtifactId());
      parent.setGroupId(gav.getGroupId());
      parent.setVersion(gav.getVersion());

      if (relativePath != null) {
        parent.setRelativePath(relativePath);
      }

      Model pom = mvn.getPOM();
      pom.setParent(parent);
      mvn.setPOM(pom);
    } else if ((path != null) && factory.containsProject(path.reify(DirectoryResource.class))) {
      Project parentProject = factory.findProject(path.reify(DirectoryResource.class));
      MavenCoreFacet parentCore = parentProject.getFacet(MavenCoreFacet.class);

      parent = new Parent();
      parent.setArtifactId(parentCore.getMavenProject().getArtifactId());
      parent.setGroupId(parentCore.getMavenProject().getGroupId());
      parent.setVersion(parentCore.getMavenProject().getVersion());

      if (relativePath != null) {
        parent.setRelativePath(relativePath);
      }

      Model pom = mvn.getPOM();
      pom.setParent(parent);
      mvn.setPOM(pom);
    } else if (relativePath != null) {
      PathspecParser parser =
          new PathspecParser(resources, shell.getCurrentProject().getProjectRoot(), relativePath);
      List<Resource<?>> resolvedResources = parser.resolve();
      if (!resolvedResources.isEmpty()
          && factory.containsProject(resolvedResources.get(0).reify(DirectoryResource.class))) {
        Project parentProject =
            factory.findProject(resolvedResources.get(0).reify(DirectoryResource.class));
        MavenCoreFacet parentCore = parentProject.getFacet(MavenCoreFacet.class);

        parent = new Parent();
        parent.setArtifactId(parentCore.getMavenProject().getArtifactId());
        parent.setGroupId(parentCore.getMavenProject().getGroupId());
        parent.setVersion(parentCore.getMavenProject().getVersion());
        parent.setRelativePath(relativePath);

        Model pom = mvn.getPOM();
        pom.setParent(parent);
        mvn.setPOM(pom);
      } else {
        out.print(ShellColor.RED, "***ERROR***");
        out.println(" relative path did not resolve to a Project [" + relativePath + "]");
      }
    } else {
      out.print(ShellColor.RED, "***ERROR***");
      out.println(" you must specify a path to or dependency id of the parent project.");
    }

    if (parent != null) {
      String parentId =
          parent.getGroupId()
              + ":"
              + parent.getArtifactId()
              + ":"
              + parent.getVersion()
              + " ("
              + (parent.getRelativePath() == null ? " " : parent.getRelativePath() + ")");

      out.println("Set parent [ " + parentId + " ]");
    }
  }
Пример #9
0
 @Override
 public void setCurrentResource(final Resource<?> resource) {
   lastResource = getCurrentResource();
   projectContext.setCurrentResource(resource);
   environment.setProperty("CWD", resource.getFullyQualifiedName());
 }