Doing calculations on properties - maven

Is it possible to do string and math operations on properties in maven 2?
I have a property ${version} that has a value of something like 5.3.0-SNAPSHOT, now I'd like to extract the 5 and do some math on it, say subtract 3 from it. So my new property would get the value 2.

You may want to look at the parse-version goal of build helper maven plugin. As the example in this page indicates, once this goal is run, it makes available a bunch of propeties which can be used to do subsequent operations.
parsedVersion.majorVersion
parsedVersion.minorVersion
parsedVersion.incrementalVersion
parsedVersion.qualifier
parsedVersion.buildNumber

There is an example here (http://ronalleva.com/groovy/maven/programming/2008/01/23/using-the-groovy-maven-plugin-to-do-magic.html) which embeds groovy into your plugin. Further in the example he sets a property in the maven project.

Related

What does create method do in gradlePlugin.plugins?

In the gradle doc: https://docs.gradle.org/current/userguide/custom_plugins.html#sec:custom_plugins_standalone_project
The code block is:
gradlePlugin {
plugins {
create("simplePlugin") {
id = "org.example.greeting"
implementationClass = "org.example.GreetingPlugin"
}
}
}
I noticed it calls create method. And I looked the source code. It says:
Creates a new item with the given name, adding it to this container,
then configuring it with the given action.
What does it mean? Is it actually used anywhere? Or it can be any name does not really matter?
gradlePlugin.plugins is a NamedDomainObjectContainer - which are used by Gradle to hold multiple objects, each with a name.
The documentation on plugin development goes into more detail on the usage of NamedDomainObjectContainers.
Sometimes you might want to expose a way for users to define multiple, named data objects of the same type.
[...]
It’s very common for a plugin to post-process the captured values within the plugin implementation e.g. to configure tasks.
Since the elements of a NamedDomainObjectContainer can be any type, there's no specific usage for one. Generally they are used to configure the Gradle project, for example creating specific tasks, configuring source code locations.

Setting a property for only a specific phase

I want to be able to set a property for a specific maven phase. How can I do that?
For example, assume that I want to set a property like this:
<properties>
<spring.profiles.active>production<spring.profiles.active>
</properties>
only when one is executing mvn package. I know that I can manually set a property, but I want it to be automatic so it is not forgotten.
This is not possible.
But probably there is a solution for the original problem you want to solve. Please write a new question which describes the use case.

JMeter Custom Plugin Variable Substitution

Context
I am developing a custom JMeter plugin which generates test data dynamically from a tree like structure.
The editor for the tree generates GUI input fields as needed, and therefore I have no set of defined configuration properties which are set in the respective TestElement. Instead, I serialize the tree as a whole in the GUI class, set the result as one property and deserialize it in the config element where it is processed further during test execution.
Problem
This works just fine, except that JMeter variable/function expressions like ${foo} or ${_bar(..)} in the dynamic input fields are not evaluated. As far as I understand the JMeter source code, the evaluation is triggered somehow if the respective property setters in org.apache.jmeter.testelement.TestElement are used which is not possible for my plugin.
Unfortunately, I was not able to find a proper implementation which can be used in my config element to evaluate such expressions explicitly after deserialization.
Question
I need a pointer to JMeter source code or documentation for evaluating variable/function expressions explicitly.
After I manages to setup the JMeter-Project properly in my IDE, I found org.apache.jmeter.engine.util.CompoundVariable which can be used like this:
CompoundVariable compoundVariable = new CompoundVariable();
compoundVariable.setParameters("${foo}");
// returns the value of the expression in the current context
compoundVariable.execute();

How to set dynamic input dependency on gradle task

I'm working on a Gradle plugin that has a task that generates compilable Java source code. It takes as input for the code generator a "static" directory (property value) which should contain files in a special language (using a specific extent). In addition, if a particular configuration property is set to true, it will also search for files with the same extent in the entire classpath (or better, in a specific configuration).
I want to make sure that the task runs if any of its input dependencies are new.
It's easy enough to add #InputDirectory to the property definition for the "static" location, but I'm unsure how to handle the "dynamic" input dependency.
I have a property that defines the name of the configuration that would be used to search for additional files with that extent. We'll call that "searchConfiguration". This property is optional. If it's not set, it will use "compile". I also have the property that specifies whether we will search for additional files in the first place. We'll call that "inspectDependencies".
I think I could write a #Input-annotated method that returns essentially the "configurations.searchConfiguration.files" list. We'll call that "getDependencies". I think that is the basic idea. However, I don't understand what to do about "inspectDependencies". I could easily make "getDependencies" return an empty list if "inspectDependencies" is false, but is that truly the correct thing to do? It seems likely that if someone changed "inspectDependencies" from "true" to "false" after a build, the next build should run the task again.
Well, this is tentative, but I asked about this on the Gradle Forum and Mark Viera convinced me that it really should be this simple, although it requires #InputFiles instead of #Input. My particular method looks like this:
#InputFiles
def getOptionalYangClasspath() {
return inspectDependencies ? project.configurations[yangFilesConfiguration] : Collections.emptyList()
}

Maven javadoc plugin: is it possible to show private selectively for certain packages

I am interested in showing private members in javadoc for only certain packages. For the all other packages only show public and protected members in javadoc. The show tag is for configuration, but not for the group.
Thank You
According to Apache Maven Javadoc Plugin it uses javadoc - The Java API Documentation Generator. I'm not aware of an option in javadoc for changing access modifiers for indivdual packages with the standard doclet. You could write your own doclet, of course.
I can also imagine the following hack:
create a "main" JavaDoc with a certain access modifier and assign the desired packages
create a second JavaDoc with a different access modifier and assign the desired packages
create a third ...
Now the hacker's part:
merge the second JavaDocs' allclasses-[frame|noframe].html (All Classes) into main's allclasses-[frame|noframe].html
merge the second JavaDocs' overview-frame.html (Packages) into main's overview-frame.html
merge the third ...
merge the third ...

Resources