Skip to content

Commit

Permalink
feat(#60): read version from MANIFEST.MF
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Nov 30, 2024
1 parent d7ec2b1 commit 7ab2740
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 29 deletions.
19 changes: 16 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ SOFTWARE.
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>3.9.9</version>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-manifests</artifactId>
<!-- version from the parent pom -->
</dependency>
<dependency>
<groupId>org.yaml</groupId>
Expand Down Expand Up @@ -200,6 +200,19 @@ SOFTWARE.
<artifactId>maven-invoker-plugin</artifactId>
<!-- version from the parent pom -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<!-- version from the parent pom -->
<configuration>
<archive>
<index>true</index>
<manifestEntries>
<Lints-Version>${project.version}</Lints-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
14 changes: 4 additions & 10 deletions src/main/java/org/eolang/lints/Defect.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
*/
package org.eolang.lints;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import com.jcabi.manifests.Manifests;

/**
* A single defect found.
Expand Down Expand Up @@ -64,7 +60,7 @@ public interface Defect {
* The linter's current version.
* @return Linter's current version
*/
String version() throws IOException, XmlPullParserException;
String version();

/**
* Default.
Expand Down Expand Up @@ -136,10 +132,8 @@ public String text() {
}

@Override
public String version() throws IOException, XmlPullParserException {
return new MavenXpp3Reader().read(
Files.newInputStream(Paths.get("pom.xml"))
).getVersion();
public String version() {
return Manifests.read("Lints-Version");
}
}

Expand Down
20 changes: 4 additions & 16 deletions src/test/java/org/eolang/lints/DefectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package org.eolang.lints;

import java.util.regex.Pattern;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
Expand All @@ -35,29 +34,18 @@
*/
final class DefectTest {

/**
* Version regexp pattern.
*/
private static final Pattern VERSION_PATTERN = Pattern.compile(
"^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(-[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)?(\\+[a-zA-Z0-9]+)?$"
);

@Test
void returnsVersion() throws Exception {
void returnsVersion() {
final String version = new Defect.Default(
"metas/incorrect-architect",
Severity.WARNING,
3,
"Something went wrong with an architect"
).version();
MatcherAssert.assertThat(
String.format(
"Version '%s' doesn't match with version regex: '%s'",
version,
DefectTest.VERSION_PATTERN
),
DefectTest.VERSION_PATTERN.matcher(version).matches(),
Matchers.equalTo(false)
"Version doesn't match with expected",
version,
Matchers.equalTo("1.2.3")
);
}
}
1 change: 1 addition & 0 deletions src/test/resources/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Lints-Version: 1.2.3

0 comments on commit 7ab2740

Please sign in to comment.