From 539b9dd8a5e1a35bd5cb0c17a36f615ade45328a Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 13 Feb 2020 17:08:48 -0500 Subject: [PATCH 1/7] rename test class to match model class --- .../repository/{MavenHelpTest.java => MavenHelperTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/{MavenHelpTest.java => MavenHelperTest.java} (98%) diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelpTest.java b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java similarity index 98% rename from plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelpTest.java rename to plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java index 5e88aef107..84bba8e5d8 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelpTest.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java @@ -27,7 +27,7 @@ import org.mockito.runners.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) -public class MavenHelpTest { +public class MavenHelperTest { private static final String EXPECTED_DOWNLOAD_FOLDER = ".metadata/.plugins/com.google.cloud.tools.eclipse.appengine.libraries/downloads/groupId/artifactId/1.0.0"; From 51d7b1de8714b63ea5b728c868abdf4194533a5e Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 13 Feb 2020 17:29:52 -0500 Subject: [PATCH 2/7] demock tests and add resolve test --- .../libraries/repository/MavenHelperTest.java | 45 +++++++++++++------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java index 84bba8e5d8..3c135675bf 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java @@ -17,35 +17,52 @@ package com.google.cloud.tools.eclipse.appengine.libraries.repository; import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; import com.google.cloud.tools.eclipse.appengine.libraries.model.MavenCoordinates; +import org.apache.maven.artifact.Artifact; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.junit.Assert; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -@RunWith(MockitoJUnitRunner.class) public class MavenHelperTest { private static final String EXPECTED_DOWNLOAD_FOLDER = ".metadata/.plugins/com.google.cloud.tools.eclipse.appengine.libraries/downloads/groupId/artifactId/1.0.0"; - @Mock private MavenCoordinates artifact; - @Test public void testBundleStateBasedMavenFolder_withSpecificVersion() { - when(artifact.getGroupId()).thenReturn("groupId"); - when(artifact.getArtifactId()).thenReturn("artifactId"); - when(artifact.getVersion()).thenReturn("1.0.0"); - IPath folder = MavenHelper.bundleStateBasedMavenFolder(artifact); + MavenCoordinates coordinates = new MavenCoordinates.Builder() + .setGroupId("groupId") + .setArtifactId("artifactId") + .setVersion("1.0.0") + .build(); + IPath folder = MavenHelper.bundleStateBasedMavenFolder(coordinates); assertTrue(folder.toString().endsWith(EXPECTED_DOWNLOAD_FOLDER)); } - @Test(expected = IllegalArgumentException.class) + @Test + public void testUseAndroidRepo() throws CoreException { + MavenCoordinates coordinates = new MavenCoordinates.Builder() + .setGroupId("com.google.cloud") + .setArtifactId("google-cloud-datastore") + .setVersion("1.30.8") + .build(); + Artifact artifact = MavenHelper.resolveArtifact(coordinates, new NullProgressMonitor()); + } + + @Test public void testBundleStateBasedMavenFolder_withLatestVersion() { - when(artifact.getVersion()).thenReturn("LATEST"); - MavenHelper.bundleStateBasedMavenFolder(artifact); + MavenCoordinates coordinates = new MavenCoordinates.Builder() + .setGroupId("com.google.cloud") + .setArtifactId("datastore") + .setVersion("LATEST") + .build(); + try { + MavenHelper.bundleStateBasedMavenFolder(coordinates); + Assert.fail(); + } catch (IllegalArgumentException expected) { + } } } From dfd5120d731ca9f3a436514ad0726de38254010e Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 13 Feb 2020 17:32:22 -0500 Subject: [PATCH 3/7] testResolveArtifact --- .../appengine/libraries/repository/MavenHelperTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java index 3c135675bf..bc47ea9f4f 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java @@ -43,13 +43,14 @@ public void testBundleStateBasedMavenFolder_withSpecificVersion() { } @Test - public void testUseAndroidRepo() throws CoreException { + public void testResolveArtifact() throws CoreException { MavenCoordinates coordinates = new MavenCoordinates.Builder() .setGroupId("com.google.cloud") .setArtifactId("google-cloud-datastore") - .setVersion("1.30.8") + .setVersion("1.102.1") .build(); Artifact artifact = MavenHelper.resolveArtifact(coordinates, new NullProgressMonitor()); + Assert.assertEquals("google-cloud-datastore", artifact.getArtifactId()); } @Test From c7f368de81a34d35a9f13a7c96fc0b2c145ddc46 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 13 Feb 2020 17:40:53 -0500 Subject: [PATCH 4/7] testResolveArtifact_android --- .../libraries/repository/MavenHelperTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java index bc47ea9f4f..ba5f657517 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java @@ -53,6 +53,31 @@ public void testResolveArtifact() throws CoreException { Assert.assertEquals("google-cloud-datastore", artifact.getArtifactId()); } + @Test + public void testResolveArtifact_googleApiClient() throws CoreException { + MavenCoordinates coordinates = new MavenCoordinates.Builder() + .setGroupId("com.google.api-client") + .setArtifactId("google-api-client") + .setVersion("1.30.8") + .build(); + Artifact artifact = MavenHelper.resolveArtifact(coordinates, new NullProgressMonitor()); + Assert.assertEquals("google-api-client", artifact.getArtifactId()); + } + + @Test + public void testResolveArtifact_android() throws CoreException { + MavenCoordinates coordinates = new MavenCoordinates.Builder() + .setGroupId("androidx.annotation") + .setArtifactId("annotation") + .setVersion("1.1.0") + .setRepository("https://maven.google.com") + .build(); + Artifact artifact = MavenHelper.resolveArtifact(coordinates, new NullProgressMonitor()); + Assert.assertEquals("annotation", artifact.getArtifactId()); + } + + + @Test public void testBundleStateBasedMavenFolder_withLatestVersion() { MavenCoordinates coordinates = new MavenCoordinates.Builder() From 2db8b170ff02b3c50386f9d0622c712b08ea3733 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 13 Feb 2020 18:01:46 -0500 Subject: [PATCH 5/7] hack around bug --- .../libraries/repository/MavenHelperTest.java | 11 ++++++++++- .../appengine/libraries/repository/MavenHelper.java | 11 ++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java index ba5f657517..d4771edee1 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelperTest.java @@ -76,7 +76,16 @@ public void testResolveArtifact_android() throws CoreException { Assert.assertEquals("annotation", artifact.getArtifactId()); } - + @Test + public void testResolveArtifact_android_noRepository() throws CoreException { + MavenCoordinates coordinates = new MavenCoordinates.Builder() + .setGroupId("androidx.annotation") + .setArtifactId("annotation") + .setVersion("1.1.0") + .build(); + Artifact artifact = MavenHelper.resolveArtifact(coordinates, new NullProgressMonitor()); + Assert.assertEquals("annotation", artifact.getArtifactId()); + } @Test public void testBundleStateBasedMavenFolder_withLatestVersion() { diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelper.java b/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelper.java index 69afc1b401..a115a6184e 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelper.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelper.java @@ -24,6 +24,7 @@ import java.io.File; import java.net.URI; import java.net.URISyntaxException; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.apache.maven.artifact.Artifact; @@ -51,17 +52,21 @@ public static Artifact resolveArtifact( monitor); } + private static List getRepository(MavenCoordinates mavenCoordinates) throws CoreException { if (MavenCoordinates.MAVEN_CENTRAL_REPO.equals(mavenCoordinates.getRepository())) { // M2Eclipse will use the Maven Central repo in case null is used - return null; + ArrayList repos = new ArrayList<>(); + repos.add(makeRepository("https://repo1.maven.org/maven2/")); + repos.add(makeRepository("https://maven.google.com")); + return repos; } else { - return Collections.singletonList(getCustomRepository(mavenCoordinates.getRepository())); + return Collections.singletonList(makeRepository(mavenCoordinates.getRepository())); } } - private static ArtifactRepository getCustomRepository(String repository) throws CoreException { + private static ArtifactRepository makeRepository(String repository) throws CoreException { try { URI repoUri = new URI(repository); if (!repoUri.isAbsolute()) { From dd477e7c339e40cac5891074e5ac563b5d41f705 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Fri, 14 Feb 2020 10:07:58 -0500 Subject: [PATCH 6/7] match group ID to repo --- .../appengine/libraries/model/MavenCoordinates.java | 3 +++ .../appengine/libraries/repository/MavenHelper.java | 8 ++------ .../com/google/cloud/tools/eclipse/util/MavenUtils.java | 7 ++++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/model/MavenCoordinates.java b/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/model/MavenCoordinates.java index 32d284fe48..5f40718d4e 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/model/MavenCoordinates.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/model/MavenCoordinates.java @@ -138,6 +138,9 @@ public Builder setGroupId(String groupId) { Preconditions.checkNotNull(groupId, "groupId null"); Preconditions.checkArgument(!groupId.isEmpty(), "groupId is empty"); this.groupId = groupId; + if (groupId.startsWith("androidx")) { + setRepository("https://maven.google.com"); + } return this; } diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelper.java b/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelper.java index a115a6184e..11585ca77a 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelper.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelper.java @@ -52,15 +52,11 @@ public static Artifact resolveArtifact( monitor); } - private static List getRepository(MavenCoordinates mavenCoordinates) throws CoreException { if (MavenCoordinates.MAVEN_CENTRAL_REPO.equals(mavenCoordinates.getRepository())) { - // M2Eclipse will use the Maven Central repo in case null is used - ArrayList repos = new ArrayList<>(); - repos.add(makeRepository("https://repo1.maven.org/maven2/")); - repos.add(makeRepository("https://maven.google.com")); - return repos; + // M2Eclipse uses the Maven Central repo if the repsoitory list is null + return null; } else { return Collections.singletonList(makeRepository(mavenCoordinates.getRepository())); } diff --git a/plugins/com.google.cloud.tools.eclipse.util/src/com/google/cloud/tools/eclipse/util/MavenUtils.java b/plugins/com.google.cloud.tools.eclipse.util/src/com/google/cloud/tools/eclipse/util/MavenUtils.java index 25522118b9..5c0cab5fa0 100644 --- a/plugins/com.google.cloud.tools.eclipse.util/src/com/google/cloud/tools/eclipse/util/MavenUtils.java +++ b/plugins/com.google.cloud.tools.eclipse.util/src/com/google/cloud/tools/eclipse/util/MavenUtils.java @@ -39,6 +39,7 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.embedder.IMaven; import org.eclipse.m2e.core.embedder.IMavenExecutionContext; import org.eclipse.m2e.core.internal.MavenPluginActivator; import org.w3c.dom.DOMException; @@ -93,9 +94,9 @@ public static Artifact resolveArtifact( return runOperation( monitor, (context, system, progress) -> { - Artifact artifact = - MavenPlugin.getMaven() - .resolve(groupId, artifactId, version, type, classifier, repositories, progress); + IMaven maven = MavenPlugin.getMaven(); + Artifact artifact = maven.resolve( + groupId, artifactId, version, type, classifier, repositories, progress); return artifact; }); } From 74d9aba70828c8e4fec66ab2204bc690985c153b Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Fri, 14 Feb 2020 12:06:31 -0500 Subject: [PATCH 7/7] unused import --- .../eclipse/appengine/libraries/repository/MavenHelper.java | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelper.java b/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelper.java index 11585ca77a..bfc191bd1f 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelper.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/repository/MavenHelper.java @@ -24,7 +24,6 @@ import java.io.File; import java.net.URI; import java.net.URISyntaxException; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.apache.maven.artifact.Artifact;