Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #12240: Add top-level make file target to generate licensed plugins #23

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 27 additions & 5 deletions Makefile
Expand Up @@ -2,15 +2,37 @@
# Copyright 2017 Normation SAS
#####################################################################################

.DEFAULT_GOAL := all
.DEFAULT_GOAL := unlicensed

PLUGINS = helloworld centreon datasources node-external-reports
# plugins-common version is defined in build.conf.
# It can be build if not published.
COMMONS_VERSION =

# all
all: $(PLUGINS)
PUB_LIBS = plugins-common
PRIV_LIBS = plugins-common-private
LIBS= $(PUB_LIBS) $(PRIV_LIBS)

PLUGINS = helloworld datasources node-external-reports
PLUGINS-LICENSED = $(addsuffix -licensed,$(PLUGINS))
ALL = $(LIBS) $(PLUGINS)

# all
all: unlicensed

unlicensed: $(PUB_LIBS) $(PLUGINS)

licensed: $(LIBS) $(PLUGINS-LICENSED)

$(LIBS):%:
cd $@ && make

$(PLUGINS):%:
cd $@ && make

$(PLUGINS-LICENSED):%-licensed:
cd $* && make licensed

clean:
for i in $(ALL); do cd $$i; $(MAKE) clean; cd ..; done

.PHONY: $(PLUGINS)
.PHONY: $(LIBS) $(PLUGINS)
Expand Up @@ -49,8 +49,9 @@ import com.normation.plugins.LicensedPluginCheck

final class CheckRudderPluginEnableImpl() extends LicensedPluginCheck {
// here are processed variables
lazy val CLASSPATH_KEYFILE = "${plugin-resource-publickey}"
lazy val FS_SIGNED_LICENSE = "${plugin-resource-license}"
lazy val VERSION = "${plugin-declared-version}"
}
def pluginClasspathPubkey = "${plugin-resource-publickey}"
def pluginLicensePath = "${plugin-resource-license}"
def pluginDeclaredVersion = "${plugin-declared-version}"
def pluginId = "${plugin-name}"
}

@@ -1,6 +1,6 @@
/*
*************************************************************************************
* Copyright 2017 Normation SAS
* Copyright 2018 Normation SAS
*************************************************************************************
*
* This file is part of Rudder.
Expand Down Expand Up @@ -49,8 +49,8 @@ import com.normation.plugins.LicensedPluginCheck

final class CheckRudderPluginEnableImpl() extends LicensedPluginCheck {
// here are processed variables
lazy val CLASSPATH_KEYFILE = "${plugin-resource-publickey}"
lazy val FS_SIGNED_LICENSE = "${plugin-resource-license}"
lazy val VERSION = "${plugin-declared-version}"
def pluginClasspathPubkey = "${plugin-resource-publickey}"
def pluginLicensePath = "${plugin-resource-license}"
def pluginDeclaredVersion = "${plugin-declared-version}"
def pluginId = "${plugin-name}"
}

2 changes: 2 additions & 0 deletions helloworld/Makefile
Expand Up @@ -16,6 +16,8 @@
# Add another archive to the plugin (files.txz is the first one)
#OTHER_ARCHIVES = target/other.txz

SCRIPTS = postinst

# Use this one for a Scala plugin
include ../makefiles/common-scala-plugin.mk

Expand Down
31 changes: 31 additions & 0 deletions makefiles/make-plugins-common.mk
@@ -0,0 +1,31 @@
# Make directive to build the two plugins-common and
# plugins-common-private library.

# Files to add to the plugin content (from the target directory)
# By default this is a directory containing the plugin jar
FILES += $(NAME)

include ../makefiles/common.mk

# maven local repo

MAVEN_OPTS = --batch-mode -U

MAVEN_LOCAL_REPO = $(shell mvn help:effective-settings | grep localRepository | sed -e "s/.*>\(.*\)<.*/\1/")
PLUGINS_JAR_PATH = $(MAVEN_LOCAL_REPO)/com/normation/plugins/$(NAME)/$(VERSION)/$(NAME)-$(VERSION).jar

.DEFAULT_GOAL := $(PLUGINS_JAR_PATH)

# maven is such a pain that "mvn install" can't be used with parametrized version (it
# uses the literal '${plugin-version}' string in path). So we are doing installation by
# hand. Yep, most beautiful tool.
$(PLUGINS_JAR_PATH):
mvn clean package && mvn install:install-file -Dfile=target/$(NAME)-$(VERSION).jar \
-DpomFile=pom.xml \
-DgroupId=com.normation.plugins \
-DartifactId=$(NAME) \
-Dversion=$(VERSION) \
-Dpackaging=jar \
-DcreateChecksum=true


10 changes: 5 additions & 5 deletions node-external-reports/Makefile
Expand Up @@ -6,15 +6,15 @@
# You can provide your own configuration file by setting env var
# CONFIG_FILE_PATH with the path toward it.

CONFIG_FILE_PATH = src/main/resources/node-external-reports.properties
CONFIG_FILE_NAME = node-external-reports.properties
CONFIG_FILE_PATH = src/main/resources/$(CONFIG_FILE_NAME)

FILES = $(NAME)/node-external-reports.properties
FILES = $(NAME)/$(CONFIG_FILE_NAME)

SCRIPTS = postinst

include ../makefiles/common-scala-plugin.mk

target/$(NAME)/$(CONFIG_FILE_PATH):
cp $(CONFIG_FILE_PATH) target/$(NAME)/node-external-reports.properties

target/$(NAME)/$(CONFIG_FILE_NAME):
cp $(CONFIG_FILE_PATH) target/$(NAME)/$(CONFIG_FILE_NAME)

@@ -1,6 +1,6 @@
/*
*************************************************************************************
* Copyright 2017 Normation SAS
* Copyright 2018 Normation SAS
*************************************************************************************
*
* This file is part of Rudder.
Expand Down Expand Up @@ -49,8 +49,9 @@ import com.normation.plugins.LicensedPluginCheck

final class CheckRudderPluginEnableImpl() extends LicensedPluginCheck {
// here are processed variables
lazy val CLASSPATH_KEYFILE = "${plugin-resource-publickey}"
lazy val FS_SIGNED_LICENSE = "${plugin-resource-license}"
lazy val VERSION = "${plugin-declared-version}"
def pluginClasspathPubkey = "${plugin-resource-publickey}"
def pluginLicensePath = "${plugin-resource-license}"
def pluginDeclaredVersion = "${plugin-declared-version}"
def pluginId = "${plugin-name}"
}

7 changes: 7 additions & 0 deletions plugins-common-private/Makefile
@@ -0,0 +1,7 @@
#
# make all : will install jar in local repository if version not present yet
#

include ../makefiles/make-plugins-common.mk


24 changes: 24 additions & 0 deletions plugins-common-private/build.conf
@@ -0,0 +1,24 @@
#
# This file defines the release information about the plugin like
# its version and its ABI compability.
#
# So version are not managed in pom.xml (safe for parent-pom version,
# which can't be a parameter, and must be equals to rudder-branch here)
#

# This version is a little bit different, as it it not for a plugin,
# but we keep the same content for convention and simpler builds.

# Unique identifier of the plugin
plugin-name=plugins-common-private

# Plugin version. It is build as follow: A.B-x.y(.z) with:
# - A.B: Rudder major.minor
# - x.y(.z): plugin major.minor.micro. Micro should be omitted. When omitted, z is assumed to be 0.
# For the build, we split the information between two properties, rudder branch and plugin version,
# which must be concaneted with "-" to build the plugin version.
plugin-branch=1.0

# rudder branch comes from parent
plugin-version=${rudder-branch}-${plugin-branch}

11 changes: 10 additions & 1 deletion plugins-common-private/pom.xml
Expand Up @@ -6,7 +6,7 @@
<!--
Do not change version here, update content into: build.conf
-->
<version>4.1-1.0</version>
<version>${plugin-version}</version>

<parent>
<groupId>com.normation.plugins</groupId>
Expand All @@ -21,6 +21,15 @@
private repository to be build, and manage licensing information.
</description>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.normation</groupId>
Expand Down
Expand Up @@ -61,38 +61,19 @@ trait LicensedPluginCheck extends CheckRudderPluginEnable {
* implementation must define variable with the following maven properties
* that will be replaced at build time:
*/
// val CLASSPATH_KEYFILE = "${plugin-resource-publickey}"
// val FS_SIGNED_LICENSE = "${plugin-resource-license}"
// val VERSION = "${plugin-declared-version}"
// val pluginClasspathPubkey = "${plugin-resource-publickey}"
// val pluginLicensePath = "${plugin-resource-license}"
// val pluginDeclaredVersion = "${plugin-declared-version}"
// val pluginId = "${plugin-name}"

def CLASSPATH_KEYFILE: String
def FS_SIGNED_LICENSE: String
def VERSION : String
def pluginClasspathPubkey: String
def pluginLicensePath : String
def pluginDeclaredVersion: String
def pluginId : String

lazy val maybeLicense = LicenseReader.readLicense(FS_SIGNED_LICENSE)
lazy val maybeInfo = LicenseReader.readAndCheckLicense(pluginLicensePath, pluginClasspathPubkey, pluginDeclaredVersion, pluginId)
lazy val hasLicense = true

// for now, we only read license info at load, because it's time consuming
lazy val maybeInfo = (
for {
unchecked <- maybeLicense
publicKey <- {
val key = this.getClass.getClassLoader.getResourceAsStream(CLASSPATH_KEYFILE)
if(key == null) {
Left(LicenseError.IO(s"The resources '${CLASSPATH_KEYFILE}' was not found"))
} else {
RSAKeyManagement.readPKCS8PublicKey(new InputStreamReader(key), None) //don't give to much info about path
}
}
checked <- LicenseChecker.checkSignature(unchecked, publicKey)
version <- Version.from(VERSION) match {
case None => Left(LicenseError.Parsing(s"Version is not valid: '${VERSION}'."))
case Some(v) => Right(v)
}
} yield {
(checked, version)
}
)

// log
maybeInfo.fold( error => PluginLogger.error(error) , ok => PluginLogger.warn("License signature is valid.") )
Expand All @@ -104,7 +85,7 @@ trait LicensedPluginCheck extends CheckRudderPluginEnable {
(for {
info <- maybeInfo
(license, version) = info
check <- LicenseChecker.checkLicense(license, DateTime.now, version)
check <- LicenseChecker.checkLicense(license, DateTime.now, version, pluginId)
} yield {
check
}) match {
Expand All @@ -113,9 +94,9 @@ trait LicensedPluginCheck extends CheckRudderPluginEnable {
}
}

def licenseInformation: Option[PluginLicenseInfo] = maybeLicense match {
case Left(_) => None
case Right(l) => Some(PluginLicenseInfo(
def licenseInformation: Option[PluginLicenseInfo] = maybeInfo match {
case Left(_) => None
case Right((l, v)) => Some(PluginLicenseInfo(
licensee = l.content.licensee.value
, softwareId = l.content.softwareId.value
, minVersion = l.content.minVersion.value.toString
Expand Down
7 changes: 7 additions & 0 deletions plugins-common/Makefile
@@ -0,0 +1,7 @@
#
# make all : will install jar in local repository if version not present yet
#

include ../makefiles/make-plugins-common.mk


24 changes: 24 additions & 0 deletions plugins-common/build.conf
@@ -0,0 +1,24 @@
#
# This file defines the release information about the plugin like
# its version and its ABI compability.
#
# So version are not managed in pom.xml (safe for parent-pom version,
# which can't be a parameter, and must be equals to rudder-branch here)
#

# This version is a little bit different, as it it not for a plugin,
# but we keep the same content for convention and simpler builds.

# Unique identifier of the plugin
plugin-name=plugins-common

# Plugin version. It is build as follow: A.B-x.y(.z) with:
# - A.B: Rudder major.minor
# - x.y(.z): plugin major.minor.micro. Micro should be omitted. When omitted, z is assumed to be 0.
# For the build, we split the information between two properties, rudder branch and plugin version,
# which must be concaneted with "-" to build the plugin version.
plugin-branch=1.0

# rudder branch comes from parent
plugin-version=${rudder-branch}-${plugin-branch}

11 changes: 10 additions & 1 deletion plugins-common/pom.xml
Expand Up @@ -6,7 +6,7 @@
<!--
Do not change version here, update content into: build.conf
-->
<version>4.1-1.0</version>
<version>${plugin-version}</version>

<parent>
<groupId>com.normation.plugins</groupId>
Expand All @@ -20,6 +20,15 @@
any API breaking
</description>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<dependencies>

<!-- Test: rudder -->
Expand Down