Java - project dependency and current\relative working directory - jvm

I have two project where one is depended on the other, i.e. project A depends on project B, and the two projects reside in different directories.
In the independent project, i.e. project B, there is a class which holds a code that tries to access directories and files with respect to independent project directory. Since the depended project, i.e. project A, instantiate an object from the independent project, when the object execute System.getProperty("user.dir") it returns the execution directory, i.e. the directory of the dependent project; the same holds for new File(".").getAbsolutePath().
I would like to solve the issue in generic way, i.e. I wish to avoid the need to pass as an argument the path, rather, I wish the use relative directories programatically.
Any guidance\clues?
P.S. not sure if it is relevant, but I am using Eclipse as my IDE.
UPDATE
This should hold...
final String clsName = getClass().getName() + ".class";
System.out.println(getClass().getResource(clsName));

I'd use the class-loader instead of using paths directly. In eclipse, and in an deployment situation both projects resources should be in the classpath.
ProjectA
example.png
ProjectB
foo.txt
Something like this should be able to load a resource from either project A or B.
URL url = getClass().getResource("/example.png"); // get URL
InputStream stream = getClass().getResource("/foo.txt").openStream(); // open a stream

Related

JetBrains Space: Using the same file in multiple repositories, in the same project

I have a JetBrains Space project and it contains two repositories (lets call them repository A and repository B).
Basically there is a JSON file in A, that I would like to access in B. Is such a thing possible?
In the main method in repository B I need to call: writeFile(String filePath).
How can I build the path for the JSON file in order for it to actually find the file from A?

In IAR v8.11, is there a predefined variable name for build configuration?

I am using IAR V 8.11.
I am currently using the build configuration to build for different platforms.
I want to be able to output the files that are generated from the build process into directories that are labelled with the build configuration name.
In order to do this, I need a variable name that has stores the build configuration, and use this variable name in the various project settings.
IAR (the IDE) provides access to custom argument variables via Tools->Configure Custom Argument Variables, but I was hoping there was a predefined variable already allocated for build configuration name.
So if I have several build configurations, Platform1, Platform2, it automatically updates the value of $VARIABLE_NAME$.
The best way to do this is to use the $CONFIG_NAME$ variable that is already available.
The value assigned to $CONFIG_NAME$ is the name of the build configuration, which is exactly what I wanted.

How to customize the temporary directory in Twisted Trial

I am trying to run a twisted.trial.TestCase that depends on resource folders (images, for instance) that reside alongside my Python package called test. Unfortunately, the temporary directory that gets created upon running the test runner (i.e. issuing trial test) doesn't include (naturally) a copy of the whole original working directory, and my tests fail because the images cannot be found. The function of the software is heavily dependent on those images, so they'll need to be a part of testing.
The question is, is there a way to customize the _trial_temp directory that the test runner normally creates from scratch so that it includes certain files and folders, besides what the test runner itself thinks it needs?
No.
Don't do it this way. If you need data from your project, it is not in any sense temporary data. If you point trial at a directory using --temp-directory, it will assume it is in fact "temporary" and will blow it away. Instead, you should access the data relative to the path of the tests.
If you put your sample data into the same directory as your tests, and treat it as package_data, you can do this:
from twisted.python.modules import getModule
thisModule = getModule(__name__)
dataPath = thisModule.filePath.parent()
and to get data in your tests:
fileobj = dataPath.child("sample_file.data").open()
databytes = dataPath.child("other_file.txt").getContent()
so keep your temporary directories and your sample data separate.

aggregate target + target paths

For one of my schemes I want to copy 2 folders into the final app bundle. For that I created an aggregate target with a copy build phase and added that target to the scheme where it should be triggered. That works fine, except for the target paths.
I appears something with the target paths is wrong however. In the copy build phase I can select whatever pre defined path exists in the drop down, the folder always end up in the same place ("Myproject/DerivedData/Myproject/Build/Products/Debug") instead of the app bundle. Is there something special to consider for aggregate targets?
I also tried to set a subpath with one of the build variables. They don't seem to be set however and have no effect. Setting a manual path works however. Though, I don't want to hard code my apps bundle name + Contents etc. if the normal way is usually to use an env var.
Btw. I also tried a script phase and checked the env vars printed in the build log. None contains the path to my app bundle (or parts of it below the Debug folder).
Maybe it has to do with the target type (aggregate target), I don't know. I couldn't get the predefined paths to work, they always seem to be empty. So, I ended up by hard coding the relative path (which rarely changes). But that is of course asking for trouble if I ever change the project's name.

Using multiple Source control folders in a single build definition TFS 2010

In the Workspace tab
Source Control Folder: I am picking only two locations from my entire team project. I do not want to pick the entire team project because it has 20 projects.
I only need two project locations for the build.
$/TeamProject/ABCProj.SVC
$/TeamProject/ABCProj.UI
Build Agent Folder, If i specify the same $(SourceDir) for both the Source control folder locations($/TeamProject/ABCProj.SVC, $/TeamProject/ABCProj.UI)
above, I am unable to save the build definition.
I am getting an error when saving the Build definition
"$(SourceDir) can only be mapped one time in a given workspace"
Can any one please suggest a solution.
You'll have to map your version control folders to different source directories, for example:
$/TeamProject/ABCProj.SVC -> $(SourceDir)/ABCProj.SVC
$/TeamProject/ABCProj.UI -> $(SourceDir)/ABCProj.UI
Alternatively, you can just map $/TeamProject to $(SourceDir) and cloak all subprojects you don't want to get the sources for.