Skip to content

Commit

Permalink
Use pluginapi v2 (#10)
Browse files Browse the repository at this point in the history
Also fix legacy configuration upgrade.
  • Loading branch information
nmiyake authored Mar 27, 2018
1 parent b2f71cc commit 3d2782c
Show file tree
Hide file tree
Showing 67 changed files with 3,623 additions and 1,414 deletions.
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions commoncmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package commoncmd

import (
"io/ioutil"
"os"

"github.com/pkg/errors"
"gopkg.in/yaml.v2"
Expand All @@ -15,6 +16,9 @@ import (

func LoadConfig(cfgFile string) (config.ProjectConfig, error) {
cfgYML, err := ioutil.ReadFile(cfgFile)
if os.IsNotExist(err) {
return config.ProjectConfig{}, nil
}
if err != nil {
return config.ProjectConfig{}, errors.Wrapf(err, "failed to read file %s", cfgFile)
}
Expand Down
11 changes: 6 additions & 5 deletions godelplugin/plugininfo.go → godelplugin/cmd/plugininfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// Use of this source code is governed by the Apache License, Version 2.0
// that can be found in the LICENSE file.

package main
package cmd

import (
"github.com/palantir/godel/framework/pluginapi"
"github.com/palantir/godel/framework/pluginapi/v2/pluginapi"
"github.com/palantir/godel/framework/verifyorder"
"github.com/palantir/pkg/cobracli"
)

var pluginInfo = pluginapi.MustNewPluginInfo(
var PluginInfo = pluginapi.MustNewPluginInfo(
"com.palantir.go-license",
"license-plugin",
cobracli.Version,
Expand All @@ -25,13 +25,14 @@ var pluginInfo = pluginapi.MustNewPluginInfo(
"license",
"Run license task",
pluginapi.TaskInfoCommand("run"),
pluginapi.TaskInfoVerifyOptions(pluginapi.NewVerifyOptions(
pluginapi.TaskInfoVerifyOptions(
pluginapi.VerifyOptionsOrdering(intVar(verifyorder.License)),
pluginapi.VerifyOptionsApplyFalseArgs("--verify"),
)),
),
),
pluginapi.PluginInfoUpgradeConfigTaskInfo(
pluginapi.UpgradeConfigTaskInfoCommand("upgrade-config"),
pluginapi.LegacyConfigFile("license.yml"),
),
)

Expand Down
5 changes: 2 additions & 3 deletions godelplugin/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
package cmd

import (
"path"

godelconfig "github.com/palantir/godel/framework/godel/config"
"github.com/palantir/godel/framework/godellauncher"
"github.com/palantir/pkg/matcher"
"github.com/spf13/cobra"
Expand All @@ -24,7 +23,7 @@ var (
return err
}
if godelConfigFileFlagVal != "" {
cfgVal, err := godellauncher.ReadGodelConfig(path.Dir(godelConfigFileFlagVal))
cfgVal, err := godelconfig.ReadGodelConfigFromFile(godelConfigFileFlagVal)
if err != nil {
return err
}
Expand Down
54 changes: 43 additions & 11 deletions godelplugin/integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,6 @@ package bar`,
}

func TestUpgradeConfig(t *testing.T) {
const (
godelYML = `exclude:
names:
- "\\..+"
- "vendor"
paths:
- "godel"
`
)

pluginPath, err := products.Bin("license-plugin")
require.NoError(t, err)
pluginProvider := pluginapitester.NewPluginProvider(pluginPath)
Expand All @@ -212,7 +202,49 @@ func TestUpgradeConfig(t *testing.T) {
nil,
[]pluginapitester.UpgradeConfigTestCase{
{
Name: "generate configuration is unmodified",
Name: "legacy config is unmodified",
ConfigFiles: map[string]string{
"godel/config/godel.yml": godelYML,
"godel/config/license-plugin.yml": `legacy-config: true
header: |
// Copyright 2016 Palantir Technologies, Inc.
//
// License content.
custom-headers:
# comment in YAML
- name: subproject
header: |
// Copyright 2016 Palantir Technologies, Inc. All rights reserved.
// Subproject license.
paths:
- subprojectDir
`,
},
WantOutput: "Upgraded configuration for license-plugin.yml\n",
WantFiles: map[string]string{
"godel/config/license-plugin.yml": `
header: |
// Copyright 2016 Palantir Technologies, Inc.
//
// License content.
custom-headers:
# comment in YAML
- name: subproject
header: |
// Copyright 2016 Palantir Technologies, Inc. All rights reserved.
// Subproject license.
paths:
- subprojectDir
`,
},
},
{
Name: "current config is unmodified",
ConfigFiles: map[string]string{
"godel/config/godel.yml": godelYML,
"godel/config/license-plugin.yml": `
Expand Down
4 changes: 2 additions & 2 deletions godelplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package main
import (
"os"

"github.com/palantir/godel/framework/pluginapi"
"github.com/palantir/godel/framework/pluginapi/v2/pluginapi"
"github.com/palantir/pkg/cobracli"

"github.com/palantir/go-license/godelplugin/cmd"
Expand All @@ -18,7 +18,7 @@ var (
)

func main() {
if ok := pluginapi.InfoCmd(os.Args, os.Stdout, pluginInfo); ok {
if ok := pluginapi.InfoCmd(os.Args, os.Stdout, cmd.PluginInfo); ok {
return
}
os.Exit(cobracli.ExecuteWithDefaultParamsWithVersion(cmd.RootCmd, &debugFlagVal, ""))
Expand Down
19 changes: 15 additions & 4 deletions golicense/config/internal/legacy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import (
"gopkg.in/yaml.v2"
)

type GoLicense struct {
type GoLicenseWithLegacy struct {
versionedconfig.ConfigWithLegacy `yaml:",inline"`
GoLicense `yaml:",inline"`
}

type GoLicense struct {
// Header is the expected license header. All applicable files are expected to start with this header followed
// by a newline.
Header string `yaml:"header"`
Expand Down Expand Up @@ -42,10 +45,18 @@ type License struct {
}

func UpgradeConfig(cfgBytes []byte) ([]byte, error) {
var legacyCfg GoLicense
var legacyCfg GoLicenseWithLegacy
if err := yaml.UnmarshalStrict(cfgBytes, &legacyCfg); err != nil {
return nil, errors.Wrapf(err, "failed to unmarshal license-plugin legacy configuration")
}
// legacy configuration is completely compatible with v0 configuration
return cfgBytes, nil
// optimization: if input bytes start with the legacy configuration key, trim it to get a valid v0 configuration
if trimmed, ok := versionedconfig.TrimLegacyPrefix(cfgBytes); ok {
return trimmed, nil
}
// otherwise, marshal just the GoLicense portion of the configuration, which is fully compatible with v0
upgradedBytes, err := yaml.Marshal(legacyCfg.GoLicense)
if err != nil {
return nil, errors.Wrapf(err, "failed to marshal dist-sls-asset legacy configuration")
}
return upgradedBytes, nil
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3d2782c

Please sign in to comment.