Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not drop appengine api when converting old-style library container #3214

Merged
merged 3 commits into from
Jul 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ public static IStatus updateProject(IProject project, SubMonitor progress) {
}
progress.worked(5);

// remove "appengine-api" as appengine-api-1.0-sdk now included in the servlet container
libraryIds.remove("appengine-api"); //$NON-NLS-1$
// remove "googlecloudcore" and "googleapiclient" as they were utility definitions, now
// pulled from library dependencies
libraryIds.remove("googlecloudcore"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.google.cloud.tools.eclipse.appengine.compat.Messages;
import com.google.cloud.tools.eclipse.ui.util.ProjectFromSelectionHelper;
import java.text.MessageFormat;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
Expand All @@ -34,11 +33,12 @@ public class UpdateCloudToolsEclipseProjectHandler extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IProject project = ProjectFromSelectionHelper.getFirstProject(event);
IProject project = ProjectFromSelectionHelper.getFirstProject(event);
if (!CloudToolsEclipseProjectUpdater.hasOldContainers(project)) {
throw new ExecutionException(Messages.getString("project.appears.up.to.date")); //$NON-NLS-1$
}
Job updateJob = new WorkspaceJob(MessageFormat.format(Messages.getString("updating.project"), project.getName())) { //$NON-NLS-1$
String jobName = Messages.getString("updating.project", project.getName()); //$NON-NLS-1$
Job updateJob = new WorkspaceJob(jobName) {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
return CloudToolsEclipseProjectUpdater.updateProject(project, SubMonitor.convert(monitor));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.common.collect.Sets.SetView;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -65,9 +64,10 @@ public void launch(IModule[] modules, String launchMode) throws CoreException {
if (isRunning(existing)) {
ILaunch launch = existing.getLaunch();
Preconditions.checkNotNull(launch, "A running server should have a launch"); //$NON-NLS-1$
String detail = launchMode.equals(launch.getLaunchMode()) ? Messages.getString("SERVER_ALREADY_RUNNING") //$NON-NLS-1$
: MessageFormat.format(Messages.getString("SERVER_ALREADY_RUNNING_IN_MODE"), //$NON-NLS-1$
launch.getLaunchMode());
String detail = launchMode.equals(launch.getLaunchMode())
? Messages.getString("SERVER_ALREADY_RUNNING") //$NON-NLS-1$
: Messages.getString(
"SERVER_ALREADY_RUNNING_IN_MODE", launch.getLaunchMode()); //$NON-NLS-1$
throw new CoreException(StatusUtil.info(this, detail));
}
server = existing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
import java.io.IOException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
Expand All @@ -63,18 +65,15 @@ public class ImportNativeAppEngineStandardProjectTest extends BaseProjectTest {
public TemporaryFolder tempFolder = new TemporaryFolder();

@Test
public void importAppEngineStandardJava7_from1_3_1() throws IOException, CoreException {
public void testImportAppEngineStandardJava7_from1_3_1() throws IOException, CoreException {
assertFalse(projectExists("AESv7"));
ZipUtil.extractZip(new URL(
"platform:/plugin/com.google.cloud.tools.eclipse.integration.appengine/test-projects/cte-1_3_1-appengine-standard-java7.zip"),
tempFolder.getRoot());
project = SwtBotAppEngineActions.importNativeProject(bot, "AESv7", tempFolder.getRoot());
assertTrue(project.exists());

updateOldContainers();

ProjectUtils.waitForProjects(project);
ProjectUtils.waitUntilNoBuildErrors(project);
updateOldContainers(project);

IFacetedProject facetedProject = ProjectFacetsManager.create(project);
assertNotNull("should be a faceted project", facetedProject);
Expand All @@ -90,7 +89,7 @@ public void importAppEngineStandardJava7_from1_3_1() throws IOException, CoreExc
}

@Test
public void importAppEngineStandardJava8_from1_3_1() throws IOException, CoreException {
public void testImportAppEngineStandardJava8_from1_3_1() throws IOException, CoreException {
Assume.assumeTrue(JavaRuntimeUtils.hasJavaSE8());
assertFalse(projectExists("AESv8"));
ZipUtil.extractZip(new URL(
Expand All @@ -99,10 +98,7 @@ public void importAppEngineStandardJava8_from1_3_1() throws IOException, CoreExc
project = SwtBotAppEngineActions.importNativeProject(bot, "AESv8", tempFolder.getRoot());
assertTrue(project.exists());

updateOldContainers();

ProjectUtils.waitForProjects(project);
ProjectUtils.waitUntilNoBuildErrors(project);
updateOldContainers(project);

IFacetedProject facetedProject = ProjectFacetsManager.create(project);
assertNotNull("should be a faceted project", facetedProject);
Expand All @@ -117,10 +113,44 @@ public void importAppEngineStandardJava8_from1_3_1() throws IOException, CoreExc
facetedProject.getProjectFacetVersion(WebFacetUtils.WEB_FACET));
}

private void updateOldContainers() throws JavaModelException {
// https://github.com/GoogleCloudPlatform/google-cloud-eclipse/issues/3202
@Test
public void testImportProjectFrom131_oldStyleContainerWithAppEngineApi()
throws IOException, CoreException {
assertFalse(projectExists("old-library-container-with-appengine-api"));
ZipUtil.extractZip(new URL(
"platform:/plugin/com.google.cloud.tools.eclipse.integration.appengine/test-projects/old-library-container-with-appengine-api.zip"),
tempFolder.getRoot());
project = SwtBotAppEngineActions.importNativeProject(
bot, "old-library-container-with-appengine-api", tempFolder.getRoot());
assertTrue(project.exists());

updateOldContainers(project);

assertTrue(hasAppEngineApi(project));
}

private static boolean hasAppEngineApi(IProject project) throws JavaModelException {
IJavaProject javaProject = JavaCore.create(project);
IClasspathContainer masterContainer =
JavaCore.getClasspathContainer(BuildPath.MASTER_CONTAINER_PATH, javaProject);

for (IClasspathEntry entry : masterContainer.getClasspathEntries()) {
if (entry.getPath().lastSegment().startsWith("appengine-api-1.0-sdk")) {
return true;
}
}
return false;
}

private static void updateOldContainers(IProject project) throws CoreException {
assertTrue(CloudToolsEclipseProjectUpdater.hasOldContainers(project));
IStatus updateStatus =
CloudToolsEclipseProjectUpdater.updateProject(project, SubMonitor.convert(null));

ProjectUtils.waitForProjects(project);
ProjectUtils.waitUntilNoBuildErrors(project);

assertTrue("Update failed: " + updateStatus.getMessage(), updateStatus.isOK());
assertFalse(CloudToolsEclipseProjectUpdater.hasOldContainers(project));

Expand Down
Binary file not shown.