Skip to content

Commit 7332128

Browse files
author
jantje
committed
#1243 stuff is better but not yet fully fixed
I think
1 parent d766478 commit 7332128

File tree

1 file changed

+31
-50
lines changed

1 file changed

+31
-50
lines changed

io.sloeber.core/src/io/sloeber/core/api/BoardDescriptor.java

+31-50
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ public boolean configureProject(IProject project, IProgressMonitor monitor) {
575575
* Method to create a project based on the board
576576
*/
577577
public IProject createProject(String projectName, URI projectURI, CodeDescriptor codeDescription,
578-
CompileOptions compileOptions, IProgressMonitor monitor) {
578+
CompileOptions compileOptions, IProgressMonitor monitor) {
579579

580580
String realProjectName = Common.MakeNameCompileSafe(projectName);
581581

@@ -584,70 +584,73 @@ public IProject createProject(String projectName, URI projectURI, CodeDescriptor
584584
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
585585
ICoreRunnable runnable = new ICoreRunnable() {
586586
@Override
587-
public void run(IProgressMonitor internalMonitor) throws CoreException {
587+
public void run(IProgressMonitor internalMonitor) throws CoreException {
588588
try {
589-
// Create the base project
590589
IWorkspaceDescription workspaceDesc = workspace.getDescription();
591590
workspaceDesc.setAutoBuilding(false);
592591
workspace.setDescription(workspaceDesc);
592+
IProjectType sloeberProjType = ManagedBuildManager.getProjectType("io.sloeber.core.sketch"); //$NON-NLS-1$
593593

594+
// create a eclipse project
594595
IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
595596
if (projectURI != null) {
596597
description.setLocationURI(projectURI);
597598
}
598599

600+
// make the eclipse project a cdt project
599601
CCorePlugin.getDefault().createCProject(description, newProjectHandle, new NullProgressMonitor(),
600602
ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID);
601-
// Add the managed build nature and builder
602-
addManagedBuildNature(newProjectHandle);
603603

604-
// Find the base project type definition
605-
IProjectType projType = ManagedBuildManager.getProjectType("io.sloeber.core.sketch"); //$NON-NLS-1$
604+
// add the required natures
605+
ManagedCProjectNature.addNature(newProjectHandle, "org.eclipse.cdt.core.ccnature", internalMonitor); //$NON-NLS-1$
606+
ManagedCProjectNature.addNature(newProjectHandle, Const.ARDUINO_NATURE_ID, internalMonitor);
607+
ManagedCProjectNature.addManagedNature(newProjectHandle, internalMonitor);
608+
ManagedCProjectNature.addManagedBuilder(newProjectHandle, internalMonitor);
609+
606610

607-
// Create the managed-project (.cdtbuild) for our project that builds an
608-
// executable.
609-
IManagedProject newProject = null;
610-
newProject = ManagedBuildManager.createManagedProject(newProjectHandle, projType);
611+
612+
// make the cdt project a managed build project
613+
ManagedBuildManager.createBuildInfo(newProjectHandle);
614+
IManagedProject newProject = ManagedBuildManager.createManagedProject(newProjectHandle,
615+
sloeberProjType);
611616
ManagedBuildManager.setNewProjectVersion(newProjectHandle);
612-
// Copy over the configs
617+
// Copy over the Sloeber configs
613618
IConfiguration defaultConfig = null;
614-
IConfiguration[] configs = projType.getConfigurations();
619+
IConfiguration[] configs = sloeberProjType.getConfigurations();
615620
for (int i = 0; i < configs.length; ++i) {
621+
IConfiguration curConfig = newProject.createConfiguration(configs[i],
622+
sloeberProjType.getId() + "." + i); //$NON-NLS-1$
623+
curConfig.setArtifactName(newProject.getDefaultArtifactName());
616624
// Make the first configuration the default
617625
if (i == 0) {
618-
defaultConfig = newProject.createConfiguration(configs[i], projType.getId() + "." + i); //$NON-NLS-1$
619-
} else {
620-
newProject.createConfiguration(configs[i], projType.getId() + "." + i); //$NON-NLS-1$
626+
defaultConfig = curConfig;
621627
}
622628
}
623-
ManagedBuildManager.setDefaultConfiguration(newProjectHandle, defaultConfig);
624629

625-
IConfiguration cfgs[] = newProject.getConfigurations();
626-
for (int i = 0; i < cfgs.length; i++) {
627-
cfgs[i].setArtifactName(newProject.getDefaultArtifactName());
628-
}
630+
ManagedBuildManager.setDefaultConfiguration(newProjectHandle, defaultConfig);
629631
Map<String, IPath> librariesToAdd = codeDescription.createFiles(newProjectHandle,
630632
new NullProgressMonitor());
631633

632-
ManagedCProjectNature.addNature(newProjectHandle, "org.eclipse.cdt.core.ccnature", internalMonitor); //$NON-NLS-1$
633-
ManagedCProjectNature.addNature(newProjectHandle, Const.ARDUINO_NATURE_ID, internalMonitor);
634-
635634
CCorePlugin cCorePlugin = CCorePlugin.getDefault();
636635
ICProjectDescription prjCDesc = cCorePlugin.getProjectDescription(newProjectHandle);
637-
Libraries.addLibrariesToProject(newProjectHandle, prjCDesc.getActiveConfiguration(), librariesToAdd);
636+
638637
for (ICConfigurationDescription curConfig : prjCDesc.getConfigurations()) {
639638
compileOptions.save(curConfig);
640639
save(curConfig);
640+
Libraries.addLibrariesToProject(newProjectHandle, curConfig, librariesToAdd);
641641
}
642+
642643
SubMonitor refreshMonitor = SubMonitor.convert(internalMonitor, 3);
643644
newProjectHandle.open(refreshMonitor);
644645
newProjectHandle.refreshLocal(IResource.DEPTH_INFINITE, refreshMonitor);
645646
cCorePlugin.setProjectDescription(newProjectHandle, prjCDesc, true, null);
647+
646648
} catch (Exception e) {
647649
Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(),
648650
"Project creation failed: " + newProjectHandle.getName(), e)); //$NON-NLS-1$
649651
}
650-
Common.log(new Status(Const.SLOEBER_STATUS_DEBUG, Activator.getId(),"internal creation of project is done: "+newProjectHandle.getName())); //$NON-NLS-1$
652+
Common.log(new Status(Const.SLOEBER_STATUS_DEBUG, Activator.getId(),
653+
"internal creation of project is done: " + newProjectHandle.getName())); //$NON-NLS-1$
651654
}
652655
};
653656

@@ -656,7 +659,7 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
656659
workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, monitor);
657660
} catch (Exception e) {
658661
Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(),
659-
"Project creation failed: " + newProjectHandle.getName(),e)); //$NON-NLS-1$
662+
"Project creation failed: " + newProjectHandle.getName(), e)); //$NON-NLS-1$
660663
}
661664

662665
monitor.done();
@@ -728,8 +731,7 @@ public boolean saveConfiguration(ICConfigurationDescription confDesc, IContribut
728731
getActualCoreCodePath());
729732
IPath variantPath = getActualVariantPath();
730733
if (variantPath != null) {
731-
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_BUILD_VARIANT_PATH,
732-
variantPath);
734+
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_BUILD_VARIANT_PATH, variantPath);
733735
} else {// teensy does not use variants
734736
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_BUILD_VARIANT_PATH, emptyString);
735737
}
@@ -1100,26 +1102,5 @@ public boolean isNetworkUpload() {
11001102
return getHost() != null;
11011103
}
11021104

1103-
static private void addManagedBuildNature(IProject project) throws Exception {
1104-
// Create the buildinformation object for the project
1105-
ManagedBuildManager.createBuildInfo(project);
1106-
1107-
// Add the managed build nature
1108-
ManagedCProjectNature.addManagedNature(project, new NullProgressMonitor());
1109-
ManagedCProjectNature.addManagedBuilder(project, new NullProgressMonitor());
1110-
1111-
// Associate the project with the managed builder so the clients can get proper
1112-
// information
11131105

1114-
CCorePlugin cCorePlugin = CCorePlugin.getDefault();
1115-
ICProjectDescription projDesc = cCorePlugin.getProjectDescription(project, true);
1116-
1117-
for (ICConfigurationDescription curConfig : projDesc.getConfigurations()) {
1118-
curConfig.remove(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID);
1119-
curConfig.create(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID, ManagedBuildManager.INTERFACE_IDENTITY);
1120-
}
1121-
1122-
cCorePlugin.setProjectDescription(project, projDesc, true, null);
1123-
1124-
}
11251106
}

0 commit comments

Comments
 (0)