Esempio n. 1
0
  private String getBuildOutputDirectories(ReactorProject otherProject) {
    StringBuilder sb = new StringBuilder();

    sb.append(otherProject.getOutputDirectory());
    sb.append(',').append(otherProject.getTestOutputDirectory());

    Properties buildProperties = new Properties();
    File file = new File(otherProject.getBasedir(), "build.properties");
    try {
      FileInputStream is = new FileInputStream(file);
      try {
        buildProperties.load(is);
      } finally {
        is.close();
      }

      // TODO plugin package mojo has this same logic, move to a helper
      final String OUTPUT = "output.";
      final String SOURCE = "source.";

      for (Iterator<Object> iterator = buildProperties.keySet().iterator(); iterator.hasNext(); ) {
        String key = (String) iterator.next();
        String[] classesDir = null;
        if (key.startsWith(OUTPUT) && !key.equals("output..")) {
          classesDir = buildProperties.getProperty(key).split(",");
        } else if (key.startsWith(SOURCE) && !key.equals("source..")) {
          String fileName = key.substring(SOURCE.length());
          classesDir =
              new String[] {
                otherProject.getBuildDirectory().getName()
                    + "/"
                    + fileName.substring(0, fileName.length() - 4)
                    + "-classes"
              };
        }
        if (classesDir != null) {
          for (String dir : classesDir) {
            if (sb.length() > 0) sb.append(',');
            sb.append(dir);
          }
        }
      }

    } catch (IOException e) {
      getLog().debug("Exception reading build.properties of " + otherProject.getId(), e);
    }

    return sb.toString();
  }
Esempio n. 2
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);
    }
  }
Esempio n. 3
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);
  }