Railo Compile into CFCLasses directory has 4 digits in name??

60 views
Skip to first unread message

Mark Niland

unread,
Feb 15, 2010, 9:23:36 AM2/15/10
to Railo
Hi Guys

I need to take the compiled classes and use them in a build process, I
am trying to locate the directories within CFClasses automatically but
know little about how and why the last digits of the file names are
generated. can anyone help?

for example Railo/CFClasses/CFC__Myproject7384

if I could find out where the 7384 comes from it would be a great help

Michael Offner-Streit

unread,
Feb 15, 2010, 12:18:24 PM2/15/10
to ra...@googlegroups.com
Hi Mark

i have somewhere a script, that translate a regular path to this
cfclasses path, give me some time to find it ;-)

/micha

p.s. the numbers makes the name identical, because railo replace all not
us-ascci characters characters with underline and because that the
following 2 example would generate the same path
- /sälü/susi
- /sülö/susi

the number represent the replaced characters and their position


Mark Niland schrieb:


--
Michael Offner-Streit
CTO
Railo Technologies GmbH
michael...@railo.ch
www.getrailo.com

Mailing List (english): http://groups.yahoo.com/group/railo_talk/
Mailing List (german): http://de.groups.yahoo.com/group/railo/
Linked in: http://www.linkedin.com/e/gis/71368/0CF7D323BBC1
Issue Tracker: http://jira.jboss.org/jira/browse/RAILO
Blog: http://www.railo-technologies.com/blog

denstar

unread,
Feb 15, 2010, 2:04:06 PM2/15/10
to ra...@googlegroups.com
On Mon, Feb 15, 2010 at 7:23 AM, Mark Niland wrote:
> Hi Guys
>
> I need to take the compiled classes and use them in a build process, I
> am trying to locate the directories within CFClasses automatically but
> know little about how and why the last digits of the file names are
> generated. can anyone help?

I've got an ant script that will ditch those numbers.

It's not heavily tested, but seemed to work alright.  It just uses a regular expression, so directories named someFun2 might not "translate" without a tweak.

It uses the ant-contrib package for doing regex and loop stuff.

Here's the target that does the dirty work:

<target name="compile-cf">
<mkdir dir="${war.temp.dir}" />
<sequential>
    <antcall target="runwar.start.background" inheritAll="true"/>
    <antcontrib:for param="file">
        <path>
            <dirset dir="${src.dir}">
                <include name="*" />
            </dirset>
        </path>
        <sequential>
            <antcontrib:propertyregex override="yes" property="mappingName" input="@{file}" regexp=".*/|.*\\([^\.]*)" replace="\1" />
            <echo message="Compiling mapping - ${mappingName} - @{file}"/>
            <get src="http://localhost:8080/railo/build.cfc?method=compile-mapping&amp;mapping=${mappingName}"
                    dest="${mappingName}.compile.results.properties"
                    verbose="true" ignoreerrors="true" />
            <copy todir="${war.temp.dir}" verbose="true">
                <fileset dir="${basedir}/WEB-INF/railo/cfclasses/" />
                <chainedmapper>
                    <regexpmapper from="^CF_.+_(${mappingName})\d{4}/+(.*)" to="\1/\2"/>
                    <regexpmapper from="(.*)_cf(.).+\.class$$" to="\1.cf\2"/>
                </chainedmapper>
            </copy>
        </sequential>
    </antcontrib:for>
    <antcall target="runwar.stop" inheritAll="true"/>
</sequential>
</target>

Igal

unread,
Feb 22, 2012, 12:42:36 PM2/22/12
to ra...@googlegroups.com
hi Michael,

do you know where I can find that algorithm?

I want to write some code that compares the source folders with the cfclasses folders so I can see which files are obsolete.

thanks,


Igal


On Monday, February 15, 2010 9:18:24 AM UTC-8, Michael Offner-Streit wrote:
Hi Mark

i have somewhere a script, that translate a regular path to this
cfclasses path, give me some time to find it ;-)

/micha

p.s. the numbers makes the name identical, because railo replace all not
us-ascci characters characters with underline and because that the
following 2 example would generate the same path
- /sälü/susi
- /sülö/susi

the number represent the replaced characters and their position


Mark Niland schrieb:
> Hi Guys
>
> I need to take the compiled classes and use them in a build process, I
> am trying to locate the directories within CFClasses automatically but
> know little about how and why the last digits of the file names are
> generated. can anyone help?
>
> for example Railo/CFClasses/CFC__Myproject7384
>
> if I could find out where the 7384 comes from it would be a great help
>
>  


--
Michael Offner-Streit
CTO
Railo Technologies GmbH

Michael Offner

unread,
Feb 22, 2012, 2:39:45 PM2/22/12
to ra...@googlegroups.com
this is a one way solution, this means it is impossible to get the original name from the class file name, but of course it is possible the other way around.

something like this should work
<cfset pc=getPageContext()>

<!--- first get a absolute path --->
<cfset abs=GetCurrentTemplatePath()>
<cfdump var="#abs#">

<!--- contract path to map to a mapping in Railo --->
<cfset contract=contractPath(abs)>
<cfdump var="#contract#">

<!--- create/load PageSource for path --->
<cfset ps=pc.getRelativePageSource(contract)>
<cfset mapping=ps.getMapping()>

<!--- get path to class root and the class file --->
<cfset classRoot=mapping.getClassRootDirectory()>
<cfset classFile=classRoot.getReal(ps.getJavaName())>
<cfdump var="#classFile#" label="classFile">



/micha



2012/2/22 Igal <d...@21solutions.net>

Michael Offner

unread,
Feb 22, 2012, 2:43:53 PM2/22/12
to ra...@googlegroups.com
replace
<cfset ps=pc.getRelativePageSource(contract)>
with
<cfset ps=pc.getPageSource(contract)>


/micha

2012/2/22 Michael Offner <mic...@getrailo.com>

Igal

unread,
Feb 22, 2012, 2:45:36 PM2/22/12
to ra...@googlegroups.com
one-way solution is all I need.  it works.  thank you :)



On Wednesday, February 22, 2012 11:39:45 AM UTC-8, Michael Offner wrote:
this is a one way solution, this means it is impossible to get the original name from the class file name, but of course it is possible the other way around.

something like this should work
<cfset pc=getPageContext()>

<!--- first get a absolute path --->
<cfset abs=GetCurrentTemplatePath()>
<cfdump var="#abs#">

<!--- contract path to map to a mapping in Railo --->
<cfset contract=contractPath(abs)>
<cfdump var="#contract#">

<!--- create/load PageSource for path --->
<cfset ps=pc.getRelativePageSource(contract)>
<cfset mapping=ps.getMapping()>

<!--- get path to class root and the class file --->
<cfset classRoot=mapping.getClassRootDirectory()>
<cfset classFile=classRoot.getReal(ps.getJavaName())>
<cfdump var="#classFile#" label="classFile">



/micha

 

Michael Offner

unread,
Feb 22, 2012, 2:57:24 PM2/22/12
to ra...@googlegroups.com
after thinking a little bit about this, i have seen a problem with my solution.
let's say you have the following structure

/my/server/webroot/a/b/c/index.cfm

and you have 2 mappings defined in the admin
virtual:"/gian"; physical:"/my/server/webroot/a/b/c/"
virtual:"/susi"; physical:"/my/server/webroot/a/b/c/"
and you have a application mapping defined in the application.cfc
virtual:"/urs"; physical:"/my/server/webroot/a/b/c/"

and then you have the following code in "/my/server/webroot/index.cfm"
<cfinclude template="/a/b/c/index.cfm">
<cfinclude template="/susi/index.cfm">
<cfinclude template="/gian/index.cfm">
<cfinclude template="/urs/index.cfm">

you generate 4 different class files!

in other words, in Railo the relation between a source template and the class file depends on the environment.
for example, the per application mapping, it is impossible to find this connection when you not have defined the same per application mapping in your case.
it is possible that one mapping hides a other mapping, the "contractPath" function i my example will return path for "/gian" or "/susi", this means i will only see one of this class files.

Igal

unread,
Feb 22, 2012, 3:16:40 PM2/22/12
to ra...@googlegroups.com
so the problem is when multiple virtual paths point to the same physical path?

maybe I can enumerate all the mappings and if multiple virtual paths point to the same physical path I can test all of them for fileExists()?

Michael Offner

unread,
Feb 22, 2012, 3:19:46 PM2/22/12
to ra...@googlegroups.com
if you know all the virtual path then yes.
it would be a much easier when you could translate from class to template.

/micha



2012/2/22 Igal <d...@21solutions.net>

Igal

unread,
Feb 22, 2012, 4:26:06 PM2/22/12
to ra...@googlegroups.com

On Wednesday, February 22, 2012 12:19:46 PM UTC-8, Michael Offner wrote:
if you know all the virtual path then yes.

I am able to get the virtual paths with the function below, but for some reason it doesn't show me mappings that are defined in this.mappings in Application.cfc 


<cffunction name="getMappingsInvert" 
hint="returns a struct where the key is the physical path and the value is a ; separated list of all virtual paths that point to it">
<cfset Local.result = {}>
<cfset Local.mappings = GetPageContext().getServletConfig().getMappings()>
<cfloop array="#Local.mappings#" index="Local.ai">
<cfset Local.physical = Local.ai.physical>
<cfif Local.physical contains '{'>

<cfset Local.physical = ExpandPath( Local.ai.physical )>
</cfif>
<cfif StructKeyExists( Local.result, Local.physical )>
<cfset Local.value = Local.result[ Local.physical ]>
<cfelse>
<cfset Local.value = "">
</cfif>
<cfset Local.value = ListAppend( Local.value, Local.ai.virtual, ';' )>
<cfset Local.result[ Local.physical ] = Local.value>
</cfloop>
<cfreturn Local.result>
</cffunction>


 
it would be a much easier when you could translate from class to template.

yes, but that would not work with the one-way solution so I guess that's not an option
 
 
/micha



2012/2/22 Igal

Igal

unread,
Feb 23, 2012, 12:18:27 AM2/23/12
to ra...@googlegroups.com
ok, I got it to work rather nicely.

if anyone's interested, I posted a working cfc at https://gist.github.com/1890454

to use it just do something like:

<cfset ofd = CreateObject( 'component', 'UnusedCfFilesDetector' )>

<cfset unused.Root = ofd.ScanFolderForUnusedCfFiles( '/' )>
<cfset unused.CFC = ofd.ScanFolderForUnusedCfFiles( '/cfc' )>
<cfset unused.Test = ofd.ScanFolderForUnusedCfFiles( '/test' )> <!--- add more folders to be scanned as needed --->

<cfdump var="#unused#">


Michael Offner

unread,
Feb 23, 2012, 3:51:39 AM2/23/12
to ra...@googlegroups.com
great!
if you need any addional help ...

/micha

2012/2/23 Igal <d...@21solutions.net>

Igal

unread,
Feb 23, 2012, 12:06:49 PM2/23/12
to ra...@googlegroups.com
thanks Michael,

you've been extremely helpful and I really appreciate your help.

and you probably get this a lot -- but thanks again for creating the Railo project and releasing it as open source.


Igal :)

Dave Merrill

unread,
Feb 23, 2012, 2:21:44 PM2/23/12
to ra...@googlegroups.com
Is there any chance that files whose names don't contain any offending characters could have their names preserved as-is? Obviously I don't understand the whole issue, but I don't see the need to modify names that don't require it. Is that in case some non-aliased files end in 4 digit numbers? If so, most code bases don't have files like that.

Dave

Igal

unread,
Feb 23, 2012, 3:52:57 PM2/23/12
to ra...@googlegroups.com
@Dave - most files do not have the digits appended, all .class filenames are lower-cased and any non-alpha characters (like dots and colons) are replaced with an under_score

in general I avoid using non-ascii characters in filenames.  the digits-suffixes that I saw are found in base folder names.

open up /WEB-INF/railo/cfclasses/ and take a look at the contents there.




Viktor Krasynskyy

unread,
Feb 23, 2012, 5:55:08 PM2/23/12
to ra...@googlegroups.com
It's good tool, but I would like to report few issues/suggestions:
1) If folder cannot be resolved (see below one of the cases), the tool is stuck in infinite loop (resolveFolder method), I think I fixed it;
2) CustomTags (not-default Railo ones) are not added in this.MappingsInvert (because the have VirtualPath with digits). I think getMappingsInvert should be changed to process custom tags separately (not fixed)
3) I think the tool should be recursive by default (check the whole tree), changed in the new revision
4) I changed default mask to "*.cf?|*.cfml". HTML does not contain CFML very often; *.cf* - would return false positive for internal SVN files (when folder is under SVN).

I posted changed version here https://gist.github.com/1895420

You can completely ignore it of course :)

Igal

unread,
Feb 23, 2012, 7:37:33 PM2/23/12
to ra...@googlegroups.com
hi Viktor,

see my comments below:

On Thursday, February 23, 2012 2:55:08 PM UTC-8, Viktor Krasynskyy wrote:
It's good tool, but I would like to report few issues/suggestions:
thank you.  I didn't think that anyone will find it useful so I didn't bother to test it too thoroughly, but now it seems like it's a good idea. 
 
1) If folder cannot be resolved (see below one of the cases), the tool is stuck in infinite loop (resolveFolder method), I think I fixed it;
can you give me an example?  when I tested it it simply returned an empty array which was the expected value. 
 
2) CustomTags (not-default Railo ones) are not added in this.MappingsInvert (because the have VirtualPath with digits). I think getMappingsInvert should be changed to process custom tags separately (not fixed)
I will look into that.
 
3) I think the tool should be recursive by default (check the whole tree), changed in the new revision
my concern was a Request Timeout with complex folder structures that contain many resources, but I will add another param to the main method to address this.
 
4) I changed default mask to "*.cf?|*.cfml". HTML does not contain CFML very often; *.cf* - would return false positive for internal SVN files (when folder is under SVN).
accepted.




I posted changed version here https://gist.github.com/1895420

You can completely ignore it of course :)

Viktor Krasynskyy

unread,
Feb 23, 2012, 8:27:13 PM2/23/12
to ra...@googlegroups.com
1) It happened when I pointed it to a my CustomTags folder. But I think the same thing would happen if you point it to a random folder, outside of Railo-related folders. There is a recursion in the end of the method, so it some point it just enters into a dead loop (at least on Windows env, C: -> C: -> C: or something like that).
3) It actually works pretty fast (timeout can always be increased by passing ?RequestTimeout=NNNNN).
 
Thank you.

Igal

unread,
Feb 23, 2012, 8:38:09 PM2/23/12
to ra...@googlegroups.com
I updated the file and it now correctly finds the custom tag folders but it will take some more work to make it scan them properly.

perhaps a better way would be to pass a physical path rather than a virtual one.


On Thursday, February 23, 2012 5:27:13 PM UTC-8, Viktor Krasynskyy wrote:
1) It happened when I pointed it to a my CustomTags folder. But I think the same thing would happen if you point it to a random folder, outside of Railo-related folders. There is a recursion in the end of the method, so it some point it just enters into a dead loop (at least on Windows env, C: -> C: -> C: or something like that).
that makes sense as I was accounting for a trailing slash but not for a colon.

 
3) It actually works pretty fast (timeout can always be increased by passing ?RequestTimeout=NNNNN).
right, but if you have a folder with thousands of files/images it will not be that fast.  anyway, I added a parameter to the function so passing true will recurse the folders.


 
 
Thank you.
Reply all
Reply to author
Forward
0 new messages