Add support for maven classifiers, make repo structures functional
For now each repo structure will resolve the absolute path of the desired file.
This commit is contained in:
26
src/model/struct/repo/BaseMavenRepo.ts
Normal file
26
src/model/struct/repo/BaseMavenRepo.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { resolve } from 'path'
|
||||||
|
import { MavenUtil } from '../../../util/maven'
|
||||||
|
import { BaseFileStructure } from '../BaseFileStructure'
|
||||||
|
|
||||||
|
export abstract class BaseMavenRepo extends BaseFileStructure {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
absoluteRoot: string,
|
||||||
|
relativeRoot: string,
|
||||||
|
structRoot: string
|
||||||
|
) {
|
||||||
|
super(absoluteRoot, relativeRoot, structRoot)
|
||||||
|
}
|
||||||
|
|
||||||
|
public getArtifactById(mavenIdentifier: string): string | null {
|
||||||
|
const resolved = MavenUtil.mavenIdentifierToString(mavenIdentifier)
|
||||||
|
return resolved == null ? null : resolve(this.containerDirectory, resolved)
|
||||||
|
}
|
||||||
|
|
||||||
|
public getArtifactByComponents(group: string, artifact: string, version: string,
|
||||||
|
classifier?: string, extension = 'jar'): string {
|
||||||
|
throw resolve(this.containerDirectory,
|
||||||
|
MavenUtil.mavenComponentsToString(group, artifact, version, classifier, extension))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { BaseFileStructure } from '../BaseFileStructure'
|
import { BaseMavenRepo } from './BaseMavenRepo'
|
||||||
|
|
||||||
export class ForgeRepoStructure extends BaseFileStructure {
|
export class ForgeRepoStructure extends BaseMavenRepo {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
absoluteRoot: string,
|
absoluteRoot: string,
|
||||||
@@ -9,4 +9,8 @@ export class ForgeRepoStructure extends BaseFileStructure {
|
|||||||
super(absoluteRoot, relativeRoot, 'forge')
|
super(absoluteRoot, relativeRoot, 'forge')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getLocalForge(version: string, classifier?: string) {
|
||||||
|
this.getArtifactByComponents('net.minecraftforge', 'forge', version, classifier, 'jar')
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { BaseFileStructure } from '../BaseFileStructure'
|
import { BaseMavenRepo } from './BaseMavenRepo'
|
||||||
|
|
||||||
export class LibRepoStructure extends BaseFileStructure {
|
export class LibRepoStructure extends BaseMavenRepo {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
absoluteRoot: string,
|
absoluteRoot: string,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { BaseFileStructure } from '../BaseFileStructure'
|
import { BaseMavenRepo } from './BaseMavenRepo'
|
||||||
|
|
||||||
export class LiteLoaderRepoStructure extends BaseFileStructure {
|
export class LiteLoaderRepoStructure extends BaseMavenRepo {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
absoluteRoot: string,
|
absoluteRoot: string,
|
||||||
@@ -9,4 +9,8 @@ export class LiteLoaderRepoStructure extends BaseFileStructure {
|
|||||||
super(absoluteRoot, relativeRoot, 'liteloader')
|
super(absoluteRoot, relativeRoot, 'liteloader')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getLocalLiteLoader(version: string, classifier?: string) {
|
||||||
|
return this.getArtifactByComponents('com.mumfrey', 'liteloader', version, classifier, 'jar')
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,36 +3,42 @@ import { URL } from 'url'
|
|||||||
|
|
||||||
export class MavenUtil {
|
export class MavenUtil {
|
||||||
|
|
||||||
public static readonly ID_REGEX = /(.+):(.+):([^@]+)(?:@{1}(.+)$)?/
|
public static readonly ID_REGEX = /(.+):(.+):([^@-]+)(?:-{1}([^@]+))?(?:@{1}(.+)$)?/
|
||||||
|
|
||||||
public static isMavenIdentifier(id: string) {
|
public static isMavenIdentifier(id: string) {
|
||||||
return this.ID_REGEX.test(id)
|
return MavenUtil.ID_REGEX.test(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static mavenToString(id: string, extension = 'jar') {
|
public static mavenIdentifierToString(id: string, extension = 'jar') {
|
||||||
if (!this.isMavenIdentifier(id)) {
|
if (!MavenUtil.isMavenIdentifier(id)) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = this.ID_REGEX.exec(id)
|
const result = MavenUtil.ID_REGEX.exec(id)
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
const group = result[1]
|
const group = result[1]
|
||||||
const artifact = result[2]
|
const artifact = result[2]
|
||||||
const version = result[3]
|
const version = result[3]
|
||||||
const ext = result[4] || extension
|
const classifier = result[4]
|
||||||
|
const ext = result[5] || extension
|
||||||
|
|
||||||
return `${group.replace(/\./g, '/')}/${artifact}/${version}/${artifact}-${version}.${ext}`
|
return MavenUtil.mavenComponentsToString(group, artifact, version, classifier, ext)
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static mavenComponentsToString(group: string, artifact: string,version: string,
|
||||||
|
classifier?: string, extension = 'jar') {
|
||||||
|
return `${group.replace(/\./g, '/')}/${artifact}/${version}/${artifact}-${version}${classifier != null ? `-${classifier}` : ''}.${extension}`
|
||||||
|
}
|
||||||
|
|
||||||
public static mavenToUrl(id: string, extension = 'jar') {
|
public static mavenToUrl(id: string, extension = 'jar') {
|
||||||
const res = this.mavenToString(id, extension)
|
const res = MavenUtil.mavenIdentifierToString(id, extension)
|
||||||
return res == null ? null : new URL(res)
|
return res == null ? null : new URL(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static mavenToPath(id: string, extension = 'jar') {
|
public static mavenToPath(id: string, extension = 'jar') {
|
||||||
const res = this.mavenToString(id, extension)
|
const res = MavenUtil.mavenIdentifierToString(id, extension)
|
||||||
return res == null ? null : normalize(res)
|
return res == null ? null : normalize(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user