Exemplo n.º 1
0
  public void testProjectInheritance() throws Exception {
    File localRepo = getLocalRepositoryPath();

    System.out.println("Local repository is at: " + localRepo.getAbsolutePath());

    File pom0 = new File(localRepo, "p0/pom.xml");
    File pom1 = new File(pom0.getParentFile(), "p1/pom.xml");
    File pom2 = new File(pom1.getParentFile(), "p2/pom.xml");
    File pom3 = new File(pom2.getParentFile(), "p3/pom.xml");
    File pom4 = new File(pom3.getParentFile(), "p4/pom.xml");
    File pom5 = new File(pom4.getParentFile(), "p5/pom.xml");

    System.out.println("Location of project-4's POM: " + pom4.getPath());

    // load everything...
    MavenProject project0 = getProject(pom0);
    MavenProject project1 = getProject(pom1);
    MavenProject project2 = getProject(pom2);
    MavenProject project3 = getProject(pom3);
    MavenProject project4 = getProject(pom4);
    MavenProject project5 = getProject(pom5);

    assertEquals("p4", project4.getName());

    // ----------------------------------------------------------------------
    // Value inherited from p3
    // ----------------------------------------------------------------------

    assertEquals("2000", project4.getInceptionYear());

    // ----------------------------------------------------------------------
    // Value taken from p2
    // ----------------------------------------------------------------------

    assertEquals("mailing-list", project4.getMailingLists().get(0).getName());

    // ----------------------------------------------------------------------
    // Value taken from p1
    // ----------------------------------------------------------------------

    assertEquals("scm-url/p2/p3/p4", project4.getScm().getUrl());

    // ----------------------------------------------------------------------
    // Value taken from p4
    // ----------------------------------------------------------------------

    assertEquals("Codehaus", project4.getOrganization().getName());

    // ----------------------------------------------------------------------
    // Value taken from super model
    // ----------------------------------------------------------------------

    assertEquals("4.0.0", project4.getModelVersion());

    Build build = project4.getBuild();
    List plugins = build.getPlugins();

    Map validPluginCounts = new HashMap();

    String testPluginArtifactId = "maven-compiler-plugin";

    // this is the plugin we're looking for.
    validPluginCounts.put(testPluginArtifactId, 0);

    // these are injected if -DperformRelease=true
    validPluginCounts.put("maven-deploy-plugin", 0);
    validPluginCounts.put("maven-javadoc-plugin", 0);
    validPluginCounts.put("maven-source-plugin", 0);

    Plugin testPlugin = null;

    for (Iterator it = plugins.iterator(); it.hasNext(); ) {
      Plugin plugin = (Plugin) it.next();

      String pluginArtifactId = plugin.getArtifactId();

      if (!validPluginCounts.containsKey(pluginArtifactId)) {
        fail("Illegal plugin found: " + pluginArtifactId);
      } else {
        if (pluginArtifactId.equals(testPluginArtifactId)) {
          testPlugin = plugin;
        }

        Integer count = (Integer) validPluginCounts.get(pluginArtifactId);

        if (count.intValue() > 0) {
          fail("Multiple copies of plugin: " + pluginArtifactId + " found in POM.");
        } else {
          count = count.intValue() + 1;

          validPluginCounts.put(pluginArtifactId, count);
        }
      }
    }

    List executions = testPlugin.getExecutions();

    assertEquals(1, executions.size());
  }
  /** Create the generated part of the NOTICE file based on the resolved license data */
  protected String generateNoticeLines(
      Map<String, String> resolvedLicenses, Map<String, Artifact> resolvedArtifacts) {
    final StringBuilder builder = new StringBuilder();

    final MessageFormat messageFormat = getNoticeMessageFormat();

    for (final Map.Entry<String, String> resolvedEntry : resolvedLicenses.entrySet()) {
      final Artifact artifact = resolvedArtifacts.get(resolvedEntry.getKey());
      final MavenProject mavenProject = loadProject(artifact);
      String line = null;
      if (mavenProject != null) {
        String copyright = "";
        if (mavenProject.getOrganization() != null
            && mavenProject.getOrganization().getName() != null
            && mavenProject.getInceptionYear() != null) {
          final MessageFormat copyrightMessageFormat = getCopyrightMessageFormat();
          final Calendar calendar = Calendar.getInstance();
          copyright =
              copyrightMessageFormat.format(
                  new Object[] {
                    mavenProject.getInceptionYear(),
                    Integer.toString(calendar.get(Calendar.YEAR)),
                    mavenProject.getOrganization().getName(),
                    (mavenProject.getOrganization().getUrl() != null
                        ? "(" + mavenProject.getOrganization().getUrl() + ")"
                        : "")
                  });
        }
        line =
            messageFormat.format(
                new Object[] {
                  resolvedEntry.getKey(),
                  resolvedEntry.getValue(),
                  (mavenProject.getGroupId() != null ? mavenProject.getGroupId() : ""),
                  (mavenProject.getArtifactId() != null ? mavenProject.getArtifactId() : ""),
                  (mavenProject.getVersion() != null ? mavenProject.getVersion() : ""),
                  (mavenProject.getOrganization() != null
                      ? (mavenProject.getOrganization().getName() != null
                          ? mavenProject.getOrganization().getName()
                          : "")
                      : ""),
                  (mavenProject.getOrganization() != null
                      ? (mavenProject.getOrganization().getUrl() != null
                          ? mavenProject.getOrganization().getUrl()
                          : "")
                      : ""),
                  (copyright != null ? copyright : "")
                });
      } else {
        line =
            messageFormat.format(new Object[] {resolvedEntry.getKey(), resolvedEntry.getValue()});
      }
      builder.append(line).append(IOUtils.LINE_SEPARATOR);
    }

    return builder.toString();
  }