diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/MavenBundleResolver.java b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/MavenBundleResolver.java index 827a87385b..f3afc9bfd9 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/MavenBundleResolver.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/MavenBundleResolver.java @@ -31,11 +31,11 @@ import org.eclipse.tycho.DependencyResolutionException; import org.eclipse.tycho.IllegalArtifactReferenceException; import org.eclipse.tycho.MavenArtifactKey; +import org.eclipse.tycho.ReactorProject; import org.eclipse.tycho.ResolvedArtifactKey; import org.eclipse.tycho.TargetPlatform; import org.eclipse.tycho.core.TychoProjectManager; import org.eclipse.tycho.core.maven.MavenDependenciesResolver; -import org.eclipse.tycho.core.utils.TychoProjectUtils; /** * {@link MavenBundleResolver} helps in gathering bundles that are living in P2 and maven world and @@ -71,7 +71,7 @@ public Optional resolveMavenBundle(MavenProject project, Ma if (project == null) { return Optional.empty(); } - TargetPlatform tp = TychoProjectUtils.getTargetPlatformIfAvailable(DefaultReactorProject.adapt(project)); + TargetPlatform tp = getTargetPlatformIfAvailable(DefaultReactorProject.adapt(project)); String type = mavenArtifactKey.getType(); String resolvedType = PublisherHelper.CAPABILITY_NS_JAVA_PACKAGE.equals(type) ? ArtifactType.TYPE_ECLIPSE_PLUGIN : type; @@ -116,6 +116,17 @@ public Optional resolveMavenBundle(MavenProject project, Ma return Optional.empty(); } + /** + * Returns the final target platform of the given project, or null if the target + * platform is not available. + * + * Projects with -Dtycho.targetPlatform use the legacy LocalDependencyResolver, which doesn't + * provide the {@link TargetPlatform} interface. + */ + private static TargetPlatform getTargetPlatformIfAvailable(ReactorProject project) { + return (TargetPlatform) project.getContextValue(TargetPlatform.FINAL_TARGET_PLATFORM_KEY); + } + public Optional resolveMavenBundle(MavenProject project, MavenSession mavenSession, String groupId, String artifactId, String version) { try { diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/utils/TychoProjectUtils.java b/tycho-core/src/main/java/org/eclipse/tycho/core/utils/TychoProjectUtils.java index a2e8999942..313e3d4e55 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/utils/TychoProjectUtils.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/utils/TychoProjectUtils.java @@ -12,53 +12,20 @@ *******************************************************************************/ package org.eclipse.tycho.core.utils; -import java.util.Optional; import java.util.Properties; import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; -import org.eclipse.tycho.DependencyArtifacts; import org.eclipse.tycho.PlatformPropertiesUtils; import org.eclipse.tycho.ReactorProject; -import org.eclipse.tycho.TargetPlatform; -import org.eclipse.tycho.TychoConstants; import org.eclipse.tycho.core.osgitools.DefaultReactorProject; public class TychoProjectUtils { - private static final String TYCHO_NOT_CONFIGURED = "Tycho build extension not configured for "; public static final String TYCHO_ENV_OSGI_WS = "tycho.env.osgi.ws"; public static final String TYCHO_ENV_OSGI_OS = "tycho.env.osgi.os"; public static final String TYCHO_ENV_OSGI_ARCH = "tycho.env.osgi.arch"; - public static Optional getOptionalDependencyArtifacts(ReactorProject project) { - DependencyArtifacts resolvedDependencies = (DependencyArtifacts) project - .getContextValue(TychoConstants.CTX_DEPENDENCY_ARTIFACTS); - return Optional.ofNullable(resolvedDependencies); - } - - /** - * Returns the final target platform of the given project. - */ - public static TargetPlatform getTargetPlatform(ReactorProject project) { - TargetPlatform targetPlatform = getTargetPlatformIfAvailable(project); - if (targetPlatform == null) { - throw new IllegalStateException(TYCHO_NOT_CONFIGURED + project.toString()); - } - return targetPlatform; - } - - /** - * Returns the final target platform of the given project, or null if the target - * platform is not available. - * - * Projects with -Dtycho.targetPlatform use the legacy LocalDependencyResolver, which doesn't - * provide the {@link TargetPlatform} interface. - */ - public static TargetPlatform getTargetPlatformIfAvailable(ReactorProject project) { - return (TargetPlatform) project.getContextValue(TargetPlatform.FINAL_TARGET_PLATFORM_KEY); - } - /** * Computes the merged properties from maven session and the project * diff --git a/tycho-core/src/test/java/org/eclipse/tycho/core/resolver/DefaultTychoResolverTest.java b/tycho-core/src/test/java/org/eclipse/tycho/core/resolver/DefaultTychoResolverTest.java deleted file mode 100644 index d4fe909aa7..0000000000 --- a/tycho-core/src/test/java/org/eclipse/tycho/core/resolver/DefaultTychoResolverTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014, 2015 Bachmann electronic GmbH and others. - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Bachmann electronic GmbH - initial API and implementation - *******************************************************************************/ -package org.eclipse.tycho.core.resolver; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Properties; - -import org.apache.maven.project.MavenProject; -import org.eclipse.tycho.PlatformPropertiesUtils; -import org.eclipse.tycho.core.utils.TychoProjectUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class DefaultTychoResolverTest { - - private DefaultTychoResolver defaultTychoResolver; - - @Before - public void setup() { - defaultTychoResolver = new DefaultTychoResolver(); - - } - - @Test - public void testTychoEnvironmentPropertiesGetSet() { - System.setProperty("os.name", PlatformPropertiesUtils.INTERNAL_OS_LINUX); - System.setProperty("os.arch", PlatformPropertiesUtils.INTERNAL_AMD64); - - MavenProject project = mock(MavenProject.class); - Properties mergedProperties = new Properties(); - Properties projectProperties = new Properties(); - when(project.getProperties()).thenReturn(projectProperties); - - TychoProjectUtils.setTychoEnvironmentProperties(mergedProperties, project); - - Object ws = projectProperties.getProperty(TychoProjectUtils.TYCHO_ENV_OSGI_WS); - Object os = projectProperties.getProperty(TychoProjectUtils.TYCHO_ENV_OSGI_OS); - Object arch = projectProperties.getProperty(TychoProjectUtils.TYCHO_ENV_OSGI_ARCH); - - Assert.assertEquals(3, projectProperties.size()); - Assert.assertEquals(PlatformPropertiesUtils.ARCH_X86_64, arch); - Assert.assertEquals(PlatformPropertiesUtils.OS_LINUX, os); - Assert.assertEquals(PlatformPropertiesUtils.WS_GTK, ws); - } -}