Non-default location maven spring-starter project corrections

This commit is contained in:
aboyko
2023-04-13 14:48:55 -04:00
parent 7b4c6beb6d
commit 0694331fdc
8 changed files with 70 additions and 35 deletions

View File

@@ -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<IProject> 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);

View File

@@ -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<IProject> oper = is.createOperation(ImportUtils.importConfig(
g,
cs
));

View File

@@ -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<IProject> {
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<IProject> createOperation(ImportConfiguration conf) {
return new GeneralProjectImport(conf);
}

View File

@@ -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<IProject> createOperation(ImportConfiguration conf);
public boolean isSupported() {
return true;

View File

@@ -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<IProject> {
//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;
}

View File

@@ -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<IProject> createOperation(ImportConfiguration conf) {
throw new IllegalStateException(getNotInstalledMessage());
}