Beispiel #1
0
 private MavenProject getTestSuite(String symbolicName) {
   for (MavenProject otherProject : session.getProjects()) {
     TychoProject projectType = projectTypes.get(otherProject.getPackaging());
     if (projectType != null
         && projectType
             .getArtifactKey(DefaultReactorProject.adapt(otherProject))
             .getId()
             .equals(symbolicName)) {
       return otherProject;
     }
   }
   return null;
 }
Beispiel #2
0
  public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip || skipExec) {
      getLog().info("Skipping tests");
      return;
    }

    if (!"eclipse-test-plugin".equals(project.getPackaging())) {
      getLog().warn("Unsupported packaging type " + project.getPackaging());
      return;
    }

    if (testSuite != null || testClass != null) {
      if (testSuite == null || testClass == null) {
        throw new MojoExecutionException(
            "Both testSuite and testClass must be provided or both should be null");
      }

      MavenProject suite = getTestSuite(testSuite);

      if (suite == null) {
        throw new MojoExecutionException(
            "Cannot find test suite project with Bundle-SymbolicName " + testSuite);
      }

      if (!suite.equals(project)) {
        getLog()
            .info(
                "Not executing tests, testSuite="
                    + testSuite
                    + " and project is not the testSuite");
        return;
      }
    }

    EquinoxInstallation testRuntime =
        createEclipseInstallation(false, DefaultReactorProject.adapt(session));

    String testBundle = null;
    boolean succeeded = runTest(testRuntime, testBundle);

    if (succeeded) {
      getLog().info("All tests passed!");
    } else {
      throw new MojoFailureException(
          "There are test failures.\n\nPlease refer to "
              + reportsDirectory
              + " for the individual test results.");
    }
  }
Beispiel #3
0
  private void createDevProperties(
      boolean includeReactorProjects, List<ReactorProject> reactorProjects)
      throws MojoExecutionException {
    Properties dev = new Properties();

    if (includeReactorProjects) {
      // this is needed for IDE integration, where we want to use reactor project output folders
      dev.put("@ignoredot@", "true");
      for (ReactorProject otherProject : reactorProjects) {
        if ("eclipse-test-plugin".equals(otherProject.getPackaging())
            || "eclipse-plugin".equals(otherProject.getPackaging())) {
          TychoProject projectType = projectTypes.get(otherProject.getPackaging());
          dev.put(
              projectType.getArtifactKey(otherProject).getId(),
              getBuildOutputDirectories(otherProject));
        }
      }
    }

    ReactorProject reactorProject = DefaultReactorProject.adapt(project);

    TychoProject projectType = projectTypes.get(project.getPackaging());
    dev.put(
        projectType.getArtifactKey(reactorProject).getId(),
        getBuildOutputDirectories(reactorProject));

    try {
      OutputStream os = new BufferedOutputStream(new FileOutputStream(devProperties));
      try {
        dev.store(os, null);
      } finally {
        os.close();
      }
    } catch (IOException e) {
      throw new MojoExecutionException("Can't create osgi dev properties file", e);
    }
  }
Beispiel #4
0
  private EquinoxInstallation createEclipseInstallation(
      boolean includeReactorProjects, List<ReactorProject> reactorProjects)
      throws MojoExecutionException {
    TargetPlatformResolver platformResolver =
        targetPlatformResolverLocator.lookupPlatformResolver(project);

    ArrayList<Dependency> dependencies = new ArrayList<Dependency>();

    if (this.dependencies != null) {
      dependencies.addAll(Arrays.asList(this.dependencies));
    }

    dependencies.addAll(getTestDependencies());

    TargetPlatform testTargetPlatform =
        platformResolver.resolvePlatform(session, project, reactorProjects, dependencies);

    if (testTargetPlatform == null) {
      throw new MojoExecutionException(
          "Cannot determinate build target platform location -- not executing tests");
    }

    work.mkdirs();

    EquinoxInstallationDescription testRuntime = new DefaultEquinoxInstallationDescription();
    testRuntime.addBundlesToExplode(getBundlesToExplode());
    testRuntime.addFrameworkExtensions(getFrameworkExtensions());
    if (bundleStartLevel != null) {
      for (BundleStartLevel level : bundleStartLevel) {
        testRuntime.addBundleStartLevel(level);
      }
    }

    BundleProject projectType = (BundleProject) projectTypes.get(project.getPackaging());
    String testFramework = new TestFramework().getTestFramework(projectType.getClasspath(project));
    if (testFramework == null) {
      throw new MojoExecutionException(
          "Could not determine test framework used by test bundle " + project.toString());
    }
    getLog().debug("Using test framework " + testFramework);

    for (ArtifactDescriptor artifact :
        testTargetPlatform.getArtifacts(ArtifactKey.TYPE_ECLIPSE_PLUGIN)) {
      // note that this project is added as directory structure rooted at project basedir.
      // project classes and test-classes are added via dev.properties file (see
      // #createDevProperties())
      // all other projects are added as bundle jars.
      ReactorProject otherProject = artifact.getMavenProject();
      if (otherProject != null) {
        if (otherProject.sameProject(project)) {
          testRuntime.addBundle(artifact.getKey(), project.getBasedir());
          continue;
        }
        File file = otherProject.getArtifact();
        if (file != null) {
          testRuntime.addBundle(artifact.getKey(), file);
          continue;
        }
      }
      testRuntime.addBundle(artifact);
    }

    Set<File> surefireBundles = getSurefirePlugins(testFramework);
    for (File file : surefireBundles) {
      testRuntime.addBundle(getBundleArtifacyKey(file), file, true);
    }

    createDevProperties(includeReactorProjects, reactorProjects);
    createSurefireProperties(
        projectType.getArtifactKey(DefaultReactorProject.adapt(project)).getId(), testFramework);

    reportsDirectory.mkdirs();
    return installationFactory.createInstallation(testRuntime, work);
  }