5 Replies Latest reply on May 30, 2010 1:55 PM by ajesse

    problem running static analysis in project

    amgad2002

      Hi,

       

      I need to work with jsfunit static analysis test

       

      i followed the article article http://community.jboss.org/wiki/JSFUnitWithMaven that guided me to check out the example of

      http://anonsvn.jboss.org/repos/jsfunit/trunk/jboss-jsfunit-examples/jboss-jsfunit-examples-hellojsf/jboss-jsfunit-examples-hellojsf-webapp

       

      which run succesfully after I checked it out

       

      the strange thing that when I copied JSFUnitStaticAnalysisTest class to my project I got the following error

       

      I work on maven 2.2.1 -  eclipse galieleo SR2

       

      It's clear that variable  ${basedir} couldn't be translated and taken as string , I don't know whay it work in hellojsf project and doesn't work for my project

       

       

       

      -------------------------------------------------------------------------------
      Test set: org.jboss.jsfunit.staticanalysis.JSFUnitStaticAnalysisTest
      -------------------------------------------------------------------------------
      Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.016 sec <<< FAILURE!
      initializationError0(org.jboss.jsfunit.staticanalysis.JSFUnitStaticAnalysisTest)  Time elapsed: 0 sec  <<< ERROR!
      java.lang.RuntimeException: Could not locate file '${basedir}/src/main/webapp/WEB-INF/faces-config.xml'
          at org.jboss.jsfunit.analysis.util.ParserUtils.getXml(ParserUtils.java:77)
          at org.jboss.jsfunit.analysis.ConfigFileTestSuite.getDomDocument(ConfigFileTestSuite.java:377)
          at org.jboss.jsfunit.analysis.ConfigFileTestSuite.getSuite(ConfigFileTestSuite.java:89)
          at org.jboss.jsfunit.analysis.ConfigFilesTestSuite.getSuite(ConfigFilesTestSuite.java:82)
          at org.jboss.jsfunit.staticanalysis.JSFUnitStaticAnalysisTest.suite(JSFUnitStaticAnalysisTest.java:68)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.junit.runners.AllTests.testFromSuiteMethod(AllTests.java:36)
          at org.junit.runners.AllTests.<init>(AllTests.java:25)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
          at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
          at org.junit.internal.requests.ClassRequest.buildRunner(ClassRequest.java:33)
          at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:28)
          at org.apache.maven.surefire.junit4.JUnit4TestSet.<init>(JUnit4TestSet.java:45)
          at org.apache.maven.surefire.junit4.JUnit4DirectoryTestSuite.createTestSet(JUnit4DirectoryTestSuite.java:56)
          at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.locateTestSets(AbstractDirectoryTestSuite.java:96)
          at org.apache.maven.surefire.Surefire.createSuiteFromDefinition(Surefire.java:209)
          at org.apache.maven.surefire.Surefire.run(Surefire.java:156)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
          at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)

       

       

       

      here is my effective pom

       

       

      <?xml version="1.0"?>
      <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <modelVersion>4.0.0</modelVersion>
        <parent>
          <artifactId>core.parentPom</artifactId>
          <groupId>com.ncs.tms</groupId>
          <version>0.0.1-SNAPSHOT</version>
        </parent>
        <groupId>com.ncs.tms</groupId>
        <artifactId>core.web</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>war</packaging>
        <distributionManagement>
          <snapshotRepository>
            <id>NCS</id>
            <name>NCS Shared Repository</name>
            <url>http://192.168.2.50:8080/mvnrpos/</url>
          </snapshotRepository>
        </distributionManagement>
        <properties>
          <hibernate.version>3.2.0.ga</hibernate.version>
          <spring.version>2.5.2</spring.version>
        </properties>
        <dependencies>
          <dependency>
            <groupId>org.apache.myfaces.trinidad</groupId>
            <artifactId>trinidad-api</artifactId>
            <version>1.2.13-SNAPSHOT</version>
            <scope>compile</scope>
          </dependency>
          <dependency>
            <groupId>org.apache.myfaces.trinidad</groupId>
            <artifactId>trinidad-impl</artifactId>
            <version>1.2.13-SNAPSHOT</version>
            <scope>compile</scope>
          </dependency>
          <dependency>
            <groupId>org.apache.myfaces.core</groupId>
            <artifactId>myfaces-api</artifactId>
            <version>1.2.6</version>
            <scope>compile</scope>
          </dependency>
          <dependency>
            <groupId>org.apache.myfaces.core</groupId>
            <artifactId>myfaces-impl</artifactId>
            <version>1.2.6</version>
            <scope>compile</scope>
          </dependency>
          <dependency>
            <groupId>com.sun.facelets</groupId>
            <artifactId>jsf-facelets</artifactId>
            <version>1.1.14</version>
            <scope>compile</scope>
          </dependency>
          <dependency>
            <groupId>com.uwyn</groupId>
            <artifactId>jhighlight</artifactId>
            <version>1.0</version>
            <scope>compile</scope>
          </dependency>
          <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
            <scope>compile</scope>
          </dependency>
          <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.13</version>
            <scope>compile</scope>
          </dependency>
          <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>compile</scope>
          </dependency>
          <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>test</scope>
          </dependency>
          <dependency>
            <groupId>javax.el</groupId>
            <artifactId>el-api</artifactId>
            <version>1.0</version>
            <scope>compile</scope>
          </dependency>
          <dependency>
            <groupId>com.ncs.tms</groupId>
            <artifactId>core.dao</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <scope>compile</scope>
          </dependency>
          <dependency>
            <groupId>org.jboss.jsfunit</groupId>
            <artifactId>jboss-jsfunit-analysis</artifactId>
            <version>1.3.0.Final-SNAPSHOT</version>
            <scope>test</scope>
          </dependency>
          <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
            <scope>test</scope>
          </dependency>
          <dependency>
            <groupId>maven-taglib</groupId>
            <artifactId>maven-taglib-plugin</artifactId>
            <version>1.4.2</version>
            <scope>test</scope>
          </dependency>
        </dependencies>
        <repositories>
          <repository>
            <id>maven2-repository.dev.java.net</id>
            <name>Java.net Repository for Maven</name>
            <url>http://download.java.net/maven/2/</url>
          </repository>
          <repository>
            <id>java.net</id>
            <url>http://download.java.net/maven/1</url>
            <layout>legacy</layout>
          </repository>
          <repository>
            <id>apache.snapshots.repo</id>
            <name>Snapshots / nightly builds of Apache projects</name>
            <url>http://people.apache.org/repo/m2-snapshot-repository/</url>
          </repository>
          <repository>
            <snapshots />
            <id>jboss</id>
            <name>JBoss Repository</name>
            <url>http://repository.jboss.org/maven2</url>
          </repository>
          <repository>
            <releases />
            <id>NCS</id>
            <name>NCS Shared Repository</name>
            <url>http://192.168.2.50:8080/mvnrpos/</url>
          </repository>
          <repository>
            <id>pia-repository</id>
            <url>http://www.pojosinaction.com/repository</url>
          </repository>
          <repository>
            <snapshots>
              <enabled>false</enabled>
            </snapshots>
            <id>central</id>
            <name>Maven Repository Switchboard</name>
            <url>http://repo1.maven.org/maven2</url>
          </repository>
        </repositories>
        <pluginRepositories>
          <pluginRepository>
            <releases>
              <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
              <enabled>false</enabled>
            </snapshots>
            <id>central</id>
            <name>Maven Plugin Repository</name>
            <url>http://repo1.maven.org/maven2</url>
          </pluginRepository>
        </pluginRepositories>
        <build>
          <sourceDirectory>C:\Documents and Settings\user\Workspaces\new\core.web\src\main\java</sourceDirectory>
          <scriptSourceDirectory>C:\Documents and Settings\user\Workspaces\new\core.web\src\main\scripts</scriptSourceDirectory>
          <testSourceDirectory>C:\Documents and Settings\user\Workspaces\new\core.web\src\test\java</testSourceDirectory>
          <outputDirectory>C:\Documents and Settings\user\Workspaces\new\core.web\target\classes</outputDirectory>
          <testOutputDirectory>C:\Documents and Settings\user\Workspaces\new\core.web\target\test-classes</testOutputDirectory>
          <defaultGoal>install</defaultGoal>
          <resources>
            <resource>
              <directory>C:\Documents and Settings\user\Workspaces\new\core.web\src\main\resources</directory>
            </resource>
          </resources>
          <testResources>
            <testResource>
              <directory>C:\Documents and Settings\user\Workspaces\new\core.web\src\test\resources</directory>
            </testResource>
          </testResources>
          <directory>C:\Documents and Settings\user\Workspaces\new\core.web\target</directory>
          <finalName>core.web-0.0.1-SNAPSHOT</finalName>
          <pluginManagement>
            <plugins>
              <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.3</version>
              </plugin>
              <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2-beta-4</version>
              </plugin>
              <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>2.3</version>
              </plugin>
              <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
              </plugin>
              <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.0</version>
              </plugin>
              <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.4</version>
              </plugin>
              <plugin>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.3.1</version>
              </plugin>
              <plugin>
                <artifactId>maven-ejb-plugin</artifactId>
                <version>2.1</version>
              </plugin>
              <plugin>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.3</version>
              </plugin>
              <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.2</version>
              </plugin>
              <plugin>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.5</version>
              </plugin>
              <plugin>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>2.5.1</version>
              </plugin>
              <plugin>
                <artifactId>maven-rar-plugin</artifactId>
                <version>2.2</version>
              </plugin>
              <plugin>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.0-beta-9</version>
              </plugin>
              <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.4.1</version>
              </plugin>
              <plugin>
                <artifactId>maven-site-plugin</artifactId>
                <version>2.0.1</version>
              </plugin>
              <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.0.4</version>
              </plugin>
              <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.4.3</version>
              </plugin>
              <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1-alpha-1</version>
              </plugin>
            </plugins>
          </pluginManagement>
          <plugins>
            <plugin>
              <artifactId>maven-source-plugin</artifactId>
              <version>2.0.4</version>
              <executions>
                <execution>
                  <id>attach-source</id>
                  <goals>
                    <goal>jar</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
            <plugin>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>2.0.2</version>
              <executions>
                <execution>
                  <id>default-compile</id>
                  <phase>compile</phase>
                  <goals>
                    <goal>compile</goal>
                  </goals>
                  <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                  </configuration>
                </execution>
                <execution>
                  <id>default-testCompile</id>
                  <phase>test-compile</phase>
                  <goals>
                    <goal>testCompile</goal>
                  </goals>
                  <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                  </configuration>
                </execution>
              </executions>
              <configuration>
                <source>1.5</source>
                <target>1.5</target>
              </configuration>
            </plugin>
            <plugin>
              <artifactId>maven-eclipse-plugin</artifactId>
              <version>2.8</version>
              <configuration>
                <downloadSources>true</downloadSources>
                <downloadJavadocs>true</downloadJavadocs>
              </configuration>
            </plugin>
            <plugin>
              <artifactId>maven-idea-plugin</artifactId>
              <version>2.2</version>
              <configuration>
                <downloadSources>true</downloadSources>
                <downloadJavadocs>true</downloadJavadocs>
              </configuration>
            </plugin>
            <plugin>
              <artifactId>maven-deploy-plugin</artifactId>
              <version>2.4</version>
              <executions>
                <execution>
                  <id>default-deploy</id>
                  <phase>deploy</phase>
                  <goals>
                    <goal>deploy</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
            <plugin>
              <artifactId>maven-install-plugin</artifactId>
              <version>2.3</version>
              <executions>
                <execution>
                  <id>default-install</id>
                  <phase>install</phase>
                  <goals>
                    <goal>install</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
            <plugin>
              <artifactId>maven-war-plugin</artifactId>
              <version>2.1-alpha-1</version>
              <executions>
                <execution>
                  <id>default-war</id>
                  <phase>package</phase>
                  <goals>
                    <goal>war</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
            <plugin>
              <artifactId>maven-resources-plugin</artifactId>
              <version>2.4.1</version>
              <executions>
                <execution>
                  <id>default-resources</id>
                  <phase>process-resources</phase>
                  <goals>
                    <goal>resources</goal>
                  </goals>
                </execution>
                <execution>
                  <id>default-testResources</id>
                  <phase>process-test-resources</phase>
                  <goals>
                    <goal>testResources</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
            <plugin>
              <artifactId>maven-surefire-plugin</artifactId>
              <version>2.4.3</version>
              <executions>
                <execution>
                  <id>default-test</id>
                  <phase>test</phase>
                  <goals>
                    <goal>test</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
            <plugin>
              <artifactId>maven-clean-plugin</artifactId>
              <version>2.3</version>
              <executions>
                <execution>
                  <id>default-clean</id>
                  <phase>clean</phase>
                  <goals>
                    <goal>clean</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
            <plugin>
              <artifactId>maven-site-plugin</artifactId>
              <version>2.0.1</version>
              <executions>
                <execution>
                  <id>default-site</id>
                  <phase>site</phase>
                  <goals>
                    <goal>site</goal>
                  </goals>
                </execution>
                <execution>
                  <id>default-deploy</id>
                  <phase>site-deploy</phase>
                  <goals>
                    <goal>deploy</goal>
                  </goals>
                </execution>
              </executions>
              <configuration>
                <outputDirectory>C:\Documents and Settings\user\Workspaces\new\core.web\target\site</outputDirectory>
                <reportPlugins>
                  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-project-info-reports-plugin</artifactId>
                  </plugin>
                </reportPlugins>
              </configuration>
            </plugin>
          </plugins>
        </build>
        <reporting>
          <outputDirectory>C:\Documents and Settings\user\Workspaces\new\core.web\target\site</outputDirectory>
        </reporting>
        <profiles>
          <profile>
            <id>release</id>
            <build>
              <plugins>
                <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>exec-maven-plugin</artifactId>
                  <executions>
                    <execution>
                      <id>generateSiteMap</id>
                      <phase>process-resources</phase>
                      <goals>
                        <goal>exec</goal>
                      </goals>
                    </execution>
                  </executions>
                  <configuration>
                    <executable>java</executable>
                    <arguments>
                      <argument>-classpath</argument>
                      <classpath />
                      <argument>org.apache.myfaces.trinidaddemo.support.util.SitemapGenerator</argument>
                    </arguments>
                  </configuration>
                </plugin>
                <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>dependency-maven-plugin</artifactId>
                  <executions>
                    <execution>
                      <id>unpack-source</id>
                      <phase>process-resources</phase>
                      <goals>
                        <goal>unpack</goal>
                      </goals>
                      <configuration>
                        <artifactItems>
                          <artifactItem>
                            <groupId>org.apache.myfaces.trinidad</groupId>
                            <artifactId>trinidad-components-demo</artifactId>
                            <version>1.0-SNAPSHOT</version>
                            <classifier>sources</classifier>
                          </artifactItem>
                        </artifactItems>
                        <outputDirectory>C:\Documents and Settings\user\Workspaces\new\core.web\target/core.web-0.0.1-SNAPSHOT/WEB-INF/src</outputDirectory>
                      </configuration>
                    </execution>
                  </executions>
                </plugin>
              </plugins>
            </build>
          </profile>
        </profiles>
      </project>

       

        • 1. Re: problem running static analysis in project
          ajesse

          If you want I'll take a look at this, but I need your project.

          Do a clean and then create a zip-file from it and send it by email or send me a link where I can download it. I won't use your code for other things that just to look at this problem.

          • 2. Re: problem running static analysis in project
            amgad2002

            Hi Alex,

             

            Thank you for your reply.

             

            the project is about 30 MB what are the files that you need

             

            {code}package org.jboss.jsfunit.staticanalysis;

            import java.io.IOException;
            import java.util.ArrayList;
            import java.util.List;
            import java.util.Properties;
            import junit.framework.Test;
            import junit.framework.TestSuite;
            import org.jboss.jsfunit.analysis.ConfigFilesTestSuite;

            /**
            * Run the JSFUnit config files static analysis suite against this WAR.
            *
            * @author ssilvert
            */
            public class JSFUnitStaticAnalysisTest extends TestSuite
            {
               private static final String WEBAPP_PATH;

               static
               {
                   Properties props = new Properties();

                   try
                   {
                        props.load(JSFUnitStaticAnalysisTest.class.getResourceAsStream("/test.properties"));
                   }
                   catch (IOException e)
                   {
                       throw new IllegalStateException(e);
                   }

                   WEBAPP_PATH = props.getProperty("webapp.path");
               }

               private static final String CONFIG_PATH = WEBAPP_PATH + "/WEB-INF/faces-config.xml";

               public static Test suite()
               {
                  TestSuite suite = new TestSuite();
                  suite.setName("MyApplication all tests");

                  List<String> configFiles = new ArrayList<String>();
                  configFiles.add(CONFIG_PATH);

                  suite.addTest(new ConfigFilesTestSuite("JSF config files").getSuite(configFiles));

                  return suite;
               }
            }{code}

            and test.properties

             

            {code:xml}

            webapp.path=${basedir}/src/main/webapp

            {code:xml}

             

            what i noticed when debugging that the problem is in ${basdir} which is not translated the base directory but it's considered as a string

             

            the strange that when I run the jsfunit hello example it runs and the the ${basedir} is translated to the base directory of the project

             

            so i just want to know what i'm missing so this vaiable is not translated

            • 3. Re: problem running static analysis in project
              ajesse

              looking for the other problem you reported I stumbled on the solution to this one

               

              In your pom you forgot to configure the resoruces-plugin. I changed the pom (line 117ff) to:

              <build>
                    <testResources>
                       <testResource>
                          <directory>src/test/resources</directory>
                          <filtering>true</filtering>
                       </testResource>
                    </testResources>
                      <defaultGoal>install</defaultGoal>
                      <plugins>

              and on the next run the file was found, meaning the property resolved.

              • 4. Re: problem running static analysis in project
                amgad2002

                I was planing for that , it worked successfully

                 

                 

                but i don't understand the soultion what is the meaning of filtering - true ?

                • 5. Re: problem running static analysis in project
                  ajesse

                  Well, I checked Stan's sample project, and saw that resources-spec. Then I looked up the maven doc (http://maven.apache.org/plugins/maven-resources-plugin/) including the subpage about filtering (http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html). The next obvious step was to add the same spec to your pom ... and it worked...

                  1 of 1 people found this helpful