I am developing some fixtures in Java to use with fitnesse slim. I run into problems (EXCEPTION:java.lang.NoClassDefFoundError:) when I must update my root page with paths like this:
!define TEST_SYSTEM {slim}
!path: C:\WORKSPACE\Projects\iperoom_67_workspace\acceptance_test_project\bin
!path: C:\WORKSPACE\Projects\iperoom_67_workspace\iperoom\BASE\common_util\target\classes
!path C:\WORKSPACE\Projects\iperoom_67_workspace\iperoom\BASE\dfc_util\target\classes
Where a class in i.e. ...BASE\dfc_util\target\classes; has the following imports:
import no.joint.iperoom.test.AbstractDfcTest;
code
.
.
.
Which gives the complete path in my local C drive workspace:
C:\WORKSPACE\Projects\iperoom_67_workspace\iperoom\BASE\dfc_util\target\classes\no\joint\iperoom\test
My question is could I say, on the root page:
classpath: C:\WORKSPACE\Projects\iperoom_67_workspace\iperoom\BASE*; as in take in all the .class files from here and up. Something more general?
and possibly import several pats to .class files on the fitnesse test page:
|import|
|dfc_util.target.classes.no.joint.iperoom.test.AbstractDfcTest|
Or is there any other and better way to solve this problem with a growing number of '!paths' in my root page due to calling one .class from another .class from antoher .class and so forth.
Or maybe my fixture code is not good enough:
public class SessionHelperTest /extends AbstractDfcTest/{
public boolean testNewSession() {
System.out.println("Hello Joint");
IDfSession session = SessionRegistry.getSuperUserSession("eRoomPCI_v_1_1");
try {
String si = session.getSessionId();
System.out.println("The sessionId is:\n" + si);
return true;
} catch (DfException e) {
e.printStackTrace();
return false;
}
}
}
Cheers
Magnus
I don't think path is going to work the way you want it to. If you define it at too low a level, I'm pretty sure it won't find your classes.
The !path works fine when you do any of the following:
This will get all of the class files under build/classes if it is under the folder fitnesse starts in:
!path build/classes
This will handle multiple jar files:
!path lib/*.jar
Important to note is that you can leverage environment variables for this. Assuming you have an environment variable called WORKSPACE defined that points to the base of your project, you can do this:
!path ${WORKSPACE}/acceptance_test_project/bin
!path ${WORKSPACE}/acceptance_test_project/common_util/target/classes
!path ${WORKSPACE}/acceptance_test_project/dfc_util/target/classes
The reality is that if your files are scattered across multiple folders, you will have to use multiple entries. If just to make sure you can control the order the path is processed. If you only do this on your FrontPage, then everything below it will inherit the same path. Then you only have to manage it in one location. So while the list might be longer than you prefer, the maintenance is managed.
Related
I would like to change package prefix and suffix in my ant build while generating java from idl. This has to be generic solution! The idea goes like that:
I have idl files (ONE.idl, TWO.idl) with namespace ONE_cb in first and TWO_cb in second (as _cb suffix is required for c++ compatibility). TWO_cb has atributes from ONE_cb, ONE_cb has only basic types. I want to change that to packages going like com.example.ONE and com.example.TWO.
I'm using JacORB 3.6. and I don't know how to do it.
My code looks like that:
<target name="idlj-generate">
<idl2java
srcdir="${psm.dir}/${project}/"
destdir="${build.generated.dir}"
includepath="${psm.dir}"
all="true">
<define key="__JACORB_GENERATE__"/>
<i2jpackage names=":com.example"/>
<i2jpackage names="_cb:"/>
</idl2java>
</target>
It doesn't work. As I stated before it has to be generic solution. adding
<i2jpackage names="TWO_cb:TWO"/> //option 2
<i2jpackage names="ONE_cb:ONE"/> //option 2b
Is not acceptable
Thank you for Your time.
If I understand you correctly you have something like
module ONE_cb
{
...
}
but you want it to be
com.example.ONE { ... }
This is feasible with i2jpackage e.g.
idl -forceOverwrite -d /tmp/generated -i2jpackage ONE_cb:com.example.ONE myfile.idl
The problem you have is that you are compiling both files at once. Remove the "all" and try compiling them in two phases.
If you are using Maven I would also recommend trying org.codehaus.mojo:idlj-maven-plugin as you can do multiple executions very easily with that.
To use multiple i2jpackage I got it working with
idl -forceOverwrite -d /tmp/generated -all -i2jpackagefile /tmp/file antBugJac608-2.idl
(where antBugJac608-2 #includes antBugJac608).
For various research I concluded that generic solution is immpossible.
Only way to perform changing prefix and suffix the same time is to explicite set all included names.
I'd like to modify some of my Grails domain classes at compilation time. I initially thought this was a job for Groovy's global ASTTransformation since I don't want to annotate my domain classes (which local transformers require). What's the best way to do this?
I also tried mimicking DefaultGrailsDomainClassInjector.java by creating my own class in the same package, implementing the same interfaces, but I probably just didn't know how to package it up in the right place because I never saw my methods get invoked.
On the other hand I was able to manually create a JAR which contained a compiled AST transformation class, along with the META-INF/services artifacts that plain Groovy global transformations require. I threw that JAR into my project's "lib" dir and visit() was successfully invoked. Obviously this was a sloppy job because I am hoping to have the source code of my AST transformation in a Grails plugin and not require a separate JAR artifact if I don't have to, plus I couldn't get this approach to work by having the JAR in my Grails plugin's "lib" but had to put it into the Grails app's "lib" instead.
This post helped a bit too: Grails 2.1.1 - How to develop a plugin with an AstTransformer?
The thing about global transforms the transform code should be available when the compilation starts. Having the transformer in a jar was what i did first! But as you said it is a sloppy job.
What you want to do is have your ast transforming class compile before others gets to the compilation phase. Here is what you do!
Preparing the transformer
Create a directory called precompiled in src folder! and add the Transformation class and the classes (such as annotations) the transformer uses in this directory with the correct packaging structure.
Then create a file called org.codehaus.groovy.transform.ASTTransformation in called precompiled/META-INF/services and you will have the following structure.
precompiled
--amanu
----LoggingASTTransformation.groovy
--META-INF
----services
------org.codehaus.groovy.transform.ASTTransformation
Then write the fully qualified name of the transformer in the org.codehaus.groovy.transform.ASTTransformation file, for the example above the fully qualified name would be amanu.LoggingASTTransformation
Implementation
package amanu
import org.codehaus.groovy.transform.GroovyASTTransformation
import org.codehaus.groovy.transform.ASTTransformation
import org.codehaus.groovy.control.CompilePhase
import org.codehaus.groovy.ast.ASTNode
import org.codehaus.groovy.control.SourceUnit
#GroovyASTTransformation(phase=CompilePhase.CANONICALIZATION)
class TeamDomainASTTransformation implements ASTTransformation{
public void visit(ASTNode[] nodes, SourceUnit sourceUnit) {
println ("*********************** VISIT ************")
source.getAST()?.getClasses()?.each { classNode ->
//Class node is a class that is contained in the file being compiled
classNode.addProperty("filed", ClassNode.ACC_PUBLIC, new ClassNode(Class.forName("java.lang.String")), null, null, null)
}
}
}
Compilation
After implementing this you can go off in two ways! The first approach is to put it in a jar, like you did! and the other is to use a groovy script to compile it before others. To do this in grails, we use _Events.groovy script.
You can do this from a plugin or the main project, it doesn't matter. If it doesn't exist create a file called _Events.groovy and add the following content.
The code is copied from reinhard-seiler.blogspot.com with modifications
eventCompileStart = {target ->
...
compileAST(pluginBasedir, classesDirPath)
...
}
def compileAST(def srcBaseDir, def destDir) {
ant.sequential {
echo "Precompiling AST Transformations ..."
echo "src ${srcBaseDir} ${destDir}"
path id: "grails.compile.classpath", compileClasspath
def classpathId = "grails.compile.classpath"
mkdir dir: destDir
groovyc(destdir: destDir,
srcDir: "$srcBaseDir/src/precompiled",
classpathref: classpathId,
stacktrace: "yes",
encoding: "UTF-8")
copy(toDir:"$destDir/META-INF"){
fileset(dir:"$srcBaseDir/src/precompiled/META-INF")
}
echo "done precompiling AST Transformations"
}
}
the previous script will compile the transformer before others are compiled! This enable the transformer to be available for transforming your domain classes.
Don't forget
If you use any class other than those added in your classpath, you will have to precompile those too. The above script will compile everything in the precompiled directory and you can also add classes that don't need ast, but are needed for it in that directory!
If you want to use domain classes in transformation, You might want to do the precompilation in evenCompileEnd block! But this will make things slower!
Update
#Douglas Mendes mentioned there is a simple way to cause pre compilation. Which is more concise.
eventCompileStart = {
target -> projectCompiler.srcDirectories.add(0, "./src/precompiled")
}
Hypothetical situation:
I have downloaded a Grails application from the web as a WAR file, foo.war. In the documentation it says that I can put my own custom configuration in /foo.groovy, because this path is included in grails.config.locations in Config.groovy. I can dump all my custom config in that one file and life is good.
How, here's my problem... The configuration for FooApp is big and hairy, and I don't want it all in one file. I would like to break it up into /bar.groovy and /baz.groovy to keep things organized. Is there a way to specify something in /foo.groovy so that FooApp will also pick up /bar.groovy and /baz.groovy and process them?
I already tried appending paths to grails.config.locations in /foo.groovy, but Grails didn't like that and threw a nasty exception on startup. I'm not sure what other approach to take.
Edit for clarity:
grails-app/conf/Config.groovy looks like this:
grails.config.locations = ["file:/foo.groovy"]
Now, without modifying grails-app/conf/Config.groovy, and only by modifying /foo.groovy, is there a way to load more config files other than /foo.groovy?
You could slurp the additional config files within foo.groovy:
foo.groovy
port {
to {
somewhere=8080
another {
place=7070
}
}
}
host = new ConfigSlurper().parse(new File("bar.groovy").toURL())
bar.groovy
to {
somewhere="http://localhost/"
another {
place="https://another.place.com/"
}
}
So within your app you have:
assert grailsApplication.config.port.to.somewhere == 8080
assert grailsApplication.config.port.to.another.place == 7070
assert grailsApplication.config.host.to.somewhere == "http://localhost/"
assert grailsApplication.config.host.to.another.place == "https://another.place.com/"
I have a symfony project which, because of DNS issues, is http://<project-name>/ locally, but it needs to be http://<qa-host-name>/<project-name>;/ when hosted in a more QA level environment but it may be http://<domain-name>/ for production (so, I need this to work for both). Now, the images folder will always be relative to the <project-name> directory, so locally it will be http://<project-name>/my-smilie.png and on QA it will be http://<qa-host-name>/<project-name>/my-smilie.png
Since everything is relative to the URL of the index.php, I thought that Symfony would have something to create dynamic URLs which work even if the context is different so that my template.php could have something like
<?php echo image_url("my-smilie.png");
/*see below for potential implementation*/?>
and it would output http://<project-name>/my-smilie.png, http://<qa-host-name>/<project-name>/my-smilie.png, or http://<domain-name>/my-smilie.png. (Relative URLs are fine, but absolute would be better).
Below is an example of what I am looking for, but I feel like I am trying to re-invent the wheel and that Symfony has already accomplished this.
function image_url($img)
{
return get_base_url() . '/images/' . $img;
}
function get_base_url()
{
$par = dirname( $_SERVER[ 'SCRIPT_NAME' ] );
if($par == "/") $par = "";
return $par;
}
try public_path('images/smilie.jpg') function
public_path() manual
I just came across a situation where the public_path helper does not work terribly well, but there is an alternative:
// this populates $host with absolue URL of the parent directory
// of the Symfony script
$host = $request->isSecure()? 'http://':'https://';
$host .= $request->getHost() . $request->getRelativeUrlRoot();
My files are referenced like so (it's all relative):
// WHERE YOU KEEP THE PAGE TITLE XML
public static string myPageTitleXML = "xml/pagetitles.xml";
and
using (StreamReader r = new StreamReader(myPageTitleXML))
{ //etc.. . .etc....etc..
}
I get system.io.directorynotfound, and "this problem needs to be shut down", when I double click the executable. But running it from the console works like a charm. What's wrong here?
I played around with attempting to set Environment.CurrentDirectory but couldn't get anything to work. Why should I have to do that anyway? It defeats the purpose of a relative path no?
responding.. .
"application" does not exist in the current context, i'll keep trying what people have mentioned, this is not a windows.form
testing
Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), myPageTitleXML); gives error URI formats are not supported, as does Path.GetFullPath(). Server.MapPath results in an error as well, this is currently offline
Well assuming this directory is somewhere under the directory in which your code is executing, it sounds like you can use ..
Application.ExecutablePath()
or
Application.StartUpPath()
.. to get an idea as to what your application is seeing when it goes in search of an 'xml' directory with the 'pagetitles.xml' file in it.
If the directory returned by one of these methods does not point where you thought it did, you'll need to move the location of your application or the location of this folder so that it is within the same directory as the app.
Hope this gets you on the right path.
So, when you run it from double clicking the executable, is there a file named pagetitles.xml in a folder named xml, where xml is a folder in the same location as the executable?
It's certainly possible to use relative paths like this, but I wouldn't really recommend it. Instead, maybe use something like:
string fileToOpen = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), myPageTitleXML);
using (StreamReader r = new StreamReader(fileToOpen))
{
//etc.. . .etc....etc..
}
Is this ASP.NET code? If so then you probably need to do MapPath("xml/pagetitles.xml")