Skip to content

Commit

Permalink
minor edits
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
  • Loading branch information
bentsherman committed Dec 12, 2024
1 parent bed76b5 commit 8411295
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import org.pf4j.update.UpdateRepository
import org.pf4j.update.verifier.CompoundVerifier

import java.nio.file.Path
import java.nio.file.Paths

/**
* Implementation of UpdateRepository which looks in a local directory of already-downloaded
* plugins to find available versions.
*/
@CompileStatic
@Slf4j
class LocalUpdateRepository implements UpdateRepository{
class LocalUpdateRepository implements UpdateRepository {
private final String id
private final Path dir
private Map<String, PluginInfo> plugins
Expand Down Expand Up @@ -60,7 +59,7 @@ class LocalUpdateRepository implements UpdateRepository{
@Override
FileDownloader getFileDownloader() {
// plugins in this repo are already downloaded, so treat any download url as a file path
return (URL url) -> Paths.get(url.toURI())
return (URL url) -> Path.of(url.toURI())
}

@Override
Expand All @@ -72,18 +71,19 @@ class LocalUpdateRepository implements UpdateRepository{
// each plugin is stored in a dir called $id-$version; grab the descriptor from each
final manifestReader = new ManifestPluginDescriptorFinder()
final descriptors = FilesEx.listFiles(dir)
.collect( plugin -> new LocalPlugin(plugin, manifestReader.find(plugin)) )
.collect { plugin -> new LocalPlugin(plugin, manifestReader.find(plugin)) }

// now group the descriptors by id, to create a PluginInfo with list of versions
return descriptors.groupBy { d -> d.getPluginId() }
.collectEntries { id, versions -> [id, toPluginInfo(id, versions)] }
return descriptors
.groupBy { d -> d.getPluginId() }
.collectEntries { id, versions -> List.of(id, toPluginInfo(id, versions)) }
}

private static PluginInfo toPluginInfo(String id, List<LocalPlugin> versions) {
def info = new PluginInfo()
final info = new PluginInfo()
info.id = id
info.releases = versions.collect { v ->
def release = new PluginInfo.PluginRelease()
final release = new PluginInfo.PluginRelease()
release.version = v.version
release.requires = v.requires
release.url = v.path.toUri().toURL()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package nextflow.plugin

import org.pf4j.InvalidPluginDescriptorException

import static java.nio.file.StandardCopyOption.*

import java.nio.file.Files
Expand All @@ -38,6 +36,7 @@ import nextflow.SysEnv
import nextflow.extension.FilesEx
import nextflow.file.FileHelper
import nextflow.file.FileMutex
import org.pf4j.InvalidPluginDescriptorException
import org.pf4j.PluginDependency
import org.pf4j.PluginRuntimeException
import org.pf4j.PluginState
Expand Down Expand Up @@ -207,7 +206,7 @@ class PluginUpdater extends UpdateManager {
}

private Path download0(String id, String version) {
// 0. check version is specified
// 0. check if version is specified
if( !version )
throw new InvalidPluginDescriptorException("Missing version for plugin $id")
log.info "Downloading plugin ${id}@${version}"
Expand Down Expand Up @@ -422,7 +421,7 @@ class PluginUpdater extends UpdateManager {
return false
}
if( offline ) {
log.debug("Update not supported in offline mode")
log.debug "Update not supported in offline mode"
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class PluginsFacade implements PluginStateListener {

private String mode
private Path root
private boolean offline
private PluginUpdater updater
private CustomPluginManager manager
private DefaultPlugins defaultPlugins = DefaultPlugins.INSTANCE
private String indexUrl = Plugins.DEFAULT_PLUGINS_REPO
private boolean embedded
private boolean offline

PluginsFacade() {
mode = getPluginsMode()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package nextflow.plugin

import com.github.zafarkhaja.semver.Version
import org.pf4j.PluginRuntimeException

import java.nio.file.FileVisitResult
import java.nio.file.Files
import java.nio.file.Path
Expand All @@ -12,18 +9,20 @@ import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream

import nextflow.BuildInfo
import com.github.zafarkhaja.semver.Version
import org.pf4j.Plugin
import org.pf4j.PluginDescriptor
import org.pf4j.PluginRuntimeException
import org.pf4j.PluginWrapper
import org.pf4j.update.PluginInfo
import spock.lang.Specification
import spock.lang.Unroll

/**
*
* @author Paolo Di Tommaso <paolo.ditommaso@gmail.com>
*/
class PluginUpdaterTest extends Specification {

private static final String PLUGIN_ID = 'my-plugin'

static class FooPlugin extends Plugin {
Expand Down

0 comments on commit 8411295

Please sign in to comment.