public static File getSdk(
      MavenProject project,
      RepositorySystem repoSystem,
      RepositorySystemSession repoSession,
      List<RemoteRepository>... repos)
      throws MojoExecutionException {
    Artifact artifact =
        (Artifact)
            find(
                project.getPluginArtifacts(),
                new Predicate<Artifact>() {
                  @Override
                  public boolean apply(Artifact artifact1) {
                    return artifact1.getArtifactId().equals("gcloud-maven-plugin");
                  }
                });

    String version = artifact.getVersion();

    if (version.endsWith("-SNAPSHOT")) {
      String newestVersion = determineNewestVersion(repoSystem, repoSession, repos);
      return getSdk(newestVersion, repoSystem, repoSession, repos);
    }

    return getSdk("1.9.30", repoSystem, repoSession, repos);
  }
示例#2
0
  public void execute() throws MojoExecutionException, MojoFailureException {
    // http://issues.appfuse.org/browse/APF-1025
    System.setProperty("file.encoding", "UTF-8");

    // If appfuse.version is specified as a property, and not a SNAPSHOT, use it for the tag
    String appfuseVersion = project.getProperties().getProperty("appfuse.version");

    if ((appfuseVersion != null) && !appfuseVersion.endsWith("SNAPSHOT") && tag.equals("trunk/")) {
      tag = "tags/APPFUSE_" + appfuseVersion.toUpperCase().replaceAll("-", "_") + "/";
      // APF-1168: Allow milestone and release candidates
      if (tag.contains("_M")) {
        tag = tag.replace("_M", "-M");
      } else if (tag.contains("_R")) {
        tag = tag.replace("_R", "-R");
      }
    }

    String daoFramework = project.getProperties().getProperty("dao.framework");

    if (daoFramework == null) {
      log("No dao.framework property specified, defaulting to 'hibernate'");
    }

    String webFramework = project.getProperties().getProperty("web.framework");

    boolean modular = (project.getPackaging().equals("pom") && !project.hasParent());
    if (project.getPackaging().equals("jar")
        || (project.getPackaging().equals("war") && !project.hasParent())) {
      // export data-common
      log("Installing source from data-common module...");
      export("data/common/src", (modular) ? "core/src" : destinationDirectory);

      // export persistence framework
      log("Installing source from " + daoFramework + " module...");
      export("data/" + daoFramework + "/src", (modular) ? "core/src" : destinationDirectory);

      // export service module
      log("Installing source from service module...");
      export("service/src", (modular) ? "core/src" : destinationDirectory);

      // move Base*TestCase to test directory
      moveFiles(
          (modular) ? "core/src/main" : destinationDirectory + "/main",
          (modular) ? "core/src/test" : destinationDirectory + "/test",
          "**/Base*TestCase.java");

      // delete dao.framework related files from test directory
      deleteFile("test/resources/hibernate.cfg.xml");
      deleteFile("test/resources/META-INF");
      deleteFile("test/resources/sql-map-config.xml");

      // If JPA, delete hibernate.cfg.xml b/c it will cause issues when
      // using jpaconfiguration with the hibernate3-maven-plugin
      if ("jpa".equalsIgnoreCase(daoFramework)) {
        deleteFile("main/resources/hibernate.cfg.xml");
      }
    }

    // it's OK if a project created with appfuse-ws doesn't have a web framework defined
    // currently, a project with appfuse-ws can be identified by enunciate
    boolean isWebServicesProject = false;
    for (Object pluginArtifact : project.getPluginArtifacts()) {
      if (((Artifact) pluginArtifact).getArtifactId().contains("enunciate")) {
        isWebServicesProject = true;
        break;
      }
    }

    if (project.getPackaging().equalsIgnoreCase("war")) {

      if (webFramework == null && !isWebServicesProject) {
        getLog()
            .error(
                "The web.framework property is not specified - please modify your pom.xml to add "
                    + " this property. For example: <web.framework>struts</web.framework>.");
        throw new MojoExecutionException(
            "No web.framework property specified, please modify pom.xml to add it.");
      }

      if (project.hasParent()) {
        // copy jdbc.properties to core/src/test/resources
        // FileUtils.copyFileToDirectory(new File("src/main/resources/jdbc.properties"), new
        // File("../core/src/test/resources"));

        // delete hibernate, ibatis and jpa files from web project
        deleteFile("main/resources/hibernate.cfg.xml");
        deleteFile("main/resources/META-INF");
        deleteFile("main/resources/sql-map-config.xml");

        // there's a jdbc.properties in test/resources that shouldn't be there
        deleteFile("test/resources/jdbc.properties");
      } else if (!isAppFuse()) {
        // there's a jdbc.properties in test/resources that shouldn't be there
        deleteFile("test/resources/jdbc.properties");
      }
    }

    log("Source successfully exported, modifying pom.xml...");

    List dependencies = project.getOriginalModel().getDependencies();
    List<Dependency> newDependencies = new ArrayList<Dependency>();

    // remove all appfuse dependencies
    for (Object dependency : dependencies) {
      Dependency dep = (Dependency) dependency;

      if (!dep.getGroupId().equals(APPFUSE_GROUP_ID)) {
        newDependencies.add(dep);
      }
    }

    if (!project.getPackaging().equals("pom") && !project.hasParent()) {

      // add dependencies from root appfuse pom
      newDependencies = addModuleDependencies(newDependencies, "root", "");

      // Add dependencies from appfuse-data
      newDependencies = addModuleDependencies(newDependencies, "data", "data");

      // Add dependencies from appfuse-data-common
      newDependencies = addModuleDependencies(newDependencies, "data-common", "data/common");

      // Add dependencies from appfuse-${dao.framework}
      newDependencies =
          addModuleDependencies(newDependencies, daoFramework, "data/" + daoFramework);

      // Add dependencies from appfuse-service
      newDependencies = addModuleDependencies(newDependencies, "service", "service");

      if (!isWebServicesProject && project.getPackaging().equals("war")) {
        newDependencies = addWebDependencies(appfuseVersion, newDependencies, webFramework);
      }

      createFullSourcePom(newDependencies);
    } else {
      if (project.getPackaging().equals("pom")) {
        // add dependencies from root appfuse pom
        newDependencies = addModuleDependencies(newDependencies, "root", "");

        createFullSourcePom(newDependencies);
      }

      if (project.getPackaging().equals("jar")) {
        newDependencies.clear();

        // Add dependencies from appfuse-data
        newDependencies = addModuleDependencies(newDependencies, "data", "data");

        // Add dependencies from appfuse-data-common
        newDependencies = addModuleDependencies(newDependencies, "data-common", "data/common");

        // Add dependencies from appfuse-${dao.framework}
        newDependencies =
            addModuleDependencies(newDependencies, daoFramework, "data/" + daoFramework);

        // Add dependencies from appfuse-service
        newDependencies = addModuleDependencies(newDependencies, "service", "service");

        createFullSourcePom(newDependencies);
      }

      if (project.getPackaging().equals("war")) {
        newDependencies.clear();

        newDependencies = addWebDependencies(appfuseVersion, newDependencies, webFramework);

        createFullSourcePom(newDependencies);
      }
    }
  }