I am excited about integrating walkmod into our build process but have ran across a few issues.
1) .* imports are not cleaned. Part of our library is dynamically generated from a customer API. These classes all have the same block of .* imports with the majority not needed for any one class. However, it appears that cleanup only occurs for the classes directly imported. Am I missing something?
2) I can't find any guide for walkmod.xml configuration. Are there default variables? What is the correct way to set properties? etc. Is there a guide for this?
3) The reader and writer directory don't seem to match. Example - if reader is set for 'src/com/company/generated' and writer is set for the same... the files are actually written at 'src/com/company/generated/com/company/generated'. It seems like you always need to write to the 'src' directory or the files will not be placed correctly. Again -- am I just missing something?
I figured I would write a single post rather than split them up since this is a forum :)
Thanks!
Hello,I am excited about integrating walkmod into our build process but have ran across a few issues.
1) .* imports are not cleaned. Part of our library is dynamically generated from a customer API. These classes all have the same block of .* imports with the majority not needed for any one class. However, it appears that cleanup only occurs for the classes directly imported. Am I missing something?
2) I can't find any guide for walkmod.xml configuration. Are there default variables? What is the correct way to set properties? etc. Is there a guide for this?
3) The reader and writer directory don't seem to match. Example - if reader is set for 'src/com/company/generated' and writer is set for the same... the files are actually written at 'src/com/company/generated/com/company/generated'. It seems like you always need to write to the 'src' directory or the files will not be placed correctly. Again -- am I just missing something?
 <reader path="src">
      <include wildcard="com/company/generated/"></include>
 </reader>
<writer path="src/generated" />
I figured I would write a single post rather than split them up since this is a forum :)
Thanks!
In DefaultJavaWalker.java --
ClassLoader cl = getClassLoader();
if (requiresSemanticAnalysis) {
if (cl != null) {
SymbolVisitorAdapter<HashMap<String, Object>> visitor = new SymbolVisitorAdapter<HashMap<String, Object>>();
visitor.setClassLoader(cl);
visitor.visit(cu, new HashMap<String, Object>());
} else {
throw new WalkModException(
"There is no available project classpath to apply "
+ "a semantic analysis");
}
}
It appears that the ClassLoader is set following the null check. Admittedly I am new to this code base, but should the visitor set the classloader before 'ClassLoader cl = getClassLoader();' is called?
walkmod.xml (I explicitely removed the walkmod-maven-plugin after testing it) --
<!DOCTYPE walkmod PUBLIC "-//WALKMOD//DTD" "http://www.walkmod.com/dtd/walkmod-1.1.dtd">
<walkmod>
<plugins>
<plugin artifactId="walkmod-dead-code-cleaner-plugin" groupId="org.walkmod" version="1.0.0" />
</plugins>
<chain name="default">
<reader path="src">
<include wildcard="co/ecg/toolkit/generated" />
</reader>
<transformation type="walkmod:commons:unused-declarations-cleaner" />
<writer path="src" type="org.walkmod:walkmod-java-formatter-plugin:writer">
<param name="configFile">dist/conf/schema/ECG-Java-Code-Formatter.xml</param>
</writer>
</chain>
</walkmod>
pom.xml (It is very long with multiple steps so I am just listing the walkmod portion) -
<!-- Clean Imports and Format -->
<plugin>
<groupId>org.walkmod</groupId>
<artifactId>maven-walkmod-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>apply</goal>
</goals>
<configuration>
<printError>true</printError>
<configFile>walkmod.xml</configFile>
</configuration>
</execution>
</executions>
</plugin>
Our currently lifecycle follows --
validate - Pre-compile code that will be used to generate API code
generate-sources - Generate code from APIs and other classes created dynamically
process-sources - Add generated sources to classpath
process-resources - Run walkmod to clean generated code
compile, etc.
   <groupId>org.walkmod</groupId>
        <artifactId>maven-walkmod-plugin</artifactId>
        <version>1.3</version>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <goals>
              <goal>apply</goal>
            </goals>
            <configuration>
              <skipWalkmod>${skipWalkmod}</skipWalkmod>
            </configuration>
          </execution>
        </executions>
      </plugin>
I made the changes you suggested. If 'skipWalkmod' is set to true then the walkmod module does not run during the maven build which defeats the point. If it is set to false I get the same error when walkmod attempts to run another maven build from within maven a maven build. See Below -
----
[ERROR] Error executing Maven.
[ERROR] Unable to create injector, see the following errors:
1) No scope is bound to org.apache.maven.SessionScoped.
at org.apache.maven.ReactorReader.class(Unknown Source)
at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule)
1 error
ERROR [main] - Invalid configuration
org.walkmod.conf.ConfigurationException: Error executing: clean mvn install -DskipTests in /Users/mkeathley/Workspace/eclipse/AlpacaLibrary
at org.walkmod.maven.providers.MavenProject.build(MavenProject.java:181)
at org.walkmod.maven.providers.MavenProject.resolveClassLoader(MavenProject.java:248)
at org.walkmod.maven.providers.ClassLoaderConfigurationProvider.load(ClassLoaderConfigurationProvider.java:82)
at org.walkmod.impl.DefaultConfigurationAdapter.prepare(DefaultConfigurationAdapter.java:55)
at org.walkmod.conf.ConfigurationManager.<init>(ConfigurationManager.java:76)
at org.walkmod.conf.ConfigurationManager.<init>(ConfigurationManager.java:81)
at org.walkmod.WalkModFacade.apply(WalkModFacade.java:329)
at org.walkmod.mojos.ApplyMojo.execute(ApplyMojo.java:32)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.lang.Exception: Error executing: clean mvn install -DskipTests in /Users/mkeathley/Workspace/eclipse/AlpacaLibrary
... 30 more
----
It seems like there needs to be a way to get the classpath and classloader from the currently running maven build when it runs the maven-walkmod-module. I can set the modules lifecycle to AFTER compile so it should have everything needed to perform the ananlysis.
Thoughts?