Skip to content

Commit

Permalink
check of compatibility archetype version and cli (draft)
Browse files Browse the repository at this point in the history
helidon init compatibility support
fix check compatibility in ArchetypeEngineV2.java
add logs to test
add logs to test, fix copyright
fix check compatibility in ArchetypeEngineV2
use maven-remote-resources-plugin to share resources between modules
refactoring
refactoring
code change after review
fix IT test

Signed-off-by: aserkes <[email protected]>
  • Loading branch information
aserkes authored and romain-grecourt committed Aug 4, 2023
1 parent 582f2f2 commit c4a0633
Show file tree
Hide file tree
Showing 19 changed files with 1,898 additions and 58 deletions.
38 changes: 26 additions & 12 deletions archetype/engine-v2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
<artifactId>helidon-build-common-xml</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.build-tools.common</groupId>
<artifactId>helidon-build-common-maven</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>compiler</artifactId>
Expand Down Expand Up @@ -77,25 +82,34 @@
</dependencies>

<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${project.basedir}/src/main/schema</directory>
<targetPath>${project.build.outputDirectory}/schemas</targetPath>
<includes>
<include>*.xsd</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<id>bundle-resources</id>
<phase>process-resources</phase>
<goals>
<goal>attach-artifact</goal>
<goal>bundle</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>src/main/schema/archetype.xsd</file>
<type>xsd</type>
<classifier>schema-2.0</classifier>
</artifact>
</artifacts>
<resourcesDirectory>${project.build.outputDirectory}</resourcesDirectory>
<includes>
<include>**/schemas/**/*.xsd</include>
</includes>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@
package io.helidon.build.archetype.engine.v2;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.function.Function;
import java.util.jar.Manifest;

import io.helidon.build.archetype.engine.v2.ast.Script;
import io.helidon.build.archetype.engine.v2.context.Context;
import io.helidon.build.archetype.engine.v2.context.ContextSerializer;
import io.helidon.build.common.FileUtils;
import io.helidon.build.common.RequirementFailure;
import io.helidon.build.common.maven.MavenVersion;
import io.helidon.build.common.maven.VersionRange;

import static java.util.Objects.requireNonNull;

Expand All @@ -37,6 +43,8 @@ public class ArchetypeEngineV2 {
private static final String ENTRYPOINT = "main.xml";
private static final String ARTIFACT_ID = "artifactId";

private static final VersionRange COMPATIBLE_SCHEMA_RANGE = VersionRange.createFromVersionSpec("[2.0.0,3.0.0)");

private final Path cwd;
private final InputResolver inputResolver;
private final Map<String, String> externalValues;
Expand All @@ -46,6 +54,7 @@ public class ArchetypeEngineV2 {
private final File outputPropsFile;

private ArchetypeEngineV2(Builder builder) {
checkCompatability(builder.cwd);
this.cwd = builder.cwd;
this.inputResolver = builder.inputResolver;
this.externalValues = builder.externalValues;
Expand All @@ -55,6 +64,32 @@ private ArchetypeEngineV2(Builder builder) {
this.outputPropsFile = builder.outputPropsFile;
}

private void checkCompatability(Path cwd) {
Path manifestPath = cwd.resolve("META-INF/MANIFEST.MF");
if (!Files.exists(manifestPath)) {
//it is not an archetype archive
return;
}
try {
Manifest manifest = new Manifest(Files.newInputStream(manifestPath));
String maxVersion = manifest.getMainAttributes().getValue("archetype-schema-version");
if (maxVersion == null) {
//it is a some previous version of archetype archive
return;
}
MavenVersion mavenVersion = MavenVersion.toMavenVersion(maxVersion);
if (!COMPATIBLE_SCHEMA_RANGE.containsVersion(mavenVersion)) {
throw new RequirementFailure(
String.format("Version of schema %s is not compatible with the current version of "
+ "the Archetype engine (v2). The version of schema must be in range %s",
maxVersion,
COMPATIBLE_SCHEMA_RANGE));
}
} catch (IOException e) {
throw new RequirementFailure(e.getMessage());
}
}

/**
* Generate a project.
*
Expand Down
3 changes: 2 additions & 1 deletion archetype/engine-v2/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,6 +26,7 @@
requires io.helidon.build.common.ansi;
requires io.helidon.build.common.xml;
requires com.github.mustachejava;
requires io.helidon.build.common.maven;

exports io.helidon.build.archetype.engine.v2;
exports io.helidon.build.archetype.engine.v2.ast;
Expand Down
Loading

0 comments on commit c4a0633

Please sign in to comment.