@Override
  public void run(PlexusContainer plexusContainer) throws Exception {
    Settings settings = mavenSettingsBuilder.buildSettings();

    File localRepository = new File(settings.getLocalRepository());
    ArtifactRepository artifactRepository =
        new DefaultArtifactRepository(
            "local", localRepository.toURI().toASCIIString(), artifactRepositoryLayout);

    ProfileManager profileManager =
        new DefaultProfileManager(plexusContainer, settings, System.getProperties());

    Method method =
        maven.getClass().getDeclaredMethod("resolveParameters", Settings.class, Properties.class);
    method.setAccessible(true);
    method.invoke(maven, settings, new Properties());

    MavenProject mavenProject =
        mavenProjectBuilder.build(
            new File("c:\\workspace\\AppercutScanner\\pom.xml"),
            artifactRepository,
            profileManager);

    plexusContainer.getLogger().info(mavenProject.toString());

    DependencyNode rootNode =
        dependencyTreeBuilder.buildDependencyTree(
            mavenProject,
            artifactRepository,
            artifactFactory,
            artifactMetadataSource,
            null,
            artifactCollector);

    plexusContainer.getLogger().info("rootNode:\n" + rootNode);
  }
  public TargetPlatformConfiguration getTargetPlatformConfiguration(
      MavenSession session, MavenProject project) {
    TargetPlatformConfiguration result = new TargetPlatformConfiguration();

    // Use org.eclipse.tycho:target-platform-configuration/configuration/environment, if provided
    Plugin plugin = project.getPlugin("org.eclipse.tycho:target-platform-configuration");

    if (plugin != null) {
      Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
      if (configuration != null) {
        if (logger.isDebugEnabled()) {
          logger.debug(
              "target-platform-configuration for "
                  + project.toString()
                  + ":\n"
                  + configuration.toString());
        }

        addTargetEnvironments(result, project, configuration);

        setTargetPlatformResolver(result, configuration);

        setTarget(result, session, project, configuration);

        setPomDependencies(result, configuration);

        setAllowConflictingDependencies(result, configuration);

        setDisableP2Mirrors(result, configuration);

        setExecutionEnvironment(result, configuration);

        readFilters(result, configuration);

        readExtraRequirements(result, configuration);

        setOptionalDependencies(result, configuration);

        setIncludePackedArtifacts(result, configuration);
      }
    }

    if (result.getEnvironments().isEmpty()) {
      TychoProject projectType = projectTypes.get(project.getPackaging());
      if (projectType != null) {
        TargetEnvironment env = projectType.getImplicitTargetEnvironment(project);
        if (env != null) {
          if (logger.isDebugEnabled()) {
            logger.debug(
                "Implicit target environment for " + project.toString() + ": " + env.toString());
          }

          result.addEnvironment(env);
        }
      }
    }

    if (result.getEnvironments().isEmpty()) {
      // applying defaults
      logger.warn(
          "No explicit target runtime environment configuration. Build is platform dependent.");

      // Otherwise, use project or execution properties, if provided
      Properties properties =
          (Properties) project.getContextValue(TychoConstants.CTX_MERGED_PROPERTIES);

      // Otherwise, use current system os/ws/nl/arch
      String os = PlatformPropertiesUtils.getOS(properties);
      String ws = PlatformPropertiesUtils.getWS(properties);
      String arch = PlatformPropertiesUtils.getArch(properties);

      result.addEnvironment(new TargetEnvironment(os, ws, arch));

      result.setImplicitTargetEnvironment(true);
    } else {
      result.setImplicitTargetEnvironment(false);
    }

    return result;
  }
Beispiel #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);
  }