Skip to content

Commit

Permalink
stick to Objectify 5 on standard (#3113)
Browse files Browse the repository at this point in the history
* stick to Objectify 5 on standard

* make maven respect pinned dependencies

* selector group tests

* objectify6

* fix test
  • Loading branch information
elharo authored May 29, 2018
1 parent 36ceb36 commit 59852ce
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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<Library> 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()
Expand All @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand All @@ -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<LibraryFile> 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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ public void testSelectObjectifyDoesNotSelectAppEngineApiAsWell() {
objectifyButton.click();
List<Library> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -140,7 +140,7 @@ public void testSelectionMaintained() {

// check the page's selected libraries
List<Library> returnedLibraries = page.getSelectedLibraries();
Assert.assertEquals(1, returnedLibraries.size());
Assert.assertEquals(2, returnedLibraries.size());
assertThat(returnedLibraries, Matchers.hasItem(new LibraryMatcher("objectify")));

// select GCS
Expand All @@ -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")));

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Library> 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<Library> getSelectedLibrariesSorted() {
List<Library> selectedLibraries = new ArrayList<>(librariesSelector.getSelectedLibraries());
Collections.sort(selectedLibraries, new LibraryComparator());
return selectedLibraries;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,26 @@

<library
id="objectify"
group="appengine,flexible"
group="appengine"
name="Objectify"
tooltip="%objectify.tooltip"
dependencies="include"
siteUri="https://github.com/objectify/objectify/wiki" >
<libraryDependency id="appengine-api" />
<libraryFile
pinned="true"
export="true"
javadocUri="https://www.javadoc.io/doc/com.googlecode.objectify/objectify/5.1.22">
<mavenCoordinates
artifactId="objectify"
groupId="com.googlecode.objectify"
version="5.1.22" />
</libraryFile>
</library>

<library
id="objectify6"
group="flexible"
name="Objectify"
tooltip="%objectify.tooltip"
dependencies="include"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,15 @@ void updateDependencies(Collection<Library> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 59852ce

Please sign in to comment.