1 /*
2 AntMake
3
4 Copyright (C) 2004 Jose San Leandro Armend?riz
5 jsanleandro@yahoo.es
6 chousz@yahoo.com
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 Thanks to ACM S.L. for distributing this library under the GPL license.
23 Contact info: jsr000@terra.es
24 Postal Address: c/Playa de Lagoa, 1
25 Urb. Valdecaba?as
26 Boadilla del monte
27 28660 Madrid
28 Spain
29
30 ******************************************************************************
31 *
32 * Filename: $RCSfile: AntMake.java,v $
33 *
34 * Author: Jose San Leandro Armend?riz
35 *
36 * Description: Manages the creation of required GNU Autotools files from
37 * a sets of Java source files.
38 *
39 * Last modified by: $Author: chous $ at $Date: 2004/02/01 17:21:12 $
40 *
41 * File version: $Revision: 1.14 $
42 *
43 * Project version: $Name: $
44 *
45 * $Id: AntMake.java,v 1.14 2004/02/01 17:21:12 chous Exp $
46 *
47 */
48 package org.acmsl.antmake;
49
50 /*
51 * Importing project classes.
52 */
53 import org.acmsl.antmake.AntMakeException;
54 import org.acmsl.antmake.AntMakeTask;
55 import org.acmsl.antmake.AntMakeUtils;
56 import org.acmsl.antmake.ConfigureInTemplate;
57 import org.acmsl.antmake.ConfigureInTemplateGenerator;
58 import org.acmsl.antmake.cvslib.CvsUtils;
59 import org.acmsl.antmake.FolderStructureHelper;
60 import org.acmsl.antmake.MakefileAmTemplate;
61 import org.acmsl.antmake.MakefileAmTemplateGenerator;
62 import org.acmsl.antmake.MakeRulesTemplate;
63 import org.acmsl.antmake.MakeRulesTemplateGenerator;
64 import org.acmsl.antmake.TopMakefileAmTemplate;
65 import org.acmsl.antmake.TopMakefileAmTemplateGenerator;
66
67 /*
68 * Importing some ACM-SL Commons classes.
69 */
70 import org.acmsl.commons.utils.io.FileUtils;
71
72 /*
73 * Importing some Ant classes.
74 */
75 import org.apache.tools.ant.AntClassLoader;
76 import org.apache.tools.ant.Project;
77 import org.apache.tools.ant.Task;
78 import org.apache.tools.ant.types.FileSet;
79 import org.apache.tools.ant.types.Path;
80
81 /*
82 * Importing some JDK1.3 classes.
83 */
84 import java.io.File;
85 import java.io.FileNotFoundException;
86 import java.io.IOException;
87 import java.lang.ref.WeakReference;
88 import java.lang.SecurityException;
89 import java.util.Collection;
90 import java.util.ArrayList;
91 import java.util.HashMap;
92 import java.util.Iterator;
93 import java.util.Map;
94
95 /***
96 * Manages the creation of required GNU Autotools files from
97 * a sets of Java source files.
98 * @author <a href="mailto:jsanleandro@yahoo.es"
99 >Jose San Leandro Armend?riz</a>
100 * @version $Revision: 1.14 $
101 */
102 public abstract class AntMake
103 {
104 /***
105 * Cached empty String array.
106 */
107 public static final String[] EMPTY_STRING_ARRAY = new String[0];
108
109 /***
110 * Singleton implemented as a weak reference.
111 */
112 private static WeakReference singleton;
113
114 /***
115 * Specifies a new weak reference.
116 * @param instance the instance to use.
117 */
118 protected static void setReference(AntMake instance)
119 {
120 singleton = new WeakReference(instance);
121 }
122
123 /***
124 * Retrieves the weak reference.
125 * @return such reference.
126 */
127 protected static WeakReference getReference()
128 {
129 return singleton;
130 }
131
132 /***
133 * Retrieves an AntMake instance.
134 * @return such instance.
135 */
136 public static AntMake getInstance()
137 {
138 AntMake result = null;
139
140 WeakReference reference = getReference();
141
142 if (reference != null)
143 {
144 result = (AntMake) reference.get();
145 }
146
147 if (result == null)
148 {
149 result = new AntMake() {};
150
151 setReference(result);
152 }
153
154 return result;
155 }
156
157 /***
158 * Protected constructor to avoid accidental instantiation.
159 */
160 protected AntMake() {};
161
162 /***
163 * Creates the basic folder structure starting from given
164 * folder.
165 * @param projectName the project name.
166 * @param projectVersion the project version.
167 * @param baseFolder the base folder.
168 * @param fileSet the file sets.
169 * @param classpath the class path.
170 * @param task the AntMake task (only for logging purposes).
171 * @throws AntMakeException if the project cannot be built for
172 * some reason.
173 */
174 public void buildProject(
175 String projectName,
176 String projectVersion,
177 File baseFolder,
178 FileSet[] fileSets,
179 Path classpath,
180 AntMakeTask task)
181 throws AntMakeException
182 {
183 AntMakeUtils t_AntMakeUtils =
184 AntMakeUtils.getInstance();
185
186 FolderStructureHelper t_FolderStructureHelper =
187 FolderStructureHelper.getInstance();
188
189 File t_TempFolder = null;
190
191 try
192 {
193 t_TempFolder =
194 t_FolderStructureHelper.createTempFolder();
195 }
196 catch (IOException ioException)
197 {
198 throw new AntMakeException(
199 "cannot create temporary folder",
200 ioException);
201 }
202
203 try
204 {
205 // Retrieves the concrete files to be copied, and copies them
206 // to the temporary folder.
207 File[] t_aFiles =
208 t_AntMakeUtils.mergeFiles(fileSets, t_TempFolder, task);
209
210 // Create the folder layout in destination folder.
211 t_FolderStructureHelper.createFolderStructure(
212 baseFolder, t_TempFolder, t_aFiles, task);
213
214 AntClassLoader t_ClassLoader =
215 new AntClassLoader(task.getProject(), task.getClasspath());
216
217 // Create fixed files:
218 // acinclude.m4, aclocal.m4, libtool.m4, ltmain.sh
219 copyFiles(
220 t_FolderStructureHelper,
221 baseFolder,
222 task,
223 t_ClassLoader);
224
225 // Copy libraries
226 String[] t_astrDependencies =
227 copyDependencies(baseFolder, classpath, task);
228
229 // Create Make-rules file
230 createMakeRulesFile(
231 projectName, baseFolder, t_astrDependencies, task);
232
233 // Create configure.in file
234 createConfigureInFile(
235 projectName, projectVersion, baseFolder, t_aFiles, task);
236
237 // Create top-level Makefile.am file
238 createTopMakefileAmFile(
239 projectName, baseFolder, t_aFiles, task);
240
241 // Create child Makefile.am files
242 // Create top-level Makefile.am file
243 createMakefileAmFiles(
244 projectName, baseFolder, t_aFiles, task);
245
246 // Copy README, AUTHORS and LICENSE.
247 copyFixedFiles(
248 baseFolder,
249 task);
250
251 // Create ChangeLog file
252 generateChangeLog(
253 task.getProject().getBaseDir(),
254 baseFolder.getAbsolutePath() + File.separator + "ChangeLog",
255 task);
256 }
257 catch (AntMakeException antMakeException)
258 {
259 throw antMakeException;
260 }
261 finally
262 {
263 t_TempFolder.delete();
264 }
265 }
266
267 /***
268 * Copies the fixed files.
269 * @param folderStructureHelper the helper.
270 * @param baseFolder the base folder.
271 * @param task the AntMake tas.
272 * @param classLoader the class loader used to get the
273 * macro files from the class path.
274 * @throws AntMakeException if some files are not found.
275 */
276 protected void copyFiles(
277 FolderStructureHelper folderStructureHelper,
278 File baseFolder,
279 AntMakeTask task,
280 ClassLoader classLoader)
281 throws AntMakeException
282 {
283 IOException t_Exception = null;
284
285 // Create fixed files:
286 // acinclude.m4, aclocal.m4, libtool.m4, ltmain.sh
287 try
288 {
289 copyFile(
290 "acinclude.m4",
291 folderStructureHelper,
292 baseFolder,
293 task,
294 classLoader);
295 }
296 catch (IOException ioException)
297 {
298 task.getProject().log(
299 task, "" + ioException, Project.MSG_ERR);
300
301 t_Exception = ioException;
302 }
303
304 if (t_Exception == null)
305 {
306 try
307 {
308 copyFile(
309 "aclocal.m4",
310 folderStructureHelper,
311 baseFolder,
312 task,
313 classLoader);
314 }
315 catch (IOException ioException)
316 {
317 task.getProject().log(
318 task, "" + ioException, Project.MSG_ERR);
319
320 t_Exception = ioException;
321 }
322 }
323
324 if (t_Exception == null)
325 {
326 try
327 {
328 copyFile(
329 "libtool.m4",
330 folderStructureHelper,
331 baseFolder,
332 task,
333 classLoader);
334 }
335 catch (IOException ioException)
336 {
337 task.getProject().log(
338 task, "" + ioException, Project.MSG_ERR);
339
340 t_Exception = ioException;
341 }
342 }
343
344 if (t_Exception == null)
345 {
346 try
347 {
348 copyFile(
349 "ltmain.sh",
350 folderStructureHelper,
351 baseFolder,
352 task,
353 classLoader);
354 }
355 catch (IOException ioException)
356 {
357 task.getProject().log(
358 task, "" + ioException, Project.MSG_ERR);
359
360 t_Exception = ioException;
361 }
362 }
363
364 if (t_Exception != null)
365 {
366 throw new AntMakeException(
367 "cannot copy required files",
368 t_Exception);
369 }
370 }
371
372 /***
373 * Copies a concrete file.
374 * @param fileName the name of the file.
375 * @param folderStructureHelper the helper.
376 * @param baseFolder the base folder.
377 * @param task the AntMake tas.
378 * @param classLoader the class loader used to get the
379 * macro files from the class path.
380 * @throws IOException if some files are not found.
381 */
382 protected void copyFile(
383 String fileName,
384 FolderStructureHelper folderStructureHelper,
385 File baseFolder,
386 AntMakeTask task,
387 ClassLoader classLoader)
388 throws IOException
389 {
390 folderStructureHelper.copy(
391 fileName,
392 baseFolder,
393 task,
394 classLoader);
395 }
396
397 /***
398 * Copies the required dependencies from the classpath.
399 * @param baseFolder the base folder.
400 * @param classpath the classpath.
401 * @param task the task, for logging purposes.
402 * @return the references to the new location of the dependencies.
403 * @throws AntMakeException if the dependencies could not be copied.
404 */
405 protected String[] copyDependencies(
406 File baseFolder, Path classpath, Task task)
407 throws AntMakeException
408 {
409 String[] result = EMPTY_STRING_ARRAY;
410
411 if (classpath != null)
412 {
413 result =
414 copyDependencies(
415 baseFolder,
416 classpath.list(),
417 "lib",
418 task);
419 }
420
421 return result;
422 }
423
424 /***
425 * Copies the required dependencies from the classpath.
426 * @param baseFolder the base folder.
427 * @param dependencies the dependencies.
428 * @param relativeFolder the relative folder for storing the
429 * dependencies starting from <i>basefolder</i>.
430 * @param task the task, for logging purposes.
431 * @return the references to the new location of the dependencies.
432 * @throws AntMakeException if the dependencies could not be copied.
433 */
434 protected String[] copyDependencies(
435 File baseFolder,
436 String[] dependencies,
437 String relativeFolder,
438 Task task)
439 throws AntMakeException
440 {
441 Collection t_cResult = new ArrayList();
442
443 org.apache.tools.ant.util.FileUtils fileUtils =
444 org.apache.tools.ant.util.FileUtils.newFileUtils();
445
446 if ( (fileUtils != null)
447 && (baseFolder != null)
448 && (dependencies != null)
449 && (relativeFolder != null))
450 {
451 String t_strCurrentDependency = null;
452
453 String t_strRelativeDestination = null;
454
455 File t_CurrentFile = null;
456
457 try
458 {
459 new File(
460 baseFolder.getAbsolutePath()
461 + File.separator
462 + relativeFolder)
463 .mkdirs();
464
465 for (int t_iDependencyIndex = 0;
466 t_iDependencyIndex < dependencies.length;
467 t_iDependencyIndex++)
468 {
469 t_strCurrentDependency =
470 dependencies[t_iDependencyIndex];
471
472 t_CurrentFile = new File(t_strCurrentDependency);
473
474 if ( (t_CurrentFile.exists())
475 && (t_CurrentFile.isFile())
476 && (t_CurrentFile.canRead()))
477 {
478 t_strRelativeDestination =
479 File.separator
480 + relativeFolder
481 + File.separator
482 + t_CurrentFile.getName();
483
484 t_cResult.add(t_strRelativeDestination);
485
486 fileUtils.copyFile(
487 t_strCurrentDependency,
488 baseFolder.getAbsolutePath()
489 + File.separator
490 + t_strRelativeDestination);
491 }
492 }
493 }
494 catch (FileNotFoundException fileNotFoundException)
495 {
496 task.getProject().log(
497 task, "" + fileNotFoundException, Project.MSG_ERR);
498
499 throw new AntMakeException(
500 "cannot copy " + t_strCurrentDependency,
501 fileNotFoundException);
502 }
503 catch (SecurityException securityException)
504 {
505 task.getProject().log(
506 task, "" + securityException, Project.MSG_ERR);
507
508 throw new AntMakeException(
509 "cannot copy " + t_strCurrentDependency,
510 securityException);
511 }
512 catch (IOException ioException)
513 {
514 task.getProject().log(
515 task, "" + ioException, Project.MSG_ERR);
516
517 throw new AntMakeException(
518 "cannot copy " + t_strCurrentDependency,
519 ioException);
520 }
521 }
522
523 return (String[]) t_cResult.toArray(new String[0]);
524 }
525
526 /***
527 * Creates the Make-rules file.
528 * @param projectName the project name.
529 * @param baseFolder the base folder.
530 * @param dependencies the dependencies.
531 * @param task the task (for logging purposes).
532 * throws AntMakeException if the Make-rules file cannot
533 * be created.
534 */
535 protected void createMakeRulesFile(
536 String projectName, File baseFolder, String[] dependencies, Task task)
537 throws AntMakeException
538 {
539 createMakeRulesFile(
540 MakeRulesTemplateGenerator.getInstance(),
541 projectName,
542 baseFolder,
543 dependencies,
544 task);
545 }
546
547 /***
548 * Creates the Make-rules file.
549 * @param generator the template generator.
550 * @param projectName the project name.
551 * @param baseFolder the base folder.
552 * @param dependencies the dependencies.
553 * @param task the task (for logging purposes).
554 * throws AntMakeException if the Make-rules file cannot
555 * be created.
556 */
557 protected void createMakeRulesFile(
558 MakeRulesTemplateGenerator generator,
559 String projectName,
560 File baseFolder,
561 String[] dependencies,
562 Task task)
563 throws AntMakeException
564 {
565 if ( (generator != null)
566 && (projectName != null)
567 && (baseFolder != null)
568 && (dependencies != null))
569 {
570 MakeRulesTemplate t_Template =
571 generator.createMakeRulesTemplate(projectName);
572
573 if (t_Template != null)
574 {
575 for (int t_iItemIndex = 0;
576 t_iItemIndex < dependencies.length;
577 t_iItemIndex++)
578 {
579 t_Template.addClasspathItem(
580 dependencies[t_iItemIndex]);
581 }
582
583 generator.write(t_Template, baseFolder, task);
584 }
585 }
586 }
587
588 /***
589 * Creates the <i>configure.in</i> file.
590 * @param projectName the project name.
591 * @param projectVersion the project version.
592 * @param baseFolder the base folder.
593 * @param sourceFiles the source files.
594 * @param task the task (for logging purposes).
595 * throws AntMakeException if the configure.in file cannot
596 * be created.
597 */
598 protected void createConfigureInFile(
599 String projectName,
600 String projectVersion,
601 File baseFolder,
602 File[] sourceFiles,
603 Task task)
604 throws AntMakeException
605 {
606 createConfigureInFile(
607 ConfigureInTemplateGenerator.getInstance(),
608 AntMakeUtils.getInstance(),
609 projectName,
610 projectVersion,
611 baseFolder,
612 sourceFiles,
613 task);
614 }
615
616 /***
617 * Creates the <i>configure.in</i> file.
618 * @param generator the template generator.
619 * @param antMakeUtils the helper instance.
620 * @param projectName the project name.
621 * @param projectVersion the project version.
622 * @param baseFolder the base folder.
623 * @param sourceFiles the source files.
624 * @param task the task (for logging purposes).
625 * throws AntMakeException if the configure.in file cannot
626 * be created.
627 */
628 protected void createConfigureInFile(
629 ConfigureInTemplateGenerator generator,
630 AntMakeUtils antMakeUtils,
631 String projectName,
632 String projectVersion,
633 File baseFolder,
634 File[] sourceFiles,
635 Task task)
636 throws AntMakeException
637 {
638 if ( (generator != null)
639 && (projectName != null)
640 && (projectVersion != null)
641 && (baseFolder != null)
642 && (sourceFiles != null))
643 {
644 ConfigureInTemplate t_Template =
645 generator.createConfigureInTemplate(
646 projectName, projectVersion);
647
648 if (t_Template != null)
649 {
650 String[] t_astrSubfolders = EMPTY_STRING_ARRAY;
651
652 for (int t_iItemIndex = 0;
653 t_iItemIndex < sourceFiles.length;
654 t_iItemIndex++)
655 {
656 t_astrSubfolders =
657 antMakeUtils.getSubfolders(
658 sourceFiles[t_iItemIndex].getParent());
659
660 for (int t_iSubfolderIndex = 0;
661 t_iSubfolderIndex < t_astrSubfolders.length;
662 t_iSubfolderIndex++)
663 {
664 t_Template.addPackage(
665 t_astrSubfolders[t_iSubfolderIndex]);
666 }
667 }
668
669 generator.write(t_Template, baseFolder, task);
670 }
671 }
672 }
673
674 /***
675 * Creates the top-level <i>Makefile.am</i> file.
676 * @param projectName the project name.
677 * @param baseFolder the base folder.
678 * @param sourceFiles the source files.
679 * @param task the task (for logging purposes).
680 * throws AntMakeException if such Makefile.am file cannot
681 * be created.
682 */
683 protected void createTopMakefileAmFile(
684 String projectName,
685 File baseFolder,
686 File[] sourceFiles,
687 Task task)
688 throws AntMakeException
689 {
690 createTopMakefileAmFile(
691 TopMakefileAmTemplateGenerator.getInstance(),
692 AntMakeUtils.getInstance(),
693 projectName,
694 baseFolder,
695 sourceFiles,
696 task);
697 }
698
699 /***
700 * Creates the top-level <i>Makefile.am</i> file.
701 * @param generator the template generator.
702 * @param antMakeUtils the helper instance.
703 * @param projectName the project name.
704 * @param baseFolder the base folder.
705 * @param sourceFiles the source files.
706 * @param task the task (for logging purposes).
707 * throws AntMakeException if such Makefile.am file cannot
708 * be created.
709 */
710 protected void createTopMakefileAmFile(
711 TopMakefileAmTemplateGenerator generator,
712 AntMakeUtils antMakeUtils,
713 String projectName,
714 File baseFolder,
715 File[] sourceFiles,
716 Task task)
717 throws AntMakeException
718 {
719 if ( (generator != null)
720 && (projectName != null)
721 && (baseFolder != null)
722 && (sourceFiles != null))
723 {
724 TopMakefileAmTemplate t_Template =
725 generator.createTopMakefileAmTemplate(projectName);
726
727 if (t_Template != null)
728 {
729 String[] t_astrSubfolders = EMPTY_STRING_ARRAY;
730 String t_CurrentSourceFolder = null;
731
732 for (int t_iItemIndex = 0;
733 t_iItemIndex < sourceFiles.length;
734 t_iItemIndex++)
735 {
736 t_CurrentSourceFolder =
737 sourceFiles[t_iItemIndex].getParent();
738
739 t_Template.addPackage(
740 antMakeUtils.toPackage(t_CurrentSourceFolder));
741
742 t_astrSubfolders =
743 antMakeUtils.getSubfolders(t_CurrentSourceFolder);
744
745 if ( (t_astrSubfolders != null)
746 && (t_astrSubfolders.length > 0))
747 {
748 t_Template.addTopFolder(t_astrSubfolders[0]);
749 t_Template.addLeafFolder(
750 t_astrSubfolders[
751 t_astrSubfolders.length - 1]);
752 }
753 }
754
755 generator.write(t_Template, baseFolder, task);
756 }
757 }
758 }
759
760 /***
761 * Creates the child <i>Makefile.am</i> files.
762 * @param projectName the project name.
763 * @param baseFolder the base folder.
764 * @param sourceFiles the source files.
765 * @param task the task (for logging purposes).
766 * throws AntMakeException if any of the Makefile.am files cannot
767 * be created.
768 */
769 protected void createMakefileAmFiles(
770 String projectName,
771 File baseFolder,
772 File[] sourceFiles,
773 Task task)
774 throws AntMakeException
775 {
776 createMakefileAmFiles(
777 MakefileAmTemplateGenerator.getInstance(),
778 AntMakeUtils.getInstance(),
779 projectName,
780 baseFolder,
781 sourceFiles,
782 task);
783 }
784
785 /***
786 * Creates the child <i>Makefile.am</i> files.
787 * @param generator the template generator.
788 * @param antMakeUtils the helper instance.
789 * @param projectName the project name.
790 * @param baseFolder the base folder.
791 * @param sourceFiles the source files.
792 * @param task the task (for logging purposes).
793 * throws AntMakeException if such Makefile.am file cannot
794 * be created.
795 */
796 protected void createMakefileAmFiles(
797 MakefileAmTemplateGenerator generator,
798 AntMakeUtils antMakeUtils,
799 String projectName,
800 File baseFolder,
801 File[] sourceFiles,
802 Task task)
803 throws AntMakeException
804 {
805 if ( (generator != null)
806 && (projectName != null)
807 && (baseFolder != null)
808 && (sourceFiles != null))
809 {
810 String[] t_astrSubfolders = EMPTY_STRING_ARRAY;
811 String t_strCurrentFolder = null;
812 Map t_mFolders2Sources = new HashMap();
813
814 for (int t_iItemIndex = 0;
815 t_iItemIndex < sourceFiles.length;
816 t_iItemIndex++)
817 {
818 t_strCurrentFolder =
819 sourceFiles[t_iItemIndex].getParent();
820
821 t_astrSubfolders =
822 antMakeUtils.getSubfolders(t_strCurrentFolder);
823
824 addSource(t_mFolders2Sources, sourceFiles[t_iItemIndex]);
825
826 addPackage(antMakeUtils, t_mFolders2Sources, t_astrSubfolders);
827 }
828
829 Collection t_cFolderList = getFolderList(t_mFolders2Sources);
830
831 if (t_cFolderList != null)
832 {
833 Iterator t_itFolderIterator = t_cFolderList.iterator();
834
835 while ( (t_itFolderIterator != null)
836 && (t_itFolderIterator.hasNext()))
837 {
838 t_strCurrentFolder = (String) t_itFolderIterator.next();
839
840 MakefileAmTemplate t_Template =
841 generator.createMakefileAmTemplate(
842 projectName, antMakeUtils.getLeafFolder(t_strCurrentFolder));
843
844 if (t_Template != null)
845 {
846 Collection t_cSubfolders =
847 getSubfolders(t_mFolders2Sources, t_strCurrentFolder);
848
849 if (t_cSubfolders != null)
850 {
851 Iterator t_itSubfolderIterator =
852 t_cSubfolders.iterator();
853
854 while ( (t_itSubfolderIterator != null)
855 && (t_itSubfolderIterator.hasNext()))
856 {
857 t_Template.addFolder(
858 (String) t_itSubfolderIterator.next());
859 }
860 }
861
862 Collection t_cSources =
863 getSources(t_mFolders2Sources, t_strCurrentFolder);
864
865 if (t_cSources != null)
866 {
867 Iterator t_itSourceIterator =
868 t_cSources.iterator();
869
870 while ( (t_itSourceIterator != null)
871 && (t_itSourceIterator.hasNext()))
872 {
873 t_Template.addSourceFile(
874 (String) t_itSourceIterator.next());
875 }
876 }
877
878 generator.write(t_Template, baseFolder, task);
879 }
880 }
881 }
882 }
883 }
884
885 /***
886 * Adds a source file to given map.
887 * @param map the container.
888 * @param source the source file.
889 */
890 protected void addSource(Map map, File source)
891 {
892 if ( (map != null)
893 && (source != null))
894 {
895 Collection t_cSources =
896 (Collection) map.get(buildSourceKey(source.getParent()));
897
898 if (t_cSources == null)
899 {
900 t_cSources = new ArrayList();
901 map.put(buildSourceKey(source.getParent()), t_cSources);
902 }
903
904 if (!t_cSources.contains(source.getName()))
905 {
906 t_cSources.add(source.getName());
907 }
908 }
909 }
910
911 /***
912 * Retrieves the sources of given folder.
913 * @param map the container.
914 * @param folder the folder.
915 * @return the collection of all sources under such folder.
916 */
917 public Collection getSources(Map map, String folder)
918 {
919 Collection result = null;
920
921 if ( (map != null)
922 && (folder != null))
923 {
924 result = (Collection) map.get(buildSourceKey(folder));
925 }
926
927 if (result == null)
928 {
929 result = new ArrayList();
930 }
931
932 return result;
933 }
934
935 /***
936 * Adds given package (and its parents) to given map.
937 * @param map the container.
938 * @param folders the folders of the package.
939 */
940 protected void addPackage(Map map, String[] folders)
941 {
942 addPackage(AntMakeUtils.getInstance(), map, folders);
943 }
944
945 /***
946 * Adds given package (and its parents) to given map.
947 * @param antMakeUtils the helper instance.
948 * @param map the container.
949 * @param folders the folders of the package.
950 */
951 protected void addPackage(AntMakeUtils antMakeUtils, Map map, String[] folders)
952 {
953 if ( (antMakeUtils != null)
954 && (map != null)
955 && (folders != null))
956 {
957 String t_strParent = "";
958
959 for (int t_iFolderIndex = 0;
960 t_iFolderIndex < folders.length;
961 t_iFolderIndex++)
962 {
963 if (t_iFolderIndex > 0)
964 {
965 t_strParent = folders[t_iFolderIndex - 1];
966 }
967
968 addFolder(map, t_strParent, folders[t_iFolderIndex]);
969 }
970 }
971 }
972
973 /***
974 * Adds given folder to given map.
975 * @param map the container.
976 * @param parent the parent.
977 * @param folder the folder of the package.
978 */
979 protected void addFolder(Map map, String parent, String folder)
980 {
981 if ( (map != null)
982 && (folder != null))
983 {
984 Collection t_cSubfolders =
985 (Collection) map.get(buildFolderKey(parent));
986
987 if (t_cSubfolders == null)
988 {
989 t_cSubfolders = new ArrayList();
990 map.put(buildFolderKey(parent), t_cSubfolders);
991 }
992
993 t_cSubfolders.add(folder);
994
995 addFolder(map, folder);
996 }
997 }
998
999 /***
1000 * Adds given folder to given map.
1001 * @param map the container.
1002 * @param folder the folder of the package.
1003 */
1004 protected void addFolder(Map map, String folder)
1005 {
1006 if ( (map != null)
1007 && (folder != null))
1008 {
1009 Collection t_cFolderList =
1010 (Collection) map.get(buildFolderListKey());
1011
1012 if (t_cFolderList == null)
1013 {
1014 t_cFolderList = new ArrayList();
1015 map.put(buildFolderListKey(), t_cFolderList);
1016 }
1017
1018 if (!t_cFolderList.contains(folder))
1019 {
1020 t_cFolderList.add(folder);
1021 }
1022 }
1023 }
1024
1025 /***
1026 * Retrieves the sources of given folder.
1027 * @param map the container.
1028 * @param folder the folder.
1029 * @return the collection of all sources under such folder.
1030 */
1031 public Collection getSubfolders(Map map, String folder)
1032 {
1033 Collection result = null;
1034
1035 if ( (map != null)
1036 && (folder != null))
1037 {
1038 result = (Collection) map.get(buildFolderKey(folder));
1039 }
1040
1041 if (result == null)
1042 {
1043 result = new ArrayList();
1044 }
1045
1046 return result;
1047 }
1048
1049 /***
1050 * Retrieves the folder list contained in given map.
1051 * @param map the container.
1052 * @return the collection of all folders.
1053 */
1054 public Collection getFolderList(Map map)
1055 {
1056 Collection result = null;
1057
1058 if (map != null)
1059 {
1060 result = (Collection) map.get(buildFolderListKey());
1061 }
1062
1063 if (result == null)
1064 {
1065 result = new ArrayList();
1066 }
1067
1068 return result;
1069 }
1070
1071 /***
1072 * Builds a key for given source file.
1073 * @param source the source file.
1074 * @return the key.
1075 */
1076 protected Object buildSourceKey(String source)
1077 {
1078 Object result = ".:unknown-source-file:.";
1079
1080 if (source != null)
1081 {
1082 result = ".:source-file|" + source + ":.";
1083 }
1084
1085 return result;
1086 }
1087
1088 /***
1089 * Builds a key for given folder.
1090 * @param folder the folder.
1091 * @return the key.
1092 */
1093 protected Object buildFolderKey(String folder)
1094 {
1095 Object result = ".:unknown-folder:.";
1096
1097 if (folder != null)
1098 {
1099 result = ".:folder|" + folder + ":.";
1100 }
1101
1102 return result;
1103 }
1104
1105 /***
1106 * Builds a key for the folder list.
1107 * @return the key.
1108 */
1109 protected Object buildFolderListKey()
1110 {
1111 return ".:folder-list:.";
1112 }
1113
1114 /***
1115 * Copies the fixed files: README, AUTHORS and COPYING.
1116 * @param baseFolder the base folder.
1117 * @param task the AntMake task instance.
1118 * @throws AntMakeException if the files could not be copied.
1119 */
1120 public void copyFixedFiles(File baseFolder, AntMakeTask task)
1121 throws AntMakeException
1122 {
1123 FileUtils t_FileUtils = FileUtils.getInstance();
1124
1125 if ( (t_FileUtils != null)
1126 && (task != null))
1127 {
1128 copyFile(
1129 t_FileUtils, task.getReadmefile(), baseFolder, task);
1130
1131 copyFile(
1132 t_FileUtils, task.getAuthorsfile(), baseFolder, task);
1133
1134 copyFile(
1135 t_FileUtils, task.getCopyingfile(), baseFolder, task);
1136 }
1137 }
1138
1139 /***
1140 * Copies given file to the specified folder.
1141 * @param file the input file.
1142 * @param folder the destination.
1143 * @param task the task (for logging purposes).
1144 * @throws AntMakeException if the file could not be copied.
1145 */
1146 public void copyFile(
1147 FileUtils fileUtils, File file, File folder, Task task)
1148 throws AntMakeException
1149 {
1150 if ( (fileUtils != null)
1151 && (file != null)
1152 && (folder != null))
1153 {
1154 try
1155 {
1156 AntMakeUtils.getInstance().log(
1157 task,
1158 "Copying " + file.getAbsolutePath()
1159 + " to " + folder.getAbsolutePath(),
1160 Project.MSG_VERBOSE);
1161
1162 fileUtils.copy(
1163 file,
1164 new File(
1165 folder.getAbsolutePath()
1166 + File.separator
1167 + file.getName()));
1168 }
1169 catch (FileNotFoundException fileNotFoundException)
1170 {
1171 throw new AntMakeException(
1172 "cannot copy " + file.getName(),
1173 fileNotFoundException);
1174 }
1175 catch (SecurityException securityException)
1176 {
1177 throw new AntMakeException(
1178 "cannot copy " + file.getName(),
1179 securityException);
1180 }
1181 catch (IOException ioException)
1182 {
1183 throw new AntMakeException(
1184 "cannot copy " + file.getName(),
1185 ioException);
1186 }
1187 }
1188 }
1189
1190 /***
1191 * Generates the changelog file.
1192 * @param rootFolder the root folder.
1193 * @param output the name of the output file.
1194 * @param task the task.
1195 * @throws AntMakeException if the file cannot be generated.
1196 */
1197 protected void generateChangeLog(
1198 File rootFolder, String output, Task task)
1199 throws AntMakeException
1200 {
1201 if ( (rootFolder != null)
1202 && (output != null)
1203 && (task != null))
1204 {
1205 generateChangeLog(
1206 CvsUtils.getInstance(),
1207 rootFolder,
1208 output,
1209 task);
1210 }
1211 }
1212
1213 /***
1214 * Generates the changelog file.
1215 * @param cvsUtils the CvsUtils instance.
1216 * @param rootFolder the root folder.
1217 * @param output the name of the output file.
1218 * @param task the task.
1219 * @throws AntMakeException if the file cannot be generated.
1220 */
1221 protected void generateChangeLog(
1222 CvsUtils cvsUtils,
1223 File rootFolder,
1224 String output,
1225 Task task)
1226 throws AntMakeException
1227 {
1228 if (cvsUtils != null)
1229 {
1230 cvsUtils.generateChangeLog(
1231 rootFolder, output, task);
1232 }
1233 }
1234 }
This page was automatically generated by Maven