Skip to content

Commit 730bbf7

Browse files
mshabarovcaalador
authored andcommitted
feat: Check license also for jars with cvdlName (#14443)
Cherry picked from commit 3005b87
1 parent f753f8b commit 730bbf7

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

flow-maven-plugin/src/main/java/com/vaadin/flow/plugin/maven/BuildFrontendMojo.java

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import java.util.Arrays;
2828
import java.util.List;
2929
import java.util.Set;
30+
import java.util.jar.Attributes;
31+
import java.util.jar.JarFile;
32+
import java.util.jar.Manifest;
3033
import java.util.stream.Collectors;
3134

3235
import org.apache.commons.io.FileUtils;
@@ -181,10 +184,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
181184
getLog().info("update-frontend took " + ms + "ms.");
182185
}
183186

184-
private void runNodeUpdater() throws ExecutionFailedException, MojoExecutionException {
185-
Set<File> jarFiles = project.getArtifacts().stream()
186-
.filter(artifact -> "jar".equals(artifact.getType()))
187-
.map(Artifact::getFile).collect(Collectors.toSet());
187+
private void runNodeUpdater()
188+
throws ExecutionFailedException, MojoExecutionException {
189+
Set<File> jarFiles = getJarFiles();
188190

189191
final URI nodeDownloadRootURI;
190192
if(nodeDownloadRoot == null) {
@@ -278,8 +280,9 @@ private void validateLicenses() {
278280
throw new RuntimeException(
279281
"Stats file " + statsFile + " does not exist");
280282
}
281-
List<Product> commercialComponents = findCommercialComponents(
283+
List<Product> commercialComponents = findCommercialFrontendComponents(
282284
nodeModulesFolder, statsFile);
285+
commercialComponents.addAll(findCommercialJavaComponents());
283286

284287
for (Product component : commercialComponents) {
285288
try {
@@ -305,7 +308,7 @@ private static Logger getLogger() {
305308
return LoggerFactory.getLogger(BuildFrontendMojo.class);
306309
}
307310

308-
private static List<Product> findCommercialComponents(
311+
private static List<Product> findCommercialFrontendComponents(
309312
File nodeModulesFolder, File statsFile) {
310313
List<Product> components = new ArrayList<>();
311314
try (InputStream in = new FileInputStream(statsFile)) {
@@ -326,6 +329,37 @@ private static List<Product> findCommercialComponents(
326329

327330
}
328331

332+
private List<Product> findCommercialJavaComponents() {
333+
List<Product> components = new ArrayList<>();
334+
335+
for (File f : getJarFiles()) {
336+
try (JarFile jarFile = new JarFile(f)) {
337+
Manifest manifest = jarFile.getManifest();
338+
if (manifest == null) {
339+
continue;
340+
}
341+
Attributes attributes = manifest.getMainAttributes();
342+
if (attributes == null) {
343+
continue;
344+
}
345+
String cvdlName = attributes.getValue("CvdlName");
346+
if (cvdlName != null) {
347+
String version = attributes.getValue("Bundle-Version");
348+
Product p = new Product(cvdlName, version);
349+
components.add(p);
350+
}
351+
} catch (IOException e) {
352+
getLogger().debug("Error reading manifest for jar " + f, e);
353+
}
354+
}
355+
356+
return components;
357+
}
358+
359+
private Set<File> getJarFiles() {
360+
return project.getArtifacts().stream().filter(artifact -> "jar".equals(artifact.getType())).map(Artifact::getFile).collect(Collectors.toSet());
361+
}
362+
329363
private FrontendTools getFrontendTools() throws MojoExecutionException {
330364
final URI nodeDownloadRootURI;
331365
try {

flow-server/src/main/java/com/vaadin/flow/server/startup/DevModeInitializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import com.vaadin.flow.server.startup.ServletDeployer.StubServletConfig;
8585
import com.vaadin.flow.theme.NoTheme;
8686
import com.vaadin.flow.theme.Theme;
87+
import com.vaadin.pro.licensechecker.LicenseChecker;
8788

8889
import elemental.json.Json;
8990
import elemental.json.JsonObject;

0 commit comments

Comments
 (0)