Skip to content

Commit

Permalink
Feature: update maven checks for Liferay toolchain (including biz.aqu…
Browse files Browse the repository at this point in the history
…te.bnd and com.liferay.ant.bnd)
  • Loading branch information
dmarks2 committed Jul 23, 2024
1 parent 74058f5 commit f881a03
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
- Feature: add deprecation checks for Liferay 2024.Q1 and Liferay 2024.Q2
- Feature: add quick fix for non-matching plugin or dependency versions in pom.xml (portal-web, service-builder, rest-builder)
- Feature: add support for ADTs for the Date Facet Portlet (available since Liferay 7.4.3.104)
- Feature: update maven checks for Liferay toolchain (including biz.aqute.bnd and com.liferay.ant.bnd)

## 0.0.20
- Change: Update support for IntelliJ 2024.1, dropped support for earlier versions
Expand Down
1 change: 1 addition & 0 deletions documentation/updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ The following areas are checked
* Maven Dependencies
* Checks if `service-builder` and `rest-builder` plugins match the used liferay version
* Checks if `portal-web` dependency matches the used liferay version
* Checks if `biz.aqute.bnd` and `com.liferay.ant.bnd` dependencies match the used liferay version

*Checking for removals or deprecations works for Liferay 7.0 to Liferay 7.4*
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -94,4 +95,34 @@ public String getBuildArtifactVersion(String liferayVersion, String path) throws
return null;
}

public String getProjectTemplateVersion(String liferayVersion, String key) throws URISyntaxException, IOException {
String gaVersion = LiferayVersions.getGAVersion(liferayVersion);

String buildFile = getGithubFileContent("/" + gaVersion + "/modules/build.gradle");

AtomicReference<String> version = new AtomicReference<>("");

buildFile.lines().forEach(
line -> {
if (version.get().isEmpty()) {
int idx = line.indexOf(key);

if (idx >= 0) {
int idx2 = line.indexOf("\"", idx + key.length() + 1);

if (idx2 >= 0) {
int idx3 = line.indexOf("\"", idx2 + 1);

if (idx3 >= 0) {
version.set(line.substring(idx2 + 1, idx3));
}
}
}
}
}
);

return version.get();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ public class LiferayMavenDeprecationsExternalAnnotator extends ExternalAnnotator

private static final String LIFERAY_GROUP_ID = "com.liferay";
private static final String LIFERAY_PORTAL_GROUP_ID = "com.liferay.portal";
private static final String BIZ_AQUTE_BND_GROUP_ID = "biz.aQute.bnd";
private static final String SERVICE_BUILDER_ARTIFACT_ID = "com.liferay.portal.tools.service.builder";
private static final String REST_BUILDER_ARTIFACT_ID = "com.liferay.portal.tools.rest.builder";
private static final String PORTAL_WEB_ARTIFACT_ID = "com.liferay.portal.web";
private static final String BIZ_AQUTE_BNDLIB_ARTIFACT_ID = "biz.aQute.bndlib";
private static final String LIFERAY_ANT_BND_ARTIFACT_ID = "com.liferay.ant.bnd";


@Override
Expand All @@ -70,7 +73,9 @@ public class LiferayMavenDeprecationsExternalAnnotator extends ExternalAnnotator
}

if (log.isDebugEnabled()) {
log.debug("Examining " + file.getName());
if (file.getVirtualFile() != null) {
log.debug("Examining " + file.getVirtualFile().getCanonicalPath());
}
}

Module module = ModuleUtilCore.findModuleForPsiElement(file);
Expand All @@ -91,8 +96,14 @@ public class LiferayMavenDeprecationsExternalAnnotator extends ExternalAnnotator
validatePluginVersion(host, mavenDomModel, liferayVersion, LIFERAY_GROUP_ID, REST_BUILDER_ARTIFACT_ID, "REST Builder", LiferayMavenDeprecationsExternalAnnotator::getRestBuilderVersion);

validateDependencyVersion(host, mavenDomModel, liferayVersion, LIFERAY_PORTAL_GROUP_ID, PORTAL_WEB_ARTIFACT_ID, "Portal Web", LiferayMavenDeprecationsExternalAnnotator::getPortalWebVersion);
validateDependencyVersion(host, mavenDomModel, liferayVersion, BIZ_AQUTE_BND_GROUP_ID, BIZ_AQUTE_BNDLIB_ARTIFACT_ID, "Biz aQute bndlib", LiferayMavenDeprecationsExternalAnnotator::getBizaQuteBnd);
validateDependencyVersion(host, mavenDomModel, liferayVersion, LIFERAY_GROUP_ID, LIFERAY_ANT_BND_ARTIFACT_ID, "Liferay Ant bnd", LiferayMavenDeprecationsExternalAnnotator::getAntBndVersion);

return host;
} else {
if (log.isDebugEnabled()) {
log.debug("Maven Model is empty or invalid. Unable to examine...");
}
}
}

Expand Down Expand Up @@ -248,26 +259,38 @@ private static String getPluginVersionFromBndFile(String liferayVersion, String
return null;
}

private static String getServiceBuilderVersion(String liferayVersion) {
//service builder found in 7.4 on GitHub only?
if (
(liferayVersion.startsWith("7.4"))
) {
return getPluginVersionFromBndFile(liferayVersion, "/modules/util/portal-tools-service-builder/bnd.bnd");
private static String getProjectTemplateVersion(String liferayVersion, String key) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
return "9.9.9";
}

try {
LiferayGithubClient githubClient = new LiferayGithubClient();

return githubClient.getProjectTemplateVersion(liferayVersion, key);
} catch (URISyntaxException | IOException e) {
if (log.isDebugEnabled()) {
log.debug("Unable to fetch plugin version from github: " + e.getMessage());
}
}

return null;
}

private static String getServiceBuilderVersion(String liferayVersion) {
return getProjectTemplateVersion(liferayVersion, "com.liferay.portal.tools.service.builder.version");
}

private static String getRestBuilderVersion(String liferayVersion) {
//rest builder found in 7.4 on GitHub only?
if (
(liferayVersion.startsWith("7.4"))
) {
return getPluginVersionFromBndFile(liferayVersion, "/modules/util/portal-tools-rest-builder/bnd.bnd");
}
return getProjectTemplateVersion(liferayVersion, "com.liferay.portal.tools.rest.builder.version");
}

return null;
private static String getBizaQuteBnd(String liferayVersion) {
return getProjectTemplateVersion(liferayVersion, "biz.aQute.bnd.version");
}

private static String getAntBndVersion(String liferayVersion) {
return getProjectTemplateVersion(liferayVersion, "com.liferay.ant.bnd.version");
}

private static String getPortalWebVersion(String liferayVersion) {
Expand Down Expand Up @@ -304,6 +327,18 @@ private static List<MavenDomDependency> findDependencies(MavenDomProjectModel mo
result.addAll(findDependencies(model.getDependencies().getDependencies(), groupId, artifactId));
result.addAll(findDependencies(model.getDependencyManagement().getDependencies().getDependencies(), groupId, artifactId));

List<MavenDomDependency> dependenciesFromPlugins = new ArrayList<>();

for (MavenDomPlugin plugin : model.getBuild().getPlugins().getPlugins()) {
dependenciesFromPlugins.addAll(plugin.getDependencies().getDependencies());
}

for (MavenDomPlugin plugin : model.getBuild().getPluginManagement().getPlugins().getPlugins()) {
dependenciesFromPlugins.addAll(plugin.getDependencies().getDependencies());
}

result.addAll(findDependencies(dependenciesFromPlugins, groupId, artifactId));

return result;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<li>Feature: add deprecation checks for Liferay 2024.Q1 and Liferay 2024.Q2</li>
<li>Feature: add quick fix for non-matching plugin or dependency versions in pom.xml (portal-web, service-builder, rest-builder)</li>
<li>Feature: add support for ADTs for the Date Facet Portlet (available since Liferay 7.4.3.104)</li>
<li>Feature: update maven checks for Liferay toolchain (including biz.aqute.bnd and com.liferay.ant.bnd)</li>
</ul>
<p>Version 0.0.20</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,34 @@ public void testPortalWebVersion() {
myFixture.checkResultByFile("portal-web/pom-expected.xml");
}

public void testBizaQuteBndVersion() {
myFixture.configureByFiles("biz-aqute-bnd/pom.xml");

myFixture.checkHighlighting();

List<IntentionAction> allQuickFixes = myFixture.getAllQuickFixes();
for (IntentionAction quickFix : allQuickFixes) {
if (quickFix.getFamilyName().startsWith("Update version")) {
myFixture.launchAction(quickFix);
}
}

myFixture.checkResultByFile("biz-aqute-bnd/pom-expected.xml");
}

public void testPluginDependencyVersion() {
myFixture.configureByFiles("plugin-dependency/pom.xml");

myFixture.checkHighlighting();

List<IntentionAction> allQuickFixes = myFixture.getAllQuickFixes();
for (IntentionAction quickFix : allQuickFixes) {
if (quickFix.getFamilyName().startsWith("Update version")) {
myFixture.launchAction(quickFix);
}
}

myFixture.checkResultByFile("plugin-dependency/pom-expected.xml");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.dm.liferay</groupId>
<artifactId>sample</artifactId>
<version>1.0.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
<version>9.9.9</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.dm.liferay</groupId>
<artifactId>sample</artifactId>
<version>1.0.0-SNAPSHOT</version>

<dependencies>
<<warning descr="Mismatched Biz aQute bndlib Dependency version (1.0.0 does not match Liferay 7.4.3.55, should be 9.9.9)">dependency</warning>>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</<warning descr="Mismatched Biz aQute bndlib Dependency version (1.0.0 does not match Liferay 7.4.3.55, should be 9.9.9)">dependency</warning>>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.dm.liferay</groupId>
<artifactId>sample</artifactId>
<version>1.0.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.2.0</version>
<dependencies>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
<version>9.9.9</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.dm.liferay</groupId>
<artifactId>sample</artifactId>
<version>1.0.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.2.0</version>
<dependencies>
<<warning descr="Mismatched Biz aQute bndlib Dependency version (1.0.0 does not match Liferay 7.4.3.55, should be 9.9.9)">dependency</warning>>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
<version>1.0.0</version>
</<warning descr="Mismatched Biz aQute bndlib Dependency version (1.0.0 does not match Liferay 7.4.3.55, should be 9.9.9)">dependency</warning>>
</dependencies>
</plugin>
</plugins>
</build>

</project>

0 comments on commit f881a03

Please sign in to comment.