Titanium: How to safely add `tiapp.xml` to VCS without exposing keys - titanium

I want to add my Titanium app to VCS.
However, I do not want to share any production keys or other important stuff that should be kept secret and thus should not added to a VCS.
Things like:
<property name="acs-password-development" type="string">XXXX</property>
<property name="acs-oauth-secret-development" type="string">XXXX</property>
<property name="acs-oauth-key-development" type="string">XXXX</property>
<property name="acs-api-key-development" type="string">XXXX</property>
<property name="acs-authbase-url-development" type="string">https://secure-identity.cloud.appcelerator.com</property>
<property name="acs-base-url-development" type="string">https://api.cloud.appcelerator.com</property>
<property name="acs-username-production" type="string">appc_app_user</property>
<property name="acs-password-production" type="string">XXX</property>
<property name="acs-oauth-secret-production" type="string">XXXX</property>
<property name="acs-oauth-key-production" type="string">XXXX</property>
<property name="acs-api-key-production" type="string">XXXX</property>
<property name="acs-authbase-url-production" type="string">https://secure-identity.cloud.appcelerator.com</property>
<property name="acs-base-url-production" type="string">https://api.cloud.appcelerator.com</property>
<property name="appc-org-id" type="string">XXXX</property>
<property name="appc-creator-user-id" type="string">XXXX</property>
etc.
(Is there any other important stuff I missed out?)
How would I deal with this issue?

Well, I think you can use a small script to build the application with a custom file configuration per environment (it's not in VCS). For example:
The configuration file could use the yaml format (or another one):
development:
configuration_variable: value
...
testing:
configuration_variable: value
...
production:
configuration_variable: value
...
The build script (you can use nodejs, python, etc) reads the configuration file and environment option to modify the tiapp.xml file. In this way you can keep out of VCS the production configuration.
To build your script, there are many libraries available in nodejs and python to modify xml files. You can check: https://www.npmjs.com/package/tiapp.xml

Related

java persistence collection of metamodel types is empty

While deploying my jpa project to wildfly server i am gettings following warning:
The collection of metamodel types is empty.
Model classes may not have been found during entity
search for Java SE and some Java EE container managed persistence units.
Please verify that your entity classes are referenced in persistence.xml using
either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element
My persistence xml looks like this
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1">
<persistence-unit name="primary" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/example</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="javax.persistence.schema-generation.create-source" value="metadata"/>
<property name="javax.persistence.schema-generation.drop-source" value="metadata"/>
<property name="eclipselink.target-server" value="JBoss"/>
<property name="eclipselink.weaving" value="static"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/example"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="xxx"/>
</properties>
</persistence-unit>
</persistence>
My Database tables are not created due to this.
Please help me understand this problem. As i am not able to understand the root cause of this.
For people who would come across this question like I did: I've just met this issue in Eclipse 2020-06 when running JPA Tools > Generate Tables from Entities, which is a situation probably different from the one in the question albeit with a strictly identical error message.
It turns out that the only thing needed to work around it is to hit Project > Clean and select the JPA project in the list.
For some unknown reason in my case, cleaning the project is necessary between runs of the Generate Tables command. I can't figure out why but that's the way it is. HTH

Migration from glassfish to apache

I created a project using Netbeans and selected Glassfish 3.1 as a server, it also uses Derby database. Now I want to migrate to Apache Tomcat 7, I just did the following:
Stopped Glassfish
Changed the Netbeans project's properties to use Apache 7 instead of Glassfish
Added Apache to Netbeans and started it
When I try to build the project, several error messages appear like:
error: cannot find symbol
import javax.persistence.Basic;
although I ensured that /bin path of Java is set correctly in Apache server properties in Netbeans and that src.zip path is also set.
I think there are some steps that must be followed to have a successful migration, can any one guide me?
Thanks
Apache Tomcat does not come with the JPA specification. It is a Servlet container only.
You must add JPA specification plus Hibernate (implementation) to your project and make sure it will be deployed on your WEB-INF/lib.
Then, make sure your Persistence Unit is of transaction-type="RESOURCE_LOCAL", and configure all necessary properties to create a connection.
Example:
<persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL">
<class>com.sample.domain.YourEntity</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:." />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>
</persistence-unit>
Obs: this is an HSQLDB example. Adjust for Derby. ;-)
UPDATE: there's a great tutorial for Tomcat+JPA+EclipseLink here.

Adding folder to classpath in Velocity using Spring framework

How can I add an entire folder to Velocity and use the files inside as resource bundles?
Currently in my velocity.xml I have this code:
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="parentMessageSource">
<ref bean="globMessageSource"/>
</property>
<property name="basenames">
<list>
<value>classpath:/WEB-INF/i18n</value>
<value>/WEB-INF/templates/velocity/my_vm_template</value>
</list>
</bean>
I need to add i18n folder to the classpath so that its containing files can be seen by the VelocityTools version 1.4 in the toolbox.xml:
<tool>
<key>test</key>
<scope>request</scope>
<class>org.apache.velocity.tools.generic.ResourceTool</class>
<parameter name="bundles" value="i18n.ss_messages"/>
<parameter name="locale" value="en_US"/>
</tool>
The code is giving me an error message: "java.util.MissingResourceException: Can't find bundle for base name i18n.ss_messages, locale en_US"
This question relates to VelocityTools error - "java.util.MissingResourceException: Can't find bundle for base name WEB-INF.conf.resources.ss_messages, locale en_US"
Sorry if it's a silly question, but I can't find anywhere describing how to add an entire folder to the classpath and be available as a bundle so it can support Velocity template localization.
IMPORTANT NOTE!! If I place my ss_messages_bg_BG.properties and ss_messages_en_US.properties files in /WEB-INF/classes/i18n then it works, but I want to place them in a different folder ideally in /WEB-INF/templates/i18n. How do I do that?
Do you use maven? You could tell maven to use that directory as a resource:
<resource>
<!-- Velocity requires to be in classpath -->
<directory>src/main/webapp/WEB-INF/i8n</directory>
<filtering>true</filtering>
</resource>

MSBuild Contrib XMLMassUpdate and NHibernate configuration

I'm attempting to build up an MSBuild file to deploy a set of several websites to multiple environments. At the moment, I've built the project and have it dumped into a directory.
I'm using the variable $(AdminConsoleConfigFilePath) to refer to the path of the web.config file in this directory. My substitutions file is denoted by the variable $(AdminConsoleConfigReplacementFile). I've set up the following task in my msbuild file for the project:
<Target Name="AdminConsoleConfig" DependsOnTargets="BuildAdminConsole">
<Message Text="Beginning configuration for AdminConsole at $(AdminConsoleConfigFilePath) using $(AdminConsoleConfigReplacementFile)" Importance="high"/>
<XmlMassUpdate ContentFile="$(AdminConsoleConfigFilePath)" SubstitutionsFile="$(AdminConsoleConfigurationReplacementPath)"
ContentRoot="$(ConfigurationContentReplacementXPathRoot)" SubstitutionsRoot="$(SubstitutionsXPathRoot)"/>
<Message Text="Finished configuration for AdminConsole using $(AdminConsoleConfigReplacementFile)" Importance="high"/>
`
The values of the other variables here are declared as follows:
<ConfigurationContentReplacementXPathRoot>/configuration</ConfigurationContentReplacementXPathRoot>
<SubstitutionsXPathRoot>/configuration/substitutions/$(Environment)</SubstitutionsXPathRoot>
Environment is the name of where the build is targeted. In this case, it's "qa".
My web.config has the typical hibernate-config section as follows:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.isolation">ReadCommitted</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">[redacted]</property>
<property name="show_sql">false</property>
<property name="generate_statistics">true</property>
<property name="current_session_context_class">web</property>
<property name="adonet.batch_size">250</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<mapping assembly="[redacted]"/>
</session-factory>
</hibernate-configuration>
My replacements file looks like the following:
<configuration xmlns:xmu="urn:msbuildcommunitytasks-xmlmassupdate">
<substitutions>
<dev></dev>
<qa>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property xmu:key="name" xmu:Transform="Replace" xmu:Locator="Match(name)" name="connection.connection_string">[redacted-qa]</property>
</session-factory>
</hibernate-configuration>
</qa>
Now, the connection.connection_string property is not being replaced (in the above code, I also could never get the closing tags for configuration and substitution to show in the editor on this site - might be a firefox issue). Any ideas? I've tried the following:
removing the namespace declaration for nhibernate-configuration from the web.config in question and the replacement file (both together and individually).
Adding a namespace prefix to the nhibernate declaration and prefixing the relevant nodes and attributes with it. Again, tried on both the web.config and the replacement file, both individually and in combination.
Attempted to use the latest nightly build from the MSBuild contrib project. Not only did this not work, it broke other things as well.
Tried using an XPath-based xmu:Locator. Also tried both with and without the xmu:key value (and even tried replacing it with xmu:Key).
I'm absolutely stumped. Does the XMLMassUpdate thing work at all? We'd like to keep the qa and production versions of the web.config (or at least the various sensitive bits) out of the main body of the code in case we get a junior dev or contractor in, so the current method of the web.qa.config and web.prod.config isn't really viable at this point. Any thoughts on how to implement this (besides the obvious one of just keeping copies of the full web.config for each environment and copying over after the build)?
Thanks,
Will
I haven't tried using the xmlmassupdate approach to configuration substitution myself. But there is an alternate approach which is to specify each configuration update individually in your target using the XmlFile/UpdateElement method, e.g.
<MSBuild.ExtensionPack.Xml.XmlFile
TaskAction="UpdateElement"
File="$(AdminConsoleConfigFilePath)"
XPath="/hibernate-configuration/session-factory/property[#name='connection.connection_string']"
InnerText="Initial Catalog=MyDatabase;Data Source=$(DatabaseServerInstance)"
/>
You then put your configurations in the header of your targets file, e.g.
<Choose>
<When Condition="$(Environment)=='DEV'">
<PropertyGroup>
<DatabaseServerInstance>DEVSERVER</DatabaseServerInstance>
</PropertyGroup>
</When>
<When Condition="$(Environment)=='QA'">
<PropertyGroup>
<DatabaseServerInstance>QASERVER</DatabaseServerInstance>
</PropertyGroup>
</When>
<When Condition="$(Environment)=='PROD'">
<PropertyGroup>
<DatabaseServerInstance>PRODSERVER</DatabaseServerInstance>
</PropertyGroup>
</When>
</Choose>
You can also put the "Choose" block into a separate file and include it from your targets file. I personally prefer this approach because it has allowed us to centralise the list of environment-specific properties, which can then be used by multiple targets files (e.g. if you have multiple applications to deploy that use the same database server in each environment).

What is the problem with NHibernate 2.1.0? I always get an error!

I've read in this post that all the ProxyFactory dependency was removed by using an interface in this post.
So you need to specify which implementation to use in the hibernate.cfg.xml file.
I've this configuration:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=.\SQLEXPRESS;Initial Catalog=MYDB;Integrated Security=true</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
</session-factory>
</hibernate-configuration>
I've added a refernce to the NHibernate.ByteCode.Castle.dll. When I run the test using MBunit, I get the error that my deployment folder should contain either NHibernate.ByteCode.Castle.dll or NHibernate.ByteCode.LinFu.dll. I guess this is right configuration and it should work. But it is not working. I've spent much time behind this.
P.S: When I donwloaded NHibernate, the NHibernate.ByteCode.Castle project was not built. I added the project to the solution and built it. Then I referenced the assembly.
I had this same situation not too long ago.
When you say you added a reference, was it to the actual project or test project? It should be within both. Also, ensure "Copy Local" is set to true in the properties(F4) of the reference.
Another approach I took to check that if dll is within the directory that the application is running from was by calling the following prior to any of the Configuration.
Console.WriteLine(Directory.GetCurrentDirectory());
In my situation, I learned that when using ReSharper to execute tests, it was running in a location different than I had expected and was not containing the dll. Doing a Clean Solution and rebuilding seemed to correct the issue.
Hope this gives you a couple of things to check.