Skip to content

Commit 752a62e

Browse files
committed
Maven Browsing
1 parent 486547f commit 752a62e

15 files changed

+751
-16
lines changed

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@
55
"scripts": {
66
"serve": "vue-cli-service serve",
77
"build": "vue-cli-service build",
8-
"lint": "vue-cli-service lint"
8+
"lint": "vue-cli-service lint",
9+
"cxsd": "cxsd"
910
},
1011
"dependencies": {
1112
"@tailwindcss/postcss7-compat": "npm:@tailwindcss/postcss7-compat@^2.0.2",
1213
"autoprefixer": "^9",
1314
"core-js": "^3.6.5",
15+
"cxsd": "^0.1.1",
16+
"fast-xml-parser": "^4.0.0-beta.8",
1417
"postcss": "^7",
1518
"tailwind": "^4.0.0",
1619
"tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.0.2",
1720
"typescript": "^4.4.3",
1821
"vue": "^3.0.0",
1922
"vue-class-component": "^8.0.0-0",
23+
"vue-router": "^4.0.12",
2024
"vue-typescript": "^0.7.0"
2125
},
2226
"devDependencies": {

public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<link rel="icon" href="<%= BASE_URL %>favicon.png">
88
<title>DelphiHub</title>
99
</head>
10-
<body>
10+
<body class="bg-delphi-gray font-mono">
1111
<noscript>
1212
<strong>We're sorry but DelphiHub doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
1313
</noscript>

src/App.vue

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<template>
2-
<div class="h-screen flex">
3-
<img src="./assets/logo.svg" alt="DelphiHub Logo" class="mx-auto my-auto w-1/2" />
2+
<div class="h-screen mx-5">
3+
<img src="./assets/logo.svg" alt="DelphiHub Logo" class="w-52" />
4+
<!--<img src="./assets/logo.svg" alt="DelphiHub Logo" class="mx-auto my-auto w-1/2" />-->
5+
<router-view/>
46
</div>
57
</template>
68

src/backend/maven/Maven.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { XMLParser } from "fast-xml-parser";
2+
3+
export class MavenAccess {
4+
async getArtifactVersion(groupId: string, artifactId: string, version: string): Promise<any> {
5+
const url = `/maven2/${groupId.replaceAll(".", "/")}/${artifactId
6+
}/${version}/${artifactId}-${version}.pom`;
7+
8+
const pom = await fetch(url)
9+
.then((response) => response.text())
10+
.then((str) => {
11+
const parser = new XMLParser();
12+
return parser.parse(str).project;
13+
})
14+
.catch((reason) => console.error(reason));
15+
return pom;
16+
}
17+
18+
async getArtifact(groupId: string, artifactId: string): Promise<any> {
19+
const url = `/maven2/${groupId.replaceAll(".", "/")}/${artifactId}/`;
20+
21+
const artifacts = await fetch(url)
22+
.then((response) => response.text())
23+
.then((text) => {
24+
const parser = new DOMParser();
25+
return Array.from(parser.parseFromString(text, "text/html")
26+
.getElementById("contents")
27+
?.querySelectorAll("A")!)
28+
.slice(1).map(a => a.textContent)
29+
.filter(link => link?.endsWith("/"))
30+
.map(link => link?.replace("/", ""));
31+
})
32+
.catch((reason) => console.error(reason));
33+
34+
return artifacts;
35+
}
36+
37+
async getGroup(groupId: string): Promise<any> {
38+
const url = `/maven2/${groupId.replaceAll(".", "/")}/`;
39+
40+
const group = await fetch(url)
41+
.then((response) => response.text())
42+
.then((text) => {
43+
const parser = new DOMParser();
44+
return Array.from(parser.parseFromString(text, "text/html")
45+
.getElementById("contents")
46+
?.querySelectorAll("A")!)
47+
.slice(1).map(a => a.textContent)
48+
.filter(link => link?.endsWith("/"))
49+
.map(link => link?.replace("/", ""));
50+
})
51+
.catch((reason) => console.error(reason));
52+
53+
return group;
54+
}
55+
56+
57+
}

src/backend/maven/index.ts

Whitespace-only changes.

src/main.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { createApp } from 'vue'
22
import App from './App.vue'
33
import './assets/tailwind.css'
4+
import router from './tools/router'
45

5-
createApp(App).mount('#app')
6+
const app = createApp(App)
7+
app.use(router)
8+
app.mount('#app')

src/pages/Home.vue

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<template>
2+
<p>Home</p>
3+
</template>
4+
<script lang="ts">
5+
import { defineComponent } from 'vue'
6+
7+
export default defineComponent({
8+
name: "Home",
9+
setup() {
10+
11+
},
12+
})
13+
</script>
+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<template>
2+
<div>
3+
<h2 class="w-full text-delphi-red text-2xl font-semibold font-serif">
4+
<router-link :to="{ name: 'maven-g', params: { groupId: groupId } }">{{
5+
groupId
6+
}}</router-link>
7+
|
8+
<router-link
9+
:to="{
10+
name: 'maven-ga',
11+
params: { groupId: groupId, artifactId: artifactId },
12+
}"
13+
>{{ artifactId }}</router-link
14+
>
15+
| {{ version }}
16+
</h2>
17+
18+
<div v-if="isLoading">Loading...</div>
19+
<div v-else class="text-xs line-height-xs">
20+
<table class="text-left">
21+
<tr v-if="pom.name != null">
22+
<th>Name</th>
23+
<td>{{ pom.name }}</td>
24+
</tr>
25+
<tr v-if="pom.description != null">
26+
<th>Description</th>
27+
<td>{{ pom.description }}</td>
28+
</tr>
29+
<tr v-if="pom.parent != null">
30+
<th>Parent</th>
31+
<td>
32+
<router-link
33+
:to="{
34+
name: 'maven-gav',
35+
params: {
36+
groupId: pom.parent.groupId,
37+
artifactId: pom.parent.artifactId,
38+
version: pom.parent.version,
39+
},
40+
}"
41+
>{{ pom.parent.groupId }} | {{ pom.parent.artifactId }} |
42+
{{ pom.parent.version }}</router-link
43+
>
44+
</td>
45+
</tr>
46+
<tr v-if="pom.url != null">
47+
<th>URL</th>
48+
<td>
49+
<a :href="pom.url">{{ pom.url }}</a>
50+
</td>
51+
</tr>
52+
<tr v-if="pom.licenses != null && pom.licenses.license != null">
53+
<th>License</th>
54+
<td>
55+
<a :href="pom.licenses.license.url">{{
56+
pom.licenses.license.name
57+
}}</a>
58+
</td>
59+
</tr>
60+
</table>
61+
62+
<table
63+
class="text-left"
64+
v-if="
65+
pom.dependencies != null &&
66+
pom.dependencies.dependency != null &&
67+
pom.dependencies.dependency.length > 0
68+
"
69+
>
70+
<caption class="text-left font-bold">
71+
Dependencies
72+
</caption>
73+
<tr>
74+
<th>Name</th>
75+
<th>Scope</th>
76+
</tr>
77+
<tr v-for="(d, index) in pom.dependencies.dependency" :key="index">
78+
<td>
79+
<router-link
80+
:to="{
81+
name: 'maven-gav',
82+
params: {
83+
groupId: d.groupId,
84+
artifactId: d.artifactId,
85+
version: d.version,
86+
},
87+
}"
88+
>{{ d.groupId }} | {{ d.artifactId }} |
89+
{{ d.version }}</router-link
90+
>
91+
</td>
92+
<td>{{ d.scope }}</td>
93+
</tr>
94+
</table>
95+
96+
<table class="text-left" v-if="pom.properties != null">
97+
<caption class="text-left font-bold">
98+
Properties
99+
</caption>
100+
<tr>
101+
<th>Key</th>
102+
<th>Value</th>
103+
</tr>
104+
<tr v-for="(value, key) in pom.properties" :key="key">
105+
<td>{{ key }}</td>
106+
<td>{{ value }}</td>
107+
</tr>
108+
</table>
109+
</div>
110+
</div>
111+
</template>
112+
<script lang="ts">
113+
import { defineComponent, onBeforeMount, ref, watch } from "vue";
114+
import { useRoute } from "vue-router";
115+
116+
import { MavenAccess } from '@/backend/maven/Maven';
117+
118+
export default defineComponent({
119+
setup() {
120+
const route = useRoute();
121+
const groupId = ref("");
122+
const artifactId = ref("");
123+
const version = ref("");
124+
125+
const isLoading = ref(false);
126+
const pom = ref(null);
127+
128+
onBeforeMount(async () => {
129+
processRouteValues();
130+
await loadPom();
131+
});
132+
133+
watch(
134+
() => route.params,
135+
async () => {
136+
processRouteValues();
137+
await loadPom();
138+
}
139+
);
140+
141+
async function loadPom() {
142+
if (groupId.value === undefined ||
143+
artifactId.value === undefined ||
144+
version.value == undefined) return;
145+
isLoading.value = true;
146+
pom.value = await new MavenAccess().getArtifactVersion(groupId.value, artifactId.value, version.value);
147+
isLoading.value = false;
148+
}
149+
150+
function processRouteValues(): void {
151+
groupId.value = route.params.groupId as string;
152+
artifactId.value = route.params.artifactId as string;
153+
version.value = route.params.version as string;
154+
}
155+
156+
return { groupId, artifactId, version, isLoading, pom };
157+
},
158+
});
159+
</script>

src/pages/MavenArtifactView.vue

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<template>
2+
<div>
3+
<h2 class="w-full text-delphi-red text-2xl font-semibold font-serif">
4+
<router-link :to="{ name: 'maven-g', params: { groupId: groupId } }">{{
5+
groupId
6+
}}</router-link>
7+
| {{ artifactId }}
8+
</h2>
9+
10+
<div v-if="isLoading">Loading...</div>
11+
<div v-else class="text-xs line-height-xs">
12+
<table class="text-left">
13+
<caption class="text-left font-bold">
14+
Versions
15+
</caption>
16+
<tr v-for="(v, index) in artifact" :key="index">
17+
<td>
18+
<router-link
19+
:to="{
20+
name: 'maven-gav',
21+
params: {
22+
groupId: groupId,
23+
artifactId: artifactId,
24+
version: v,
25+
},
26+
}"
27+
>{{ v }}</router-link>
28+
</td>
29+
</tr>
30+
</table>
31+
</div>
32+
</div>
33+
</template>
34+
<script lang="ts">
35+
import { MavenAccess } from "@/backend/maven/Maven";
36+
import { defineComponent, onBeforeMount, ref, watch } from "vue";
37+
import { useRoute } from "vue-router";
38+
39+
export default defineComponent({
40+
setup() {
41+
const route = useRoute();
42+
const groupId = ref("");
43+
const artifactId = ref("");
44+
45+
const isLoading = ref(false);
46+
const artifact = ref(null);
47+
48+
onBeforeMount(async () => {
49+
processRouteValues();
50+
await loadArtifact();
51+
});
52+
53+
watch(
54+
() => route.params,
55+
async () => {
56+
processRouteValues();
57+
await loadArtifact();
58+
}
59+
);
60+
61+
function processRouteValues(): void {
62+
groupId.value = route.params.groupId as string;
63+
artifactId.value = route.params.artifactId as string;
64+
}
65+
66+
async function loadArtifact() {
67+
if (groupId.value === undefined ||
68+
artifactId.value === undefined) return;
69+
isLoading.value = true;
70+
artifact.value = await new MavenAccess().getArtifact(groupId.value, artifactId.value);
71+
isLoading.value = false;
72+
}
73+
74+
return { groupId, artifactId, isLoading, artifact };
75+
},
76+
});
77+
</script>

0 commit comments

Comments
 (0)