Search in sources :

Example 1 with BuildFailureException

use of org.eclipse.tycho.core.shared.BuildFailureException in project tycho by eclipse.

the class DefaultTargetPlatformConfigurationReaderTest method testExtraRequirementId.

@Test
public void testExtraRequirementId() throws Exception {
    Xpp3Dom dom = createConfigurationDom("type", "versionRange");
    try {
        configurationReader.readExtraRequirements(new TargetPlatformConfiguration(), dom);
        fail();
    } catch (BuildFailureException e) {
        assertTrue(e.getMessage().contains("Element <id> is missing in <extraRequirements><requirement> section."));
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) BuildFailureException(org.eclipse.tycho.core.shared.BuildFailureException) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration) Test(org.junit.Test)

Example 2 with BuildFailureException

use of org.eclipse.tycho.core.shared.BuildFailureException in project tycho by eclipse.

the class DefaultTargetPlatformConfigurationReaderTest method testAddTargetWithMissingGroupInTargetDefinition.

@Test
public void testAddTargetWithMissingGroupInTargetDefinition() {
    Xpp3Dom dom = createGavConfiguration(null, "myArtifactId", "myVersion");
    MavenSession session = setupMockSession();
    TargetPlatformConfiguration configuration = new TargetPlatformConfiguration();
    try {
        configurationReader.addTargetArtifact(configuration, session, null, dom);
        fail();
    } catch (BuildFailureException e) {
        assertTrue(e.getMessage().contains("The target artifact configuration is invalid"));
    }
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) BuildFailureException(org.eclipse.tycho.core.shared.BuildFailureException) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration) Test(org.junit.Test)

Example 3 with BuildFailureException

use of org.eclipse.tycho.core.shared.BuildFailureException in project tycho by eclipse.

the class DefaultTargetPlatformConfigurationReaderTest method testAddTargetWithMissingArtifactIdInTargetDefinition.

@Test
public void testAddTargetWithMissingArtifactIdInTargetDefinition() {
    Xpp3Dom dom = createGavConfiguration("myGroupId", null, "myVersion");
    MavenSession session = setupMockSession();
    TargetPlatformConfiguration configuration = new TargetPlatformConfiguration();
    try {
        configurationReader.addTargetArtifact(configuration, session, null, dom);
        fail();
    } catch (BuildFailureException e) {
        assertTrue(e.getMessage().contains("The target artifact configuration is invalid"));
    }
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) BuildFailureException(org.eclipse.tycho.core.shared.BuildFailureException) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration) Test(org.junit.Test)

Example 4 with BuildFailureException

use of org.eclipse.tycho.core.shared.BuildFailureException in project tycho by eclipse.

the class DefaultTargetPlatformConfigurationReader method addTargetArtifact.

protected void addTargetArtifact(TargetPlatformConfiguration result, MavenSession session, MavenProject project, Xpp3Dom artifactDom) {
    Xpp3Dom groupIdDom = artifactDom.getChild("groupId");
    Xpp3Dom artifactIdDom = artifactDom.getChild("artifactId");
    Xpp3Dom versionDom = artifactDom.getChild("version");
    if (groupIdDom == null || artifactIdDom == null || versionDom == null) {
        throw new BuildFailureException("The target artifact configuration is invalid - <groupId>, <artifactId> and <version> are mandatory");
    }
    Xpp3Dom classifierDom = artifactDom.getChild("classifier");
    String groupId = groupIdDom.getValue();
    String artifactId = artifactIdDom.getValue();
    String version = versionDom.getValue();
    String classifier = classifierDom != null ? classifierDom.getValue() : null;
    File targetFile = null;
    for (MavenProject otherProject : session.getProjects()) {
        if (groupId.equals(otherProject.getGroupId()) && artifactId.equals(otherProject.getArtifactId()) && version.equals(otherProject.getVersion())) {
            String fileName;
            if (classifier == null) {
                // no classifier means target is provided using packaging type eclipse-target-definition
                fileName = artifactId;
            } else {
                // backward compat for target files manually installed via build-helper-maven-plugin
                fileName = classifier;
            }
            targetFile = new File(otherProject.getBasedir(), fileName + ".target");
            break;
        }
    }
    if (targetFile == null) {
        Artifact artifact = repositorySystem.createArtifactWithClassifier(groupId, artifactId, version, "target", classifier);
        ArtifactResolutionRequest request = new ArtifactResolutionRequest();
        request.setArtifact(artifact);
        request.setLocalRepository(session.getLocalRepository());
        request.setRemoteRepositories(project.getRemoteArtifactRepositories());
        repositorySystem.resolve(request);
        if (!artifact.isResolved()) {
            throw new RuntimeException("Could not resolve target platform specification artifact " + artifact);
        }
        targetFile = artifact.getFile();
    }
    result.addTarget(targetFile);
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MavenProject(org.apache.maven.project.MavenProject) BuildFailureException(org.eclipse.tycho.core.shared.BuildFailureException) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 5 with BuildFailureException

use of org.eclipse.tycho.core.shared.BuildFailureException in project tycho by eclipse.

the class P2DependencyResolver method doResolveDependencies.

private DependencyArtifacts doResolveDependencies(MavenSession session, MavenProject project, List<ReactorProject> reactorProjects, DependencyResolverConfiguration resolverConfiguration, TargetPlatform targetPlatform, P2Resolver resolver, TargetPlatformConfiguration configuration) {
    Map<File, ReactorProject> projects = new HashMap<>();
    resolver.setEnvironments(configuration.getEnvironments());
    resolver.setAdditionalFilterProperties(configuration.getProfileProperties());
    for (ReactorProject otherProject : reactorProjects) {
        projects.put(otherProject.getBasedir(), otherProject);
    }
    if (resolverConfiguration != null) {
        for (Dependency dependency : resolverConfiguration.getExtraRequirements()) {
            try {
                resolver.addDependency(dependency.getType(), dependency.getArtifactId(), dependency.getVersion());
            } catch (IllegalArtifactReferenceException e) {
                throw new BuildFailureException("Invalid extraRequirement " + dependency.getType() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion() + ": " + e.getMessage(), e);
            }
        }
    }
    // get reactor project with prepared optional dependencies // TODO use original IU and have the resolver create the modified IUs
    ReactorProject optionalDependencyPreparedProject = getThisReactorProject(session, project, configuration);
    if (!isAllowConflictingDependencies(project, configuration)) {
        List<P2ResolutionResult> results = resolver.resolveDependencies(targetPlatform, optionalDependencyPreparedProject);
        MultiEnvironmentDependencyArtifacts multiPlatform = new MultiEnvironmentDependencyArtifacts(DefaultReactorProject.adapt(project));
        // FIXME this is just wrong
        for (int i = 0; i < configuration.getEnvironments().size(); i++) {
            TargetEnvironment environment = configuration.getEnvironments().get(i);
            P2ResolutionResult result = results.get(i);
            DefaultDependencyArtifacts platform = newDefaultTargetPlatform(DefaultReactorProject.adapt(project), projects, result);
            multiPlatform.addPlatform(environment, platform);
        }
        return multiPlatform;
    } else {
        P2ResolutionResult result = resolver.collectProjectDependencies(targetPlatform, optionalDependencyPreparedProject);
        return newDefaultTargetPlatform(DefaultReactorProject.adapt(project), projects, result);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IllegalArtifactReferenceException(org.eclipse.tycho.artifacts.IllegalArtifactReferenceException) BuildFailureException(org.eclipse.tycho.core.shared.BuildFailureException) ReactorProject(org.eclipse.tycho.ReactorProject) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) ComponentDependency(org.codehaus.plexus.component.repository.ComponentDependency) Dependency(org.apache.maven.model.Dependency) TargetEnvironment(org.eclipse.tycho.core.shared.TargetEnvironment) MultiEnvironmentDependencyArtifacts(org.eclipse.tycho.core.osgitools.targetplatform.MultiEnvironmentDependencyArtifacts) DefaultDependencyArtifacts(org.eclipse.tycho.core.osgitools.targetplatform.DefaultDependencyArtifacts) P2ResolutionResult(org.eclipse.tycho.p2.resolver.facade.P2ResolutionResult) File(java.io.File)

Aggregations

BuildFailureException (org.eclipse.tycho.core.shared.BuildFailureException)10 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)8 TargetPlatformConfiguration (org.eclipse.tycho.core.TargetPlatformConfiguration)6 Test (org.junit.Test)6 MavenSession (org.apache.maven.execution.MavenSession)3 File (java.io.File)2 Dependency (org.apache.maven.model.Dependency)2 MavenProject (org.apache.maven.project.MavenProject)2 ReactorProject (org.eclipse.tycho.ReactorProject)2 DefaultReactorProject (org.eclipse.tycho.core.osgitools.DefaultReactorProject)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 MavenExecutionException (org.apache.maven.MavenExecutionException)1 Artifact (org.apache.maven.artifact.Artifact)1 ArtifactResolutionRequest (org.apache.maven.artifact.resolver.ArtifactResolutionRequest)1 ComponentDependency (org.codehaus.plexus.component.repository.ComponentDependency)1 IllegalArtifactReferenceException (org.eclipse.tycho.artifacts.IllegalArtifactReferenceException)1 DefaultDependencyArtifacts (org.eclipse.tycho.core.osgitools.targetplatform.DefaultDependencyArtifacts)1 MultiEnvironmentDependencyArtifacts (org.eclipse.tycho.core.osgitools.targetplatform.MultiEnvironmentDependencyArtifacts)1 TargetEnvironment (org.eclipse.tycho.core.shared.TargetEnvironment)1