Skip to content

Commit

Permalink
Merge pull request mvnpm#1296 from phillip-kruger/pinkie
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
phillip-kruger authored Oct 16, 2023
2 parents 145f4f0 + 6bb44cf commit 38bac96
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ nbactions.xml
# Local environment
.env
/dev.sh
/local.sh
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.mvnpm</groupId>
<artifactId>mvnpm</artifactId>
<version>2.0.20-SNAPSHOT</version>
<version>2.0.24-SNAPSHOT</version>

<name>mvnpm</name>
<description>Maven on NPM</description>
Expand Down Expand Up @@ -56,7 +56,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.4.2</quarkus.platform.version>
<quarkus.platform.version>3.4.3</quarkus.platform.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.0.0</surefire-plugin.version>
<formatter.plugin.version>2.23.0</formatter.plugin.version>
Expand All @@ -65,7 +65,7 @@

<!-- UI Libs -->
<quarkus-qute-server-pages.version>2.1.0.Final</quarkus-qute-server-pages.version>
<quarkus-web-bundler.version>1.1.3</quarkus-web-bundler.version>
<quarkus-web-bundler.version>1.1.4</quarkus-web-bundler.version>
<importmap.version>1.0.10</importmap.version>
</properties>

Expand Down Expand Up @@ -430,7 +430,7 @@
<dependency>
<groupId>org.mvnpm.at.codemirror</groupId>
<artifactId>commands</artifactId>
<version>6.2.5</version>
<version>6.3.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -460,7 +460,7 @@
<dependency>
<groupId>org.mvnpm.at.codemirror</groupId>
<artifactId>view</artifactId>
<version>6.20.0</version>
<version>6.21.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
Expand Down
40 changes: 29 additions & 11 deletions src/main/java/io/mvnpm/file/type/PomClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -118,13 +117,22 @@ private String toUrl(Model model, URL homepage) {
}
}

private List<License> toLicenses(String license) {
if (license != null && !license.isEmpty()) {
License l = new License();
l.setName(license);
return List.of(l);
private List<License> toLicenses(io.mvnpm.npm.model.License license) {
License l = new License();

if (license != null) {
if (license.type() != null) {
l.setName(license.type());
}
if (license.url() != null) {
l.setUrl(license.url().toString());
}
}
return Collections.EMPTY_LIST;

if (l.getName() == null && l.getUrl() == null) {
l.setName("none");
}
return List.of(l);
}

private Organization toOrganization(io.mvnpm.npm.model.Package p) {
Expand Down Expand Up @@ -168,22 +176,32 @@ private Scm toScm(Repository repository) {
s.setConnection(conn);
s.setDeveloperConnection(conn);
return s;
} else {
Scm s = new Scm();
s.setUrl("https://github.com/mvnpm/mvnpm.git");
s.setConnection("https://github.com/mvnpm/mvnpm.git");
s.setDeveloperConnection("https://github.com/mvnpm/mvnpm.git");
return s;
}
return null;

}

private List<Developer> toDevelopers(List<Maintainer> maintainers) {
List<Developer> ds = new ArrayList<>();
if (maintainers != null && !maintainers.isEmpty()) {
List<Developer> ds = new ArrayList<>();
for (Maintainer m : maintainers) {
Developer d = new Developer();
d.setEmail(m.email());
d.setName(m.name());
ds.add(d);
}
return ds;
}
return Collections.EMPTY_LIST;
if (ds.isEmpty()) {
Developer d = new Developer();
d.setName("unknown");
ds.add(d);
}
return ds;
}

private List<Dependency> toDependencies(Map<Name, String> dependencies) {
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/io/mvnpm/maven/UrlPathParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.mvnpm.maven;

import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import io.mvnpm.Constants;
import io.mvnpm.npm.model.Name;
Expand All @@ -26,6 +28,9 @@ public static Name parseMavenMetaDataXml(String fullName) {
}

public static NameVersionType parseMavenFile(String urlPath) {
if (urlPath.contains("/git:/") || urlPath.contains("/git+http:/") || urlPath.contains("/git+https:/")) { // We do not support git repos as version. Maybe something we can add later
urlPath = cleanUrlPath(urlPath);
}
String[] parts = urlPath.split(Constants.SLASH);

// We need at least 3 (name / version / filename)
Expand All @@ -42,6 +47,25 @@ public static NameVersionType parseMavenFile(String urlPath) {
fullName = fullName.replaceFirst(Constants.AT_SLASH, Constants.AT);
}

// Make sure the version is in the correct format
version = fixVersion(version);
return new NameVersionType(NameParser.fromNpmProject(fullName), version);
}

private static String cleanUrlPath(String urlPath) {
Matcher m = PATTERN.matcher(urlPath);
return m.replaceAll("latest");
}

private static String fixVersion(String version) {
String[] parts = version.split("\\.");

for (int i = parts.length; i < 3; i++) {
version += ".0";
}

return version;
}

private static final Pattern PATTERN = Pattern.compile("git\\+.*?\\.git");
}
10 changes: 8 additions & 2 deletions src/main/java/io/mvnpm/npm/NpmRegistryFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,23 @@ public Project getProject(String project) {
if (response.getStatus() < 300) {
return response.readEntity(Project.class);
} else {
throw new WebApplicationException(response);
throw new WebApplicationException("Error while getting Project for [" + project + "]", response);
}
}

@CacheResult(cacheName = "npm-package-cache")
public io.mvnpm.npm.model.Package getPackage(String project, String version) {
if (null == version || version.startsWith("git:/") || version.startsWith("git+http")) {
// We do not support git repos as version. Maybe something we can add later
version = "*";
}

Response response = npmRegistryClient.getPackage(project, version);
if (response.getStatus() < 300) {
return response.readEntity(io.mvnpm.npm.model.Package.class);
} else {
throw new WebApplicationException(response);
throw new WebApplicationException("Error while getting Package for [" + project + "] version [" + version + "]",
response);
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/mvnpm/npm/model/License.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.mvnpm.npm.model;

import java.net.URL;

public record License(String type, URL url) {

}
52 changes: 52 additions & 0 deletions src/main/java/io/mvnpm/npm/model/LicenseDeserializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.mvnpm.npm.model;

import java.io.IOException;
import java.net.URL;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

/**
* To handle some License values that comes in with a String only
*
* @author Phillip Kruger ([email protected])
*/
public class LicenseDeserializer extends StdDeserializer<License> {

public LicenseDeserializer() {
this(null);
}

public LicenseDeserializer(Class<?> vc) {
super(vc);
}

@Override
public License deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JacksonException {
try {
return jp.readValueAs(License.class);
} catch (Throwable t) {
// Let try with String
try {
URL url = jp.readValueAs(URL.class);
return new License(null, url);
} catch (Throwable tt) {
try {
String type = jp.readValueAs(String.class);
return new License(type, null);
} catch (Throwable ttt) {
try {
String type = jp.getText();
return new License(type, null);
} catch (Throwable tttt) {
ttt.printStackTrace();
return null;
}

}
}
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/io/mvnpm/npm/model/Package.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public record Package(
Name name,
String version,
String description,
String license,
@JsonDeserialize(using = LicenseDeserializer.class) License license,
@JsonDeserialize(using = AuthorDeserializer.class) Author author,
URL homepage,
Repository repository,
@JsonDeserialize(using = RepositoryDeserializer.class) Repository repository,
@JsonDeserialize(using = BugsDeserializer.class) Bugs bugs,
String main,
String module,
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/io/mvnpm/npm/model/RepositoryDeserializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.mvnpm.npm.model;

import java.io.IOException;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

/**
* To handle some Repository values that comes in with a String only
*
* @author Phillip Kruger ([email protected])
*/
public class RepositoryDeserializer extends StdDeserializer<Repository> {

public RepositoryDeserializer() {
this(null);
}

public RepositoryDeserializer(Class<?> vc) {
super(vc);
}

@Override
public Repository deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JacksonException {
try {
return jp.readValueAs(Repository.class);
} catch (Throwable t) {
// Let try with String
try {
String url = jp.readValueAs(String.class);
return new Repository(null, url, null);
} catch (Throwable tt) {
tt.printStackTrace();
return null;
}
}
}

}
9 changes: 6 additions & 3 deletions src/main/java/io/mvnpm/version/VersionConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ private VersionConverter() {

public static String convert(String versionString) {
try {
if (null == versionString)
if (null == versionString || versionString.startsWith("git:/") || versionString.startsWith("git+http")) { // We do not support git repos as version. Maybe something we can add later
versionString = EMPTY;
}

versionString = versionString.trim();
String[] orSet;
Expand Down Expand Up @@ -238,7 +239,8 @@ private static String getLowerBoundary(String s) {
} else if (s.startsWith(GREATER_THAN)) {
return OPEN_ROUND + Version.fromString(s.substring(1));
} else {
throw new InvalidVersionException(s);
// Equal. If no operator is specified, then equality is assumed, so this operator is optional, but MAY be included.
return cleanVersion(s);
}
}

Expand All @@ -248,7 +250,8 @@ private static String getUpperBoundary(String s) {
} else if (s.startsWith(LESS_THAN)) {
return Version.fromString(s.substring(1)) + CLOSE_ROUND;
} else {
throw new InvalidVersionException(s);
// Equal. If no operator is specified, then equality is assumed, so this operator is optional, but MAY be included.
return cleanVersion(s);
}
}

Expand Down

0 comments on commit 38bac96

Please sign in to comment.