use of org.expath.pkg.repo.PackageException in project exist by eXist-db.
the class RemoveFunction method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
Sequence removed = BooleanValue.TRUE;
boolean force = false;
UserInteractionStrategy interact = new BatchUserInteraction();
String pkg = args[0].getStringValue();
try {
Optional<ExistRepository> repo = getContext().getRepository();
if (repo.isPresent()) {
Repository parent_repo = repo.get().getParentRepo();
parent_repo.removePackage(pkg, force, interact);
repo.get().reportAction(ExistRepository.Action.UNINSTALL, pkg);
context.getBroker().getBrokerPool().getXQueryPool().clear();
} else {
throw new XPathException("expath repository not available");
}
} catch (PackageException | XPathException pe) {
return BooleanValue.FALSE;
// /TODO: _repo.removePackage seems to throw PackageException
// throw new XPathException("Problem removing package " + pkg + " in expath repository, check that eXist-db has access permissions to expath repository file directory ", pe);
}
return removed;
}
use of org.expath.pkg.repo.PackageException in project exist by eXist-db.
the class AutoDeploymentTrigger method execute.
@Override
public void execute(final DBBroker sysBroker, final Txn transaction, final Map<String, List<? extends Object>> params) {
final boolean ignoreAutodeploySystemProperty = Optional.ofNullable(getFirstParamValue(params, IGNORE_AUTODEPLOY_SYSTEM_PROPERTY_PARAM, v -> Boolean.valueOf(v.toString()))).orElse(false);
if (!ignoreAutodeploySystemProperty) {
// do not execute if the system property exist.autodeploy=off
final String property = System.getProperty(AUTODEPLOY_PROPERTY, "on");
if (property.equalsIgnoreCase("off")) {
return;
}
}
Path autodeployDir = Optional.ofNullable(System.getProperty(AUTODEPLOY_DIRECTORY_PROPERTY)).map(Paths::get).orElse(null);
if (autodeployDir == null) {
final String dir = getFirstParamValue(params, AUTODEPLOY_DIRECTORY_PARAM, Object::toString);
if (dir != null) {
autodeployDir = Paths.get(dir);
} else {
final Optional<Path> homeDir = sysBroker.getConfiguration().getExistHome();
autodeployDir = FileUtils.resolve(homeDir, AUTODEPLOY_DIRECTORY);
}
}
if (!Files.isReadable(autodeployDir) && Files.isDirectory(autodeployDir)) {
LOG.warn("Unable to read autodeploy directory: {}", autodeployDir);
return;
}
try (Stream<Path> xarsStream = Files.find(autodeployDir, 1, (path, attrs) -> (!attrs.isDirectory()) && FileUtils.fileName(path).endsWith(".xar")).sorted(Comparator.comparing(Path::getFileName))) {
final List<Path> xars = xarsStream.collect(Collectors.toList());
LOG.info("Scanning autodeploy directory. Found {} app packages.", xars.size());
final Deployment deployment = new Deployment();
// build a map with uri -> file so we can resolve dependencies
final Map<String, Path> packages = new HashMap<>();
for (final Path xar : xars) {
try {
final Optional<String> name = deployment.getNameFromDescriptor(sysBroker, new XarFileSource(xar));
if (name.isPresent()) {
packages.put(name.get(), xar);
} else {
LOG.error("No descriptor name for: {}", xar.toAbsolutePath().toString());
}
} catch (final IOException | PackageException e) {
LOG.error("Caught exception while reading app package {}", xar.toAbsolutePath().toString(), e);
}
}
final PackageLoader loader = (name, version) -> {
// TODO: enforce version check
final Path p = packages.get(name);
if (p == null) {
return null;
}
return new XarFileSource(p);
};
for (final Path xar : xars) {
try {
deployment.installAndDeploy(sysBroker, transaction, new XarFileSource(xar), loader, false);
} catch (final PackageException | IOException e) {
LOG.error("Exception during deployment of app {}: {}", FileUtils.fileName(xar), e.getMessage(), e);
sysBroker.getBrokerPool().reportStatus("An error occurred during app deployment: " + e.getMessage());
}
}
} catch (final IOException ioe) {
LOG.error(ioe);
}
}
use of org.expath.pkg.repo.PackageException in project exist by eXist-db.
the class ExistPkgExtension method setupPackage.
// TODO: Must not be here (in the parsing class). See the comment at the
// end of parseDescriptor().
private void setupPackage(Package pkg, ExistPkgInfo info) throws PackageException {
// TODO: FIXME: Bad, BAD design! But will be resolved naturally by moving the
// install code within the storage class (because we are writing on disk)...
final FileSystemResolver res = (FileSystemResolver) pkg.getResolver();
final Path classpath = res.resolveResourceAsFile(".exist/classpath.txt");
// create [pkg_dir]/.exist/classpath.txt if not already
final Path exist = classpath.getParent();
if (!Files.exists(exist)) {
try {
Files.createDirectories(exist);
} catch (final IOException e) {
throw new PackageException("Impossible to create directory: " + exist);
}
}
final Set<String> jars = info.getJars();
try (final Writer out = Files.newBufferedWriter(classpath)) {
for (final String jar : jars) {
StreamSource jar_src;
try {
jar_src = res.resolveComponent(jar);
} catch (final NotExistException ex) {
final String msg = "Inconsistent package descriptor, the JAR file is not in the package: ";
throw new PackageException(msg + jar, ex);
}
final URI uri = URI.create(jar_src.getSystemId());
final Path file = Paths.get(uri);
out.write(file.normalize().toString());
out.write("\n");
}
} catch (final IOException ex) {
throw new PackageException("Error writing the eXist classpath file: " + classpath, ex);
}
}
use of org.expath.pkg.repo.PackageException in project exist by eXist-db.
the class ExistPkgExtension method handleXQuery.
private void handleXQuery(XMLStreamReader parser, Package pkg, ExistPkgInfo info) throws PackageException, XMLStreamException {
if (!myXSHelper.isNextElement(parser, "import-uri")) {
myXSHelper.ensureElement(parser, "namespace");
}
final String href = myXSHelper.getElementValue(parser);
myXSHelper.ensureNextElement(parser, "file");
final String file = myXSHelper.getElementValue(parser);
// position to </xquery>
parser.next();
try {
info.addXQuery(new URI(href), file);
} catch (final URISyntaxException ex) {
throw new PackageException("Invalid URI: " + href, ex);
}
}
use of org.expath.pkg.repo.PackageException in project exist by eXist-db.
the class ExistPkgExtension method handleJava.
private void handleJava(XMLStreamReader parser, ExistPkgInfo info) throws PackageException, XMLStreamException {
myXSHelper.ensureNextElement(parser, "namespace");
final String href = myXSHelper.getElementValue(parser);
myXSHelper.ensureNextElement(parser, "class");
final String clazz = myXSHelper.getElementValue(parser);
// position to </java>
parser.next();
try {
info.addJava(new URI(href), clazz);
} catch (final URISyntaxException ex) {
throw new PackageException("Invalid URI: " + href, ex);
}
}
Aggregations