src/share/classes/org/openjdk/jigsaw/PublishedRepository.java
Print this page
*** 171,182 ****
if (e == null)
throw new IllegalArgumentException(mid + ": No such module");
return jms.parseModuleInfo(e.mibs);
}
! private ModuleType getModuleType(Path modp) {
! for (ModuleType type: ModuleType.values()) {
if (modp.getFileName().toString().endsWith(type.getFileNameSuffix())) {
return type;
}
}
--- 171,182 ----
if (e == null)
throw new IllegalArgumentException(mid + ": No such module");
return jms.parseModuleInfo(e.mibs);
}
! private ModuleFileType getModuleFileType(Path modp) {
! for (ModuleFileType type: ModuleFileType.values()) {
if (modp.getFileName().toString().endsWith(type.getFileNameSuffix())) {
return type;
}
}
*** 186,219 ****
private Path getModulePath(ModuleId mid, String ext) throws IOException {
return path.resolve(mid.toString() + ext);
}
! private Path getModulePath(ModuleId mid, ModuleType type) throws IOException {
return getModulePath(mid, type.getFileNameSuffix());
}
private Path getModulePath(ModuleId mid) throws IOException {
! for (ModuleType type: ModuleType.values()) {
Path file = getModulePath(mid, type);
if (Files.exists(file)) {
return file;
}
}
throw new IllegalArgumentException(mid + ": No such module file");
}
private Entry readModuleInfo(Path modp) throws IOException {
! return readModuleInfo(modp, getModuleType(modp));
}
private Entry getModuleInfo(ModuleId mid) throws IOException {
return readModuleInfo(getModulePath(mid));
}
! private Entry readModuleInfo(Path modp, ModuleType type) throws IOException {
! switch(getModuleType(modp)) {
case JAR:
return readModuleInfoFromModularJarFile(modp);
case JMOD:
return readModuleInfoFromJmodFile(modp);
default:
--- 186,219 ----
private Path getModulePath(ModuleId mid, String ext) throws IOException {
return path.resolve(mid.toString() + ext);
}
! private Path getModulePath(ModuleId mid, ModuleFileType type) throws IOException {
return getModulePath(mid, type.getFileNameSuffix());
}
private Path getModulePath(ModuleId mid) throws IOException {
! for (ModuleFileType type: ModuleFileType.values()) {
Path file = getModulePath(mid, type);
if (Files.exists(file)) {
return file;
}
}
throw new IllegalArgumentException(mid + ": No such module file");
}
private Entry readModuleInfo(Path modp) throws IOException {
! return readModuleInfo(modp, getModuleFileType(modp));
}
private Entry getModuleInfo(ModuleId mid) throws IOException {
return readModuleInfo(getModulePath(mid));
}
! private Entry readModuleInfo(Path modp, ModuleFileType type) throws IOException {
! switch(getModuleFileType(modp)) {
case JAR:
return readModuleInfoFromModularJarFile(modp);
case JMOD:
return readModuleInfoFromJmodFile(modp);
default:
*** 230,240 ****
ModuleFileHeader mfh = parser.fileHeader();
// Move to the module info section
parser.next();
! return new Entry(ModuleType.JMOD,
toByteArray(parser.getContentStream()),
mfh.getCSize(),
mfh.getUSize(),
mfh.getHashType(),
mfh.getHash());
--- 230,241 ----
ModuleFileHeader mfh = parser.fileHeader();
// Move to the module info section
parser.next();
! return new Entry(ModuleFileType.JMOD,
! mfh.getArchitecture(),
toByteArray(parser.getContentStream()),
mfh.getCSize(),
mfh.getUSize(),
mfh.getHashType(),
mfh.getHash());
*** 256,266 ****
}
usize += je.getSize();
}
! return new Entry(ModuleType.JAR,
toByteArray(j, moduleInfo),
jf.length(),
usize,
HashType.SHA256,
digest(jf));
--- 257,268 ----
}
usize += je.getSize();
}
! return new Entry(ModuleFileType.JAR,
! ModuleArchitecture.ANY,
toByteArray(j, moduleInfo),
jf.length(),
usize,
HashType.SHA256,
digest(jf));
*** 334,349 ****
throw new IllegalArgumentException(mid + ": No such module");
return Files.newInputStream(getModulePath(mid, e.type));
}
@Override
! public ModuleMetaData fetchMetaData(ModuleId mid) throws IOException {
RepositoryCatalog cat = loadCatalog();
Entry e = cat.get(mid);
if (e == null)
throw new IllegalArgumentException(mid + ": No such module");
! return new ModuleMetaData(e.type, e.csize, e.usize);
}
public boolean remove(ModuleId mid) throws IOException {
try (FileChannel lc = FileChannel.open(lockp, READ, WRITE)) {
lc.lock();
--- 336,351 ----
throw new IllegalArgumentException(mid + ": No such module");
return Files.newInputStream(getModulePath(mid, e.type));
}
@Override
! public ModuleFileMetaData fetchMetaData(ModuleId mid) throws IOException {
RepositoryCatalog cat = loadCatalog();
Entry e = cat.get(mid);
if (e == null)
throw new IllegalArgumentException(mid + ": No such module");
! return new ModuleFileMetaData(e.type, e.modArch, e.csize, e.usize);
}
public boolean remove(ModuleId mid) throws IOException {
try (FileChannel lc = FileChannel.open(lockp, READ, WRITE)) {
lc.lock();
*** 373,392 ****
{
// ## Change to use String joiner when lamda is merged into JDK8
StringBuilder sb = new StringBuilder();
sb.append("*.{");
int l = sb.length();
! for (ModuleType type: ModuleType.values()) {
if (sb.length() > l) {
sb.append(",");
}
sb.append(type.getFileNameExtension());
}
sb.append("}");
try (DirectoryStream<Path> ds = Files.newDirectoryStream(path, sb.toString())) {
for (Path modp : ds) {
! ModuleType type = getModuleType(modp);
String fn = modp.getFileName().toString();
ModuleId mid
= jms.parseModuleId(fn.substring(0, fn.length() - type.getFileNameSuffix().length()));
mids.add(mid);
}
--- 375,394 ----
{
// ## Change to use String joiner when lamda is merged into JDK8
StringBuilder sb = new StringBuilder();
sb.append("*.{");
int l = sb.length();
! for (ModuleFileType type: ModuleFileType.values()) {
if (sb.length() > l) {
sb.append(",");
}
sb.append(type.getFileNameExtension());
}
sb.append("}");
try (DirectoryStream<Path> ds = Files.newDirectoryStream(path, sb.toString())) {
for (Path modp : ds) {
! ModuleFileType type = getModuleFileType(modp);
String fn = modp.getFileName().toString();
ModuleId mid
= jms.parseModuleId(fn.substring(0, fn.length() - type.getFileNameSuffix().length()));
mids.add(mid);
}