11package code2code .ui .wizards .generate ;
22
3+ import java .util .ArrayList ;
4+ import java .util .List ;
5+
36import org .eclipse .core .resources .IContainer ;
47import org .eclipse .core .resources .IFile ;
58import org .eclipse .core .resources .IProject ;
@@ -43,6 +46,7 @@ public boolean performFinish() {
4346 IProject project = selectedGenerator .getGeneratorFolder ()
4447 .getProject ();
4548
49+ List <IFile > projectfiles = new ArrayList <IFile >();
4650 for (Template template : selectedGenerator
4751 .calculateChoosenTemplatesToGenerate ()) {
4852
@@ -56,8 +60,12 @@ public boolean performFinish() {
5660 Console .write ("-------------------------------------------------------------" );
5761 } else {
5862 Path destinationPath = new Path (destination );
63+
64+ IFile file = project .getFile (destinationPath );
65+
5966 if (project .exists (destinationPath )) {
60- if (!template .isOverwriteAllowed ()) {
67+ if (!template .isOverwriteAllowed ()
68+ && !projectfiles .contains (file )) {
6169
6270 Console .write ("File already exists. Skipping: "
6371 + destinationPath );
@@ -72,18 +80,23 @@ public boolean performFinish() {
7280 Console .write ("Generating: " + template .getTemplateName ()
7381 + " to " + destination );
7482
75- IFile file = project .getFile (destinationPath );
76-
7783 IContainer parent = file .getParent ();
7884 while (parent != null ) {
7985 if (parent instanceof IProject ) {
8086 IProject p = (IProject ) parent ;
81- if (!p .exists ()) {
87+ boolean exists = p .exists ();
88+ if (!exists ) {
8289 p .create (null );
8390 }
8491 if (!p .isOpen ()) {
8592 p .open (null );
8693 }
94+ if (!exists ) {
95+ // we must indicate if .project must be
96+ // overwrited
97+ IFile f = p .getFile (".project" );
98+ projectfiles .add (f );
99+ }
87100 }
88101 parent = parent .getParent ();
89102 }
0 commit comments