Skip to content

Commit

Permalink
git subrepo pull framework
Browse files Browse the repository at this point in the history
subrepo:
  subdir:   "framework"
  merged:   "182e1106f8"
upstream:
  origin:   "[email protected]:daisy/pipeline-framework.git"
  branch:   "master"
  commit:   "e97e38124f"
git-subrepo:
  version:  "0.3.1"
  origin:   "???"
  commit:   "???"
  • Loading branch information
bertfrees committed Jan 4, 2025
1 parent 99266ad commit e599cab
Show file tree
Hide file tree
Showing 62 changed files with 1,114 additions and 895 deletions.
4 changes: 2 additions & 2 deletions framework/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
[subrepo]
remote = [email protected]:daisy/pipeline-framework.git
branch = master
commit = e9a0e7138b6a1e508fe0734413ab6b6136a0a3da
parent = 6ab8727d70af90110701604c630ed8e280a28b46
commit = e97e38124f1c8b446f27e4d05f5b434358144f55
parent = 0e4ac3656cd5011b8557e9dcfa4894fc3ff6d17d
cmdver = 0.3.1
18 changes: 9 additions & 9 deletions framework/bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>org.daisy.pipeline</groupId>
<artifactId>framework-bom</artifactId>
<version>1.14.21-SNAPSHOT</version>
<version>1.14.22-SNAPSHOT</version>
<packaging>pom</packaging>

<name>DAISY Pipeline 2 :: Framework BoM</name>
Expand Down Expand Up @@ -45,32 +45,32 @@
<dependency>
<groupId>org.daisy.pipeline</groupId>
<artifactId>calabash-adapter</artifactId>
<version>6.2.0</version>
<version>6.2.1</version>
</dependency>
<dependency>
<groupId>org.daisy.pipeline</groupId>
<artifactId>common-utils</artifactId>
<version>6.1.0</version>
<version>6.2.0</version>
</dependency>
<dependency>
<groupId>org.daisy.pipeline</groupId>
<artifactId>framework-core</artifactId>
<version>9.0.0</version>
<version>10.0.0</version>
</dependency>
<dependency>
<groupId>org.daisy.pipeline</groupId>
<artifactId>framework-persistence</artifactId>
<version>2.1.10</version>
<version>2.1.11</version>
</dependency>
<dependency>
<groupId>org.daisy.pipeline</groupId>
<artifactId>logging-appender</artifactId>
<version>2.1.4</version>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>org.daisy.pipeline</groupId>
<artifactId>modules-registry</artifactId>
<version>5.0.0-SNAPSHOT</version>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.daisy.pipeline</groupId>
Expand All @@ -80,12 +80,12 @@
<dependency>
<groupId>org.daisy.pipeline</groupId>
<artifactId>saxon-adapter</artifactId>
<version>5.5.0-SNAPSHOT</version>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>org.daisy.pipeline</groupId>
<artifactId>webservice</artifactId>
<version>3.5.0</version>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.daisy.pipeline</groupId>
Expand Down
4 changes: 2 additions & 2 deletions framework/calabash-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<parent>
<groupId>org.daisy.pipeline</groupId>
<artifactId>framework-parent</artifactId>
<version>1.14.21-SNAPSHOT</version>
<version>1.14.22-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>

<artifactId>calabash-adapter</artifactId>
<version>6.2.1-SNAPSHOT</version>
<version>6.2.2-SNAPSHOT</version>
<packaging>bundle</packaging>

<name>DAISY Pipeline 2 :: Calabash adapter for the XProc API</name>
Expand Down
4 changes: 2 additions & 2 deletions framework/common-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<parent>
<groupId>org.daisy.pipeline</groupId>
<artifactId>framework-parent</artifactId>
<version>1.14.21-SNAPSHOT</version>
<version>1.14.22-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>

<artifactId>common-utils</artifactId>
<version>6.1.1-SNAPSHOT</version>
<version>6.2.1-SNAPSHOT</version>

<packaging>bundle</packaging>
<name>DAISY Pipeline 2 :: Common Utilities</name>
Expand Down
191 changes: 108 additions & 83 deletions framework/common-utils/src/main/java/org/daisy/common/file/URLs.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.attribute.BasicFileAttributes;
import java.nio.file.attribute.BasicFileAttributeView;
import static java.nio.file.Files.walkFileTree;
import java.nio.file.Files;
import java.nio.file.FileSystem;
import java.nio.file.FileSystemNotFoundException;
Expand Down Expand Up @@ -154,54 +153,74 @@ public static URL getResourceFromJAR(String resource, Class<?> context) {
if (OSGiHelper.inOSGiContext())
return OSGiHelper.getResourceFromJAR(resource, context);
else {
URL jarFileURL = context.getProtectionDomain().getCodeSource().getLocation();
if ("location:local".equals(jarFileURL.toString()) || jarFileURL.toString().startsWith("mvn:"))
throw new RuntimeException("expected file URI");
File jarFile = new File(asURI(jarFileURL));
File jarFile = getCurrentJAR(context);
logger.trace("Getting resource {} from JAR (current class: {}; JAR file: {})", resource, context, jarFile);
if (resource.startsWith("/"))
resource = resource.substring(1);
boolean requestedDirectory = resource.endsWith("/");
if (requestedDirectory)
resource = resource.substring(0, resource.length() - 1);
if (!jarFile.exists())
throw new RuntimeException("coding error");
else if (jarFile.isDirectory()) {
File f = new File(jarFile, resource);
if (!f.exists())
throw new RuntimeException("file does not exist");
else if (!f.isDirectory() && requestedDirectory)
throw new RuntimeException("is not a directory");
else
return asURL(f); }
Path p = getResourceFromJAR(resource, jarFile.toPath());
URL u = asURL(p.toUri());
if (isDirectory(p) && !u.toString().endsWith("/"))
u = asURL(u.toString() + "/");
try {
p.getFileSystem().close();
} catch (UnsupportedOperationException e) {
// default file system
} catch (IOException e) {
throw new RuntimeException(e);
}
return u;
}
}

public static File getCurrentJAR(Class<?> context) {
URL jarFileURL = context.getProtectionDomain().getCodeSource().getLocation();
if ("location:local".equals(jarFileURL.toString()) || jarFileURL.toString().startsWith("mvn:"))
throw new RuntimeException("expected file URI");
File jarFile = new File(URLs.asURI(jarFileURL));
if (!jarFile.exists())
throw new RuntimeException("coding error");
return jarFile;
}

/**
* Closing the file system of the returned path is the responsibility of the caller.
*/
public static Path getResourceFromJAR(String resource, Path jarFilePath) {
if (resource.startsWith("/"))
resource = resource.substring(1);
boolean requestedDirectory = resource.endsWith("/");
if (requestedDirectory)
resource = resource.substring(0, resource.length() - 1);
Path f = null; {
if (isDirectory(jarFilePath))
f = jarFilePath.resolve(resource);
else {
FileSystem fs; {
try {
fs = FileSystems.newFileSystem(asURI("jar:" + asURI(jarFileURL)), fsEnv); }
fs = FileSystems.newFileSystem(jarFilePath, (ClassLoader)null); }
catch (IOException e) {
throw new RuntimeException(e); }}
try {
Path f = fs.getPath("/" + resource);
boolean isDirectory = isDirectory(f);
if (!isDirectory && requestedDirectory)
throw new RuntimeException("is not a directory");
else
f = fs.getPath("/" + resource);
} finally {
if (f == null)
try {
return new URL("jar:" + jarFileURL + "!/" + resource + (isDirectory ? "/" : "")); }
catch (MalformedURLException e) {
throw new RuntimeException(e); }}
finally {
try {
fs.close(); }
catch (IOException e) {
throw new RuntimeException(e); }
fs.close(); }
catch (IOException e) {
throw new RuntimeException(e); }
}
}
}
if (!Files.exists(f))
throw new RuntimeException("file does not exist: " + resource);
else if (requestedDirectory && !isDirectory(f))
throw new RuntimeException("not a directory: " + resource);
else
return f;
}

/**
* @param resource The (not URL-encoded) path of a directory inside the specified JAR or class directory
* @param directory The (not URL-encoded) path of a directory inside the specified JAR or class directory
* @param context A class from the JAR or class directory that is to be searched for resources
* @return A list of resource paths (not URL-encoded)
*/
Expand All @@ -213,55 +232,61 @@ public static Iterator<String> listResourcesFromJAR(String directory, Class<?> c
if ("location:local".equals(jarFileURL.toString()) || jarFileURL.toString().startsWith("mvn:"))
throw new RuntimeException("expected file URI");
File jarFile = new File(asURI(jarFileURL));
if (directory.startsWith("/"))
directory = directory.substring(1);
if (directory.endsWith("/"))
directory = directory.substring(0, directory.length() - 1);
if (!jarFile.exists())
throw new RuntimeException("coding error");
else if (jarFile.isDirectory()) {
File d = new File(jarFile, directory);
if (!d.exists())
throw new RuntimeException("file does not exist");
else if (!d.isDirectory())
throw new RuntimeException("is not a directory");
else {
ImmutableList.Builder<String> resources = ImmutableList.<String>builder();
for (File f : d.listFiles())
resources.add(directory + "/" + f.getName() + (f.isDirectory() ? "/" : ""));
return resources.build().iterator(); }}
return listResourcesFromJAR(directory, jarFile.toPath());
}
}

/**
* @param directory The (not URL-encoded) path of a directory inside the specified JAR or class directory
* @param jarFilePath The location of the JAR file in a file system. Does not need to be be representable by a {@link File}.
* @return A list of resource paths (not URL-encoded)
*/
public static Iterator<String> listResourcesFromJAR(String directory, Path jarFilePath) {
if (directory.startsWith("/"))
directory = directory.substring(1);
if (directory.endsWith("/"))
directory = directory.substring(0, directory.length() - 1);
final String _directory = directory;
final ImmutableList.Builder<String> resources = ImmutableList.<String>builder();
Path d;
FileSystem fs = null;
try {
if (isDirectory(jarFilePath))
d = jarFilePath.resolve(directory);
else {
FileSystem fs; {
try {
fs = FileSystems.newFileSystem(asURI("jar:" + asURI(jarFileURL)), fsEnv); }
catch (IOException e) {
throw new RuntimeException(e); }}
try {
Path d = fs.getPath("/" + directory);
if (!isDirectory(d))
throw new RuntimeException("is not a directory");
final ImmutableList.Builder<String> resources = ImmutableList.<String>builder();
final String _directory = directory;
try {
walkFileTree(d, EnumSet.noneOf(FileVisitOption.class), 1, new SimpleFileVisitor<Path>() {
public FileVisitResult visitFile(Path f, BasicFileAttributes _) throws IOException {
String fileName = f.getFileName().toString();
if (!fileName.endsWith("/") && isDirectory(f))
fileName += "/";
resources.add(_directory + "/" + fileName);
return FileVisitResult.CONTINUE; }}); }
catch (NoSuchFileException e) {
throw new RuntimeException(e); }
catch (IOException e) {
throw new RuntimeException(e); }
return resources.build().iterator(); }
finally {
try {
fs.close(); }
catch (IOException e) {
throw new RuntimeException(e); }
}
fs = FileSystems.newFileSystem(jarFilePath, (ClassLoader)null); }
catch (IOException e) {
throw new RuntimeException(e); }
d = fs.getPath("/" + directory);
}
if (!Files.exists(d))
throw new RuntimeException("file does not exist: " + directory);
else if (!isDirectory(d))
throw new RuntimeException("not a directory: " + directory);
else {
try {
Files.walkFileTree(d, EnumSet.noneOf(FileVisitOption.class), 1, new SimpleFileVisitor<Path>() {
public FileVisitResult visitFile(Path f, BasicFileAttributes _) throws IOException {
String fileName = f.getFileName().toString();
if (!fileName.endsWith("/") && isDirectory(f))
fileName += "/";
resources.add(_directory + "/" + fileName);
return FileVisitResult.CONTINUE; }}); }
catch (NoSuchFileException e) {
throw new RuntimeException(e); }
catch (IOException e) {
throw new RuntimeException(e); }
return resources.build().iterator();
}
} finally {
if (fs != null)
try {
fs.close(); }
catch (IOException e) {
throw new RuntimeException(e); }
}
}

Expand All @@ -271,9 +296,9 @@ public FileVisitResult visitFile(Path f, BasicFileAttributes _) throws IOExcepti
private static boolean isDirectory(Path p) throws RuntimeException {
BasicFileAttributes a; {
try {
a = java.nio.file.Files.getFileAttributeView(p, BasicFileAttributeView.class).readAttributes(); }
a = Files.getFileAttributeView(p, BasicFileAttributeView.class).readAttributes(); }
catch (NoSuchFileException e) {
throw new RuntimeException("file does not exist"); }
throw new RuntimeException("file does not exist: " + p); }
catch (FileSystemNotFoundException e) {
throw new RuntimeException(e); }
catch (IOException e) {
Expand Down Expand Up @@ -303,12 +328,12 @@ static URL getResourceFromJAR(String resource, Class<?> context) {
if (resource.endsWith("/")) {
url = bundle.getEntry(resource.substring(0, resource.length() - 1));
if (url != null)
throw new RuntimeException("is not a directory"); }
throw new RuntimeException("not a directory: " + resource); }
else {
url = bundle.getEntry(resource + "/");
if (url != null)
return asURL(encode(url)); }
throw new RuntimeException("file does not exist"); }
throw new RuntimeException("file does not exist: " + resource); }
else {
url = asURL(encode(url));
if (!url.toString().endsWith("/")
Expand All @@ -329,9 +354,9 @@ static Iterator<String> listResourcesFromJAR(String directory, Class<?> context)
Enumeration<String> resources = bundle.getEntryPaths(directory);
if (resources == null) {
if (bundle.getEntry(directory.substring(0, directory.length() - 1)) != null)
throw new RuntimeException("is not a directory");
throw new RuntimeException("not a directory: " + directory);
else
throw new RuntimeException("file does not exist"); }
throw new RuntimeException("file does not exist: " + directory); }
else
return Iterators.forEnumeration(resources);
}
Expand Down
Loading

0 comments on commit e599cab

Please sign in to comment.