Skip to content

Commit e1ff929

Browse files
author
jantje
committed
#1204 Add libraries at new library example crreation
That is the creation of a project based on a library example should also link in the library
1 parent e0bf907 commit e1ff929

File tree

5 files changed

+81
-60
lines changed

5 files changed

+81
-60
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.eclipse.core.runtime.SubMonitor;
4343
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
4444
import org.eclipse.core.runtime.preferences.InstanceScope;
45+
4546
import io.sloeber.core.Activator;
4647
import io.sloeber.core.InternalBoardDescriptor;
4748
import io.sloeber.core.Messages;
@@ -52,6 +53,7 @@
5253
import io.sloeber.core.managers.InternalPackageManager;
5354
import io.sloeber.core.tools.Helpers;
5455
import io.sloeber.core.tools.KeyValue;
56+
import io.sloeber.core.tools.Libraries;
5557
import io.sloeber.core.tools.Programmers;
5658
import io.sloeber.core.tools.TxtFile;
5759

@@ -624,12 +626,15 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
624626
for (int i = 0; i < cfgs.length; i++) {
625627
cfgs[i].setArtifactName(newProject.getDefaultArtifactName());
626628
}
627-
codeDescription.createFiles(newProjectHandle, new NullProgressMonitor());
629+
Map<String, IPath> librariesToAdd = codeDescription.createFiles(newProjectHandle,
630+
new NullProgressMonitor());
631+
628632
ManagedCProjectNature.addNature(newProjectHandle, "org.eclipse.cdt.core.ccnature", internalMonitor); //$NON-NLS-1$
629633
ManagedCProjectNature.addNature(newProjectHandle, Const.ARDUINO_NATURE_ID, internalMonitor);
630634

631635
CCorePlugin cCorePlugin = CCorePlugin.getDefault();
632636
ICProjectDescription prjCDesc = cCorePlugin.getProjectDescription(newProjectHandle);
637+
Libraries.addLibrariesToProject(newProjectHandle, prjCDesc.getActiveConfiguration(), librariesToAdd);
633638
for (ICConfigurationDescription curConfig : prjCDesc.getConfigurations()) {
634639
compileOptions.save(curConfig);
635640
save(curConfig);

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import java.io.InputStream;
66
import java.util.ArrayList;
77
import java.util.Map;
8-
import java.util.Set;
98
import java.util.TreeMap;
10-
import java.util.TreeSet;
119

1210
import org.apache.commons.io.FileUtils;
1311
import org.apache.commons.lang.StringUtils;
@@ -24,6 +22,7 @@
2422
import io.sloeber.core.common.InstancePreferences;
2523
import io.sloeber.core.tools.FileModifiers;
2624
import io.sloeber.core.tools.Helpers;
25+
import io.sloeber.core.tools.Libraries;
2726
import io.sloeber.core.tools.Stream;
2827

2928
/**
@@ -140,8 +139,8 @@ public void save() {
140139
* of libraries that need to be installed
141140
**/
142141
@SuppressWarnings("nls")
143-
public Set<String> createFiles(IProject project, IProgressMonitor monitor) throws CoreException {
144-
Set<String> libraries = new TreeSet<>();
142+
public Map<String, IPath> createFiles(IProject project, IProgressMonitor monitor) throws CoreException {
143+
Map<String, IPath> libraries = new TreeMap<>();
145144

146145
save();
147146
Map<String, String> replacers=new TreeMap<>();
@@ -201,7 +200,7 @@ public Set<String> createFiles(IProject project, IProgressMonitor monitor) throw
201200
FileUtils.copyDirectory(curPath.toFile(), project.getLocation().toFile());
202201
FileModifiers.addPragmaOnce(curPath);
203202
}
204-
libraries.add(getLibraryName(curPath));
203+
libraries.put(getLibraryName(curPath), Libraries.getLibraryCodeFolder(curPath));
205204
}
206205
} catch (IOException e) {
207206
e.printStackTrace();

io.sloeber.core/src/io/sloeber/core/tools/Helpers.java

+45-50
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,6 @@ public class Helpers extends Common {
9292

9393
private static boolean myHasBeenLogged = false;
9494

95-
/**
96-
* conveniance method because java does not know default values as parameters
97-
* default is isWorkSpace=true
98-
*
99-
* @param configurationDescription
100-
* @param IncludePath
101-
*/
102-
103-
public static void addIncludeFolder(ICFolderDescription folderDescription, IPath IncludePath)
104-
{
105-
addIncludeFolder( folderDescription, IncludePath,true) ;
106-
}
10795

10896
/**
10997
* This method is the internal working class that adds the provided include path
@@ -114,8 +102,10 @@ public static void addIncludeFolder(ICFolderDescription folderDescription, IPat
114102
* @param IncludePath The path to add to the include folders
115103
* @see addLibraryDependency {@link #addLibraryDependency(IProject, IProject)}
116104
*/
117-
public static void addIncludeFolder(ICFolderDescription folderDescription, IPath IncludePath,boolean isWorkspacePath) {
118-
ICLanguageSetting[] languageSettings = folderDescription.getLanguageSettings();
105+
public static void addIncludeFolder(ICConfigurationDescription configurationDescription, IPath IncludePath,
106+
boolean isWorkspacePath) {
107+
ICLanguageSetting[] languageSettings = configurationDescription.getRootFolderDescription()
108+
.getLanguageSettings();
119109
int pathSetting = ICSettingEntry.VALUE_WORKSPACE_PATH;
120110
if (!isWorkspacePath) {
121111
pathSetting = 0;
@@ -241,8 +231,7 @@ public static void LinkFolderToFolder(IProject project, IPath source, IPath targ
241231
*/
242232
public static void addCodeFolder(IProject project, IPath toLinkFolder, String LinkName,
243233
ICConfigurationDescription configurationDescription, boolean forceRoot) throws CoreException {
244-
IFolder link = project.getFolder(LinkName);
245-
ICFolderDescription folderDescription = configurationDescription.getRootFolderDescription();
234+
IFolder link = project.getFolder(LinkName);
246235

247236
LinkFolderToFolder(project, toLinkFolder, new Path(LinkName));
248237

@@ -252,29 +241,35 @@ public static void addCodeFolder(IProject project, IPath toLinkFolder, String Li
252241
String possibleIncludeFolder = "utility"; //$NON-NLS-1$
253242
File file = toLinkFolder.append(possibleIncludeFolder).toFile();
254243
if (file.exists()) {
255-
addIncludeFolder(folderDescription, link.getFullPath().append(possibleIncludeFolder));
244+
addIncludeFolder(configurationDescription, link.getFullPath().append(possibleIncludeFolder), true);
256245
}
257246

258247
if (forceRoot) {
259-
addIncludeFolder(folderDescription, link.getFullPath());
248+
addIncludeFolder(configurationDescription, link.getFullPath(), true);
260249
} else {
261250
// add src or root give priority to src
262251
possibleIncludeFolder = Library.LIBRARY_SOURCE_FODER;
263252
file = toLinkFolder.append(possibleIncludeFolder).toFile();
264253
if (file.exists()) {
265-
addIncludeFolder(folderDescription, link.getFullPath().append(possibleIncludeFolder));
254+
addIncludeFolder(configurationDescription, link.getFullPath().append(possibleIncludeFolder), true);
266255
} else {
267-
addIncludeFolder(folderDescription, link.getFullPath());
256+
addIncludeFolder(configurationDescription, link.getFullPath(), true);
268257
}
269258
}
270-
271-
possibleIncludeFolder = "arch"; //$NON-NLS-1$
272-
file = toLinkFolder.append(possibleIncludeFolder).toFile();
273-
if (file.exists()) {
274-
InternalBoardDescriptor boardDescriptor = new InternalBoardDescriptor(configurationDescription);
275-
addIncludeFolder(folderDescription,
276-
link.getFullPath().append(possibleIncludeFolder).append(boardDescriptor.getArchitecture()));
277-
}
259+
// TOFIX removed this code as part of libraries not included in project after
260+
// creation,
261+
// Should run a lib test to see how this works without this code
262+
// if this is needed I should create a include with a environment var so I do
263+
// not need to get the boardDescriptor
264+
265+
// possibleIncludeFolder = "arch"; //$NON-NLS-1$
266+
// file = toLinkFolder.append(possibleIncludeFolder).toFile();
267+
// if (file.exists()) {
268+
// InternalBoardDescriptor boardDescriptor = new
269+
// InternalBoardDescriptor(configurationDescription);
270+
// addIncludeFolder(rootFolderDescr,
271+
// link.getFullPath().append(possibleIncludeFolder).append(boardDescriptor.getArchitecture()));
272+
// }
278273
}
279274

280275
public static void removeCodeFolder(IProject project, String LinkName) throws CoreException {
@@ -285,30 +280,30 @@ public static void removeCodeFolder(IProject project, String LinkName) throws Co
285280
}
286281

287282
/**
288-
* This method creates a link folder in the project and adds the folder as a
289-
* source path to the project it also adds the path to the include folder if the
290-
* include path parameter points to a path that contains a subfolder named
291-
* "utility" this subfolder will be added to the include path as well <br/>
292-
* <br/>
293-
*
294-
* note Arduino has these subfolders in the libraries that need to be
295-
* include.<br/>
296-
* <br/>
297-
*
298-
* note that in the current eclipse version, there is no need to add the
299-
* subfolder as a code folder. This may change in the future as it looks like a
300-
* bug to me.<br/>
301-
*
302-
* @param project
303-
* @param Path
304-
* @throws CoreException
305-
*
306-
* @see addLibraryDependency {@link #addLibraryDependency(IProject, IProject)}
307-
*/
283+
* This method creates a link folder in the project descriptor and adds the
284+
* folder as a source path to the projectdescriptor it also adds the path to the
285+
* include folder if the include path parameter points to a path that contains a
286+
* subfolder named "utility" this subfolder will be added to the include path as
287+
* well <br/>
288+
* <br/>
289+
*
290+
* note Arduino has these subfolders in the libraries that need to be
291+
* include.<br/>
292+
* <br/>
293+
*
294+
* note that in the current eclipse version, there is no need to add the
295+
* subfolder as a code folder. This may change in the future as it looks like a
296+
* bug to me.<br/>
297+
*
298+
* @param project
299+
* @param Path
300+
* @throws CoreException
301+
*
302+
* @see addLibraryDependency {@link #addLibraryDependency(IProject, IProject)}
303+
*/
308304
public static void addCodeFolder(IProject project, Path Path, ICConfigurationDescription configurationDescription,
309305
boolean forceRoot) throws CoreException {
310-
311-
String NiceName = Path.lastSegment();
306+
String NiceName = Path.lastSegment();
312307
addCodeFolder(project, Path, NiceName, configurationDescription, forceRoot);
313308
}
314309

io.sloeber.core/src/io/sloeber/core/tools/Libraries.java

+24-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import io.sloeber.core.common.Const;
4646
import io.sloeber.core.common.InstancePreferences;
4747
import io.sloeber.core.managers.Library;
48-
@SuppressWarnings("unused")
48+
4949
public class Libraries {
5050
public static final String WORKSPACE_LIB_FOLDER = "libraries/"; //$NON-NLS-1$
5151
private static final String LIB = Messages.LIB;
@@ -241,7 +241,7 @@ public static void addLibrariesToProject(IProject project,
241241
* the list of libraries to add
242242
* @return true if the configuration description has changed
243243
*/
244-
private static void addLibrariesToProject(IProject project,
244+
public static void addLibrariesToProject(IProject project,
245245
ICConfigurationDescription confdesc, Map<String, IPath> libraries) {
246246
List<IPath> foldersToRemoveFromBuildPath = new LinkedList<>();
247247
for (Entry<String, IPath> CurItem : libraries.entrySet()) {
@@ -593,4 +593,26 @@ public boolean accept(File dir, String name) {
593593
return map;
594594
}
595595

596+
/**
597+
* based on a folder inside the library get the folder that starts the library
598+
* if that path is not found will return path
599+
*
600+
* @param path
601+
* path somewhere inside the library
602+
* @return path to the source code
603+
*/
604+
public static IPath getLibraryCodeFolder(IPath path) {
605+
// is it a Sloeber managed Library
606+
IPath libraryInstallPath = ConfigurationPreferences.getInstallationPathLibraries();
607+
if (libraryInstallPath.matchingFirstSegments(path) == libraryInstallPath.segmentCount()) {
608+
return path.uptoSegment(libraryInstallPath.segmentCount() + 2);
609+
}
610+
// is it a library of the hardware
611+
IPath hardwareInstallPath = ConfigurationPreferences.getInstallationPathPackages();
612+
if (hardwareInstallPath.matchingFirstSegments(path) == hardwareInstallPath.segmentCount()) {
613+
return path.uptoSegment(hardwareInstallPath.segmentCount() + 6);
614+
}
615+
return path;
616+
}
617+
596618
}

io.sloeber.tests/src/io/sloeber/core/NightlyJenkins.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
@RunWith(Suite.class)
1111
// removed NightlyBoardPatronTest due to issue #1204
1212
//this should be reenabled after #1204 is fixed
13-
//@SuiteClasses({ NightlyBoardPatronTest.class, RegressionTest.class,
14-
@SuiteClasses({ RegressionTest.class,
13+
@SuiteClasses({ NightlyBoardPatronTest.class, RegressionTest.class,
14+
// @SuiteClasses({ RegressionTest.class,
1515
RegressionTestFailingOnTravis.class })
1616
public class NightlyJenkins {
1717
@BeforeClass

0 commit comments

Comments
 (0)