private String resolveVersion(String modelVersion, Model mavenModel, boolean dependency) {
    String version = modelVersion;

    // TODO: download parents and resolve pom.xml properties using aether ? could be pretty
    // expensive for
    // the init
    if (version == null) {
      if (!dependency) {
        Parent parent = mavenModel.getParent();

        if (parent != null) {
          version = parent.getVersion();
        }
      }
    } else if (version.startsWith("$")) {
      String propertyName = version.substring(2, version.length() - 1);

      if (propertyName.equals("project.version")
          || propertyName.equals("pom.version")
          || propertyName.equals("version")) {
        version = resolveVersion(mavenModel.getVersion(), mavenModel, false);
      } else {
        String value = mavenModel.getProperties().getProperty(propertyName);
        if (value != null) {
          version = value;
        }
      }
    }

    if (version == null) {
      version = UNKNOWN;
    }

    return version;
  }
  private String resolveGroupId(String modelGroupId, Model mavenModel, boolean dependency) {
    String groupId = modelGroupId;

    // TODO: download parents and resolve pom.xml properties using aether ? could be pretty
    // expensive for
    // the init
    if (groupId == null) {
      if (!dependency) {
        Parent parent = mavenModel.getParent();

        if (parent != null) {
          groupId = parent.getGroupId();
        }
      }
    } else if (groupId.startsWith("$")) {
      String propertyName = groupId.substring(2, groupId.length() - 1);

      String value = mavenModel.getProperties().getProperty(propertyName);
      if (value != null) {
        groupId = value;
      }
    }

    if (groupId == null) {
      groupId = UNKNOWN;
    }

    return groupId;
  }
Пример #3
0
  /*
   * (non-Javadoc)
   *
   * @see org.apache.maven.plugin.Mojo#execute()
   */
  public void execute() throws MojoExecutionException, MojoFailureException {

    // VelocityTemplates.init();
    try {
      List components =
          container.lookupList("org.richfaces.templatecompiler.elements.ElementsFactory");

      for (Iterator iter = components.iterator(); iter.hasNext(); ) {
        Object element = iter.next();

        System.out.println(element.getClass().getName());
      }

      System.out.println("Components Map");

      Map componentsMap =
          container.lookupMap("org.richfaces.templatecompiler.elements.ElementsFactory");

      for (Iterator iter = componentsMap.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry element = (Map.Entry) iter.next();

        System.out.println(element.getKey() + ":" + element.getValue().getClass().getName());
      }
    } catch (ComponentLookupException e) {
      throw new MojoExecutionException("Error lookup ElementFactory components");
    }

    Parent parentModel = project.getModel().getParent();

    if (null != parentModel) {
      String relativePath = parentModel.getRelativePath();
      File parentPom = new File(project.getFile().getParentFile(), relativePath);

      if (parentPom.isDirectory()) {
        parentPom = new File(parentPom, "pom.xml");
      }

      if (parentPom.exists()) {
        try {
          parentProject = mavenProjectBuilder.build(parentPom, localRepository, null);
        } catch (ProjectBuildingException e) {
          throw new MojoExecutionException("Error get parent project for a components library", e);
        }
      } else {
        throw new MojoFailureException(
            "Parent project pom file "
                + parentPom.getAbsolutePath()
                + " is not found for a components library");
      }
    } else {
      throw new MojoFailureException(
          "Components library project must have parent pom with components modules");
    }

    getLog().info("Parent Project object :\n" + toLog(parentProject) + "\n");
    getLog().info("Project object :\n" + toLog(project) + "\n");
    getLog().info("Project object Model :\n" + toLog(project.getModel()) + "\n");
    getLog().info("Project object Parent Model :\n" + toLog(project.getModel().getParent()) + "\n");
    getLog().info("Executed Project object :\n" + toLog(executedProject) + "\n");
  }
Пример #4
0
  @Command("remove-parent")
  public void removeParent(final PipeOut out) {
    MavenCoreFacet mvn = project.getFacet(MavenCoreFacet.class);

    Model pom = mvn.getPOM();
    Parent parent = pom.getParent();

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

      if (shell.promptBoolean(
          "Are you sure you want to remove all parent information from this project? [ "
              + parentId
              + "]",
          false)) {
        out.println("Removed parent [ " + parentId + " ]");
        pom.setParent(null);
        mvn.setPOM(pom);
      } else {
        out.println("Aborted...");
      }
    } else {
      out.println("Nothing to remove...");
    }
  }
Пример #5
0
  private static ProjectVersionRef modelKey(final Model model) throws ManipulationException {
    String g = model.getGroupId();
    final String a = model.getArtifactId();
    String v = model.getVersion();

    if (g == null || v == null) {
      final Parent p = model.getParent();
      if (p == null) {
        throw new ManipulationException(
            "Invalid model: " + model + " Cannot find groupId and/or version!");
      }

      if (g == null) {
        g = p.getGroupId();
      }
      if (v == null) {
        v = p.getVersion();
      }
    }

    return new ProjectVersionRef(g, a, v);
  }
Пример #6
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 + " ]");
    }
  }
 private Coordinates extractParentCoordinates(Parent parent) {
   return new Coordinates(parent.getGroupId(), parent.getArtifactId(), parent.getVersion());
 }