2323import com .headwire .aem .tooling .intellij .facet .SlingModuleFacetConfiguration ;
2424import com .headwire .aem .tooling .intellij .util .ComponentProvider ;
2525import com .intellij .openapi .components .AbstractProjectComponent ;
26+ import com .intellij .openapi .diagnostic .Logger ;
2627import com .intellij .openapi .module .Module ;
2728import com .intellij .openapi .project .Project ;
2829import com .intellij .openapi .vfs .VirtualFile ;
@@ -40,6 +41,8 @@ public class ModuleManagerImpl
4041 extends AbstractProjectComponent
4142 implements ModuleManager
4243{
44+ private static final Logger LOGGER = Logger .getInstance (ModuleManagerImpl .class );
45+
4346 private ServerConfigurationManager serverConfigurationManager ;
4447
4548 protected ModuleManagerImpl (Project project ) {
@@ -124,18 +127,25 @@ public ServerConfiguration.Module findModule(@NotNull UnifiedModule unifiedModul
124127 public List <UnifiedModule > getUnifiedModules (boolean force ) {
125128 List <UnifiedModule > ret = new ArrayList <UnifiedModule >();
126129 if (!force && serverConfiguration .isBound ()) {
130+ LOGGER .debug ("Get Unified Modules, not forced and is bound" );
127131 for (ServerConfiguration .Module module : serverConfiguration .getModuleList ()) {
132+ LOGGER .debug ("Get Unified Modules, add unified module: " , module .getUnifiedModule ().getName ());
128133 ret .add (module .getUnifiedModule ());
129134 }
130135 } else {
131136 Module [] modules = com .intellij .openapi .module .ModuleManager .getInstance (project ).getModules ();
132137 MavenProjectsManager mavenProjectsManager = MavenProjectsManager .getInstance (project );
133138 List <MavenProject > mavenProjects = mavenProjectsManager .getNonIgnoredProjects ();
134139 for (Module module : modules ) {
140+ LOGGER .debug ("Get Unified Modules, handle module: " , module .getName ());
135141 if (!force ) {
136142 // First look for a Server Configuration Module with that Module in the Module Context and see if it is bound
137143 // (If found then this is most likely)
138144 ServerConfiguration .Module scm = serverConfiguration .obtainModuleByName (module .getName ());
145+ LOGGER .debug ("Get Unified Modules, add unforced module (scm, name, is bound): " ,
146+ scm , scm != null ? scm .getName () : "null" ,
147+ scm != null ? scm .isBound () : "null"
148+ );
139149 if (scm != null && scm .isBound ()) {
140150 ret .add (scm .getUnifiedModule ());
141151 // We found our Module so go to the next
@@ -146,6 +156,10 @@ public List<UnifiedModule> getUnifiedModules(boolean force) {
146156 // Find a corresponding Maven Project
147157 UnifiedModule unifiedModule = null ;
148158 for (MavenProject mavenProject : mavenProjects ) {
159+ LOGGER .debug ("Get Unified Modules, handled Maven project: " ,
160+ mavenProject != null ?
161+ mavenProject .getName () : "null"
162+ );
149163 if (!"pom" .equalsIgnoreCase (mavenProject .getPackaging ())) {
150164 // Use the Parent of the Module and Maven Pom File as they should be in the same folder
151165 //AS TODO: We might want to check if one is the child folder of the other instead being in the same
@@ -154,11 +168,13 @@ public List<UnifiedModule> getUnifiedModules(boolean force) {
154168 // Temporary issue where the IML file is not found by the Virtual File System
155169 // Fix: get the path, remove the IML file and find the Virtual File with that folder
156170 String filePath = module .getModuleFilePath ();
171+ LOGGER .debug ("Get Unified Modules, Maven project file path: " , filePath );
157172 if (filePath != null ) {
158173 int index = filePath .lastIndexOf ("/" );
159174 if (index > 0 && index < filePath .length () - 2 ) {
160175 filePath = filePath .substring (0 , index );
161176 moduleFile = project .getBaseDir ().getFileSystem ().findFileByPath (filePath );
177+ LOGGER .debug ("Get Unified Modules, Maven project module file: " , moduleFile );
162178 }
163179 }
164180 }
@@ -167,6 +183,7 @@ public List<UnifiedModule> getUnifiedModules(boolean force) {
167183 VirtualFile mavenFolder = mavenProject .getFile ().getParent ();
168184 if (moduleFolder .equals (mavenFolder )) {
169185 unifiedModule = new UnifiedModuleImpl (mavenProject , module );
186+ LOGGER .debug ("Get Unified Modules, Maven project module unified module: " , unifiedModule .getName ());
170187 break ;
171188 }
172189 }
@@ -175,31 +192,39 @@ public List<UnifiedModule> getUnifiedModules(boolean force) {
175192 if (unifiedModule != null ) {
176193 if (unifiedModule .isOSGiBundle ()) {
177194 if (slingModuleFacet != null ) {
195+ LOGGER .debug ("Get Unified Modules, check OSGi" );
178196 SlingModuleFacetConfiguration slingModuleFacetConfiguration = slingModuleFacet .getConfiguration ();
197+ LOGGER .debug ("Get Unified Modules, sling module facet (fact, facet conf): " , slingModuleFacet , slingModuleFacetConfiguration );
179198 if (slingModuleFacetConfiguration .getModuleType () != ModuleType .bundle ) {
180199 //AS TODO: Show an alert that Maven Module and Sling Facet Module type od not match
200+ LOGGER .debug ("Get Unified Modules, not a maven bundle -> ignore" );
181201 continue ;
182202 } else {
183203 if (slingModuleFacetConfiguration .getOsgiSymbolicName ().length () == 0 ) {
184204 //AS TODO: Show an alert that no Symbolic Name is provided
205+ LOGGER .debug ("Get Unified Modules, no Symbolic Name -> ignore" );
185206 continue ;
186207 }
187208 if (slingModuleFacetConfiguration .isIgnoreMaven ()) {
188209 if (slingModuleFacetConfiguration .getOsgiVersion ().length () == 0 ) {
189210 //AS TODO: Show an alert that no Version is provided
211+ LOGGER .debug ("Get Unified Modules, no OSGi Version -> ignore" );
190212 continue ;
191213 }
192214 if (slingModuleFacetConfiguration .getOsgiJarFileName ().length () == 0 ) {
193215 //AS TODO: Show an alert that no Jar File Name is provided
216+ LOGGER .debug ("Get Unified Modules, no OSGi Jar File Name -> ignore" );
194217 continue ;
195218 }
196219 }
197220 }
198221 }
199222 } else if (unifiedModule .isContent ()) {
200223 if (slingModuleFacet != null ) {
224+ LOGGER .debug ("Get Unified Modules, check Content" );
201225 if (slingModuleFacet .getConfiguration ().getModuleType () != ModuleType .content ) {
202226 //AS TODO: Warn about the miss configuration but proceed
227+ LOGGER .debug ("Get Unified Modules, not a Maven content -> ignore" );
203228 continue ;
204229 } else {
205230 unifiedModule = new UnifiedModuleImpl (module );
@@ -208,18 +233,22 @@ public List<UnifiedModule> getUnifiedModules(boolean force) {
208233 }
209234 } else {
210235 if (slingModuleFacet != null ) {
236+ LOGGER .debug ("Get Unified Modules, check others" );
211237 if (slingModuleFacet .getConfiguration ().getModuleType () != ModuleType .excluded ) {
212238 unifiedModule = new UnifiedModuleImpl (module );
213239 }
214240 }
215241 }
216242 if (unifiedModule != null ) {
243+ LOGGER .debug ("Get Unified Modules, finally add unified module to response: " , unifiedModule .getName ());
217244 ret .add (unifiedModule );
218245 // Bind the Server Configuration Module with the Module Context
219246 ServerConfiguration .Module serverConfigurationModule = serverConfiguration .obtainModuleByName (unifiedModule .getName ());
220247 if (serverConfigurationModule == null ) {
248+ LOGGER .debug ("Get Unified Modules, add module to server configuration: " , unifiedModule .getName ());
221249 serverConfiguration .addModule (project , unifiedModule );
222250 } else {
251+ LOGGER .debug ("Get Unified Modules, rebind module with server configuration: " , unifiedModule .getName ());
223252 serverConfigurationModule .rebind (project , unifiedModule );
224253 }
225254 }
0 commit comments