Search in sources :

Example 6 with TestFrameworkProvider

use of org.eclipse.tycho.surefire.provider.spi.TestFrameworkProvider in project tycho by eclipse.

the class TestMojo method createEclipseInstallation.

private EquinoxInstallation createEclipseInstallation() throws MojoExecutionException {
    DependencyResolver platformResolver = dependencyResolverLocator.lookupDependencyResolver(project);
    final List<Dependency> extraDependencies = getExtraDependencies();
    List<ReactorProject> reactorProjects = getReactorProjects();
    final DependencyResolverConfiguration resolverConfiguration = new DependencyResolverConfiguration() {

        @Override
        public OptionalResolutionAction getOptionalResolutionAction() {
            return OptionalResolutionAction.IGNORE;
        }

        @Override
        public List<Dependency> getExtraRequirements() {
            return extraDependencies;
        }
    };
    DependencyArtifacts testRuntimeArtifacts = platformResolver.resolveDependencies(session, project, null, reactorProjects, resolverConfiguration);
    if (testRuntimeArtifacts == null) {
        throw new MojoExecutionException("Cannot determinate build target platform location -- not executing tests");
    }
    work.mkdirs();
    EquinoxInstallationDescription testRuntime = new DefaultEquinoxInstallationDescription();
    testRuntime.setDefaultBundleStartLevel(defaultStartLevel);
    testRuntime.addBundlesToExplode(getBundlesToExplode());
    testRuntime.addFrameworkExtensions(getFrameworkExtensions());
    if (bundleStartLevel != null) {
        for (BundleStartLevel level : bundleStartLevel) {
            testRuntime.addBundleStartLevel(level);
        }
    }
    TestFrameworkProvider provider = providerHelper.selectProvider(getProjectType().getClasspath(project), getMergedProviderProperties(), providerHint);
    createSurefireProperties(provider);
    for (ArtifactDescriptor artifact : testRuntimeArtifacts.getArtifacts(ArtifactType.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(artifact.getClassifier());
            if (file != null) {
                testRuntime.addBundle(artifact.getKey(), file);
                continue;
            }
        }
        testRuntime.addBundle(artifact);
    }
    Set<Artifact> testFrameworkBundles = providerHelper.filterTestFrameworkBundles(provider, pluginArtifacts);
    for (Artifact artifact : testFrameworkBundles) {
        DevBundleInfo devInfo = workspaceState.getBundleInfo(session, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), project.getPluginArtifactRepositories());
        if (devInfo != null) {
            testRuntime.addBundle(devInfo.getArtifactKey(), devInfo.getLocation(), true);
            testRuntime.addDevEntries(devInfo.getSymbolicName(), devInfo.getDevEntries());
        } else {
            File bundleLocation = artifact.getFile();
            ArtifactKey bundleArtifactKey = getBundleArtifactKey(bundleLocation);
            testRuntime.addBundle(bundleArtifactKey, bundleLocation, true);
        }
    }
    testRuntime.addDevEntries(getTestBundleSymbolicName(), getBuildOutputDirectories());
    reportsDirectory.mkdirs();
    return installationFactory.createInstallation(testRuntime, work);
}
Also used : DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) BundleStartLevel(org.eclipse.sisu.equinox.launching.BundleStartLevel) ArtifactKey(org.eclipse.tycho.ArtifactKey) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ReactorProject(org.eclipse.tycho.ReactorProject) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) Dependency(org.apache.maven.model.Dependency) DependencyResolverConfiguration(org.eclipse.tycho.core.DependencyResolverConfiguration) Artifact(org.apache.maven.artifact.Artifact) DependencyResolver(org.eclipse.tycho.core.DependencyResolver) EquinoxInstallationDescription(org.eclipse.sisu.equinox.launching.EquinoxInstallationDescription) DefaultEquinoxInstallationDescription(org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) DevBundleInfo(org.eclipse.tycho.dev.DevBundleInfo) DefaultEquinoxInstallationDescription(org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription) TestFrameworkProvider(org.eclipse.tycho.surefire.provider.spi.TestFrameworkProvider) File(java.io.File)

Example 7 with TestFrameworkProvider

use of org.eclipse.tycho.surefire.provider.spi.TestFrameworkProvider in project tycho by eclipse.

the class TestMojo method createProvisionedInstallation.

private EquinoxInstallation createProvisionedInstallation() throws MojoExecutionException {
    try {
        TestFrameworkProvider provider = providerHelper.selectProvider(getProjectType().getClasspath(project), getMergedProviderProperties(), providerHint);
        createSurefireProperties(provider);
        ProvisionedInstallationBuilder installationBuilder = provisionedInstallationBuilderFactory.createInstallationBuilder();
        Set<Artifact> testHarnessArtifacts = providerHelper.filterTestFrameworkBundles(provider, pluginArtifacts);
        for (Artifact testHarnessArtifact : testHarnessArtifacts) {
            installationBuilder.addBundleJar(testHarnessArtifact.getFile());
        }
        RepositoryReferences sources = repositoryReferenceTool.getVisibleRepositories(project, session, RepositoryReferenceTool.REPOSITORIES_INCLUDE_CURRENT_MODULE);
        installationBuilder.addMetadataRepositories(sources.getMetadataRepositories());
        installationBuilder.addArtifactRepositories(sources.getArtifactRepositories());
        installationBuilder.setProfileName(profileName);
        installationBuilder.addIUsToBeInstalled(getIUsToInstall(testHarnessArtifacts));
        File workingDir = new File(project.getBuild().getDirectory(), "p2temp");
        workingDir.mkdirs();
        installationBuilder.setWorkingDir(workingDir);
        installationBuilder.setDestination(work);
        return installationBuilder.install();
    } catch (Exception ex) {
        throw new MojoExecutionException(ex.getMessage(), ex);
    }
}
Also used : ProvisionedInstallationBuilder(org.eclipse.tycho.surefire.provisioning.ProvisionedInstallationBuilder) RepositoryReferences(org.eclipse.tycho.p2.tools.RepositoryReferences) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) TestFrameworkProvider(org.eclipse.tycho.surefire.provider.spi.TestFrameworkProvider) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) MalformedURLException(java.net.MalformedURLException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 8 with TestFrameworkProvider

use of org.eclipse.tycho.surefire.provider.spi.TestFrameworkProvider in project tycho by eclipse.

the class ProviderHelper method selectProvider.

public TestFrameworkProvider selectProvider(List<ClasspathEntry> classpath, Properties providerProperties, String providerHint) throws MojoExecutionException {
    if (providerHint != null) {
        TestFrameworkProvider provider = providers.get(providerHint);
        if (provider == null) {
            throw new MojoExecutionException("Could not find test framework provider with role hint '" + providerHint + "'. Available providers: " + providers.keySet());
        } else {
            return provider;
        }
    }
    List<TestFrameworkProvider> candidates = new ArrayList<>();
    for (TestFrameworkProvider provider : providers.values()) {
        if (provider.isEnabled(classpath, providerProperties)) {
            candidates.add(provider);
        }
    }
    validateCandidates(candidates);
    TestFrameworkProvider highestVersionProvider = Collections.max(candidates, VERSION_COMPARATOR);
    validate(highestVersionProvider, providerProperties);
    return highestVersionProvider;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) TestFrameworkProvider(org.eclipse.tycho.surefire.provider.spi.TestFrameworkProvider)

Example 9 with TestFrameworkProvider

use of org.eclipse.tycho.surefire.provider.spi.TestFrameworkProvider in project tycho by eclipse.

the class ProviderHelperTest method testSelectTestNG.

public void testSelectTestNG() throws Exception {
    TestFrameworkProvider provider = providerHelper.selectProvider(classPath("org.testng:6.9.12"), new Properties(), null);
    assertEquals(TestNGProvider.class, provider.getClass());
}
Also used : TestFrameworkProvider(org.eclipse.tycho.surefire.provider.spi.TestFrameworkProvider) Properties(java.util.Properties)

Example 10 with TestFrameworkProvider

use of org.eclipse.tycho.surefire.provider.spi.TestFrameworkProvider in project tycho by eclipse.

the class ProviderHelperTest method testSelectJunit4.

public void testSelectJunit4() throws Exception {
    TestFrameworkProvider provider = providerHelper.selectProvider(classPath("org.junit:4.8.1"), new Properties(), null);
    assertEquals(JUnit4Provider.class, provider.getClass());
}
Also used : TestFrameworkProvider(org.eclipse.tycho.surefire.provider.spi.TestFrameworkProvider) Properties(java.util.Properties)

Aggregations

TestFrameworkProvider (org.eclipse.tycho.surefire.provider.spi.TestFrameworkProvider)12 Properties (java.util.Properties)9 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 File (java.io.File)2 Artifact (org.apache.maven.artifact.Artifact)2 Dependency (org.apache.maven.model.Dependency)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 PlexusContainer (org.codehaus.plexus.PlexusContainer)1 BundleStartLevel (org.eclipse.sisu.equinox.launching.BundleStartLevel)1 DefaultEquinoxInstallationDescription (org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription)1 EquinoxInstallationDescription (org.eclipse.sisu.equinox.launching.EquinoxInstallationDescription)1 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)1 ArtifactKey (org.eclipse.tycho.ArtifactKey)1