1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.repository.aether.internal; |
21 |
|
|
22 |
|
import java.io.File; |
23 |
|
import java.io.FileInputStream; |
24 |
|
import java.io.FileNotFoundException; |
25 |
|
import java.io.IOException; |
26 |
|
import java.io.InputStream; |
27 |
|
import java.util.Arrays; |
28 |
|
import java.util.List; |
29 |
|
|
30 |
|
import org.eclipse.aether.RepositorySystem; |
31 |
|
import org.eclipse.aether.artifact.Artifact; |
32 |
|
import org.eclipse.aether.impl.RepositoryConnectorProvider; |
33 |
|
import org.eclipse.aether.repository.RemoteRepository; |
34 |
|
import org.eclipse.aether.resolution.ArtifactRequest; |
35 |
|
import org.eclipse.aether.resolution.ArtifactResolutionException; |
36 |
|
import org.eclipse.aether.resolution.ArtifactResult; |
37 |
|
import org.eclipse.aether.spi.connector.ArtifactDownload; |
38 |
|
import org.eclipse.aether.spi.connector.RepositoryConnector; |
39 |
|
import org.eclipse.aether.transfer.NoRepositoryConnectorException; |
40 |
|
import org.xwiki.extension.ExtensionFile; |
41 |
|
|
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
|
|
|
| 93.3% |
Uncovered Elements: 2 (30) |
Complexity: 5 |
Complexity Density: 0.19 |
|
46 |
|
public class AetherExtensionFile implements ExtensionFile |
47 |
|
{ |
48 |
|
private Artifact artifact; |
49 |
|
|
50 |
|
private AetherExtensionRepository repository; |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
52 |
|
static class AetherExtensionFileInputStream extends FileInputStream |
53 |
|
{ |
54 |
|
private XWikiRepositorySystemSession session; |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
56 |
10 |
public AetherExtensionFileInputStream(File file, XWikiRepositorySystemSession session)... |
57 |
|
throws FileNotFoundException |
58 |
|
{ |
59 |
10 |
super(file); |
60 |
|
|
61 |
10 |
this.session = session; |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
64 |
23 |
@Override... |
65 |
|
public void close() throws IOException |
66 |
|
{ |
67 |
23 |
super.close(); |
68 |
|
|
69 |
|
|
70 |
23 |
this.session.close(); |
71 |
|
} |
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
74 |
51 |
public AetherExtensionFile(Artifact artifact, AetherExtensionRepository repository)... |
75 |
|
{ |
76 |
51 |
this.repository = repository; |
77 |
51 |
this.artifact = artifact; |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
80 |
3 |
@Override... |
81 |
|
public long getLength() |
82 |
|
{ |
83 |
|
|
84 |
3 |
return -1; |
85 |
|
} |
86 |
|
|
|
|
| 91.7% |
Uncovered Elements: 2 (24) |
Complexity: 3 |
Complexity Density: 0.12 |
|
87 |
10 |
@Override... |
88 |
|
public InputStream openStream() throws IOException |
89 |
|
{ |
90 |
10 |
XWikiRepositorySystemSession session = this.repository.createRepositorySystemSession(); |
91 |
|
|
92 |
10 |
List<RemoteRepository> repositories = this.repository.newResolutionRepositories(session); |
93 |
10 |
RemoteRepository repository = repositories.get(0); |
94 |
|
|
95 |
10 |
RepositoryConnector connector; |
96 |
10 |
try { |
97 |
10 |
RepositoryConnectorProvider repositoryConnectorProvider = this.repository.getRepositoryConnectorProvider(); |
98 |
10 |
connector = repositoryConnectorProvider.newRepositoryConnector(session, repository); |
99 |
|
} catch (NoRepositoryConnectorException e) { |
100 |
0 |
throw new IOException("Failed to download artifact [" + this.artifact + "]", e); |
101 |
|
} |
102 |
|
|
103 |
10 |
ArtifactDownload download = new ArtifactDownload(); |
104 |
10 |
download.setArtifact(this.artifact); |
105 |
10 |
download.setRepositories(repositories); |
106 |
|
|
107 |
10 |
try { |
108 |
10 |
connector.get(Arrays.asList(download), null); |
109 |
|
} finally { |
110 |
10 |
connector.close(); |
111 |
|
} |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
10 |
ArtifactRequest artifactRequest = new ArtifactRequest(); |
116 |
10 |
artifactRequest.setRepositories(repositories); |
117 |
10 |
artifactRequest.setArtifact(this.artifact); |
118 |
|
|
119 |
10 |
ArtifactResult artifactResult; |
120 |
10 |
try { |
121 |
10 |
RepositorySystem repositorySystem = this.repository.getRepositorySystem(); |
122 |
10 |
artifactResult = repositorySystem.resolveArtifact(session, artifactRequest); |
123 |
|
} catch (ArtifactResolutionException e) { |
124 |
0 |
throw new IOException("Failed to resolve artifact", e); |
125 |
|
} |
126 |
|
|
127 |
10 |
File aetherFile = artifactResult.getArtifact().getFile(); |
128 |
|
|
129 |
10 |
return new AetherExtensionFileInputStream(aetherFile, session); |
130 |
|
} |
131 |
|
} |