Skip to content

Commit 0834d80

Browse files
author
jantje
committed
#1260 add a generator dummy creation and a delete
1 parent 9bcff8c commit 0834d80

File tree

1 file changed

+59
-13
lines changed

1 file changed

+59
-13
lines changed

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

+59-13
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@
5454

5555
@SuppressWarnings({ "nls", "restriction","unused" })
5656
public class PdePreprocessor {
57-
private static String oldGeneratedFile = ".ino.cpp";// somethimes having the
57+
private static String oldGeneratedFile = ".ino.cpp";// Sometimes having the
5858
// file hidden is
5959
// annoying
6060
private static String generatedFile = "sloeber.ino.cpp";
6161
private static final String DEFINE_IN_ECLIPSE = "__IN_ECLIPSE__";
6262
private static final String NEWLINE = "\n";
6363

6464
public static void processProject(boolean canSkip,IProject iProject) throws CoreException {
65-
deleteTheGeneratedFileInPreviousBersionsOfSloeber(iProject);
65+
deleteTheGeneratedFileInPreviousVersionsOfSloeber(iProject);
6666

6767
// loop through all the files in the project to see we need to generate a file
6868
//This way we can avoid hitting the indexer when we use .cpp files
@@ -79,9 +79,9 @@ public static void processProject(boolean canSkip,IProject iProject) throws Core
7979

8080

8181
if (inoResources.isEmpty()) {
82-
// delete the generated .ino.cpp file this is to cope with
82+
// delete the generated file this is to cope with
8383
// renaming ino files to cpp files removing the need for
84-
// .ino.cpp file
84+
// the generated file
8585
deleteTheGeneratedFile(iProject);
8686
return;
8787
}
@@ -131,14 +131,60 @@ public static void processProject(boolean canSkip,IProject iProject) throws Core
131131
}
132132

133133
/**
134-
* Add some operational stuff and write the file if changed
135-
*
136-
* @param iProject
137-
* the project for which the ino files have been parsed
138-
* @param content
139-
* the ouput of the ino file parsing
140-
* @throws CoreException
141-
*/
134+
* Make a dummy sloeber.ino.cpp file if there is at least 1 .ino .pde file The
135+
* file is created to have the makefile process it
136+
*
137+
* @param iProject
138+
*/
139+
public static void writeDummySloeberInoCPPFile(IProject iProject) {
140+
try {
141+
List<IResource> allResources = new ArrayList<>();
142+
List<IResource> inoResources = new ArrayList<>();
143+
allResources.addAll(Arrays.asList(iProject.members(0)));
144+
for (IResource curResource : allResources) {
145+
String extension = curResource.getFileExtension();
146+
if (extension != null && ((extension.equals("pde") || extension.equals("ino")))) {
147+
String header = "//This is a automatic generated file" + NEWLINE;
148+
header += "//Please do not modify this file" + NEWLINE;
149+
header += "//If you touch this file your change will be overwritten during the next build"
150+
+ NEWLINE;
151+
header += "//This file has been generated on during project creation " + NEWLINE;
152+
writeTheGeneratedFile(iProject, header);
153+
return;
154+
}
155+
}
156+
} catch (CoreException e) {
157+
// TODO Auto-generated catch block
158+
e.printStackTrace();
159+
}
160+
}
161+
162+
/**
163+
* Delete the sloeber.ino.cpp or .ino.cpp file if there is one
164+
*
165+
* @param iProject
166+
* @throws CoreException
167+
*/
168+
public static void deleteSloeberInoCPPFile(IProject iProject) throws CoreException {
169+
IResource sloeberInoCpp = iProject.findMember(generatedFile);
170+
if (sloeberInoCpp != null) {
171+
sloeberInoCpp.delete(true, null);
172+
}
173+
sloeberInoCpp = iProject.findMember(oldGeneratedFile);
174+
if (sloeberInoCpp != null) {
175+
sloeberInoCpp.delete(true, null);
176+
}
177+
}
178+
179+
/**
180+
* Add some operational stuff and write the file if changed
181+
*
182+
* @param iProject
183+
* the project for which the ino files have been parsed
184+
* @param content
185+
* the ouput of the ino file parsing
186+
* @throws CoreException
187+
*/
142188
private static void writeTheGeneratedFile(IProject iProject, String content) throws CoreException {
143189

144190
// Make sure the file is not processed by Arduino IDE
@@ -301,7 +347,7 @@ private static String extendIncludedInoPartForFile(String existingIncludeCodePar
301347

302348
}
303349

304-
private static void deleteTheGeneratedFileInPreviousBersionsOfSloeber(IProject iProject) throws CoreException {
350+
private static void deleteTheGeneratedFileInPreviousVersionsOfSloeber(IProject iProject) throws CoreException {
305351
IResource inofile = iProject.findMember(oldGeneratedFile);
306352
if (inofile != null) {
307353
inofile.delete(true, null);

0 commit comments

Comments
 (0)