Skip to content

Commit

Permalink
Merge branch 'release/1.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
djha-skin committed Jul 6, 2017
2 parents c0108f0 + c7dc393 commit 1bf1341
Show file tree
Hide file tree
Showing 13 changed files with 401 additions and 174 deletions.
21 changes: 0 additions & 21 deletions CHANGELOG.md

This file was deleted.

1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- [ ] Add ``--remove-from``
- [ ] Options imply other options, but these can be turned off
- [ ] Make display-config work with ALL cmdline options.
- [ ] Disable alternatives option
- [ ] Add docs URL to help page.
Expand Down
177 changes: 141 additions & 36 deletions artifactory-plugin/degasolv.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,163 @@
// If your plugin requires any external dependencies, you can place them under
// the ${ARTIFACTORY_HOME}/etc/plugins/lib directory.
// -- https://www.jfrog.com/confluence/display/RTF/User+Plugins
// So, you need to put these there:
// https://mvnrepository.com/artifact/us.bpsm/edn-java/0.5.0
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3/3.6
// https://mvnrepository.com/artifact/org.codehaus.plexus/plexus-utils/3.0.24
// https://mvnrepository.com/artifact/org.apache.maven/maven-artifact/3.5.0
import us.bpsm.edn.parser.Parseable
import us.bpsm.edn.parser.Parser
import us.bpsm.edn.parser.Parsers
import us.bpsm.edn.TaggedValue
import static us.bpsm.edn.Keyword.newKeyword
import static us.bpsm.edn.parser.Parsers.defaultConfiguration;
// So, you simply need to put the degasolv jar file there.
// This is why we call clojure from groovy: so that the user's only
// dependency is the degasolv jar itself.

import java.util.Map
import java.util.List
import java.util.HashMap
import java.util.ArrayList
import java.io.ByteArrayInputStream

import groovy.io.FileType
import us.bpsm.edn.printer.Printers

def recalculateIndex(dir) {
import clojure.java.api.Clojure
import clojure.lang.IFn
import degasolv.resolver.PackageInfo

IFn require = Clojure.var("clojure.core", "require")
require.invoke(Clojure.read("miner.tagged"))
require.invoke(Clojure.read("serovers.core"))
require.invoke(Clojure.read("degasolv.resolver"))
require.invoke(Clojure.read("degasolv.util"))

readString = Clojure.var("miner.tagged", "read-string")
verCmp = Clojure.var("serovers.core", "maven-vercmp")
prStr = Clojure.var("clojure.core", "pr-str")

sortBy = { a, b ->
versKeyword = Clojure.read(":version")
return -(verCmp.invoke(a.get(versKeyword), b.get(versKeyword)))
}

List<RepoPath> getDirs(RepoPath dir) {
return repositories.getChildren(dir)
.findAll { finfo ->
finfo.isFolder()
}
.collect { finfo ->
finfo.getRepoPath()
}
}

List<RepoPath> getFiles(RepoPath dir) {
return repositories.getChildren(dir)
.findAll { finfo ->
!finfo.isFolder()
}
.collect { finfo ->
finfo.getRepoPath()
}
}

//String getContent(file) {
// return file.getText("UTF-8")
//}

String getContent(RepoPath p) {
return p.getContent()
.getInputStream()
.getText("UTF-8")
}

Map<String, List<PackageInfo>> mergeRepoInfo(
Map<String, List<PackageInfo>> a,
Map<String, List<PackageInfo>> b) {
b.each{ k, v ->
if (!a.containsKey(k)) {
a.put(k, new ArrayList<PackageInfo>())
}
lst = a.get(k)
lst.add(v)
}
return a
}

def gatherRepoInfo(RepoPath dir) {

Map<String, List<TaggedValue>> repoInfo =
new HashMap<String, List<TaggedValue>>();
Map<String, List<PackageInfo>> repoInfo =
new HashMap<String, List<PackageInfo>>()

findDSCards = ~/\.dscard$/
idKeyword = newKeyword("id")

Parser p = Parsers.newParser(defaultConfiguration())
baseDir = new File(dir);
baseDir.eachFileRecurse (FileType.FILES) { file ->
getFiles(dir).each { file ->
m = (file =~ findDSCards)
if (m.find()) {
String cardContents = file.getText('UTF-8')
println cardContents
Parseable pbr = Parsers.newParseable(cardContents)
t = p.nextValue(pbr)
Map<?, ?> m = t.getValue()
String id = m.get(idKeyword)
if (!repoInfo.containsKey(id)) {
repoInfo.put(id, new ArrayList<TaggedValue>())
String cardContents = getContents(file)
cardData = readString.invoke(cardContents)
cardID = cardData.get(Clojure.read(":id"))
cardVersion = cardData.get(Clojure.read(":version"))
cardLocation = cardData.get(Clojure.read(":location"))

if (!repoInfo.containsKey(cardID)) {
repoInfo.put(cardID, new ArrayList<PackageInfo>())
}
lst = repoInfo.get(id)
lst.add(t)
lst = repoInfo.get(cardID)
lst.add(cardData)

// maybe?
repositories.setProperty(file, "degasolv.id", cardID)
repositories.setProperty(file, "degasolv.version", cardVersion)
repositories.setProperty(file, "degasolv.location", cardLocation)
}
}
getDirs(dir).each { cdir ->
gatherRepoInfo(cdir).each { subRepoInfo ->
repoInfo = mergeRepoInfo(repoInfo, subRepoInfo)
}
}
// for each here that sorts each list using magics
return repoInfo
}

def recalculateIndex(RepoPath dir) {
logger.info("Recalculating degasolv index `" + dir + "`.")

indexFile = new File('index.dsrepo')
indexFile.withWriter('UTF-8') { writer ->
writer.write(Printers.printString(
Printers.defaultPrinterProtocol(),
repoInfo))
logger.info("Gathering repository info...")
repoInfo = gatherRepoInfo(dir)

logger.info("Done. Sorting repository info...")
repoInfo.each{ k, v ->
v.sort(sortBy)
}

logger.info("Done. Writing out ``index.dsrepo``...")
indexPathStr = dir.toPath()
indexPathStr += (path[-1] == "/" ? "" : "/")
indexPathStr += "index.dsrepo"

indexAsStr = prStr.invoke(repoInfo)
indexStream = new ByteArrayInputStream(indexAsStr.getBytes("UTF-8"))

indexPath = RepoPathFactory.create(indexPathStr)
repositories.deploy(indexPath, indexStream)
logger.info("Done recalculating degasolv index")
}

recalculateIndex("./")

name = "degasolv"
version = "1.6.0"
description = "Degasolv artifactory plugin for recalculating the ``index.dsrepo`` file."

executions {
degasolvReindex (version:version, description:description, httpMethod: 'GET', users:[], groups:[], params:[:]) { params ->
if (! params.get("repo"))
{
logger.warning("The ``repo`` key was not given in ``params`` query value, refusing to recalculate an unspecified degasolv repository.")
}
else
{
repoLoc = params.get("repo")
repoPath = RepoPathFactory.create(repoLoc)
if (! repoPath)
{
logger.warning("The ``repo`` key was not valid in the ``params`` query value, refusing to recalculate an unspecified degasolv repository.")
}
else
{
recalculateIndex(repoPath)
}
}
}
}
2 changes: 1 addition & 1 deletion artifactory-plugin/run
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

groovy -cp commons-lang3-3.6.jar:edn-java-0.5.0.jar:maven-artifact-3.5.0.jar:plexus-utils-3.0.24.jar:edn-java-0.5.0.jar degasolv.groovy
groovy -cp degasolv-1.5.2-SNAPSHOT-standalone.jar degasolv.groovy
1 change: 1 addition & 0 deletions changelog.rst
45 changes: 45 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Changelog
=========

All notable changes to this project will be documented in this file.

The format is based on `Keep a Changelog`_
and this project adheres to `Semantic Versioning`_.

.. _Semantic Versioning: http://semver.org/spec/v2.0.0.html
.. _Keep a Changelog: http://keepachangelog.com/en/1.0.0/

`Unreleased`_
-------------

`1.7.0`_
--------

Added
+++++
- Added ``--option-pack``, the ability to specify multiple options

Fixed
+++++
- Fixed how default options work, they no longer override stuff
found in the config file (ouch)
- Fixed output of printed warning when configuration file is not used

`1.6.0`_
--------

Added
+++++
- Formatted docs better on the front page for PDF purposes
- Add ability to use any (long) option on the command line in display-config

Improved
++++++++
- Memoized core Degasolv package system repository function (should
speed the resolver up a bit)
- Changed apt reop function from filtering a list to lookup in a map,
increasing its speed

.. _Unreleased: https://github.com/djhaskin987/degasolv/compare/1.7.0...HEAD
.. _1.7.0: https://github.com/djhaskin987/degasolv/compare/1.6.0...1.7.0
.. _1.6.0: https://github.com/djhaskin987/degasolv/compare/1.5.1...1.6.0
56 changes: 38 additions & 18 deletions docs/command-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ a page that looks something like this::
descriptions. Options marked with `**` may be
used more than once.

-c, --config-file FILE ./degasolv.edn config file
-c, --config-file FILE ./degasolv.edn Config file location **
-k, --option-pack PACK Specify option pack **
-h, --help Print this help page

Commands are:
Expand Down Expand Up @@ -54,17 +55,14 @@ Explanation of options:
--config-file "$PWD/config.edn" \
generate-repo-index [...]

A few notable exceptions to this rule is the ``--repository`` and
``--present-package`` options of the ``resolve-locations`` and ``query-repo``
commands, and the ``--requirement`` option of the ``generate-card`` and
``resolve-locations`` commands. This is because these options can be
specified multiple times, and so their configuration file key equivalents are
named ``:repositories``, ``:present-packages`` and ``:requirements``
respectively, and they show up in the configuration file as a list of
strings. Finally, the ``--enable-alternatives`` and
``--disable-alternatives`` options of the ``resolve-locations`` command map a
boolean value to the ``alternatives`` config file key. So, instead of using
this command::
Notable exceptions to this rule include options which may be
specified multiple times. These options are named using singular
nouns (e.g. ``--repository REPO``), but their corresponding
configuration file keys are specified using plural nouns (e.g.,
``:repositories ["REPO1",...]``).

So, instead of using this
command::

java -jar degasolv-<version>-standalone.jar \
resolve-locations \
Expand Down Expand Up @@ -103,7 +101,7 @@ Explanation of options:
URL.

As of version 1.2.0, the ``--config-file`` option may be specified multiple
times. Each config file specified will get its configuration
times. Each configuration file specified will get its configuration
merged into the previously specified configuration files. If both
configuration files contain the same option, the option specified in
the latter specified configuration file will be used.
Expand Down Expand Up @@ -165,6 +163,27 @@ Explanation of options:
--config-file "./degasolv.edn" \
generate-card

.. _option pack:

- ``-k PACK``, ``--option-pack PACK``, ``:option-packs ["PACK1",...]``: Specify
one or more option packs.

Degasolv ships with several "option packs", each of which imply several degasolv
options at once. When an
option pack is specified, degasolv looks up which option pack is used and what
options are implied by using it. More than one option pack may be specified.
If option packs are specified both on the command line and in the config file,
the option packs on the command line are used and the ones in the config file
are ignored.

The following option packs are supported in the current version:
- ``multi-version-mode``: Added as of version 1.7.0 . Implies
``--conflict-strat inclusive``,
``--resolve-strat fast``, and ``--disable-alternatives``.
- ``firstfound-version-mode``: Added as of version 1.7.0 . Implies
``--conflic-strat prioritized``,
``--resolve-strat fast``, and ``--disable-alternatives``.

- ``-h``, ``--help``: Prints the help page. This can be used on every
sub-command as well.

Expand Down Expand Up @@ -468,7 +487,8 @@ Explanation of options:
of each package are allowed to be part of the solution. To call for
similar behavior to ruby's gem or node's npm, for example, set
``--conflict-strat`` to ``inclusive`` and set ``--resolve-strat``
to ``fast``.
to ``fast``. This can be easily and cleanly specified done by using the
``multi-version-mode`` `option pack`_.

- If set to ``prioritized``, then the first time a package is required and
is found at a particular version, it will be considered to fulfill the
Expand All @@ -485,8 +505,10 @@ Explanation of options:
``1`` and that version was assumed to fulfill all requirements asking
for package ``b``.

To mimic the behavior of maven, set ``--conflict-strat`` to ``prioritized``
and ``--resolve-strat`` to ``fast``.
To mimic the behavior of maven, set ``--conflict-strat`` to
``prioritized`` and ``--resolve-strat`` to ``fast``. This can be
easily and cleanly specified done by using the
``firstfound-version-mode`` `option pack`_.

.. _present package:

Expand Down Expand Up @@ -835,8 +857,6 @@ interpretations.
| | the absence of the ``pine`` package. |
+-------------------------+---------------------------------------------------+


.. _maven: https://maven.apache.org/


.. _managed dependency: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Management
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
# built documents.
#
# The short X.Y version.
version = '1.6'
version = '1.7'
# The full version, including alpha/beta/rc tags.
release = '1.6.0'
release = '1.7.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
Loading

0 comments on commit 1bf1341

Please sign in to comment.