54
54
55
55
@ SuppressWarnings ({ "nls" , "restriction" ,"unused" })
56
56
public class PdePreprocessor {
57
- private static String oldGeneratedFile = ".ino.cpp" ;// somethimes having the
57
+ private static String oldGeneratedFile = ".ino.cpp" ;// Sometimes having the
58
58
// file hidden is
59
59
// annoying
60
60
private static String generatedFile = "sloeber.ino.cpp" ;
61
61
private static final String DEFINE_IN_ECLIPSE = "__IN_ECLIPSE__" ;
62
62
private static final String NEWLINE = "\n " ;
63
63
64
64
public static void processProject (boolean canSkip ,IProject iProject ) throws CoreException {
65
- deleteTheGeneratedFileInPreviousBersionsOfSloeber (iProject );
65
+ deleteTheGeneratedFileInPreviousVersionsOfSloeber (iProject );
66
66
67
67
// loop through all the files in the project to see we need to generate a file
68
68
//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
79
79
80
80
81
81
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
83
83
// renaming ino files to cpp files removing the need for
84
- // .ino.cpp file
84
+ // the generated file
85
85
deleteTheGeneratedFile (iProject );
86
86
return ;
87
87
}
@@ -131,14 +131,60 @@ public static void processProject(boolean canSkip,IProject iProject) throws Core
131
131
}
132
132
133
133
/**
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
+ */
142
188
private static void writeTheGeneratedFile (IProject iProject , String content ) throws CoreException {
143
189
144
190
// Make sure the file is not processed by Arduino IDE
@@ -301,7 +347,7 @@ private static String extendIncludedInoPartForFile(String existingIncludeCodePar
301
347
302
348
}
303
349
304
- private static void deleteTheGeneratedFileInPreviousBersionsOfSloeber (IProject iProject ) throws CoreException {
350
+ private static void deleteTheGeneratedFileInPreviousVersionsOfSloeber (IProject iProject ) throws CoreException {
305
351
IResource inofile = iProject .findMember (oldGeneratedFile );
306
352
if (inofile != null ) {
307
353
inofile .delete (true , null );
0 commit comments