I'm trying to parse a list of maven dependencies and display it in a simpler format. Specifically I'm trying to convert the standard maven xml of:
<dependency>
<groupId>groupId1</groupId>
<artifactId>artifactId1</artifactId>
<version>version1</version>
</dependency>
To something like this:
groupId1:artifactId1:version1
The poms I'm working with are sorted by sortpom-maven-plugin, so I can assume the order to always be groupId, artifactId, version; but I can't assume the version will always be there, or that there won't be other configurations for the dependency.
That means something like the following could be possible:
<dependency>
<groupId>groupId1</groupId>
<artifactId>artifactId1</artifactId>
<version>version1</version>
</dependency>
<dependency>
<groupId>groupId2</groupId>
<artifactId>artifactId2</artifactId>
</dependency>
<dependency>
<groupId>groupId3</groupId>
<artifactId>artifactId3</artifactId>
<version>version3</version>
</dependency>
<dependency>
<groupId>groupId4</groupId>
<artifactId>artifactId4</artifactId>
<version>version4</version>
<exclusions>
<exclusion>
<groupId>groupId4</groupId>
<artifactId>artifactId4</artifactId>
</exclusion>
</exclusions>
</dependency>
I have been using Notepad++ to try and parse these dependencies with regular expressions, and my best effort has come up with the following:
With Search Mode set to Regular Expression and match newlines selected I search for the following:
.*?<dependency>.*?<groupId>(.*?)</groupId>.*?<artifactId>(.*?)</artifactId>.*?<version>(.*?)</version>.*?</dependency>.*?\R*
and replace with:
\1:\2:\3
Unfortunately this does not cover the case of an omitted version, so the following
<dependency>
<groupId>groupId2</groupId>
<artifactId>artifactId2</artifactId>
</dependency>
<dependency>
<groupId>groupId3</groupId>
<artifactId>artifactId3</artifactId>
<version>version3</version>
</dependency>
Would be transformed to:
groupId1:artifactId1:version2
When ideally I would like to see it converted to something like this:
groupId1:artifactId1
groupId2:artifactId2:version2
Would anyone have suggestions on improving my regular expression? It doesn't have to be a single regular express either. If running sequential expressions will ultimately transform the dependencies into the desired format that's ok.
1st replacement
Find what:
<([^>]+)>([^<]+)</\1>(?:(?!\s*</)\s*)?
Replace with:
\2:
That will result in almost what you want: groupId1:artifactId1:version1:
2nd replacement
To remove the trailing ":", Find what:
:\s*?$
Replace with:
{leave empty}
Related
I could not find the class ProjectSubscriptionName/MessageReceiver and eclipse reporting ProjectSubscriptionName/MessageReceiver class can not resolved error tough the related google-cloud-pubsub jar imported to build path by defining in pom.xml file.
pom.xml:
<dependency>
<groupId>com.google.cloud.dataflow</groupId>
<artifactId>google-cloud-dataflow-java-sdk-all</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>0.8.0</version>
</dependency>
Need help here to find the correct jar for missing classes. Appreciate your help. Jar should be stable one not alpha/beta version.
Hi Kamal,
Google released pubsub 1.31.0 version yesterday and pom entry below:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>1.31.0</version>
</dependency>
Link:
https://mvnrepository.com/artifact/com.google.cloud/google-cloud-pubsub/1.31.0
The ProjectSubscriptionName and MessageReceiver are only defined in later versions of the client library that were in beta until version 1.31.0 was released. The newer client libraries are designed to make it easier to handle high throughput and low latency. The MessageReceiver interface first appeared in version 0.9.0-alpha. The ProjectSubscriptionName class first appeared in 0.36.0-beta.
In the Jetty 9.3.1 documentation the Class HttpTester is referenced, however it doesn't appear to be in any of the jar files provided in the download package.
HttpTester.Request request = HttpTester.newRequest();
request.setURI("/some/resource");
HttpTester.Response response =
HttpTester.parseResponse(HttpTester.from(localConnector.getResponse(request.generate())));
I want to use HttpTester.Response and HttpTester.Request in my unit test cases.
Was this class removed in 9.3.1? If so, is there a recommended alternative?
It was moved to the tests classified artifacts.
Try this (in maven-speak):
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
<version>9.3.11.v20160721</version>
<classifier>tests</classifier>
</dependency>
Some cases, I have to replace/delete lines starts with particular word like 'public' 'private' Java classes or <version> for XML file.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${version.bean.validation.hibernate}</version>
</dependency>
Here using find/replace, I want to delete all lines starts with '<version>'.
How to achieve this.
use this regexp: ^\s+<version>.*$
This will remove all lines starting with <version>. Make sure you have checked the checkbox "Regular expression"
See the image:
add regular expression as Jens correctly mentioned ^\s+<version>.*$
put nothing in here.
Check on regular expression option.
Click Replace All.
Use the following regular expression to hide lines starting with 'public' -
Regex Line Replacement
public(.*)\R
Eclipse Config
Example
Trying to set up a JPA+EJB testing after these instructions:
http://ctpjava.blogspot.fi/2009/10/unit-testing-ejbs-and-jpa-with.html
There seems to be few problems that I can't seem to get quite right.
First I get this error (which I am able to work around, but it still needs to be fixed):
SEVERE: EJB6004:Specified application server installation location [C:\Users\<userName>\.m2\repository\org\glassfish\extras\glassfish-embedded-all\domains\domain1] does not exist.
Found this site, which gives the (more correct?) properties to set:
http://docs.oracle.com/cd/E18930_01/html/821-2424/gjlde.html
And modified my testing setup to this:
import javax.ejb.embeddable.EJBContainer;
import javax.naming.Context;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
...
#BeforeClass
public static void createContainer() {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(EJBContainer.MODULES, new File("target/classes"));
properties.put("installation.root", "./src/test/glassfish");
properties.put("configuration.file", "./src/test/glassfish/domains/domain1/config/domain.xml");
container = EJBContainer.createEJBContainer(properties);
ctx = container.getContext();
}
And in pom.xml I have the following that seems to be required for this:
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.9.1.0</version>
<scope>test</scope>
</dependency>
<!-- Must be before java-ee -->
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
The error pointed into user directory and I was able to get pass this by setting up the required stuff there (and got past this), but that is not a proper place, since everything must be available via SVN.
According to the latter link I think I have the correct properties set, but those seem to be ignored. Maybe I am missing something obvious?
Missed this text in the properties link:
Properties that can be passed to the
EJBContainer#createEJBContainer(Properties) method are summarized in
the following table. All properties are in the
org.glassfish.ejb.embedded.glassfish package. For example, the full
name of the installation.root property is
org.glassfish.ejb.embedded.glassfish.installation.root.
So the answer was to have:
org.glassfish.ejb.embedded.glassfish.
Before each property
Thus:
org.glassfish.ejb.embedded.glassfish.installation.root
intead of:
installation.root
I am introducing JPA2.0 in my application working on Oracle9i database and I added the libraries EclipseLink(JPA2.0) and created the entity classes but when I use
javax.persistence.criteria.CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
I get the following error
cannot find symbol
symbol : method getCriteriaBuilder()
location: interface javax.persistence.EntityManager
my web.xml is version 2.4 and here's my persistence.xml
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="MiraclinPU" transaction-type="JTA">
<jta-data-source>jdbc/Miraclin</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>
It looks like the app is using JPA1.0 as I read on the forums...Can anyone help?
Use:
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
And not:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
Search in all libraries that are included in your project, and remove the ones containing persistence.xml except the one you need. Then reinclude them again.
In eclipse:
Project -> Properties -> Java Build Path -> Configure Build Path -> Libraries
remove references to javax/persistente
insert a reference to hibernate-jpa-2.0-api-/version/.jar
how to verify:
in your sourceDAO.java press F3 in EntityManagerFactory and look what .jar eclipse open.
Missing
import javax.persistence.criteria.*;
possibly?
Due to org.hibernate.orm artifact was moved to hibernate-core;
I removed this from pom.xml:
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.9.Final</version>
</dependency>
and added this:
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.9.Final</version>
</dependency>
That was solved the cannot find symbol getCriteriaBuilder() problem.