diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/PomTest.java b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/PomTest.java index 355f1e0726..c0acc349cb 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/PomTest.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/PomTest.java @@ -213,7 +213,8 @@ public void testAddDependencies_areDirect() try (InputStream contents = pomFile.getContents()) { Document actual = parse(contents); - NodeList dependencies = actual.getElementsByTagNameNS("http://maven.apache.org/POM/4.0.0", "dependencies"); + NodeList dependencies = + actual.getElementsByTagNameNS("http://maven.apache.org/POM/4.0.0", "dependencies"); Assert.assertEquals(2, dependencies.getLength()); Element dependency = getOnlyChild(((Element) dependencies.item(1)), "dependency"); @@ -225,6 +226,33 @@ public void testAddDependencies_areDirect() Assert.assertNotEquals("5.1.10", version.getTextContent()); } } + + @Test + public void testPinnedDependencies() + throws CoreException, ParserConfigurationException, IOException, SAXException { + + LibraryFile objectify = + new LibraryFile(coordinates("com.googlecode.objectify", "objectify", "5.1.10")); + objectify.setPinned(true); + Library library = newLibrary("objectify", objectify); + + List libraries = new ArrayList<>(); + libraries.add(library); + + pom.addDependencies(libraries); + + try (InputStream contents = pomFile.getContents()) { + Document actual = parse(contents); + + NodeList dependencies = + actual.getElementsByTagNameNS("http://maven.apache.org/POM/4.0.0", "dependencies"); + Assert.assertEquals(2, dependencies.getLength()); + + Element dependency = getOnlyChild(((Element) dependencies.item(1)), "dependency"); + Element version = getOnlyChild(dependency, "version"); + Assert.assertEquals("5.1.10", version.getTextContent()); + } + } @Test public void testRemoveUnusedDependencies_selectAll() @@ -237,17 +265,20 @@ public void testRemoveUnusedDependencies_selectAll() pom.addDependencies(Arrays.asList(library1, library2)); try (InputStream contents = pomFile.getContents()) { Document actual = parse(contents); - NodeList dependenciesList = actual.getElementsByTagNameNS("http://maven.apache.org/POM/4.0.0", "dependencies"); + NodeList dependenciesList = + actual.getElementsByTagNameNS("http://maven.apache.org/POM/4.0.0", "dependencies"); Assert.assertEquals(2, dependenciesList.getLength()); // first one is in dependencyManagement Element dependencies = (Element) dependenciesList.item(1); - Assert.assertEquals(2, dependencies.getElementsByTagNameNS("http://maven.apache.org/POM/4.0.0", "dependency").getLength()); + Assert.assertEquals(2, dependencies + .getElementsByTagNameNS("http://maven.apache.org/POM/4.0.0", "dependency").getLength()); // no dependencies should be removed Pom.removeUnusedDependencies(dependencies, Arrays.asList(library1, library2), Arrays.asList(library1, library2)); - Assert.assertEquals(2, dependencies.getElementsByTagNameNS("http://maven.apache.org/POM/4.0.0", "dependency").getLength()); + Assert.assertEquals(2, dependencies + .getElementsByTagNameNS("http://maven.apache.org/POM/4.0.0", "dependency").getLength()); } } diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/model/CloudLibrariesInPluginXmlTest.java b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/model/CloudLibrariesInPluginXmlTest.java index b7cd71240c..1587d81754 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/model/CloudLibrariesInPluginXmlTest.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/model/CloudLibrariesInPluginXmlTest.java @@ -17,6 +17,7 @@ package com.google.cloud.tools.eclipse.appengine.libraries.model; import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -138,7 +139,7 @@ public void testEndpointsLibraryConfig() throws URISyntaxException { } @Test - public void testObjectifyLibraryConfig() throws URISyntaxException { + public void testObjectify5LibraryConfig() throws URISyntaxException { Library objectifyLibrary = CloudLibraries.getLibrary(OBJECTIFY_LIBRARY_ID); assertThat(objectifyLibrary.getId(), is(OBJECTIFY_LIBRARY_ID)); assertThat(objectifyLibrary.getName(), is("Objectify")); @@ -163,6 +164,63 @@ public void testObjectifyLibraryConfig() throws URISyntaxException { assertTrue("Objectify not exported", objectifyLibraryFile.isExport()); assertNotNull("guava not found", guavaLibraryFile); + MavenCoordinates objectifyMavenCoordinates = objectifyLibraryFile.getMavenCoordinates(); + assertThat(objectifyMavenCoordinates.getRepository(), is("central")); + assertThat(objectifyMavenCoordinates.getGroupId(), is("com.googlecode.objectify")); + assertThat(objectifyMavenCoordinates.getArtifactId(), is("objectify")); + DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion( + objectifyMavenCoordinates.getVersion()); + // this library is pinned + assertEquals(new DefaultArtifactVersion("5.1.22"), artifactVersion); + assertThat(objectifyMavenCoordinates.getType(), is("jar")); + assertNull(objectifyMavenCoordinates.getClassifier()); + + assertNotNull(objectifyLibraryFile.getFilters()); + assertTrue(objectifyLibraryFile.getFilters().isEmpty()); + assertTrue(objectifyLibraryFile.getJavadocUri().toString().startsWith( + "https://www.javadoc.io/doc/com.googlecode.objectify/objectify/")); + + assertNull(guavaLibraryFile.getSourceUri()); + assertTrue("Guava not exported", guavaLibraryFile.isExport()); + + MavenCoordinates guavaMavenCoordinates = guavaLibraryFile.getMavenCoordinates(); + assertThat(guavaMavenCoordinates.getRepository(), is("central")); + assertThat(guavaMavenCoordinates.getGroupId(), is("com.google.guava")); + assertThat(guavaMavenCoordinates.getArtifactId(), is("guava")); + assertThat(guavaMavenCoordinates.getVersion(), is("20.0")); + assertThat(guavaMavenCoordinates.getType(), is("jar")); + assertNull(guavaMavenCoordinates.getClassifier()); + + assertNotNull(guavaLibraryFile.getFilters()); + assertTrue(guavaLibraryFile.getFilters().isEmpty()); + } + + @Test + public void testObjectify6LibraryConfig() throws URISyntaxException { + Library objectifyLibrary = CloudLibraries.getLibrary("objectify6"); + assertThat(objectifyLibrary.getId(), is("objectify6")); + assertThat(objectifyLibrary.getName(), is("Objectify")); + assertThat(objectifyLibrary.getGroups().get(0), is("flexible")); + assertThat(objectifyLibrary.getSiteUri(), + is(new URI("https://github.com/objectify/objectify/wiki"))); + assertTrue(objectifyLibrary.isExport()); + + List allDependencies = objectifyLibrary.getAllDependencies(); + assertTrue(allDependencies.size() + " dependencies", allDependencies.size() > 2); + + LibraryFile objectifyLibraryFile = null; + LibraryFile guavaLibraryFile = null; + for (LibraryFile file : allDependencies) { + if (file.getMavenCoordinates().getArtifactId().equals("objectify")) { + objectifyLibraryFile = file; + } else if (file.getMavenCoordinates().getArtifactId().equals("guava")) { + guavaLibraryFile = file; + } + } + assertNotNull("objectify not found", objectifyLibraryFile); + assertTrue("Objectify not exported", objectifyLibraryFile.isExport()); + assertNotNull("guava not found", guavaLibraryFile); + MavenCoordinates objectifyMavenCoordinates = objectifyLibraryFile.getMavenCoordinates(); assertThat(objectifyMavenCoordinates.getRepository(), is("central")); assertThat(objectifyMavenCoordinates.getGroupId(), is("com.googlecode.objectify")); diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/model/CloudLibrariesTest.java b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/model/CloudLibrariesTest.java index 184a2a889b..3f5bdab808 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/model/CloudLibrariesTest.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/model/CloudLibrariesTest.java @@ -73,4 +73,11 @@ public void testGetLibrary() { Assert.assertEquals("appengine", library.getGroups().get(0)); Assert.assertEquals("Objectify", library.getName()); } + + @Test + public void testGetLibraryObjectify6() { + Library library = CloudLibraries.getLibrary("objectify6"); + Assert.assertEquals("flexible", library.getGroups().get(0)); + Assert.assertEquals("Objectify", library.getName()); + } } diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.ui.test/src/com/google/cloud/tools/eclipse/appengine/libraries/ui/AppEngineLibrariesSelectorGroupTest.java b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.ui.test/src/com/google/cloud/tools/eclipse/appengine/libraries/ui/AppEngineLibrariesSelectorGroupTest.java index d382860d7f..24c1360bbf 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.ui.test/src/com/google/cloud/tools/eclipse/appengine/libraries/ui/AppEngineLibrariesSelectorGroupTest.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.ui.test/src/com/google/cloud/tools/eclipse/appengine/libraries/ui/AppEngineLibrariesSelectorGroupTest.java @@ -109,8 +109,9 @@ public void testSelectObjectifyDoesNotSelectAppEngineApiAsWell() { objectifyButton.click(); List selectedLibraries = getSelectedLibrariesSorted(); assertNotNull(selectedLibraries); - assertThat(selectedLibraries.size(), is(1)); - assertThat(selectedLibraries.get(0).getId(), is("objectify")); + assertThat(selectedLibraries.size(), is(2)); + assertThat(selectedLibraries.get(0).getId(), is("appengine-api")); + assertThat(selectedLibraries.get(1).getId(), is("objectify")); } @Test diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.ui.test/src/com/google/cloud/tools/eclipse/appengine/libraries/ui/CloudLibrariesPageTest.java b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.ui.test/src/com/google/cloud/tools/eclipse/appengine/libraries/ui/CloudLibrariesPageTest.java index 5b09a2d6dc..0bec74069b 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.ui.test/src/com/google/cloud/tools/eclipse/appengine/libraries/ui/CloudLibrariesPageTest.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.ui.test/src/com/google/cloud/tools/eclipse/appengine/libraries/ui/CloudLibrariesPageTest.java @@ -100,7 +100,7 @@ public void testSelectionRoundTrip() { } @Test - public void testAppEngineLibraries_foundOnAppEngineProject() { + public void testAppEngineLibraries_foundOnAppEngineStandardProject() { IJavaProject javaProject = plainJavaProjectCreator .withFacets(WebFacetUtils.WEB_25, AppEngineStandardFacet.JRE7).getJavaProject(); page.initialize(javaProject, null); @@ -140,7 +140,7 @@ public void testSelectionMaintained() { // check the page's selected libraries List returnedLibraries = page.getSelectedLibraries(); - Assert.assertEquals(1, returnedLibraries.size()); + Assert.assertEquals(2, returnedLibraries.size()); assertThat(returnedLibraries, Matchers.hasItem(new LibraryMatcher("objectify"))); // select GCS @@ -153,7 +153,8 @@ public void testSelectionMaintained() { Matchers.hasItem(new LibraryMatcher("googlecloudstorage"))); returnedLibraries = page.getSelectedLibraries(); - Assert.assertEquals(2, returnedLibraries.size()); + Assert.assertEquals(3, returnedLibraries.size()); + assertThat(returnedLibraries, Matchers.hasItem(new LibraryMatcher("appengine-api"))); assertThat(returnedLibraries, Matchers.hasItem(new LibraryMatcher("objectify"))); assertThat(returnedLibraries, Matchers.hasItem(new LibraryMatcher("googlecloudstorage"))); diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries.ui.test/src/com/google/cloud/tools/eclipse/appengine/libraries/ui/FlexibleLibrariesSelectorGroupTest.java b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.ui.test/src/com/google/cloud/tools/eclipse/appengine/libraries/ui/FlexibleLibrariesSelectorGroupTest.java new file mode 100644 index 0000000000..0c44c0a3c8 --- /dev/null +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries.ui.test/src/com/google/cloud/tools/eclipse/appengine/libraries/ui/FlexibleLibrariesSelectorGroupTest.java @@ -0,0 +1,91 @@ +/* + * Copyright 2018 Google LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.tools.eclipse.appengine.libraries.ui; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import com.google.cloud.tools.eclipse.appengine.libraries.model.CloudLibraries; +import com.google.cloud.tools.eclipse.appengine.libraries.model.Library; +import com.google.cloud.tools.eclipse.test.util.ui.ShellTestResource; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class FlexibleLibrariesSelectorGroupTest { + + @Rule public ShellTestResource shellTestResource = new ShellTestResource(); + + private Shell shell; + private LibrarySelectorGroup librariesSelector; + private SWTBotCheckBox objectifyButton; + + @Before + public void setUp() { + shell = shellTestResource.getShell(); + shell.setLayout(new FillLayout()); + librariesSelector = new LibrarySelectorGroup( + shell, CloudLibraries.APP_ENGINE_FLEXIBLE_GROUP, "xxx"); //$NON-NLS-1$ + shell.open(); + objectifyButton = getButton("objectify6"); + } + + @Test + public void testToolTips() { + assertTrue(objectifyButton.getToolTipText().length() > 0); + } + + @Test + public void testInitiallyNoLibrariesSelected() { + assertTrue(getSelectedLibrariesSorted().isEmpty()); + } + + @Test + public void testSelectObjectify() { + objectifyButton.click(); + List selectedLibraries = getSelectedLibrariesSorted(); + assertNotNull(selectedLibraries); + assertThat(selectedLibraries.size(), is(1)); + assertThat(selectedLibraries.get(0).getId(), is("objectify6")); + } + + private SWTBotCheckBox getButton(String libraryId) { + for (Button button : librariesSelector.getLibraryButtons()) { + if (libraryId.equals(((Library) button.getData()).getId())) { + return new SWTBotCheckBox(button); + } + } + fail("Could not find button for " + libraryId); + return null; // won't be reached + } + + private List getSelectedLibrariesSorted() { + List selectedLibraries = new ArrayList<>(librariesSelector.getSelectedLibraries()); + Collections.sort(selectedLibraries, new LibraryComparator()); + return selectedLibraries; + } +} diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries/plugin.xml b/plugins/com.google.cloud.tools.eclipse.appengine.libraries/plugin.xml index 0b8a49a74a..6f4f94da19 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.libraries/plugin.xml +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries/plugin.xml @@ -45,7 +45,26 @@ + + + + + + + selectedLibraries, "http://maven.apache.org/POM/4.0.0", "artifactId"); artifactIdElement.setTextContent(artifactId); dependency.appendChild(artifactIdElement); - + if (!dependencyManaged(groupId, artifactId)) { String version = coordinates.getVersion(); - ArtifactVersion latestVersion = - ArtifactRetriever.DEFAULT.getBestVersion(groupId, artifactId); - if (latestVersion != null) { - version = latestVersion.toString(); + if (!artifact.isPinned()) { + ArtifactVersion latestVersion = + ArtifactRetriever.DEFAULT.getBestVersion(groupId, artifactId); + if (latestVersion != null) { + version = latestVersion.toString(); + } } // todo latest version may not be needed anymore. diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/model/LibraryFile.java b/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/model/LibraryFile.java index 546916fad4..ff60bca008 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/model/LibraryFile.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.libraries/src/com/google/cloud/tools/eclipse/appengine/libraries/model/LibraryFile.java @@ -133,11 +133,12 @@ void updateVersion() { } } - private boolean isPinned() { + public boolean isPinned() { return pinned; } - void setPinned(boolean pinned) { + @VisibleForTesting + public void setPinned(boolean pinned) { this.pinned = pinned; } diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.newproject/src/com/google/cloud/tools/eclipse/appengine/newproject/CodeTemplates.java b/plugins/com.google.cloud.tools.eclipse.appengine.newproject/src/com/google/cloud/tools/eclipse/appengine/newproject/CodeTemplates.java index 3c0ddc7727..654de48d06 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.newproject/src/com/google/cloud/tools/eclipse/appengine/newproject/CodeTemplates.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.newproject/src/com/google/cloud/tools/eclipse/appengine/newproject/CodeTemplates.java @@ -204,7 +204,7 @@ private static void createPomXml(IProject project, AppEngineProjectConfig config String bomVersion = getCurrentVersion( "com.google.cloud", //$NON-NLS-1$ "google-cloud", //$NON-NLS-1$ - "0.42.0-alpha"); //$NON-NLS-1$ + "0.47.0-alpha"); //$NON-NLS-1$ properties.put("googleCloudJavaBomVersion", bomVersion); //$NON-NLS-1$ String mavenPluginVersion = getCurrentVersion(