From 0694331fdc8683390036ffc9f38d3a9b5f7833e6 Mon Sep 17 00:00:00 2001 From: aboyko Date: Thu, 13 Apr 2023 14:48:55 -0400 Subject: [PATCH] Non-default location maven spring-starter project corrections --- .../boot/wizard/NewSpringBootWizardModel.java | 22 ++++++++++++------- .../wizard/guides/GSImportWizardModel.java | 7 +++--- .../importing/GeneralProjectStrategy.java | 11 +++++----- .../boot/wizard/importing/ImportStrategy.java | 7 +++--- .../boot/wizard/importing/MavenStrategy.java | 18 ++++++++------- .../wizard/importing/NullImportStrategy.java | 7 +++--- .../Buildship30ImportStrategy.java | 12 +++++----- .../core/IRunnableWithProgressAndResult.java | 21 ++++++++++++++++++ 8 files changed, 70 insertions(+), 35 deletions(-) create mode 100644 eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/IRunnableWithProgressAndResult.java diff --git a/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/NewSpringBootWizardModel.java b/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/NewSpringBootWizardModel.java index 4f9575324..722572f86 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/NewSpringBootWizardModel.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/NewSpringBootWizardModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2017 Pivotal, Inc. + * Copyright (c) 2013, 2023 Pivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -26,12 +26,11 @@ import java.util.Set; import org.apache.commons.lang3.StringUtils; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.IWorkingSetManager; @@ -48,6 +47,7 @@ import org.springframework.ide.eclipse.boot.wizard.content.BuildType; import org.springframework.ide.eclipse.boot.wizard.content.CodeSet; import org.springframework.ide.eclipse.boot.wizard.importing.ImportStrategy; import org.springframework.ide.eclipse.boot.wizard.importing.ImportUtils; +import org.springsource.ide.eclipse.commons.core.IRunnableWithProgressAndResult; import org.springsource.ide.eclipse.commons.core.util.NameGenerator; import org.springsource.ide.eclipse.commons.frameworks.core.downloadmanager.DownloadManager; import org.springsource.ide.eclipse.commons.frameworks.core.downloadmanager.DownloadableItem; @@ -335,15 +335,21 @@ public class NewSpringBootWizardModel { if (strat==null) { strat = BuildType.GENERAL.getDefaultStrategy(); } - IRunnableWithProgress oper = strat.createOperation(ImportUtils.importConfig( + IRunnableWithProgressAndResult oper = strat.createOperation(ImportUtils.importConfig( new Path(location.getValue()), projectNameValue, cs )); - oper.run(SubMonitor.convert(mon, 3)); - - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectNameValue); - addToWorkingSets(project, SubMonitor.convert(mon, 1)); + IProject project = oper.run(SubMonitor.convert(mon, 3)); + if (project != null) { + addToWorkingSets(project, SubMonitor.convert(mon, 1)); + } else { + MessageDialog.openWarning(PlatformUI.getWorkbench().getDisplay().getActiveShell(), + "Failed to Create Project", + "Failed to create project `" + projectNameValue + + "' for the imported code set. Import code set manually into STS from folder " + + location.getValue()); + } } catch (IOException e) { throw new InvocationTargetException(e); diff --git a/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/guides/GSImportWizardModel.java b/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/guides/GSImportWizardModel.java index e0e3234ce..9d3c27ebd 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/guides/GSImportWizardModel.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/guides/GSImportWizardModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2016 Pivotal Software, Inc. + * Copyright (c) 2013, 2023 Pivotal Software, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -18,12 +18,12 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.operation.IRunnableWithProgress; import org.springframework.ide.eclipse.boot.wizard.BootWizardActivator; import org.springframework.ide.eclipse.boot.wizard.content.BuildType; import org.springframework.ide.eclipse.boot.wizard.content.CodeSet; @@ -37,6 +37,7 @@ import org.springframework.ide.eclipse.boot.wizard.importing.ImportConfiguration import org.springframework.ide.eclipse.boot.wizard.importing.ImportStrategies; import org.springframework.ide.eclipse.boot.wizard.importing.ImportStrategy; import org.springframework.ide.eclipse.boot.wizard.importing.ImportUtils; +import org.springsource.ide.eclipse.commons.core.IRunnableWithProgressAndResult; import org.springsource.ide.eclipse.commons.frameworks.core.downloadmanager.UIThreadDownloadDisallowed; import org.springsource.ide.eclipse.commons.livexp.core.LiveExpression; import org.springsource.ide.eclipse.commons.livexp.core.LiveSet; @@ -437,7 +438,7 @@ public class GSImportWizardModel { // a guide). mon.worked(1); } else { - IRunnableWithProgress oper = is.createOperation(ImportUtils.importConfig( + IRunnableWithProgressAndResult oper = is.createOperation(ImportUtils.importConfig( g, cs )); diff --git a/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/importing/GeneralProjectStrategy.java b/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/importing/GeneralProjectStrategy.java index 28acd4fde..bc43358b6 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/importing/GeneralProjectStrategy.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/importing/GeneralProjectStrategy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2016 GoPivotal, Inc. + * Copyright (c) 2013, 2023 GoPivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -26,6 +26,7 @@ import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.operation.IRunnableWithProgress; import org.springframework.ide.eclipse.boot.wizard.content.BuildType; import org.springframework.ide.eclipse.boot.wizard.content.CodeSet; +import org.springsource.ide.eclipse.commons.core.IRunnableWithProgressAndResult; import org.springsource.ide.eclipse.commons.livexp.util.ExceptionUtil; /** @@ -42,7 +43,7 @@ public class GeneralProjectStrategy extends ImportStrategy { super(buildType, name, notInstalledMessage); } - public static class GeneralProjectImport implements IRunnableWithProgress { + public static class GeneralProjectImport implements IRunnableWithProgressAndResult { private final String projectName; private final File location; @@ -54,7 +55,7 @@ public class GeneralProjectStrategy extends ImportStrategy { this.codeset = conf.getCodeSet(); } - public void run(IProgressMonitor mon) throws InvocationTargetException, InterruptedException { + public IProject run(IProgressMonitor mon) throws InvocationTargetException, InterruptedException { mon.beginTask("Create General Project '"+projectName+"'", 2); try { //1: copy/isntantiate codeset data @@ -62,7 +63,7 @@ public class GeneralProjectStrategy extends ImportStrategy { mon.worked(1); //2: create project in workspace - GeneralProjectImport.createGeneralProject(projectName, location, new SubProgressMonitor(mon, 1)); + return GeneralProjectImport.createGeneralProject(projectName, location, new SubProgressMonitor(mon, 1)); } catch (InterruptedException e) { throw e; @@ -127,7 +128,7 @@ public class GeneralProjectStrategy extends ImportStrategy { } @Override - public IRunnableWithProgress createOperation(ImportConfiguration conf) { + public IRunnableWithProgressAndResult createOperation(ImportConfiguration conf) { return new GeneralProjectImport(conf); } diff --git a/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/importing/ImportStrategy.java b/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/importing/ImportStrategy.java index 66bc4b7e6..9f10e91ac 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/importing/ImportStrategy.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/importing/ImportStrategy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 GoPivotal, Inc. + * Copyright (c) 2013, 2023 GoPivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,9 +10,10 @@ *******************************************************************************/ package org.springframework.ide.eclipse.boot.wizard.importing; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.operation.IRunnableWithProgress; import org.springframework.ide.eclipse.boot.wizard.content.BuildType; +import org.springsource.ide.eclipse.commons.core.IRunnableWithProgressAndResult; /** * Strategy for importing a certain type of getting started content @@ -31,7 +32,7 @@ public abstract class ImportStrategy { this.notInstalledMessage = notInstalledMessage; } - public abstract IRunnableWithProgress createOperation(ImportConfiguration conf); + public abstract IRunnableWithProgressAndResult createOperation(ImportConfiguration conf); public boolean isSupported() { return true; diff --git a/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/importing/MavenStrategy.java b/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/importing/MavenStrategy.java index 02e46725d..841925969 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/importing/MavenStrategy.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/importing/MavenStrategy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2016 GoPivotal, Inc. + * Copyright (c) 2013, 2023 GoPivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -16,17 +16,16 @@ import java.util.ArrayList; import java.util.List; import org.apache.maven.model.Model; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.m2e.core.MavenPlugin; import org.eclipse.m2e.core.project.IMavenProjectImportResult; import org.eclipse.m2e.core.project.MavenProjectInfo; @@ -36,6 +35,7 @@ import org.eclipse.osgi.util.NLS; import org.springframework.ide.eclipse.boot.wizard.BootWizardActivator; import org.springframework.ide.eclipse.boot.wizard.content.BuildType; import org.springframework.ide.eclipse.boot.wizard.content.CodeSet; +import org.springsource.ide.eclipse.commons.core.IRunnableWithProgressAndResult; /** * Importer strategy implementation for importing CodeSets into the workspace and set them @@ -53,7 +53,7 @@ public class MavenStrategy extends ImportStrategy { /** * Implements the import by means of 'NewGradleProjectOperation' */ - private static class MavenCodeSetImport implements IRunnableWithProgress { + private static class MavenCodeSetImport implements IRunnableWithProgressAndResult { //TODO: This import startegy doesn't even read projectName. The name actually comes from the // maven pom file. Actually makes sense for inport to determine projectName from project @@ -70,7 +70,7 @@ public class MavenStrategy extends ImportStrategy { } @Override - public void run(IProgressMonitor mon) throws InvocationTargetException, InterruptedException { + public IProject run(IProgressMonitor mon) throws InvocationTargetException, InterruptedException { mon.beginTask("Create maven project "+projectName, 5); Job.getJobManager().beginRule(getRule(), new SubProgressMonitor(mon, 1)); try { @@ -82,7 +82,7 @@ public class MavenStrategy extends ImportStrategy { File pomFile = new File(location, "pom.xml"); Assert.isTrue(pomFile.isFile(), "No pom file found: "+pomFile); Assert.isTrue(pomFile.length()>0, "Pom file contains no data: "+pomFile); - createEclipseProjectFromExistingMavenProject(pomFile, new SubProgressMonitor(mon, 3)); + return createEclipseProjectFromExistingMavenProject(pomFile, new SubProgressMonitor(mon, 3)); } catch (InterruptedException e) { throw e; } catch (InvocationTargetException e) { @@ -102,11 +102,11 @@ public class MavenStrategy extends ImportStrategy { } @Override - public IRunnableWithProgress createOperation(ImportConfiguration conf) { + public MavenCodeSetImport createOperation(ImportConfiguration conf) { return new MavenCodeSetImport(conf); } - protected static void createEclipseProjectFromExistingMavenProject(File pomFile, IProgressMonitor monitor) throws CoreException { + protected static IProject createEclipseProjectFromExistingMavenProject(File pomFile, IProgressMonitor monitor) throws CoreException { Model model = MavenPlugin.getMavenModelManager().readMavenModel(pomFile); String derivedProjectName = model.getName(); if (derivedProjectName == null) { @@ -138,6 +138,8 @@ public class MavenStrategy extends ImportStrategy { if (importResult.getProject() != null) MavenPlugin.getProjectConfigurationManager().updateProjectConfiguration(importResult.getProject(), monitor); } + + return importResults != null && importResults.size() > 0 ? importResults.get(0).getProject() : null; } diff --git a/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/importing/NullImportStrategy.java b/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/importing/NullImportStrategy.java index 80c434959..275043e59 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/importing/NullImportStrategy.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.boot.wizard/src/org/springframework/ide/eclipse/boot/wizard/importing/NullImportStrategy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2015 Pivotal, Inc. + * Copyright (c) 2013, 2023 Pivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,8 +10,9 @@ *******************************************************************************/ package org.springframework.ide.eclipse.boot.wizard.importing; -import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.core.resources.IProject; import org.springframework.ide.eclipse.boot.wizard.content.BuildType; +import org.springsource.ide.eclipse.commons.core.IRunnableWithProgressAndResult; /** * Import stratgety used in place of a Strategy that could not be instantiated, presumably because @@ -26,7 +27,7 @@ public class NullImportStrategy extends ImportStrategy { } @Override - public IRunnableWithProgress createOperation(ImportConfiguration conf) { + public IRunnableWithProgressAndResult createOperation(ImportConfiguration conf) { throw new IllegalStateException(getNotInstalledMessage()); } diff --git a/eclipse-extensions/org.springframework.ide.eclipse.buildship30/src/org/springframework/ide/eclipse/buildship30/Buildship30ImportStrategy.java b/eclipse-extensions/org.springframework.ide.eclipse.buildship30/src/org/springframework/ide/eclipse/buildship30/Buildship30ImportStrategy.java index 351fc4e7b..26fc46dd2 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.buildship30/src/org/springframework/ide/eclipse/buildship30/Buildship30ImportStrategy.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.buildship30/src/org/springframework/ide/eclipse/buildship30/Buildship30ImportStrategy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2020 Pivotal, Inc. + * Copyright (c) 2015, 2023 Pivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -29,11 +29,11 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.jface.operation.IRunnableWithProgress; import org.springframework.ide.eclipse.boot.wizard.content.BuildType; import org.springframework.ide.eclipse.boot.wizard.importing.ImportConfiguration; import org.springframework.ide.eclipse.boot.wizard.importing.ImportStrategy; import org.springframework.ide.eclipse.boot.wizard.importing.ImportStrategyFactory; +import org.springsource.ide.eclipse.commons.core.IRunnableWithProgressAndResult; import org.springsource.ide.eclipse.commons.core.SpringCoreUtils; import org.springsource.ide.eclipse.commons.core.util.NatureUtils; import org.springsource.ide.eclipse.commons.livexp.util.ExceptionUtil; @@ -62,10 +62,10 @@ public class Buildship30ImportStrategy extends ImportStrategy { } @Override - public IRunnableWithProgress createOperation(final ImportConfiguration conf) { - return new IRunnableWithProgress() { + public IRunnableWithProgressAndResult createOperation(final ImportConfiguration conf) { + return new IRunnableWithProgressAndResult() { @Override - public void run(IProgressMonitor mon) throws InvocationTargetException, InterruptedException { + public IProject run(IProgressMonitor mon) throws InvocationTargetException, InterruptedException { mon.beginTask("Import Gradle Buildship project", 10); try { File loc = new File(conf.getLocation()); @@ -95,6 +95,7 @@ public class Buildship30ImportStrategy extends ImportStrategy { } catch (CoreException e) { //Ignore: happens in STS 4 which no longer has spring nature. } + return p; } } } @@ -102,6 +103,7 @@ public class Buildship30ImportStrategy extends ImportStrategy { //Try not to loose the error completely. throw ExceptionUtil.coreException(buildResult.getStatus()); } + return null; } catch (Exception e) { if (e instanceof InterruptedException) { throw (InterruptedException)e; diff --git a/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/IRunnableWithProgressAndResult.java b/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/IRunnableWithProgressAndResult.java new file mode 100644 index 000000000..9b16300ca --- /dev/null +++ b/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/IRunnableWithProgressAndResult.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2023 VMware, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VMware, Inc. - initial API and implementation + *******************************************************************************/ +package org.springsource.ide.eclipse.commons.core; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.runtime.IProgressMonitor; + +public interface IRunnableWithProgressAndResult { + + public T run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException; + +}