Is it possible to get the artifactId of the current Mojo?
#Mojo(...)
public class MyMojo extends AbstractMojo {
#Parameter(property = "project")
private MavenProject project;
#Parameter(property = "inputDirectory", defaultValue = "${project.basedir}/src/main/${artifact id of the plugin}")
private File inputDirectory;
...
I could hardcode the artifact id of the plugin, but I would rather get it dynamically.
The accepted answer does not answer the question.
You can use a field to dynamically get the artifactId of the mojo (not the artifactId of the project which the plugin is attached on)
#Parameter(defaultValue = "${mojo.artifactId}")
private String mojoArtifactId;
Or in your case:
#Parameter(property = "project")
private MavenProject project;
#Parameter(property = "inputDirectory", defaultValue = "${project.basedir}/src/main/${mojo.artifactId}")
private File inputDirectory;
BTW what comes into my mind is that you are using old style injection
#Parameter(property = "project")
private MavenProject project;
#Parameter(property = "inputDirectory", defaultValue = "${project.basedir}/src/main/${artifact id of the plugin}")
private File inputDirectory;
They should look like this:
The expression values for defaultValue are documented here:
http://maven.apache.org/ref/3.1.1/maven-core/apidocs/org/apache/maven/plugin/PluginParameterExpressionEvaluator.html depending on your used Maven version.
#Parameter(defaultValue = "${project}, required = true, readonly = true)
private MavenProject project;
#Parameter(defaultValue = "${project.basedir}/src/main/${artifact id of the plugin}", property = "inputDirectory", required = true)
private File inputDirectory;
Related
This is my first time using Room Persistence Library and I am having difficulties understanding the concept of entity.
So I have these two classes:
public class CapturedTime
{
#SerializedName("startTime")
#Expose
private Long startTime;
#SerializedName("endTime")
#Expose
private Long endTime;}
and
public class CapturedItem implements Parcelable {
private String serialNumber;
private CapturedTime firstCapturedTime;
private CapturedTime secondCapturedTime;}
I believe it's pretty straightforward for the CapturedTime class but I have no idea what I should do for the CapturedItem class. Can I just make the CapturedTime variables into columns or are there steps that I should do first?
First add dependency in buid.gradle file
dependencies {
def room_version = "2.1.0-rc01"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version" // For Kotlin use kapt instead of annotationProcessor
}
After that use #Entity annotation to declare normal POJO class as entity in Room persistence library.
#Entity(tableName = "your_table_name")
public class CapturedTime{
#SerializedName("startTime")
#Expose
#ColumnInfo(name = "start_time")
private long startTime;
#SerializedName("endTime")
#Expose
#ColumnInfo(name = "end_time")
private long endTime;
}
#ColumnInfo used to declare column name in table, by default column name is variable name if you do't provide #ColumnInfo annotation
If you want to store custom object in room you use
#TypeConverters() annotation
In your case,
#TypeConverters(CapturedTime.class)
private CapturedTime firstCapturedTime;
For more information please visit this
Hey everyone I am fairly new to Neo4j and am having an issue querying my repositories.
Repository is the follow:
public interface NodeOneRepository extends GraphRepository<NodeOne> {
List<NodeOne> findByNodeTwoNodeThreeAndActiveTrue(NodeThree nodeThree);
}
My entities are the following:
#NodeEntity(label = "NodeOne")
public class NodeOne {
#GraphId
private Long id;
private Boolean active = TRUE;
#Relationship(type = "IS_ON")
private NodeTwo nodeTwo;
}
#NodeEntity(label = "NodeTwo")
public class NodeTwo {
#GraphId
private Long id;
#Relationship(type = "CONTAINS", direction = "INCOMING")
private NodeThree nodeThree;
#Relationship(type = "IS_ON", direction = "INCOMING")
private List<NodeOne> nodeOnes = new ArrayList<>();
}
#NodeEntity(label = "NodeThree")
public class NodeThree {
#GraphId
private Long id;
#Relationship(type = "CONTAINS")
private List<NodeTwo> nodeTwos = new ArrayList<>();
}
Getters & Setters omitted. When I call the method I get an empty list. Is there something I am doing incorrectly?
You didn't describe exactly what you wanted to achieve, but I can see two problems:
Problem 1:
The current version of Spring Data Neo4j and OGM only allow nested finders, that is, finders that specify a relationship property, to one depth.
Supported
findByNodeTwoSomePropertyAndActiveTrue(String relatedNodePropertyValue)
Not Supported
findByNodeTwoNodeThree //Nesting relationships in finders is not supported
Problem 2:
Derived Finders Allow Matching Properties and Nested Properties. Not a whole instance of that class.
You can probably achieve what you would like using a custom query.
#Query("custom query here")
List<NodeOne> findByNodeTwoNodeThreeAndActiveTrue(NodeThree nodeThree);
If you need help to write a custom query, you can post another question or join the neo4j-users public slack channel.
I am not so into Spring Data JPA and I have the following doubt about how to implement a simple query.
I have this AccomodationMedia entity class mapping the accomodation_media on my database:
#Entity
#Table(name = "accomodation_media")
public class AccomodationMedia {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "id")
private Long id;
#Column(name = "id_accomodation")
private Long idAccomodation;
#Column(name = "is_master")
private boolean isMaster;
#Lob
#Column(name = "media")
private byte[] media;
private String description;
private Date time_stamp;
public AccomodationMedia() {
}
...............................................................
...............................................................
...............................................................
// GETTER AND SETTER METHODS
...............................................................
...............................................................
...............................................................
}
The instance of this class represents the photo associated to an accomodation (an hotel)
So as you can see in the prvious code snippet I have this field :
#Column(name = "id_accomodation")
private Long idAccomodation;
that contains the id of an accomodation (the id of an hotel on my database).
I also have this boolean field that specify if an image is the master image or not:
#Column(name = "is_master")
private boolean isMaster;
So, at this time, in my repository class I have this method that should return all the images associated to a specific hotel:
#Repository
public interface AccomodationMediaDAO extends JpaRepository<AccomodationMedia, Long> {
List<AccomodationMedia> findByIdAccomodation(Long accomodationId);
}
I want to modify this method passing also the boolean parameter that specify if have to be returned also the master image or only the images that are not master.
So I tryied doing in this way:
List<AccomodationMedia> findByIdAccomodationAndIsMaster(Long accomodationId, boolean isMaster);
but this is not correct because setting to true the isMaster parameter it will return only the master image (because it is first selecting all the Accomodation having a specific accomodation ID and then the one that have the isMaster field setted as true).
So, how can I correctly create this query that use the isMaster boolean parameter to include or exclude the AccomodationMedia instance that represent my master image?
I know that I can use also native SQL or HQL to do it but I prefer do it using the "query creation from method names"
I don't have how to test this, but essentially your final query should be:
id_accomodation = ?1 AND (is_master = ?2 OR is_master = false)
So I would try the following method signature:
findByIdAccomodationAndIsMasterOrIsMasterFalse(Long accomodationId, boolean isMaster);
I would go with two methods one for isMaster true, while second for false value like this:
List<AccomodationMedia> findByIdAccomodationAndIsMasterFalse(Long accomodationId);
List<AccomodationMedia> findByIdAccomodationAndIsMasterTrue(Long accomodationId);
Change your acommodation id as accomodationId instead of idAccomodation. When you write findByIdAccomodationAndIsMaster spring confusing findByIdAccomodationAndIsMaster
Try this this convention
#Column(name = "accomodation_id")
private Long accomodationId;
If I use the Lombok #Setting annotation on a field with a value of PRIVATE
#Data
#AllArgsConstructor
#NoArgsConstructor
public class Notification implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Setter(value = AccessLevel.PRIVATE)
private String id;
private long userId;
private Event event;
private long timestamp = System.currentTimeMillis();
public Notification(final String id) {
this.id = id;
}
}
The Sonar Maven plugin gives the following error:
ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.7.1:sonar (default-cli) on project mio-events: Unable to analyze .class file tv/nativ/mio/event/model/Notification: 0 is not a valid line for a file -> [Help 1]
Changing the #Setting value to public fixes the issue, as does removing #Setting altogether and adding a manual private setter for the field.
Any idea what the issue might be?
Thanks
Nick
Sonar doesn't really support Lombok: Feature request for lombok like tools
Prior to running sonar you should delombok the source and use the generated sources for analysis. Information about this is on the page: Delombok. If you are using maven there's an example of using this technique here: Example Pom
I am trying to develop a mojo, where i am injecting my project in my plugin to list out all the dependencies defined in the project.
#Parameter(defaultValue = "${project}", required = true, readonly = true)
private MavenProject project;
Is it possible to inject another project ? For e.g. i have 1 project
A it has sub project X, Y and Z. When the plugin executed i would like the project Y also injected in my plugin, so that i can get dependencies from that project as well. I tried something like this.
#Parameter(defaultValue = "${project}", property = "other.project", required = true, readonly = true)
private MavenProject project2;
But doesnot seems to be working. project2 is always null.