Packaging a Repast model as a jar file without including the source code? - repast-simphony

I want to create a model jar file but not include the source code. Is it possible? The Repast model installer includes the source code by default, but I would like to hide it from the recipient of the model.

Yes, it’s possible but there is an important caveat. Compiled Java code distributed as binary files like jars can be trivially de-compiled back into the original source code with remarkable accuracy. If your goal is to protect proprietary source code then code obfuscation is required – see https://www.excelsior-usa.com/articles/java-obfuscators.html for more details. Code obfuscation is unfortunately a fairly complicated subject.
There are two ways to omit the project source code from the Repast model installer:
Method 1 – Remove /src elements from the model installer configuration files. This will instruct the model installer to omit /src files in the installer jar. The compiled agent classes will be in the usual project /bin folder.
In the /installer/installation_compnents.xml file, around line 156 comment the following:
<!--
<pack name="Sources" required="no">
<description>The model source code</description>
<file src="$StagingOptionalArea/src" targetdir="$INSTALL_PATH/Geography"/>
</pack>
-->
The “” denote the start and end of the code block that is commented. Next, in the /installer/installation_coordinator.xml file, comment around line 62:
<!-- Copy optional files to a separate directory -->
<copy todir="${StagingOptionalArea}" overwrite="true" failonerror="false">
<fileset dir="." casesensitive="no">
<!-- <include name="**/src/**" /> -->
<include name="**/docs/**" />
</fileset>
</copy>
Here you only want to comment the single line that copies the /src folder and not the /docs folder (although you can if you like). Now just build the model installer as usual.
Method 2 – export the /src folder to a jar file. This method does not require any changes to the default installer files as in the first method. However it requires deleting the source code after exporting it to a JAR file which means you would need to work on a copy of the project to preserve your source code. To export the model code to a JAR file, right click on the /src folder and select Export… -> Java -> JAR file. In the export dialog, make sure the src folder is checked in the “Select resources to export” box and then specify the JAR file name and location. The best place to export the jar file in in the project /lib folder. Most other options should be left as default. Make sure that “Export Java source files and resources” is unchecked, otherwise it will copy the source into the jar file. After the JAR files is generated and you verify that it exists in the /lib folder, then delete the contents of the /src folder but not the /src folder itself. This will permanently delete the model source code, so again please work on a copy of the project if you take this route. Simply renaming or deleting the /src folder will cause the installer to fail, so the delete is required for this method. Last, the user_path.xml file in the .rs folder needs to be updated to reflect the change in the source code location. Change the line to assuming that the exported model JAR file is in the /lib folder. All of the model code is now in the single JAR file in your project/lib folder. The /src and /bin folder should be empty at this point. build the model installer as usual. The option to install source code will still appear in the installer, but no source is contained in the installer JAR so no source will be copied upon installation.

Related

Xcode Build path and copying additional files

I'm writing a plugin for Elgato Stream Deck. https://developer.elgato.com/documentation/stream-deck/sdk/overview/
Basically it is a binary command line tool written in C++/OBJ-C/Swift combined with a JSON manifest and optionally some HTML and JS files as well as different assets (.png, ...). All files have to be included in a folder (com.companyname.pluginname.sdPlugin) which lives in Library/Application Support/com.elgato.StreamDeck/Plugins/
At the moment, I'm building the binary to the default build path (derived data, ...) and manually copy it to the above folder. But I need to build and run that binary with an executable (Stream Deck app) defined in the scheme for debugging under Xcode. The JSON manifest and assets also lives in my xcode project folder and have to be copied manually.
So Before:
After:
So my question: how can I automate that under Xcode? I assume I can do some sort of post build scripting, but I have no knowledge about all that stuff.
Thanks
Solution:
go to target -> build settings
Deployment Location = YES
Installation Build Products Location = / (empty this one!)
Installation Directory = path to folder (= $INSTALL_PATH)
this will copy your binary to the defined installation path
go to target -> build phases
new phase -> run script
cp -r "$SRCROOT"/<FILE OR FOLDER NAME> "$INSTALL_PATH"/<FILE OR FOLDER NAME>
repeat this for all files and folders you need to be copied to the installation path. be careful with empty spaces in the folder/file names, they won't be recognized correctly and you have to use quotation marks

How to import external JARs from one project to another?

I have created a new IntelliJ Project, and I want it to have JAR dependencies like I have in another project.
Is there a way to Export-Import / Copy-Paste JAR dependencies from one IntelliJ project to another without using POM?
Thanks.
Optional Solution:
1. Open <old-project>/.idea/libraries folder and <new-project>/.idea/libraries folder.
2. Make sure to enable the displaying of hidden files (in Win7, go to control-panel--> Folder Options --> View, and select the 'Show hidden files...')
3. Copy all XML files exists in .idea/libraries from the old project to the new one.
4. Make sure that each xml points to the right location of Jar. (In case of relative link)
5. Open the <old-project>.iml and <new-project>.iml, and copy all <orderEntry type="library" name"..."/> elements.
6. Restart your new project.
I'm not aware of a way to do this from within IDEA, but under your project folder you can find a directory called .idea/libraries that has a series of XML files, one for each external dependency. You should be able to copy these between projects and thus "share" dependencies.

Visual Studio ASP.NET Web API Precompiled files placed in a different folder with TFS

I have an asp.net web api project whose output needs to be packaged in a setup project using wix.
I would like to precompile the site. The problem is that the precompilation process generates variable file names (ie. *.compiled files in particular).
I also would like to build the setup in a TFS build.
It seems that my only option is to generate a .wxs file wihtin the prebuild step of the wix project.
The .wxs files source paths are using $(var._My_Web_Project_.TargetDir). This seems to be translated to a Sources based directory.
I'm using paraffin to do that already and it works perfectly fine when building the solution with visual studio.
When building the solution through a TFS build, the .compiled files are copied to a Binaries folder, whereas all the other related web site files are copied to a Sources based directory.
The build errors are like the following :
The system cannot find the file 'd:\BuildAgents\___basedir___\Binaries\___web_project_dir\_PublishedWebSites\___site___\bin\textsample.cshtml.c6fb271c.compiled'.
The file is indeed in the Sources directory.
'd:\BuildAgents\___basedir___\Sources\___web_project_dir\_PublishedWebSites\___site___\bin\textsample.cshtml.c6fb271c.compiled'
I think I somehow need to redefine the aspnet_compiler output or something like this, but can't figure out how to do that.
The msbuild command line arguments are the follwing:
/p:GenerateProjectSpecificOutputFolder=true /p:VisualStudioVersion=14.0 /p:DeployOnBuild=true /p:PublishProfile=local /p:CleanWebProjectOutputDir=False /verbosity:d
EDIT 1: I'm using XAML build.
Any help appreciated.
EDIT 2:
With the new task based build, it works as is (no need to use an additional Copy Files task).
The aspnet_compiler output the .compiled files in the correct folder :
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v / -p D:\BuildAgents\vNext\_work\1\s\Softs\__Solution__\__Web_Project\obj\Release\AspnetCompileMerge\Source -c D:\BuildAgents\vNext\_work\1\s\Softs\__Solution__\__Web_Project__\obj\Release\AspnetCompileMerge\TempBuildDir
In the new tasks based build system, it's easy to copy files from a source folder to a target folder with Copy Files task.
Source Folder: Folder that contains the files you want to copy.
Contents: Specify minimatch pattern filters (one on each line) that you want to apply to the list of files to be copied.
Target Folder: Folder where the files will be copied. In most cases you specify this folder using a variable.

Something strange with Project Paths in IntelliJ 14.1.4

So, something has started to act weird in my intelliJ project. I even tried removing the iml and .idea data, to no avail.
I go to Project Structure. There, I have a content root. Withing, I have three folders - one for my jar (and jni lib), one for Samples and one for Tools (just tools written to use the jar). The jar, Samples and Tools are marked blue (sources).
In the jar folder, I have my source tree (com\company\projectname\XXX), a lib folder, a folder for my JNI lib and a folder I created call 'junit', which is the focus of this question. It is marked in Project Structure in green (Tests).
Within, I have a folder structure eerily similar to my code: com\company\projectname\junit.
When I open a file in junit\com\company\xxx\junit, I have a big red underline under my package com.company.xxx.junit; line which tells me: "Package name 'com.company.xxx.junit' does not correspond to the file path 'junit.com.company.xxx.junit'.
I was under the impression that marking a folder as 'Tests' would instruct the IDE to use that as a "parent" folder, if you will, eliminating the need to prepend another folder name.
How can I separate the code from unit tests and in fact, create two junit test suites (one is for internal use, the other is a 'skeleton' for distribution), park them under one "umbrella" folder and NOT have to prepend the package names with that folder name?
Update: Project structure:
Based on your screen shot, the issue is that the junit directory is a subdirectory of another source directory, namely MyProvider. A source directory (whether a "production" source or a unit test source directory) cannot be a subdirectory of another source directory.
You need to either:
move the junit directory out of MyProvider so it is a sibling directory, or
unmark MyProvider as a source directory, create a main (or some such directory) in MyProvider, mark it as a source directory, and then move the com directory/package into main.
Option 2 would be the preferred way to deal with this as it follows a very common directory structure standard.
UPDATE (Following comment from OP)
Here's a couple of screenshot showing the configuration you desire:
I removed the .IdeaIC15 folder and started over. Working for now. Something must have gotten confused in the config, either as part of the update, or in the course of operation. I have taken a backup copy as it is now, so if this happens again, I will have something to check.

Moving a file in MSBuild using relative path

I'm trying to move all files of a certain type to a directory relative to the file itself and I'm wondering if it's possible using MSBuild.
Basically, I'm using the Microsoft AJAX Minifier to minify all Javascript and CSS files on my site. This outputs .min.js and .min.css files into the same directory as the Javascript and CSS files. Because my site has numerous skins, there are JS and CSS files located in numerous directories. I want to be able to add a task that runs after the AJAX Minifier that moves all .min.js and .min.css files to /min/ relative to the file location. So /Skin1/somescript.min.js would move to /Skin1/min/somescript.min.js and /Skin2/somescript.min.js would move to /Skin2/somescript.min.js.
The only way I know to accomplish a copy/move requires knowledge of the absolute directory (or should I say directory relative to the Project file) but I can't seem to find a way to move based on a directory relative to the file I'm moving.
Can this be done?
<CreateItem Include="wwwroot\**\*.min.js;wwwroot\**\*.min.css">
<Output TaskParameter="Include" ItemName="FilesToMove" />
</CreateItem>
<Move SourceFiles="#(FilesToMove)" DestinationFiles="#(FilesToMove->'wwwroot\%(RecursiveDir)\min\%(Filename)%(Extension)')"/>
Assuming you're using the Move task from MSBuild community tasks. If not, you could just copy and then delete the originals instead.