/**
   * Utility method that locates a project producing the given artifact.
   *
   * @param artifact the artifact a project should produce.
   * @return <code>true</code> if the artifact is produced by a reactor projectart.
   */
  protected boolean isAvailableAsAReactorProject(Artifact artifact) {
    if (this.reactorProjects != null
        && (Constants.PROJECT_PACKAGING_JAR.equals(artifact.getType())
            || Constants.PROJECT_PACKAGING_EJB.equals(artifact.getType())
            || Constants.PROJECT_PACKAGING_WAR.equals(artifact.getType()))) {
      for (Object reactorProject1 : this.reactorProjects) {
        MavenProject reactorProject = (MavenProject) reactorProject1;

        if (reactorProject.getGroupId().equals(artifact.getGroupId())
            && reactorProject.getArtifactId().equals(artifact.getArtifactId())) {
          if (reactorProject.getVersion().equals(artifact.getVersion())) {
            return true;
          } else {
            getLog()
                .info(
                    "Artifact "
                        + artifact.getId()
                        + " already available as a reactor project, but with different version. "
                        + "Expected: "
                        + artifact.getVersion()
                        + ", found: "
                        + reactorProject.getVersion());
          }
        }
      }
    }
    return false;
  }
  /**
   * overwite the default builders with the builders required by RAD6.
   *
   * @param packaging packaging-type (jar,war,ejb,ear)
   */
  protected void fillDefaultBuilders(String packaging) {
    super.fillDefaultBuilders(packaging);

    ArrayList buildcommands = new ArrayList();
    if (Constants.PROJECT_PACKAGING_EAR.equals(packaging)) {
      buildcommands.add(COM_IBM_ETOOLS_VALIDATION_VALIDATIONBUILDER);
      buildcommands.add(COM_IBM_SSE_MODEL_STRUCTUREDBUILDER);
    } else if (Constants.PROJECT_PACKAGING_WAR.equals(packaging)) {
      buildcommands.add(COM_IBM_WTP_MIGRATION_MIGRATION_BUILDER);
      buildcommands.add(ORG_ECLIPSE_JDT_CORE_JAVABUILDER);
      buildcommands.add(COM_IBM_ETOOLS_J2EE_UI_LIB_DIR_BUILDER);
      buildcommands.add(COM_IBM_ETOOLS_WEBTOOLS_ADDITIONS_LINKSBUILDER);
      buildcommands.add(COM_IBM_ETOOLS_WEBPAGE_TEMPLATE_TEMPLATEBUILDER);
      buildcommands.add(COM_IBM_ETOOLS_SITEEDIT_SITE_NAV_BUILDER);
      buildcommands.add(COM_IBM_ETOOLS_SITEEDIT_SITE_UPDATE_BUILDER);
      buildcommands.add(COM_IBM_ETOOLS_VALIDATION_VALIDATIONBUILDER);
      buildcommands.add(COM_IBM_WTP_J2EE_LIB_COPY_BUILDER);
      buildcommands.add(COM_IBM_ETOOLS_WEBTOOLS_ADDITIONS_JSPCOMPILATIONBUILDER);
      buildcommands.add(COM_IBM_SSE_MODEL_STRUCTUREDBUILDER);
    } else if (Constants.PROJECT_PACKAGING_EJB.equals(packaging)) {
      buildcommands.add(ORG_ECLIPSE_JDT_CORE_JAVABUILDER);
      buildcommands.add(COM_IBM_ETOOLS_VALIDATION_VALIDATIONBUILDER);
      buildcommands.add(COM_IBM_WTP_J2EE_LIB_COPY_BUILDER);
      buildcommands.add(COM_IBM_SSE_MODEL_STRUCTUREDBUILDER);
    } else if (isJavaProject()) {
      buildcommands.add(ORG_ECLIPSE_JDT_CORE_JAVABUILDER);
      buildcommands.add(COM_IBM_SSE_MODEL_STRUCTUREDBUILDER);
    }
    setBuildcommands(buildcommands);
  }
  /**
   * make room for a Manifest file. use a generated resource for JARS and for WARS use the manifest
   * in the webapp/meta-inf directory.
   *
   * @throws MojoExecutionException
   */
  private void addManifestResource(EclipseWriterConfig config) throws MojoExecutionException {
    if (isJavaProject()) {
      // special case must be done first because it can add stuff to the classpath that will be
      // written by the superclass
      new RadManifestWriter().init(getLog(), config).write();
    }

    if (isJavaProject()
        && !Constants.PROJECT_PACKAGING_EAR.equals(packaging)
        && !Constants.PROJECT_PACKAGING_WAR.equals(packaging)
        && !Constants.PROJECT_PACKAGING_EJB.equals(packaging)
        && !NO_GENERATED_RESOURCE_DIRNAME.equals(this.generatedResourceDirName)) {

      String generatedResourceDir =
          this.project.getBasedir().getAbsolutePath()
              + File.separatorChar
              + this.generatedResourceDirName;

      String metainfDir = generatedResourceDir + File.separatorChar + "META-INF";

      new File(metainfDir).mkdirs();

      final Resource resource = new Resource();

      getLog().debug("Adding " + this.generatedResourceDirName + " to resources");

      resource.setDirectory(generatedResourceDir);

      this.executedProject.addResource(resource);
    }

    if (Constants.PROJECT_PACKAGING_WAR.equals(packaging)) {
      new File(getWebContentBaseDirectory(config) + File.separatorChar + "META-INF").mkdirs();
    }
  }
  /**
   * overwite the default natures with the natures required by RAD6.
   *
   * @param packaging packaging-type (jar,war,ejb,ear)
   */
  protected void fillDefaultNatures(String packaging) {
    super.fillDefaultNatures(packaging);

    ArrayList projectnatures = new ArrayList();
    if (Constants.PROJECT_PACKAGING_EAR.equals(packaging)) {
      projectnatures.add(COM_IBM_WTP_J2EE_EARNATURE);
    } else if (Constants.PROJECT_PACKAGING_WAR.equals(packaging)) {
      projectnatures.add(COM_IBM_WTP_WEB_WEB_NATURE);
      projectnatures.add(ORG_ECLIPSE_JDT_CORE_JAVANATURE);
      projectnatures.add(COM_IBM_ETOOLS_SITEEDIT_WEB_SITE_NATURE);
      projectnatures.add(COM_IBM_ETOOLS_WEBPAGE_TEMPLATE_TEMPLATENATURE);
    } else if (Constants.PROJECT_PACKAGING_EJB.equals(packaging)) {
      projectnatures.add(COM_IBM_WTP_EJB_EJBNATURE);
      projectnatures.add(ORG_ECLIPSE_JDT_CORE_JAVANATURE);
    } else if (isJavaProject()) {
      projectnatures.add(ORG_ECLIPSE_JDT_CORE_JAVANATURE);
    }
    setProjectnatures(projectnatures);
  }