How to load mapper xml files with wildcard? - mybatis

Mybatis(ibatis) can load typeAlliases with package as
<typeAliases>
<package name="com.my.example.bean"/>
</typeAliases>
If so , how can I load mapper xml files also ? I hate I always need to add in mybatis-config.xml for every new xml mapper files as
<mappers>
<mapper resource="mybatis/mapper/A.xml" />
<mapper resource="mybatis/mapper/B.xml" />
<mapper resource="mybatis/mapper/C.xml" />
<mapper resource="mybatis/mapper/D.xml" />
.......
</mappers>
I'd like to use with wildcard "*.xml" as
<mappers>
<mapper resource="mybatis/mapper/*.xml" />
</mappers>
How can I achieve it ?

MyBatis can also load mappers (Interfaces) from a package, see the documentation.
<mappers>
<package name="org.mybatis.builder"/>
</mappers>
Of course this seems to require that you have the interfaces, too, and not just xml files. Don't know of any method to load all the XML files, if you have no Interfaces, though.

I had the same problem today and I have resovled it with wildcard.
Is there a xml file for configure the sqlSessionFactory bean.append a property like <property name="mapperLocations" value="classpath:sqlmap/**/*Mapper.xml"/> ,
classpath:sqlmap/**/*Mapper.xml is your mapper.xml's location,and delete all the mapper resource,thant's all.

Related

sun_checks.xml location in checkstyle-idea.xml

My checkstyle-idea.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CheckStyle-IDEA">
<option name="configuration">
<map>
<entry key="active-configuration" value="CLASSPATH:/sun_checks.xml:The default CheckStyle rules" />
<entry key="check-nonjava-files" value="false" />
<entry key="check-test-classes" value="false" />
<entry key="location-0" value="CLASSPATH:/sun_checks.xml:The default CheckStyle rules" />
<entry key="suppress-errors" value="false" />
<entry key="thirdparty-classpath" value="" />
</map>
</option>
</component>
</project>
And i can't seem to find this file in my Ubuntu 14.04. Searched everywhere. The only solution i see is to download it and replace that location.
But is there a way to understand where it is located now?
My /etc/environment doesn't contain it also. So where is it? Because CheckStyle works and checks the code in Idea.
The Checkstyle-IDEA plugin contains a copy of the Sun Checks (sun_checks.xml). It is contained in the root of the plugin's JAR file. The plugin JAR is usually located at:
Linux: ~/.<PRODUCT><VERSION>/config/plugins/CheckStyle-IDEA/lib/checkstyle-idea-4.5.2.jar
Windows: C:\Users\<YourUserName>\.<PRODUCT><VERSION>\config\plugins\CheckStyle-IDEA\lib\checkstyle-idea-4.5.2.jar
Version numbers may differ in your case. The part .<PRODUCT><VERSION> should appear as something like .IdeaIC13 (for IntelliJ IDEA version 13).
Note that you should not need to find this file. You should never change it or touch it in any way. If you need to change the rules configuration, create your own rule set and use that. You may of course create your own rule set based on a copy of sun_checks.xml.
For mac I located it by typing:
sudo find / -iname Checkstyle-IDEA
Which lead me to
~/Library/Application Support/IntelliJIdea15/CheckStyle-IDEA/lib
I was then able to open the jar with an archive program and make a copy of the sun_checks.xml for my own customization.

How to deploy different App.config values (with WiX)

I've been looking for a best practice recommendation on how to deploy an application with a WiX installer for different values in its App.config file. For example.
On my local development machine, I use App.config settings for our test environment:
<configuration>
<appSettings>
<WorkingDirectory>C:\Working</WorkingDirectory>
</appSettings>
<connectionStrings>
<add name="ApplicationEntities"
connectionString="[TestingConnectionString]"
providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
When I deploy to a test environment, those settings are acceptable. However, when we deploy to a production environment, I'd like them to be different. For example:
<configuration>
<appSettings>
<WorkingDirectory>\\prodserver\Working</WorkingDirectory>
</appSettings>
<connectionStrings>
<add name="ApplicationEntities"
connectionString="[ProductionConnectionString]"
providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
The answer to my question may very well be independent of WiX. But just in case, here is my WiX Product.wxs file's relavent fragment:
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="ProductComponent" Guid="{MY-GUID}">
<File Id="Application.exe"
Name="Application.exe"
Source="..\Application.exe"
Vital="yes"
KeyPath="yes"
DiskId="1" />
<File Id="Application.exe.config"
Name="Application.exe.config"
Source="..\Application.exe.config"
Vital="yes"
KeyPath="no"
DiskId="1" />
</Component>
</ComponentGroup>
</Fragment>
This setup ends with a manual edit of the App.config on the production server, which invites manual error. What would be a better way to handle this to accommodate an automated deployment?
I can think of two options, either deploy the app.config file and edit it using the XmlFile Element, or maintain multiple app.config files each representing your target environment, then deploy the appropriate file.
Here's an exmaple of both options, notice that I copy the file rather than just placing it on the file system. This serves two purposes, firstly you can see by the filename which one has been deployed, secondly if development.app.config and production.app.config are placed in the same location you will get an ICE30 validation error, by copying the file afterwards it avoids this error.
Notice also that I have a condition associated with the component, you'll need to decide how you identify which environment you are deploying to. Some ideas could be to use the machine name, the OU or simply pass it in on the command line as a property.
<Component Id="development.app.config" Guid="*">
<Condition>DEVELOPMENT</Condition>
<File Name="development.app.config" KeyPath="yes">
<CopyFile Id="development.app.config" DestinationName="app.config" />
</File>
<util:XmlFile
Id="WorkingDirectory"
Action="setValue"
File="app.config"
ElementPath="/configuration/appSettings"
Name="WorkingDirectory"
Value="C:\Working"
Permanent="no" />
</Component>
<Component Id="production.app.config" Guid="*">
<Condition>PRODUCTION</Condition>
<File Name="production.app.config" KeyPath="yes">
<CopyFile Id="production.app.config" DestinationName="app.config" />
</File>
<util:XmlFile
Id="WorkingDirectory"
Action="setValue"
File="app.config"
ElementPath="/configuration/appSettings"
Name="WorkingDirectory"
Value="\\prodserver\Working"
Permanent="no" />
</Component>

What are the steps needed in DITA-OT to pass ANT command line parameters to custom plugin's override XSLT-script

This question follows this: Is it possible to pass custom ANT parameters into custom plugin with DITA-OT?
I have plugin folder called: com.mymods.pdf under DITA-OT/plugins folder. Under is explained the structure and files shortly (follows this example closely http://dita-ot.github.io/1.8/readme/dita2pdf-customization.html). Plugin works but now I want to pass ANT command line parameters into mycustom.xsl:
com.mymods.pdf/
cfg/
common/
vars/
en.xml
fo/
attrs/
mycustom.xsl
xsl/
mycustom.xsl
catalog.xml
integrator.xml
plugin.xml
build_mymods_pdf_template.xml (dita2com.mymods.pdf.init target is here and it depends on dita2pdf2)
build.xml (<project><import file="build_mymods_pdf.xml"/></project>)
insertParameters.xml (see the linked question for contents)
So where I need to apply changes and/or add new files?
I use the plugin from other location with "mainANT.xml" which has target and transtype for using "dita2mymodsPDF".
plugin.xml code:
<?xml version='1.0' encoding='UTF-8'?>
<plugin id="com.mymods.pdf">
<require plugin="org.dita.pdf2" />
<feature extension="dita.conductor.transtype.check" value="com.mymods.pdf" />
<feature extension="dita.transtype.print" value="com.mymods.pdf" />
<feature extension="dita.conductor.target.relative" file="integrator.xml" />
<feature extension="dita.conductor.com.mymods.pdf.param" file="insertParameters.xml"/>
<extension-point id="dita.conductor.com.mymods.pdf.param" name="PDF XSLT parameters"/>
</plugin>
build_mymods_pdf_template.xml code:
<?xml version='1.0' encoding='UTF-8'?>
<project name="com.mymods.pdf" default="com.mymods.pdf">
<property name="transtype" value="com.mymods.pdf"/>
<target name="dita2com.mymods.pdf.init">
<property location="${dita.plugin.com.mymods.pdf.dir}/cfg" name="customization.dir" />
<property location="${dita.plugin.com.mymods.pdf.dir}/xsl/fo/topic2fo_shell_fop.xsl" name="args.xsl.pdf" />
<property name="args.chapter.layout" value="BASIC" />
<property name="args.bookmark.style" value="COLLAPSED" />
<!--property name="args.fo.include.rellinks" value="nofamily" /-->
</target>
<target depends="dita2com.mymods.pdf.init, dita2pdf2" name="dita2com.mymods.pdf" />
</project>
Also integrator.xml code:
<?xml version='1.0' encoding='UTF-8'?>
<project name="com.mymods.pdf">
<target name="dita2com.mymods.pdf.init">
<property location="${dita.plugin.com.mymods.pdf.dir}/cfg" name="customization.dir" />
<property location="${dita.plugin.com.mymods.pdf.dir}/xsl/fo/topic2fo_shell_fop.xsl" name="args.xsl.pdf" />
<property name="args.chapter.layout" value="BASIC" />
<property name="args.bookmark.style" value="COLLAPSED" />
<!--property name="args.fo.include.rellinks" value="nofamily" /-->
</target>
<target depends="dita2com.mymods.pdf.init, dita2pdf2" name="dita2com.mymods.pdf" />
</project>
Not totally sure whether integrator.xml or build_mymods_pdf_template.xml is like it actually should. But this fileset works and uses mycustom.xsl (other for attributes and other for XSLT overrides). Now the problem is that how to get my own custom ANT parameters so the plugin can see its value.
This is really easy for pdf2 plugin but still can't yet get it working inside my com.mymods.pdf . I think I don't need to post catalog.xml because it just tells where are "mycustom.xsl" files that are working properly.
Really easy way, not the cleanest way to do this is:
Note: This applies for DITA-OT 1.8.4 check suitability for other versions.
Create your custom PDF plugin as told in: http://dita-ot.github.io/1.8/readme/dita2pdf-customization.html
Create "insertParameters.xml" as in: http://dita-ot.github.io/1.8/dev_ref/plugin-xsltparams.html
In my case with following custom parameters:
<?xml version='1.0' encoding='UTF-8'?>
<dummy>
<!-- EXAMPLE: <param name="paramNameinXSLT" expression="${antProperty}" if="antProperty"/> -->
<param name="custom.data1" expression="${custom.data1}" if="custom.data1"/>
<param name="custom.data2" expression="${custom.data2}" if="custom.data2"/>
</dummy>
Now drop this "insertParameters.xml" into DITA-OT\plugins\org.dita.pdf2
Create processing to custom.xsl under xsl\custom.xsl.
Here is an example code snippet for custom.xsl
<?xml version='1.0' encoding='UTF-8'?>
<snippet>
<xsl:param name="custom.data1"/>
<xsl:param name="custom.data2"/>
<fo:block><xsl:value-of select="$custom.data1"/></fo:block>
<fo:block><xsl:value-of select="$custom.data2"/></fo:block>
</snippet>
Run integrator.xml to integrate changes into your DITA-OT.
Give in command line commands for running your PDF scenario like: "ant dita2mypdf -f -Dcustom.data1="myCustomParameter1value" -Dcustom.data2="myCustomParameter2value"
Run the process to create PDF and your parameters should be visible!
What this question was really intended to achieve to get a step by step instruction to set all these things to work 100% in the custom plugin that not a single thing needs to be added into DITA-OT default plugins (not even single file into pdf2 folder as in this solution). This could make updating DITA-OT remarkably easier for future.
The cleaner? alternative to this approach is
add a placeholder insertParameters.xml to the root of the DITA-OT 1.8.5. The file does not exist in the standard DITA-OT 1.8.5
<?xml version='1.0' encoding='UTF-8'?>
<dummy>
<param name="dummy" expression="{$dummy} if="dummy"/>
</dummy>
add the override insertParameters.xml to the root of your plugin
<?xml version='1.0' encoding='UTF-8'?>
<dummy>
<param name="my.runtime.parameter" expression="{$my.runtime.parameter} if="my.runtime.parameter"/>
</dummy>
Then run ant -f integrator.xml
Without knowing precisely which parameters you need to pass, it's difficult to answer this question. However, let's assume you're invoking this from the command line and you've defined a transtype of mymodspdf. The command would look like this:
ant -f build.xml -Dtranstype mymodspdf -Dmyparameter1 paramval1 -Dmyparameter2 paramval2
HTH,
Julio J. Vazquez
Write Spirit
http://www.writespiritservices.com

How can I let CruiseControl.NET/nant run all Unittest projects postfixed with .Test?

In our continuous integration setup, I would like to set up CruisControl.NET to automatically run all our unittests. However, I don't want to have to specify every unittest dll seperately in the configuration.
All the unittest projects are all postfixed with .Test (and all non-unittest projects are not). How can I configure CruiseControl.NET to run all the unittests from these projects (I am using v1.5.7256.1 of CruiseControl.NET)?
My current config attempt:
<nunit>
<path>$(nunit.path)</path>
<assemblies>
<assembly>$(working.dir)\**\*.Test.dll</assembly>
</assemblies>
</nunit>
I'm finding it very difficult to find documentation on this specific nunit element. Most pages I can find talk about using exec, nunit2 or another nunit element or the nunit-console commandline options.
I don't have much experience with managing the build environment and am working on an existing configuration where every assembly was specified separately in the following manner.
<nunit>
<path>$(nunit.path)</path>
<assemblies>
<assembly>$(artifact.dir)\test1.dll</assembly>
<assembly>$(artifact.dir)\test2.dll</assembly>
</assemblies>
</nunit>
Hence my failed attempt using wild cards.
EDIT:
Here is some extra xml of my configuration file to show the context a little bit:
<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
<project name="MyProject">
<!-- whole bunch of other elements -->
<tasks>
<nunit>
<!-- see above -->
</nunit>
</tasks>
</project>
</cruiscontrol>
After Mightmuke's suggestion, I tried replacing the <nunit> element with his suggestion, but got the following exception: Unable to instantiate CruiseControl projects from configuration document. Configuration document is likely missing Xml nodes required for properly populating CruiseControl configuration. Unable to load array item 'property' - Cannot convert from type System.String to ThoughtWorks.CruiseControl.Core.ITask for object with value: ""
Then I tried to move the <property> and <foreach> element outside the element. Then I get the exception: Unused node detected: <property name="nunit.filelist" value="" />
I'm now trying to find out more about the <foreach> element and where I can put that, but somehow I find it hard to find any documentation about it.
EDIT2:
I found the documentation of the nunit task I'm using: http://ccnet.sourceforge.net/CCNET/NUnit%20Task.html
I specifies the element to be of type String[]. I'm not sure what that means... but it seems from the example that it just means that it must contain a list of child elements of the same name in Singular form.
PS: I realize this question is getting a bit out of hand... When the whole thing is solved, I'll try to edit it in such a format so that it might be useful to someone else later.
This is an example configuration if you were to use the nunit console.
<property name="nunit.filelist" value="" />
<foreach item="File" property="testfile" verbose="true">
<in>
<items basedir=".">
<include name="${working.dir}\**\*.Test.dll" />
</items>
</in>
<do>
<property name="nunit.filelist" value="${nunitfile.list + ' ' + testfile}" />
</do>
</foreach>
<exec program="nunit-console-x86.exe" failonerror="true" verbose="true">
<arg value="${nunit.filelist}" />
<arg value="/xml=nunit-results.xml" />
<arg value="/nologo" />
<arg value="/nodots" />
</exec>
This hasn't been tested, and there are likely better ways to skin it, but it will hopefully provide a starting point for you.

Running a TestNG class via testng.xml in Eclipse (Windows)

I have a class named "ATestClass" and it has some methods such as "launchSite", "loginToSite" etc.
Now, I want to control the order of execution of these methods. So, I created an xml file "testng.xml" as below:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Classes" verbose="10">
<test name="ATestClass" preserve-order="true">
<classes>
<class name="ATestClass" >
<methods>
<include name="launchSite" />
<include name="searchAndExport" />
<include name="loginToSite" />
</methods>
</class>
</classes>
</test>
</suite>
Now, my class doesn't care this xml file and executes the methods in alphabetical order. I created both class and xml file in the same package.
Somehow, the class is not able to recognize its corresponding xml config file.
Please help me!
Are you using the latest version of TestNG? Make sure you are.