I have just created a new zend framework application to try out unit testing.
I have followed this tutorial and everything seems to be working correctly for testing. There is a problem with the display of the coverage report. It displays the correct information, but the report starts at the root of my hard drive and I need to traverse the tree to my project folder to see useful information.
This means that every time I ran the tests, I need to click 5 folders deep to get to the actual report.
How do I make the report start in my project folder? This is my phpunit config file:
<phpunit bootstrap="./bootstrap.php">
<testsuite name="Application Test Suite">
<directory>./application</directory>
</testsuite>
<testsuite name="Library Test Suite">
<directory>./library</directory>
</testsuite>
<filter>
<whitelist>
<directory>../../library/Zend</directory>
<exclude>
<directory suffix=".phtml">../application/</directory>
<file>../application/Bootstrap.php</file>
<file>../application/controllers/ErrorController.php</file>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="./log/report" charset="UTF-8" yui="true"
hightlight="true" lowupperbound="50" highlowerbound="80">
<log type="testdox" target="./log/testdox.html">
</log>
</log>
</logging>
</phpunit>
I fixed the problem...
I needed to explicitly specify my application folder in the whitelist. If it is empty, the code coverage report just starts from 'c:' and tries to find every '.php' file.
After adding the line in the whitelist section:
<directory>../application/</directory>
It works as expected.
Since I don't have any library tests in my test folder, including the Zend library folder probably had no effect and the report must have considered the whitelist empty. And because there is no blacklist, it just started from the root.
The code coverage starts at the most common path for all files included in the report. So if your web root is in /var/www and you include libraries in /usr/local/zend/ the most common path will be the root path.
The solution would be to exclude the library path because usually you don't want to measure the code coverage for external libraries anyway.
Related
I would like to use web deploy to publish a Visual Studio "Console" application to a folder on the target system.
I have had some luck, and have been able to produce something similar to what I need, but not quite.
I've added the following to the console .csproj:
added the following projectName.wpp.targets file
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
and I've added the following projectName.wpp.targets:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<DeployAsIisApp>false</DeployAsIisApp>
<IncludeSetAclProviderOnDestination>false</IncludeSetAclProviderOnDestination>
</PropertyGroup>
<ItemGroup>
<FilesForPackagingFromProject Include="$(IntermediateOutputPath)$(TargetFileName).config">
<DestinationRelativePath>bin\%(RecursiveDir)%(FileName)%(Extension)</DestinationRelativePath>
<FromTarget>projectName.wpp.targets</FromTarget>
</FilesForPackagingFromProject>
</ItemGroup>
</Project>
I then edit the .SetParameters.xml file as follows:
<parameters>
<setParameter name="IIS Web Application Name" value="c:\company\project" />
</parameters>
When I then deploy using the generated .cmd file, I get all the files deployed to C:\company\project\bin.
That's not bad, but I'd like to do better. In particular, I'd like to omit the "bin" folder and put all files in the "C:\company\project" folder, and I'd like to be able to specify the ACLs
Has anybody been able to work around these problems?
Ok, so here's the way how to omit the 'bin' folder.
First of all, I'd like to emphasize that all this msdeploy-related stuff is for web apps deployment, and 'bin' folder seems for me to be almost hardcoded deeply inside. So if you want to get rid of it - you have to do some dirty things. Which I did.
We'll have to change $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets project a little bit, so it's better to change not it, but it's copy.
Steps:
1.Backup $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets(alternatively, you could install MSBuild.Microsoft.VisualStudio.Web.targets package, redirect your csproj file to Microsoft.WebApplication.targets file obtained from package and work with it).
2. In the $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplicaton.targets find the xml node which looks like <CopyPipelineFiles PipelineItems="#(FilesForPackagingFromProject)"(there are several ones of them, take the one from the line ~2570).
3. Comment the node out, replace with the custom one, so eventually it will look like:
<!--
<CopyPipelineFiles PipelineItems="#(FilesForPackagingFromProject)"
SourceDirectory="$(WebPublishPipelineProjectDirectory)"
TargetDirectory="$(WPPAllFilesInSingleFolder)"
SkipMetadataExcludeTrueItems="True"
UpdateItemSpec="True"
DeleteItemsMarkAsExcludeTrue ="True"
Condition="'#(FilesForPackagingFromProject)' != ''">
<Output TaskParameter="ResultPipelineItems" ItemName="_FilesForPackagingFromProjectTempory"/>
</CopyPipelineFiles>-->
<!-- Copying files to package folder in 'custom'(dirty) way -->
<CreateItem Include="$(OutputPath)\**\*.*">
<Output TaskParameter="Include" ItemName="YourFilesToCopy" />
</CreateItem>
<Copy SourceFiles="#(YourFilesToCopy)"
DestinationFiles="#(YourFilesToCopy->'$(WPPAllFilesInSingleFolder)\%(RecursiveDir)%(Filename)%(Extension)')" />
Then
4. Your projectName.wpp.targets don't have to have FilesForPackagingFromProject, so it will look like:
<!-- targets -->
<PropertyGroup>
<DeployAsIisApp>false</DeployAsIisApp>
<IncludeSetAclProviderOnDestination>false</IncludeSetAclProviderOnDestination>
</PropertyGroup>
<ItemGroup>
<!-- intentionally left blank -->
</ItemGroup>
</Project>
That's it. Worked for me(tm), tested. Let me be honest, I don't like this approach, but that was the only way I made it working in the needed way. It's up to you whether you'll use it in your project or not.
My opinion is not to use msdeploy here - it was not for you task.
Better to write msbuild-scripts from scratch or accept the 'bin' folder, and fight against the framework again once next customization is required.
Looking for some help from anyone that's worked with SlowCheetah to transform config files under a web project. We're finding that partial config files referenced from the web.config are not being transformed.
For example, we've included references to partial configs AppSettings.config and ConnectionsString.config in the web.config like so:
</system.web>
<connectionStrings configSource ="ConnectionsString.config"></connectionStrings>
<appSettings configSource ="AppSettings.config"></appSettings>
</configuration>
and then in the AppSettings.config we have just the AppSettings section like so:
<appSettings>
<add key="LostPasswordBCC" value="knock#timmons.com" />
</appSettings>
and finally in the transform file AppSettings.Debug.config we have some additions:
<?xml version="1.0" encoding="utf-8" ?>
<!-- For more information on using transformations
see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings >
<add key="Release" value="Something" xdt:Transform="Insert" />
</appSettings>
</configuration>
Obviously the above is just a test to see the transform occur, but what we're finding is that on attempting to preview the transform all we get back is an error "There was an error processing the transformation." The publish attempt also fails.
If we make the config files fully formed xml and not referenced from web.config, the transformation seems to work fine - but were looking to share these files across multiple projects.
Does anyone know if there's a workaround where we can both reference partial configs from the web.config and also have transforms off those partial files? We're dealing with legacy code with a large number of config files across multiple web projects that were attempting to consolidate, thus the need to link from web config to separate shared files.
Problem has been resolved, turns out after help from Sayed, we determined that in our efforts to understand the config transformation process with a web project we had corrupted the transform config file's format. With freshly created config files we were able to get transforms to work using SlowCheetah.
This allowed us to move on the real problem we needed to address which was wanting to transform project configs other than the web.config using Visual Studio 2012's publish profiles. This did not work originally, but again Sayed helped us out and provided a new copy of SlowCheetah that allowed this to work.
Below is a link to the new version of SlowCheetah with the fix: https://github.com/sayedihashimi/slow-cheetah/issues/46
Much thanks for all your time and patience Sayed.
I'm working on an internal ivy repository with a decent number of projects under it, each with many revisions. I would like to make a dependency report for the entire repository showing which versions of which artifacts depend on which revisions of other artifacts. Obviously it isn't too difficult to make a script to parse the published ivy xml files, but if this functionality exists already I'll use that. Something like the repreport task would be nice, but for a whole repo.
My main goal here is to get a report of artifacts that are not referenced by any other artifacts so as to make a list of candidates for removal from the repo.
So, does ivy have any way to build a dependency report against and entire repository?
Edit: Working through this, it looks like ivy:repreport is the way to go.
Here is my build.xml file:
<project name="Report Build" xmlns:ivy="antlib:org.apache.ivy.ant" basedir=".">
<property name="ivy.version" value="2.2.0"/>
<property name="ivy.home" value="${user.home}/.ivy2"/>
<target name="fetch-ivy" unless="offline" description="Install Ivy if it doesn't already exist">
<mkdir dir="${ivy.home}"/>
<get
src="http://repo2.maven.org/maven2/org/apache/ivy/ivy/${ivy.version}/ivy-${ivy.version}.jar"
dest="${ivy.home}" usetimestamp="true"/>
</target>
<target name="init-ivy" depends="fetch-ivy" unless="ivy-initialized">
<path id="ivy.lib.path">
<fileset dir="${ivy.home}" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
<property name="ivy-initialized" value="yes"/>
</target>
<target name="report" depends="init-ivy">
<ivy:settings file="ivy-settings-report.xml" id="report.ivy.settings"/>
<ivy:repreport settingsref="report.ivy.settings"/>
</target>
</project>
And here is my ivy settings file:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-settings>
<settings defaultResolver="main"/>
<resolvers>
<chain name="main">
<url name="internalartifacts" m2compatible="false">
<artifact
pattern="http://internalartifacts.local/[organization]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"/>
<ivy pattern="http://internalartifacts.local/[organization]/[module]/[revision]/ivy-[revision].xml"/>
</url>
</chain>
</resolvers>
</ivy-settings>
The documentation for repreport says:
To generate a xml report for all the latest versions of all the
modules in your repository:
<ivy:repreport />
Limitation: this task requires to be able to browse the repository,
and is thus limited to resolvers supporting repository listing. In
particular, it means it doesn't work to report all organizations in a
repository using m2compatible mode. Moreover, to be able to list
organizations, this task requires an [organisation] token in the
resolver(s) used.
So this should totally work.
As mentioned in the comment:
It is important that your repository has ivy.xml files for the artifacts in it. Otherwise ivy cannot recognize the dependencies between the artifacts and your report will be empty.
I used to work with Hudson on my project, and lately I had to move it to a new server.
I configured it the exact same way it use to be (for all I can tell) but when I try to launch a build, it fails and I get the following error:
Démarré par l'utilisateur anonymous
Checking out http://[...]/trunk/MyProject/ear
A .classpath
A .project
A target
AU target/ear-1.0-SNAPSHOT.ear
A target/application.xml
A target/ear-1.0-SNAPSHOT
A target/ear-1.0-SNAPSHOT/META-INF
A target/ear-1.0-SNAPSHOT/META-INF/application.xml
AU target/ear-1.0-SNAPSHOT/web-1.0-SNAPSHOT.war
AU target/ear-1.0-SNAPSHOT/business-1.0-SNAPSHOT.jar
A pom.xml
A .settings
A .settings/org.eclipse.jdt.core.prefs
A .settings/org.maven.ide.eclipse.prefs
At revision 136
no change for http://[...]/trunk/MyProject/ear since the previous build
Found mavenVersion 3.0.2 from file jar:file:/usr/share/maven/apache-maven-3.0.2/lib/maven-core-3.0.2.jar!/META-INF/maven/org.apache.maven/maven-core/pom.properties
Parsing POMs
ERROR: Echec à la lecture des POMs
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM: Could not find artifact com.rha:MyProject:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 9, column 10
at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:325)
at hudson.maven.MavenEmbedder.buildProjects(MavenEmbedder.java:360)
at hudson.maven.MavenEmbedder.readProjects(MavenEmbedder.java:330)
at hudson.maven.MavenModuleSetBuild$PomParser.invoke(MavenModuleSetBuild.java:1148)
at hudson.maven.MavenModuleSetBuild$PomParser.invoke(MavenModuleSetBuild.java:991)
at hudson.FilePath.act(FilePath.java:756)
at hudson.FilePath.act(FilePath.java:738)
at hudson.maven.MavenModuleSetBuild$RunnerImpl.parsePoms(MavenModuleSetBuild.java:698)
at hudson.maven.MavenModuleSetBuild$RunnerImpl.doRun(MavenModuleSetBuild.java:531)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:420)
at hudson.model.Run.run(Run.java:1362)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:405)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:145)
Finished: FAILURE
The pom.xml file when I got to Hudson "workspace" looks like this:
[...]
<parent>
<groupId>com.rha</groupId>
<artifactId>MyProject</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
[...]
<dependencies>
<dependency>
<groupId>com.rha</groupId>
<artifactId>business</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.rha</groupId>
<artifactId>web</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
</project>
[Edit]
Actually I forgot some important informations:
My project is divided into 3 parts:
business (packaged into .jar)
web (packaged into a .war)
ear (packaged the .war and .jar into a .ear)
I'm using Subversion, and under my "trunk" folder I got a "MyProject" folder including:
.project
.settings/
business/
ear/
pom.xml
src/
web/
what happens is:
in my Hudson job configuration, I filled the SVN field "repository URL" with:
http://[...]/trunk/MyProject/ear
and here is the "pom.xml" from "MyProject" folder:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
[...]
<modules>
<module>business</module>
<module>web</module>
<module>ear</module>
</modules>
[...]
so the parent "pom.xml" is actually located at "../pom.xml" on my SVN repository, under "trunk/MyFolder".
But Hudson can't see it for some reason (but like I said, it used to work on the previous server).
Any clue ?
[/Edit]
I guess this is a rookie mistake, I'm a total beginner on Maven, but I just can't figure out why it's not working anymore ...
Any help will be greatly appreciated !
Nicolas
relativePath (of the parent) defaults to ../pom.xml. It looks like it is not present in there. You could set it to an empty value so that maven downloads it as a dependency.
<relativePath/>
This link discusses this.
[Edit: based on the edits to the question]
Hudson only sees the source code inside ear folder. Though the parent pom is present in SVN, it is not available to Hudson. Missing parent pom was aa warning in Maven 2 but strict in Maven 3.
There are two ways to solve this.
One is to specify to hudson, the url http://[...]/trunk/MyProject/. You can then chose to build all the modules or still choose to build the pom.xml of ear project alone.
The other is to manually run mvn install on the hudson system so that the parent pom gets deployed once and thereafter used by hudson. However, this will not get updated if parent pom is subsequently changed.
Retrieving the Root-POM from the Maven-REPO should usually also work (like you do), but I would expect you havn't triggered the root pom to be installed into the REPO on the new hudson site so far.
To avoid this use the relativePath property, e.g. something like this:
<relativePath>../pom.xml</relativePath>
in your <parent> tag which will tell maven to look for the root pom in your module structure.
I had the same problem with Hudson, Sonar plugin and a multi-module Maven project: "Non-resolvable parent POM" when Hudson tried to run sonar:sonar. The solution was to specify the Root POM location in the Hudson job configuration under the Sonar section.
The project structure in SVN (each one is a Maven project with pom.xml in the project root):
foo-parent
+- foo-ui-module
+- bar-other-module
I have individual Hudson jobs for each project, "foo-parent", "foo-ui-module" and "bar-other-module". The Sonar run in a Hudson job could not find the parent POM even though the build was successful until that point. Maybe the Sonar plugin doesn't use the same Maven settings as the rest of the job because it didn't try to look for the parent POM from our Artifactory repository, not even with <relativePath/> in the project POM.
The place for the Root POM setting was under the job's Configure -> Sonar -> Advanced -> Root POM: ../foo-parent/pom.xml (I have foo-parent job at this path)
We managed to get this working by simply deleting the relevant pom file, plus some sort of metadata file with a similar name in the same folder, from the .m2/repository/a/b/c folder on our jenkins server.
Rerunning the jenkins build after doing this worked just fine.
Hope this helps someone...
I am trying log some entries in a log file (Log.Trace / Log.Debug) while my VS unit test runs. I have also copied the file NLog.config to out directory through DeploymentItem attribute over class. Still my log file is not created. Any help as to how can we log entries in a file same as we do for normal web application.
I've just found a solution to this problem:
Add the App.config file to yout unit test project with the following contents:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="debugLog" xsi:type="Console" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="debugLog"></logger>
</rules>
</nlog>
</configuration>
You may put any configuration you wish as with NLog.config file.
Unfortunately that is the only XML solution at the time. It is not only about Unit Testing, though. NLog.config does not work with just any Console Application.
Do not know if it is by design or just an oversight. Anyway I would not say that moving NLog.config to App.config section is any way satisfactory =/
Maybe it is worth to notice that there is a possibility of configuring nlog directly from code, what could be helpful in some scenarios.
One could be also glad to find nlog debug option, that will log the whole process of processing configuration file, registering targets and so on...
To turn it on, just add internalLogFile and internalLogLevel attributes to nlog element:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" internalLogFile="C:/logs/nlog.txt" internalLogLevel="Debug">
or from code:
InternalLogger.LogFile = #"c:\logs\nlog.txt";
InternalLogger.LogLevel = LogLevel.Trace;