I'm trying debug mvn compile of a file with many dependencies with javac.
This is how I'm trying to do this:
CLASSPATH=`find ~/.m2 -name *.jar -print0`; javac -verbose BogusFile.java
My problem is that I'm not sure how to tell find to separate each jar found with the unix file separator (:).
Maybe the -printf has the solution?
Sorry I can not answer your question but give a possible other solution approach.
If you need to build a classpath for your maven project you can run the copy-dependencies goal of the Maven Dependency Plugin on your project:
mvn dependency:copy-dependencies
Maven will copy all dependencies for your project (also transitive) to the target/dependency directory and classpath can be set to target/dependency/*; (you still have to include your artifact jar).
Example:
Code:
import org.apache.commons.lang.WordUtils;
import org.apache.log4j.Logger;
public class Bogus {
private static final Logger LOG = Logger.getLogger(Bogus.class);
public static void main(final String[] args) {
LOG.debug(WordUtils.capitalize("hello world"));
}
}
Directory:
C:.
│
├───src
│ └───main
│ └───java
│ Bogus.java
│
└───target
└───dependency
commons-lang-2.6.jar
log4j-1.2.16.jar
Compile Command:
.....\bogus>javac -cp target\dependency\*; src\main\java\Bogus.java
Result:
C:.
│
├───src
│ └───main
│ └───java
│ Bogus.class
│ Bogus.java
│
└───target
└───dependency
commons-lang-2.6.jar
log4j-1.2.16.jar
Join all the jars by : separator, to use as the classpath for the compiler.
export TEST_CLASSPATH=$(find ~/.m2 -name *.jar | sed -z 's/\n/:/g')
javac -classpath $TEST_CLASSPATH:./ BogusFile.java
Related
Problem statement
When building a Python package I want the build tool to automatically execute the steps to generate the necessary Python files and include them in the package.
Here are some details about the project:
the project repository contains only the hand-written Python and YAML files
to have a fully functional package the YAML files must be compiled into Python scripts
once the Python files are generated from YAMLs, the program needed to compile them is no longer necessary (build dependency).
the hand-written and generated Python files are then packaged together.
The package would then be uploaded to PyPI.
I want to achieve the following:
When the user installs the package from PyPI, all necessary files required for the package to function are included and it is not necessary to perform any compile steps
When the user checks-out the repository and builds the package with python -m build . --wheel, the YAML files are automatically compiled into Python and included in the package. Compiler is required.
When the user checks-out the repository and installs the package from source, the YAML files are automatically compiled into Python and installed. Compiler is required.
(nice to have) When the user checks-out the repository and installs in editable mode, the YAML files are compiled into Python. The user is free to make modifications to both generated and hand-written Python files. Compiler is required.
I have a repository with the following layout:
├── <project>
│ └── <project>
│ ├── __init__.py
│ ├── hand_written.py
│ └── specs
│ └── file.ksc (YAML file)
└── pyproject.toml
And the functional package should look something like this
├── <project>
│ └── <project>
│ ├── __init__.py
│ ├── hand_written.py
│ └── generated
│ └── file.py
├── pyproject.toml
└── <other package metadata>
How can I achieve those goals?
What I have so far
As I am very fresh to Python packaging, I have been struggling to understand the relations between the pyproject.toml, setup.cfg and setup.py and how I can use them to achieve the goals I have outlined above. So far I have a pyproject.toml with the following content:
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[project]
name = "<package>"
version = "xyz"
description = "<description>"
authors = [ <authors> ]
dependencies = [
"kaitaistruct",
]
From reading the setuptools documentation, I understand that there are the build commands, such as:
build_py -- simply copies Python files into the package (no compiling; works differently in editable mode)
build_ext -- builds C/C++ modules (not relevant here?)
I suppose adding the compile steps for the YAML files will involve writing a setup.py file and overwriting a command, but I don't know if this is the right approach, whether it will even work, or if there are better methods, such as using a different build backend.
Alternative approaches
A possible alternative approach would be to manually compile the YAML files prior to starting the installation or build of the package.
I'm new to cucumber and after trying various not fully working tutorials, I try to make this example work : https://github.com/cucumber/cucumber-java-skeleton
Here is the plugin i'm using :
My version of Eclipse (wrapped into STS 4.17.1) :
To import it, I do "Import Existing maven project" on the maven project :
What works : After completing the 2 missing steps, when I run the .feature through eclipse cucumber plugin (Run as "Cucumber feature") or through "mvn test", I get :
Scenario: a few cukes # src/test/resources/io/cucumber/skeleton/belly.feature:3
Given I have 42 cukes in my belly # io.cucumber.skeleton.StepDefinitions.I_have_cukes_in_my_belly(int)
When I wait 1 hour # io.cucumber.skeleton.StepDefinitions.i_wait_hour(java.lang.Integer)
growl !
Then my belly should growl # io.cucumber.skeleton.StepDefinitions.my_belly_should_growl()
1 Scenarios (1 passed)
3 Steps (3 passed)
0m1,134s
What doesn't work (related to the eclipse cucumber plugin ?), 3. and 4. are the main issues :
In Eclipse, output starts with :
janv. 31, 2023 3:23:38 PM cucumber.api.cli.Main run
WARNING: You are using deprecated Main class. Please use io.cucumber.core.cli.Main
This may or may not be important for the following not working items.
1b. "growl !" is displayed BEFORE the step where it is implemented :
#Then("my belly should growl")
public void my_belly_should_growl() {
System.out.println("growl !");
}
In Eclipse, I'm getting this message despite all the "quiet" properties positionned in the right .properties files :
┌───────────────────────────────────────────────────────────────────────────────────┐
│ Share your Cucumber Report with your team at https://reports.cucumber.io │
│ Activate publishing with one of the following: │
│ │
│ src/test/resources/cucumber.properties: cucumber.publish.enabled=true │
│ src/test/resources/junit-platform.properties: cucumber.publish.enabled=true │
│ Environment variable: CUCUMBER_PUBLISH_ENABLED=true │
│ JUnit: #CucumberOptions(publish = true) │
│ │
│ More information at https://cucumber.io/docs/cucumber/environment-variables/ │
│ │
│ Disable this message with one of the following: │
│ │
│ src/test/resources/cucumber.properties: cucumber.publish.quiet=true │
│ src/test/resources/junit-platform.properties: cucumber.publish.quiet=true │
└───────────────────────────────────────────────────────────────────────────────────┘
I'm not getting any generated cucumber report in maven "target" directory
If I do "Run as JUnit" in Eclipse on this project to get a visual report in the JUnit tab, I get :
org.junit.platform.suite.engine.NoTestsDiscoveredException: Suite [io.cucumber.skeleton.RunCucumberTest] did not discover any tests
I'd like to see the cucumber tests like this in Eclipse :
Please help me make Cucumber work in Eclipse or at least generate an html cucumber report in target.
what I can say you regarding your q:
seems like the answer is here: github issue thread
1b. I do not see in the repo you provided this example, so it is hard to say what is wrong here, I am assuming you have an extra repo with updated skeleton, so you may provide more details
have you checked this thread? quite props
What I know about Cucumber reports, you need in your Runner class, you set a path to your json cucumber report:
#CucumberOptions(
features = "src/test/resources/functionalTests",
glue= {"stepDefinitions"},
plugin = { "pretty", "json:target/cucumber-reports/Cucumber.json" },
monochrome = true )
More examples are here: cucumber reports
Check if your setup is correct, I think the best place for it is: Running Cucumber Tests
I have opened a folder in VS code and I am trying to set it up.
It's a python project and its directory structure is as:
Project
├── common_features
│ ├── ...
├── core
│ ├── features
│ └── main.py
│ └── tests
├── django project
│ ├── django_app1
│ ├── manage.py
│ ├── ...
└── tests
│ ├── ...
└── runner.py
The project runs as a django project from the django_project dir. It uses modules located in common_features and core. Core is designed such that it could also run on its own. You can also run core from runner.py
The problem is that all our module imports are not being resolved but 3rd party packages work well.
unresolved import 'core.config' Python(unresolved-import)
In PyCharm, I have marked Project, core and django_project as "sources root" and it works like a charm. Not sure how to do that in VS code.
I have tried making some changes in launch.json and settings.json but none are working. I am new to VS code so I'm unable to understand what it is that I'm doing wrong.
Thanks.
Can you try adding the following line to your settings.json file?
{
"python.autoComplete.extraPaths": ["./src"]
}
More info about this here: https://github.com/microsoft/python-language-server/blob/master/TROUBLESHOOTING.md#unresolved-import-warnings
If using the same nuget package(s) over multiple solutions, how do I keep them up to date without having to open up every solution and update packages when a new version is released?
Folder structure is typically something like this but over many more projects. Each project has its own packages.config with various package references.
$tfs/
├── Solution One/
│ ├ Solution 1.sln
│ ├ nuget.config (solution item)
│ ├── Packages/
│ ├ ├── Newtonsoft.JSON.12.0.2/
│ ├ ├── Jquery3.1.4/
│ ├── Project one/
│ ├ ── packages.config
│ ├ ── whatever.cs
│ ├ ── folder /
│ ├ ── another folder /
│ ├── Project Two/
│ ├ ── packages.config
│ ├ ── file.cs
│ ├ ── folder/
│ ├ ── another folder/
├── Solution Two/
│ ├ Solution 2.sln
│ ├ nuget.config
│ ├── Packages/
│ ├ ├── Newtonsoft.JSON.11.1.0/
│ ├ ├── Jquery1.3.4/
│ ├── Project one/
│ ├ ── packages.config
│ ├ ── whatever.cs
│ ├ ── folder /
│ ├ ── another folder /
│ ├── Project two/
│ ├ ── packages.config
│ ├ ── file.cs
│ ├ ── folder/
│ ├ ── another folder/
I have tried running this powershell in Package Manager Console but this only applies to one solution at a time:
$packageId = "jquery"
Get-ChildItem *.sln -recurse | %{.\\nuget.exe restore $_.fullname}
Get-ChildItem packages.config -Recurse `
| Where-Object {$_ | Select-String -Pattern $packageId} `
| %{.\\nuget.exe update -Id $packageId $_.FullName}
Do I need to update packages.config in each solution of each project and open them in order to get the updates? I would have thought there would be an easier way to do this. I am using a private nuget server if it makes a difference.
Note: I have looked at this question: Updating nuget packages in all projects in a solution and it is not the same scenario as mine. I'm looking to update packages across multiple solutions, not multiple projects in one solution.
As #imps said in the comments, there's no solution for packages.config projects across solutions. Within a solution you can use the NuGet Package Manager UI's "Manage packages for solution" and the consolidate tab helps makes sure all projects use the same version, but you'll need to repeat this for all solutions.
If you migrate from packages.config to PackageReference, you could take advantage of MSBuild extensibility and either import a common props file, or if using Visual Studio 2017 or newer, use Directory.Build.Props in the highest common parent directory of all the projects.
In your props file, you define the versions of the packages you care about, something like this:
<Project>
<PropertyGroup>
<NewtonsoftJsonVersion>12.0.1</NewtonsoftJsonVersion>
</PropertyGroup>
</Project>
and then in your csproj files, use <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />. The issue with this is that you can no longer use the Package Manager UI or Package Manager Console in VS to upgrade (well you can, but it'll change it in the csproj, not your props file), but you can still use the UI to check for updates. If you add your props file to your solution, then it just takes two clicks and a few taps on your keyboard to update, so it's really not a big deal.
In your example, the common parent directory would be the TFS root, so $/Directory.Build.props. The problem with this is if you use CI and have a trigger to run the Solution One build on changes to $/Solution One/* and run the Solution Two build on changes to $/Solution Two/*, then they'll both miss changes to $/Directory.Build.props. Or maybe it is possible to configure TFS build triggers to include it, but I don't remember because I haven't used TFVC is such a long time.
However, the bigger issue is that in your example, it's clear you're using the jQuery package. This uses content, which copies files into your project on install/upgrade. PackageReference doesn't work this way (it's listed as a package compatibility issue) , so unless you want to have a different process for upgrading jQuery and any other js/css in your web projects, you can't migrate ASP.NET projects to PackageReference. Note that ASP.NET Core projects are SDK style which only support PackageReference, not packages.config, and typically use either LibMan or npm to get css and javascript.
Customers who can migrate to SDK style projects, they could even consider using this SDK for central package management that helps ensure you don't accidently leave a version number in your csproj.
Currently I have a bunch of files living in a directory under TFS. Essentially I want to make a NuGet package out of it in my build server.
I do want however to move the file structure into a sub-directory and re-base from there. Let me explain:
The TFS path watched is: $/Foo/Bar/
$/Foo/Bar/
│
│ Bar.nuspec
│
└───PackageContent/
│ GenPumpGraphCtrl.dll
│ MultiPumpCurve.dll
│ PumpGraphCtrl2.dll
│
├───Dwg/
│ Logofnt1.wmf
│ LOGOFNT1a.wmf
│ LOGOFNT1b.wmf
│
├───Ref/
│ AqSolutions.xbn
│ Astring.bin
│ WordTranslation.xbn
│
└───Temp/
│
└───Notes/
Notes.txt
My .nuspec uses:
<files>
<file src="PackageContent\**"/>
</files>
However, I want to rename the PackageContent directory to .package-content and updated my .nuspec:
<files>
<file src=".package-content\**"/>
</files>
But by NuGet Pack step in TeamCity complains with the following error:
>> Cannot create a package that has no dependencies nor content.
Are .dot-prefixed directories somewhat hidden from TFS?
Are .dot-prefixed directories automatically ignored by the some obscure rule in the .nuspec?
Further investigation into the problem shows that in fact, if I place any .dot-prefixed directory, it gets entirely excluded from my NuGet package, despite using a wildcard.
The question is clearer now: How can I ensure I really include everything? Including .dot-prefixed directories?
Ok, in fact there is this obscure -NoDefaultExcludes parameter for nuget pack.
In my case, I had to add it to the Command line parameters box for the TeamCity NuGet Pack step: