changes) {
61 | boolean answer = false;
62 | for (DependencyVersionChange change : changes) {
63 | if (applyChange(change)) {
64 | answer = true;
65 | }
66 | }
67 | return answer;
68 | }
69 |
70 | public boolean applyChange(DependencyVersionChange change) {
71 | String name = change.getDependency();
72 | String version = change.getVersion();
73 | boolean answer = false;
74 | if (dependencies != null) {
75 | for (ChartDependency dependency : dependencies) {
76 | if (Objects.equals(name, dependency.getName())) {
77 | String oldVersion = dependency.getVersion();
78 | if (oldVersion == null || !Objects.equals(oldVersion, version)) {
79 | dependency.setVersion(version);
80 | answer = true;
81 | }
82 | }
83 | }
84 | }
85 | return answer;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/kind/maven/ElementProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.kind.maven;
17 |
18 | import de.pdark.decentxml.Element;
19 |
20 | /**
21 | * Allows processing on a per dependency or plugin basis to add default configuration
22 | */
23 | public interface ElementProcessor {
24 | void process(Element element, String separator);
25 | }
26 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/kind/maven/ElementProcessors.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.kind.maven;
17 |
18 | import de.pdark.decentxml.Element;
19 |
20 | import static io.jenkins.updatebot.support.DecentXmlHelper.addChildElement;
21 | import static io.jenkins.updatebot.support.DecentXmlHelper.addText;
22 | import static io.jenkins.updatebot.support.DecentXmlHelper.createChild;
23 |
24 | /**
25 | */
26 | public class ElementProcessors {
27 | public static ElementProcessor createFabric8MavenPluginElementProcessor() {
28 | return new ElementProcessor() {
29 | @Override
30 | public String toString() {
31 | return "Fabric8MavenPluginElementProcessor";
32 | }
33 |
34 | @Override
35 | public void process(Element element, String separator) {
36 | addFabric8MavenPluginConfig(element, separator);
37 | }
38 | };
39 | }
40 |
41 | protected static void addFabric8MavenPluginConfig(Element plugin, String separator) {
42 | Element executions = createChild(plugin, "executions", separator);
43 | separator += " ";
44 | Element execution = createChild(executions, "execution", separator);
45 | separator += " ";
46 | Element goals = createChild(execution, "goals", separator);
47 | String closeSep = separator;
48 | separator += " ";
49 | addText(goals, separator);
50 | addChildElement(goals, "goal", "resource");
51 | addText(goals, separator);
52 | addChildElement(goals, "goal", "build");
53 | addText(goals, closeSep);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/kind/maven/MavenDependencyVersionChange.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.kind.maven;
17 |
18 | import io.jenkins.updatebot.kind.Kind;
19 | import io.jenkins.updatebot.model.DependencyVersionChange;
20 |
21 | /**
22 | * Used to indicate a dependency change which is lazily created if not present but only applies
23 | * to the root pom.xml
.
24 | *
25 | * For example to add a particular maven plugin which updates the version if used in any pom but is added
26 | * only in the root pom.xml
27 | */
28 | public class MavenDependencyVersionChange extends DependencyVersionChange {
29 | private final boolean addOnlyToRootPom;
30 | private final ElementProcessor elementProcessor;
31 |
32 | public MavenDependencyVersionChange(String dependency, String version, boolean addOnlyToRootPom, ElementProcessor elementProcessor) {
33 | super(Kind.MAVEN, dependency, version);
34 | this.addOnlyToRootPom = addOnlyToRootPom;
35 | this.elementProcessor = elementProcessor;
36 | }
37 |
38 | public MavenDependencyVersionChange(String dependency, String version, String scope, boolean addOnlyToRootPom, ElementProcessor elementProcessor) {
39 | super(Kind.MAVEN, dependency, version, scope);
40 | this.addOnlyToRootPom = addOnlyToRootPom;
41 | this.elementProcessor = elementProcessor;
42 | }
43 |
44 | public MavenDependencyVersionChange(String dependency, String version, String scope, boolean add, boolean addOnlyToRootPom, ElementProcessor elementProcessor) {
45 | super(Kind.MAVEN, dependency, version, scope, add);
46 | this.addOnlyToRootPom = addOnlyToRootPom;
47 | this.elementProcessor = elementProcessor;
48 | }
49 |
50 | public static ElementProcessor elementProcessor(DependencyVersionChange change) {
51 | if (change instanceof MavenDependencyVersionChange) {
52 | MavenDependencyVersionChange mavenDependencyVersionChange = (MavenDependencyVersionChange) change;
53 | return mavenDependencyVersionChange.getElementProcessor();
54 | }
55 | return null;
56 | }
57 |
58 | public boolean isAddOnlyToRootPom() {
59 | return addOnlyToRootPom;
60 | }
61 |
62 | public ElementProcessor getElementProcessor() {
63 | return elementProcessor;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/kind/maven/MavenScopes.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.kind.maven;
17 |
18 | /**
19 | */
20 | public class MavenScopes {
21 | public static final String DEPENDENCY = "dependency";
22 | public static final String ARTIFACT = "artifact";
23 | public static final String PLUGIN = "plugin";
24 | }
25 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/kind/npm/DefaultNpmDependencyTreeGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.kind.npm;
17 |
18 | import io.jenkins.updatebot.Configuration;
19 | import io.jenkins.updatebot.commands.CommandContext;
20 | import io.jenkins.updatebot.support.FileDeleter;
21 | import io.jenkins.updatebot.support.ProcessHelper;
22 | import org.slf4j.Logger;
23 | import org.slf4j.LoggerFactory;
24 |
25 | import java.io.File;
26 | import java.io.IOException;
27 |
28 | /**
29 | */
30 | public class DefaultNpmDependencyTreeGenerator implements NpmDependencyTreeGenerator {
31 | private static final transient Logger LOG = LoggerFactory.getLogger(DefaultNpmDependencyTreeGenerator.class);
32 |
33 | @Override
34 | public void generateDependencyTree(CommandContext context, String dependencyFileName) throws IOException {
35 | File dir = context.getDir();
36 | context.info(LOG, "Generating dependency tree file " + dependencyFileName + " in " + dir);
37 |
38 | Configuration configuration = context.getConfiguration();
39 | String npmBinary = configuration.getNpmCommand();
40 | ProcessHelper.runCommandIgnoreOutput(dir, configuration.getNpmEnvironmentVariables(), npmBinary, "install");
41 |
42 | File outputFile = new File(dir, dependencyFileName);
43 | File errorFile = new File(dir, "npm-list-errors.log");
44 | try (FileDeleter ignored = new FileDeleter(errorFile)) {
45 | if (ProcessHelper.runCommand(dir, outputFile, errorFile, npmBinary, "list", "-json") != 0) {
46 | context.warn(LOG, "Failed to generate dependencies file " + outputFile);
47 | } else {
48 | LOG.debug("Generate dependencies file " + outputFile);
49 | }
50 | }
51 |
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/kind/npm/NpmDependencyKinds.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.kind.npm;
17 |
18 | /**
19 | */
20 | public class NpmDependencyKinds {
21 | public static final String DEPENDENCIES = "dependencies";
22 | public static final String DEV_DEPENDENCIES = "devDependencies";
23 | public static final String PEER_DEPENDENCIES = "peerDependencies";
24 |
25 | public static final String[] DEPENDENCY_KEYS = {
26 | DEPENDENCIES, DEV_DEPENDENCIES, PEER_DEPENDENCIES
27 | };
28 | }
29 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/kind/npm/NpmDependencyTreeGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.kind.npm;
17 |
18 | import io.jenkins.updatebot.commands.CommandContext;
19 |
20 | import java.io.IOException;
21 |
22 | /**
23 | * The strategy used to generate the npm dependency tree
24 | */
25 | public interface NpmDependencyTreeGenerator {
26 | void generateDependencyTree(CommandContext context, String dependencyFileName) throws IOException;
27 | }
28 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/kind/npm/dependency/DependencyCheck.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.kind.npm.dependency;
17 |
18 | /**
19 | */
20 | public class DependencyCheck {
21 | private final boolean valid;
22 | private final String message;
23 | private final DependencyInfo dependencyInfo;
24 |
25 | public DependencyCheck(boolean valid, String message, DependencyInfo dependencyInfo) {
26 | this.valid = valid;
27 | this.message = message;
28 | this.dependencyInfo = dependencyInfo;
29 | }
30 |
31 | @Override
32 | public String toString() {
33 | return "DependencyCheck{" +
34 | "valid=" + valid +
35 | ", message='" + message + '\'' +
36 | '}';
37 | }
38 |
39 | public boolean isValid() {
40 | return valid;
41 | }
42 |
43 | public String getMessage() {
44 | return message;
45 | }
46 |
47 | public DependencyInfo getDependencyInfo() {
48 | return dependencyInfo;
49 | }
50 |
51 | public String getDependency() {
52 | return dependencyInfo.getDependency();
53 | }
54 |
55 | public String getVersion() {
56 | return dependencyInfo.getVersion();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/kind/npm/dependency/DependencyLink.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.kind.npm.dependency;
17 |
18 | /**
19 | * A dependency link from a parent dependency to a child dependency
20 | */
21 | public class DependencyLink {
22 | private final DependencyInfo parent;
23 | private final DependencyInfo child;
24 | private final String version;
25 | private final String dependencyKind;
26 |
27 | public DependencyLink(DependencyInfo parent, DependencyInfo child, String version, String dependencyKind) {
28 | this.parent = parent;
29 | this.child = child;
30 | this.version = version;
31 | this.dependencyKind = dependencyKind;
32 | }
33 |
34 | @Override
35 | public String toString() {
36 | return "DependencyLink{" +
37 | "parent=" + parent +
38 | ", child=" + child +
39 | ", version='" + version + '\'' +
40 | ", dependencyKind='" + dependencyKind + '\'' +
41 | '}';
42 | }
43 |
44 | public DependencyInfo getParent() {
45 | return parent;
46 | }
47 |
48 | public DependencyInfo getChild() {
49 | return child;
50 | }
51 |
52 | public String getVersion() {
53 | return version;
54 | }
55 |
56 | public String getDependencyKind() {
57 | return dependencyKind;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/kind/npm/dependency/DependencyTree.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.kind.npm.dependency;
17 |
18 | import com.fasterxml.jackson.databind.JsonNode;
19 | import com.fasterxml.jackson.databind.node.ObjectNode;
20 | import io.jenkins.updatebot.support.JsonNodes;
21 |
22 | import java.util.Iterator;
23 | import java.util.LinkedHashMap;
24 | import java.util.Map;
25 |
26 | import static io.jenkins.updatebot.kind.npm.NpmDependencyKinds.DEPENDENCY_KEYS;
27 |
28 | /**
29 | */
30 | public class DependencyTree {
31 | private Map dependencies = new LinkedHashMap<>();
32 |
33 | public static DependencyTree parseTree(JsonNode tree) {
34 | DependencyTree dependencyTree = new DependencyTree();
35 | dependencyTree.parse(tree, null);
36 | return dependencyTree;
37 | }
38 |
39 | protected void parse(JsonNode tree, DependencyInfo parent) {
40 | for (String dependencyKey : DEPENDENCY_KEYS) {
41 | JsonNode deps = tree.get(dependencyKey);
42 | if (deps instanceof ObjectNode) {
43 | ObjectNode objectNode = (ObjectNode) deps;
44 | Iterator iter = objectNode.fieldNames();
45 | while (iter.hasNext()) {
46 | String field = iter.next();
47 | JsonNode properties = objectNode.get(field);
48 | String version = JsonNodes.textValue(properties, "version");
49 | DependencyInfo dependencyInfo = getOrCreateDependencyInfo(field);
50 | if (parent == null) {
51 | dependencyInfo.setVersion(version);
52 | } else {
53 | dependencyInfo.addDependency(parent, version, dependencyKey);
54 | }
55 | parse(properties, dependencyInfo);
56 | }
57 | }
58 | }
59 | }
60 |
61 | public DependencyCheck dependencyCheck(String dependency) {
62 | DependencyInfo info = getDependencyInfo(dependency);
63 | if (info == null) {
64 | return new DependencyCheck(true, "Not found!", null);
65 | }
66 | return info.dependencyCheck();
67 | }
68 |
69 | protected DependencyInfo getOrCreateDependencyInfo(String dependency) {
70 | DependencyInfo answer = getDependencyInfo(dependency);
71 | if (answer == null) {
72 | answer = new DependencyInfo(dependency);
73 | dependencies.put(dependency, answer);
74 | }
75 | return answer;
76 |
77 | }
78 |
79 | public DependencyInfo getDependencyInfo(String dependency) {
80 | return dependencies.get(dependency);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/kind/plugins/PluginVersion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.kind.plugins;
17 |
18 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
19 | import io.jenkins.updatebot.model.DtoSupport;
20 |
21 | /**
22 | */
23 | @JsonIgnoreProperties(ignoreUnknown = true)
24 | public class PluginVersion extends DtoSupport {
25 | private String url;
26 | private String version;
27 | private String wiki;
28 | private String title;
29 | private String scm;
30 |
31 | @Override
32 | public String toString() {
33 | return "PluginVersion{" +
34 | "url='" + url + '\'' +
35 | ", version='" + version + '\'' +
36 | ", wiki='" + wiki + '\'' +
37 | ", title='" + title + '\'' +
38 | ", scm='" + scm + '\'' +
39 | '}';
40 | }
41 |
42 | public String getUrl() {
43 | return url;
44 | }
45 |
46 | public void setUrl(String url) {
47 | this.url = url;
48 | }
49 |
50 | public String getVersion() {
51 | return version;
52 | }
53 |
54 | public void setVersion(String version) {
55 | this.version = version;
56 | }
57 |
58 | public String getWiki() {
59 | return wiki;
60 | }
61 |
62 | public void setWiki(String wiki) {
63 | this.wiki = wiki;
64 | }
65 |
66 | public String getTitle() {
67 | return title;
68 | }
69 |
70 | public void setTitle(String title) {
71 | this.title = title;
72 | }
73 |
74 | public String getScm() {
75 | return scm;
76 | }
77 |
78 | public void setScm(String scm) {
79 | this.scm = scm;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/kind/plugins/PluginVersions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.kind.plugins;
17 |
18 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
19 | import io.jenkins.updatebot.model.DtoSupport;
20 |
21 | import java.util.HashMap;
22 | import java.util.Map;
23 |
24 | /**
25 | */
26 | @JsonIgnoreProperties(ignoreUnknown = true)
27 | public class PluginVersions extends DtoSupport {
28 | private Map plugins = new HashMap<>();
29 |
30 | @Override
31 | public String toString() {
32 | return "PluginVersions{" +
33 | "plugins=" + plugins +
34 | '}';
35 | }
36 |
37 | public String getVersion(String artifactId) {
38 | if (plugins != null) {
39 | PluginVersion plugin = plugins.get(artifactId);
40 | if (plugin != null) {
41 | return plugin.getVersion();
42 | }
43 | }
44 | return null;
45 | }
46 |
47 | public Map getPlugins() {
48 | return plugins;
49 | }
50 |
51 | public void setPlugins(Map plugins) {
52 | this.plugins = plugins;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/Dependencies.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | import io.jenkins.updatebot.support.Strings;
19 |
20 | /**
21 | */
22 | public class Dependencies {
23 | private NpmDependencies npm;
24 | private MavenDependencies maven;
25 | private FileDependencies file;
26 | private PluginsDependencies plugins;
27 |
28 | @Override
29 | public String toString() {
30 | String mavenText = "maven=" + maven;
31 | String npmText = "npm=" + npm;
32 | return "Dependencies{" +
33 | Strings.joinNotEmpty(", ", mavenText, npmText) + '}';
34 | }
35 |
36 | public NpmDependencies getNpm() {
37 | return npm;
38 | }
39 |
40 | public void setNpm(NpmDependencies npm) {
41 | this.npm = npm;
42 | }
43 |
44 | public MavenDependencies getMaven() {
45 | return maven;
46 | }
47 |
48 | public void setMaven(MavenDependencies maven) {
49 | this.maven = maven;
50 | }
51 |
52 | public FileDependencies getFile() {
53 | return file;
54 | }
55 |
56 | public void setFile(FileDependencies file) {
57 | this.file = file;
58 | }
59 |
60 | public PluginsDependencies getPlugins() {
61 | return plugins;
62 | }
63 |
64 | public void setPlugins(PluginsDependencies plugins) {
65 | this.plugins = plugins;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/DependencySet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | /**
19 | */
20 | public class DependencySet extends FilterSupport {
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/DtoSupport.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 |
17 | package io.jenkins.updatebot.model;
18 |
19 | import com.fasterxml.jackson.annotation.JsonAnyGetter;
20 | import com.fasterxml.jackson.annotation.JsonAnySetter;
21 | import com.fasterxml.jackson.annotation.JsonIgnore;
22 | import com.fasterxml.jackson.annotation.JsonInclude;
23 | import com.fasterxml.jackson.databind.PropertyNamingStrategy;
24 | import com.fasterxml.jackson.databind.annotation.JsonNaming;
25 |
26 | import java.util.HashMap;
27 | import java.util.Map;
28 |
29 | /**
30 | * A helper base class for DTOs
31 | */
32 | @JsonNaming(value = PropertyNamingStrategy.LowerCaseStrategy.class)
33 | @JsonInclude(JsonInclude.Include.NON_EMPTY)
34 | public abstract class DtoSupport {
35 | @JsonIgnore
36 | private Map additionalProperties = new HashMap();
37 |
38 | @JsonAnyGetter
39 | public Map getAdditionalProperties() {
40 | return this.additionalProperties;
41 | }
42 |
43 | @JsonAnySetter
44 | public void setAdditionalProperty(String name, Object value) {
45 | this.additionalProperties.put(name, value);
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/Environment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | /**
19 | */
20 | public class Environment extends DtoSupport {
21 | private String id;
22 | private String name;
23 | private String description;
24 | private String github;
25 |
26 | public Environment() {
27 | }
28 |
29 | @Override
30 | public String toString() {
31 | return "Environment{" +
32 | "id='" + id + '\'' +
33 | ", name='" + name + '\'' +
34 | '}';
35 | }
36 |
37 | public String getId() {
38 | return id;
39 | }
40 |
41 | public void setId(String id) {
42 | this.id = id;
43 | }
44 |
45 | public String getName() {
46 | return name;
47 | }
48 |
49 | public void setName(String name) {
50 | this.name = name;
51 | }
52 |
53 | public String getDescription() {
54 | return description;
55 | }
56 |
57 | public void setDescription(String description) {
58 | this.description = description;
59 | }
60 |
61 | public String getGithub() {
62 | return github;
63 | }
64 |
65 | public void setGithub(String github) {
66 | this.github = github;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/FileDependencies.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | /**
19 | * Represents sets of file dependencies
20 | */
21 | public class FileDependencies {
22 |
23 | public boolean isEmpty() {
24 | // TODO
25 | return true;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/FilterSupport.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | import io.jenkins.updatebot.support.FilterHelpers;
19 | import io.fabric8.utils.Filter;
20 | import io.fabric8.utils.Filters;
21 |
22 | import java.util.ArrayList;
23 | import java.util.List;
24 |
25 | /**
26 | */
27 | public class FilterSupport extends DtoSupport {
28 | private List includes = new ArrayList<>();
29 | private List excludes = new ArrayList<>();
30 |
31 | public void include(String... values) {
32 | addValues(this.includes, values);
33 | }
34 |
35 | public void exclude(String... values) {
36 | addValues(this.excludes, values);
37 | }
38 |
39 | public List getIncludes() {
40 | return includes;
41 | }
42 |
43 | public void setIncludes(List includes) {
44 | this.includes = includes;
45 | }
46 |
47 | public List getExcludes() {
48 | return excludes;
49 | }
50 |
51 | public void setExcludes(List excludes) {
52 | this.excludes = excludes;
53 | }
54 |
55 | /**
56 | * Returns a filter for the names
57 | */
58 | public Filter createFilter() {
59 | Filter includeFilter = Filters.createStringFilters(includes);
60 | if (excludes.isEmpty()) {
61 | if (includes.isEmpty()) {
62 | return Filters.falseFilter();
63 | }
64 | return includeFilter;
65 | }
66 | Filter excludeFilter = Filters.createStringFilters(excludes);
67 | if (includes.isEmpty()) {
68 | return excludeFilter;
69 | }
70 | return FilterHelpers.and(includeFilter, Filters.not(excludeFilter));
71 | }
72 |
73 | protected void addValues(List list, String[] values) {
74 | for (String value : values) {
75 | if (!list.contains(value)) {
76 | list.add(value);
77 | }
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/GitHubProjects.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | import io.fabric8.utils.Objects;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | /**
24 | */
25 | public class GitHubProjects extends DtoSupport {
26 | private List organisations;
27 |
28 | @Override
29 | public String toString() {
30 | return "GitHubProjects{" +
31 | "organisations=" + organisations +
32 | '}';
33 | }
34 |
35 | public GithubOrganisation organisation(String name) {
36 | GithubOrganisation answer = findOrganisation(name);
37 | if (answer == null) {
38 | if (organisations == null) {
39 | organisations = new ArrayList<>();
40 | }
41 | answer = new GithubOrganisation(name);
42 | organisations.add(answer);
43 | }
44 | return answer;
45 | }
46 |
47 | public GithubOrganisation findOrganisation(String name) {
48 | if (organisations != null) {
49 | for (GithubOrganisation organisation : organisations) {
50 | if (Objects.equal(name, organisation.getName())) {
51 | return organisation;
52 | }
53 | }
54 | }
55 | return null;
56 | }
57 |
58 | public List getOrganisations() {
59 | return organisations;
60 | }
61 |
62 | public void setOrganisations(List organisations) {
63 | this.organisations = organisations;
64 | }
65 |
66 | public GitRepositoryConfig getRepositoryDetails(String cloneUrl) {
67 | if (organisations != null) {
68 | for (GithubOrganisation organisation : organisations) {
69 | GitRepositoryConfig answer = organisation.getRepositoryDetails(cloneUrl);
70 | if (answer != null) {
71 | return answer;
72 | }
73 | }
74 | }
75 | return null;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/GitRepositoryConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | import io.jenkins.updatebot.support.Strings;
19 |
20 | /**
21 | * Represents the configuration of a git repository
22 | */
23 | public class GitRepositoryConfig extends DtoSupport {
24 | private String name;
25 | private String branch; // need to resolve branch name at runtime
26 | private boolean useSinglePullRequest; // use single pull request to push commits from upstream
27 | private Boolean excludeUpdateLoop;
28 | private Dependencies push;
29 | private Dependencies pull;
30 |
31 | public GitRepositoryConfig() {
32 | }
33 |
34 | public GitRepositoryConfig(String name) {
35 | this.name = name;
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | String nameText = Strings.notEmpty(name) ? "name='" + name + '\'' : "";
41 | String pushText = push != null ? "push=" + push : "";
42 | String pullText = pull != null ? "pull=" + pull : "";
43 | String branchText = branch != null ? "branch=" + branch : "";
44 | String singlePullRequestText = "useSinglePullRequest=" + useSinglePullRequest;
45 |
46 | return "GitRepositoryConfig{" +
47 | Strings.joinNotEmpty(", ", nameText, pushText, pullText, branchText, singlePullRequestText) + '}';
48 | }
49 |
50 | public String getName() {
51 | return name;
52 | }
53 |
54 | public void setName(String name) {
55 | this.name = name;
56 | }
57 |
58 | public Dependencies getPush() {
59 | return push;
60 | }
61 |
62 | public void setPush(Dependencies push) {
63 | this.push = push;
64 | }
65 |
66 | public Dependencies getPull() {
67 | return pull;
68 | }
69 |
70 | public void setPull(Dependencies pull) {
71 | this.pull = pull;
72 | }
73 |
74 | public String getBranch() {
75 | return this.branch;
76 | }
77 |
78 | public void setBranch(String branch) {
79 | this.branch = branch;
80 | }
81 |
82 | public boolean isUseSinglePullRequest() {
83 | return this.useSinglePullRequest;
84 | }
85 |
86 | public void setUseSinglePullRequest(boolean single) {
87 | this.useSinglePullRequest = single;
88 | }
89 |
90 | public Boolean getExcludeUpdateLoop() {
91 | return excludeUpdateLoop;
92 | }
93 |
94 | public void setExcludeUpdateLoop(Boolean excludeUpdateLoop) {
95 | this.excludeUpdateLoop = excludeUpdateLoop;
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/GithubOrganisation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | import io.jenkins.updatebot.git.GitHelper;
19 | import io.jenkins.updatebot.support.Strings;
20 | import io.fabric8.utils.Objects;
21 |
22 | import java.util.ArrayList;
23 | import java.util.List;
24 |
25 | /**
26 | */
27 | public class GithubOrganisation extends FilterSupport {
28 | private String name;
29 | private List repositories = new ArrayList<>();
30 |
31 | public GithubOrganisation() {
32 | }
33 |
34 | public GithubOrganisation(String name) {
35 | this.name = name;
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | return "GithubOrganisation{" +
41 | "name='" + name + '\'' +
42 | ", repositories=" + repositories +
43 | '}';
44 | }
45 |
46 | public String getName() {
47 | return name;
48 | }
49 |
50 | public void setName(String name) {
51 | this.name = name;
52 | }
53 |
54 | public List getRepositories() {
55 | return repositories;
56 | }
57 |
58 | public void setRepositories(List repositories) {
59 | this.repositories = repositories;
60 | }
61 |
62 | public GitRepositoryConfig getRepositoryDetails(String cloneUrl) {
63 | for (GitRepositoryConfig repository : repositories) {
64 | if (hasCloneUrl(repository, cloneUrl)) {
65 | return repository;
66 | }
67 | }
68 | return null;
69 | }
70 |
71 | protected boolean hasCloneUrl(GitRepositoryConfig repository, String cloneUrl) {
72 | List gitUrls = GitHelper.getGitHubCloneUrls("github.com", getName(), repository.getName());
73 | return Strings.equalAnyValue(cloneUrl, gitUrls);
74 | }
75 |
76 | /**
77 | * Returns the github repository for the given name, lazily creating or updating if required
78 | */
79 | public GitRepositoryConfig repository(String name) {
80 | GitRepositoryConfig config = findRepository(name);
81 | if (config == null) {
82 | config = new GitRepositoryConfig(name);
83 | repositories.add(config);
84 | }
85 | return config;
86 | }
87 |
88 | public GitRepositoryConfig findRepository(String name) {
89 | for (GitRepositoryConfig repository : repositories) {
90 | if (Objects.equal(name, repository.getName())) {
91 | return repository;
92 | }
93 | }
94 | return null;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/MavenArtifactKey.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | /**
19 | */
20 | public class MavenArtifactKey implements Comparable {
21 | private final String groupId;
22 | private final String artifactId;
23 |
24 | public final static String DEFAULT_MAVEN_PLUGIN_GROUP = "org.apache.maven.plugins";
25 |
26 | public MavenArtifactKey(String groupId, String artifactId) {
27 | this.groupId = groupId;
28 | this.artifactId = artifactId;
29 | }
30 |
31 | /**
32 | * Returns a maven dependency from the given string using :
to separate the group id and artifact
33 | */
34 | public static MavenArtifactKey fromString(String value) {
35 | int idx = value.indexOf(':');
36 | if (idx < 0) {
37 | throw new IllegalArgumentException("No `:` character in the maven dependency: " + value);
38 | }
39 | return new MavenArtifactKey(value.substring(0, idx), value.substring(idx + 1));
40 | }
41 |
42 | @Override
43 | public String toString() {
44 | return groupId + ":" + artifactId;
45 | }
46 |
47 | @Override
48 | public boolean equals(Object o) {
49 | if (this == o) return true;
50 | if (o == null || getClass() != o.getClass()) return false;
51 |
52 | MavenArtifactKey that = (MavenArtifactKey) o;
53 |
54 | if (!groupId.equals(that.groupId)) return false;
55 | return artifactId.equals(that.artifactId);
56 | }
57 |
58 | @Override
59 | public int hashCode() {
60 | int result = groupId.hashCode();
61 | result = 31 * result + artifactId.hashCode();
62 | return result;
63 | }
64 |
65 | @Override
66 | public int compareTo(MavenArtifactKey that) {
67 | int answer = this.groupId.compareTo(that.groupId);
68 | if (answer == 0) {
69 | answer = this.artifactId.compareTo(that.artifactId);
70 | }
71 | return answer;
72 | }
73 |
74 | public String getGroupId() {
75 | return groupId;
76 | }
77 |
78 | public String getArtifactId() {
79 | return artifactId;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/MavenArtifactVersionChange.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | import io.jenkins.updatebot.kind.Kind;
19 |
20 | /**
21 | */
22 | public class MavenArtifactVersionChange {
23 | private String groupId;
24 | private String artifactId;
25 | private String version;
26 | private String scope;
27 |
28 | public MavenArtifactVersionChange() {
29 | }
30 |
31 | public MavenArtifactVersionChange(String groupId, String artifactId, String version, String scope) {
32 | this.groupId = groupId;
33 | this.artifactId = artifactId;
34 | this.version = version;
35 | this.scope = scope;
36 | }
37 |
38 | public MavenArtifactVersionChange(MavenArtifactKey artifactKey, String version, String scope) {
39 | this(artifactKey.getGroupId(), artifactKey.getArtifactId(), version, scope);
40 | }
41 |
42 | public MavenArtifactVersionChange(DependencyVersionChange change) {
43 | this(MavenArtifactKey.fromString(change.getDependency()), change.getVersion(), change.getScope());
44 | }
45 |
46 | @Override
47 | public String toString() {
48 | return "MavenArtifactVersionChange{" +
49 | "groupId='" + groupId + '\'' +
50 | ", artifactId='" + artifactId + '\'' +
51 | ", version='" + version + '\'' +
52 | ", scope='" + scope + '\'' +
53 | '}';
54 | }
55 |
56 | public String getGroupId() {
57 | return groupId;
58 | }
59 |
60 | public void setGroupId(String groupId) {
61 | this.groupId = groupId;
62 | }
63 |
64 | public String getArtifactId() {
65 | return artifactId;
66 | }
67 |
68 | public void setArtifactId(String artifactId) {
69 | this.artifactId = artifactId;
70 | }
71 |
72 | public String getVersion() {
73 | return version;
74 | }
75 |
76 | public void setVersion(String version) {
77 | this.version = version;
78 | }
79 |
80 | public String getScope() {
81 | return scope;
82 | }
83 |
84 | public void setScope(String scope) {
85 | this.scope = scope;
86 | }
87 |
88 | public DependencyVersionChange createDependencyVersionChange() {
89 | return new DependencyVersionChange(Kind.MAVEN, new MavenArtifactKey(groupId, artifactId).toString(), version, scope);
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/MavenArtifactVersionChanges.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | import com.fasterxml.jackson.annotation.JsonIgnore;
19 |
20 | import java.util.ArrayList;
21 | import java.util.Collection;
22 | import java.util.List;
23 |
24 | /**
25 | */
26 | public class MavenArtifactVersionChanges {
27 | private List changes = new ArrayList<>();
28 |
29 | public MavenArtifactVersionChanges() {
30 | }
31 |
32 | public MavenArtifactVersionChanges(Collection changes) {
33 | this.changes = new ArrayList<>(changes);
34 | }
35 |
36 | public List getChanges() {
37 | return changes;
38 | }
39 |
40 | public void setChanges(List changes) {
41 | this.changes = changes;
42 | }
43 |
44 |
45 | public void addChange(DependencyVersionChange change) {
46 | addChange(new MavenArtifactVersionChange(change));
47 | }
48 |
49 | public void addChange(MavenArtifactVersionChange change) {
50 | changes.add(change);
51 | }
52 |
53 | @JsonIgnore
54 | public boolean isEmpty() {
55 | return changes.isEmpty();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/MavenDependencies.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | /**
22 | */
23 | public class MavenDependencies {
24 | private List plugins = new ArrayList();
25 | private List dependencies = new ArrayList();
26 |
27 |
28 | public List getPlugins() {
29 | return plugins;
30 | }
31 |
32 | public void setPlugins(List plugins) {
33 | this.plugins = plugins;
34 | }
35 |
36 | public List getDependencies() {
37 | return dependencies;
38 | }
39 |
40 | public void setDependencies(List dependencies) {
41 | this.dependencies = dependencies;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/MavenDependencySet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | /**
19 | */
20 | public class MavenDependencySet {
21 | private DependencySet groupId = new DependencySet();
22 | private DependencySet artifactId = new DependencySet();
23 |
24 | public DependencySet getGroupId() {
25 | return groupId;
26 | }
27 |
28 | public void setGroupId(DependencySet groupId) {
29 | this.groupId = groupId;
30 | }
31 |
32 | public DependencySet getArtifactId() {
33 | return artifactId;
34 | }
35 |
36 | public void setArtifactId(DependencySet artifactId) {
37 | this.artifactId = artifactId;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/NpmDependencies.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | /**
19 | * Represents the push or pull dependencies for NPM based projects
20 | */
21 | public class NpmDependencies {
22 | private DependencySet dependencies = new DependencySet();
23 | private DependencySet devDependencies = new DependencySet();
24 | private DependencySet peerDependencies = new DependencySet();
25 |
26 | public DependencySet getDependencies() {
27 | return dependencies;
28 | }
29 |
30 | public void setDependencies(DependencySet dependencies) {
31 | this.dependencies = dependencies;
32 | }
33 |
34 | public DependencySet getDevDependencies() {
35 | return devDependencies;
36 | }
37 |
38 | public void setDevDependencies(DependencySet devDependencies) {
39 | this.devDependencies = devDependencies;
40 | }
41 |
42 | public DependencySet getPeerDependencies() {
43 | return peerDependencies;
44 | }
45 |
46 | public void setPeerDependencies(DependencySet peerDependencies) {
47 | this.peerDependencies = peerDependencies;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/PluginsDependencies.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | import io.jenkins.updatebot.support.FileMatcher;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | /**
24 | */
25 | public class PluginsDependencies {
26 | private List includes = new ArrayList<>();
27 | private List excludes = new ArrayList<>();
28 |
29 | public boolean isEmpty() {
30 | return includes.isEmpty();
31 | }
32 |
33 | public List getIncludes() {
34 | return includes;
35 | }
36 |
37 | public void setIncludes(List includes) {
38 | this.includes = includes;
39 | }
40 |
41 | public List getExcludes() {
42 | return excludes;
43 | }
44 |
45 | public void setExcludes(List excludes) {
46 | this.excludes = excludes;
47 | }
48 |
49 | public FileMatcher createFileMatcher() {
50 | return FileMatcher.createFileMatcher(includes, excludes);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/model/RepositoryConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | import io.fabric8.utils.Objects;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | /**
24 | */
25 | public class RepositoryConfig {
26 | private GitHubProjects github;
27 | private List git = new ArrayList<>();
28 | private GitRepositoryConfig local;
29 | private List environments = new ArrayList();
30 |
31 | @Override
32 | public String toString() {
33 | return "RepositoryConfig{" +
34 | "github=" + github +
35 | ", git=" + git +
36 | '}';
37 | }
38 |
39 | /**
40 | * Returns the github configuration, lazily created if required
41 | */
42 | public GitHubProjects github() {
43 | if (github == null) {
44 | github = new GitHubProjects();
45 | }
46 | return github;
47 | }
48 |
49 | public GitHubProjects getGithub() {
50 | return github;
51 | }
52 |
53 | public void setGithub(GitHubProjects github) {
54 | this.github = github;
55 | }
56 |
57 | public List getGit() {
58 | return git;
59 | }
60 |
61 | public void setGit(List git) {
62 | this.git = git;
63 | }
64 |
65 | public GitRepositoryConfig getLocal() {
66 | return local;
67 | }
68 |
69 | public void setLocal(GitRepositoryConfig local) {
70 | this.local = local;
71 | }
72 |
73 | public List getEnvironments() {
74 | return environments;
75 | }
76 |
77 | public void setEnvironments(List environments) {
78 | this.environments = environments;
79 | }
80 |
81 | public GitRepositoryConfig getRepositoryDetails(String cloneUrl) {
82 | GitRepositoryConfig answer = github.getRepositoryDetails(cloneUrl);
83 | if (answer == null) {
84 | for (GitRepository gitRepository : git) {
85 | if (Objects.equal(cloneUrl, gitRepository.getCloneUrl())) {
86 | answer = gitRepository.getRepositoryDetails();
87 | if (answer != null) {
88 | return answer;
89 | }
90 | }
91 | }
92 | }
93 | return answer;
94 | }
95 |
96 | public void add(GitRepository gitRepository) {
97 | if (git == null) {
98 | git = new ArrayList<>();
99 | }
100 | git.add(gitRepository);
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/support/FileDeleter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.support;
17 |
18 | import java.io.Closeable;
19 | import java.io.File;
20 | import java.io.IOException;
21 |
22 | /**
23 | * Allows a number of files to be deleted using a Java try-with-resources block (try / catch).
24 | *
25 | *
26 | * try (new FileDeleter(file1, file2)) { ... }
27 | *
28 | */
29 | public class FileDeleter implements Closeable {
30 | private final File[] files;
31 |
32 | public FileDeleter(File... files) {
33 | this.files = files;
34 | }
35 |
36 | @Override
37 | public void close() throws IOException {
38 | for (File file : files) {
39 | if (file.exists()) {
40 | file.delete();
41 | }
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/support/FileExtensionFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.support;
17 |
18 | import io.fabric8.utils.Files;
19 | import io.fabric8.utils.Objects;
20 |
21 | import java.io.File;
22 | import java.io.FileFilter;
23 |
24 | /**
25 | */
26 | public class FileExtensionFilter implements FileFilter {
27 |
28 | private final String extension;
29 |
30 | public FileExtensionFilter(String extension) {
31 | this.extension = extension;
32 | }
33 |
34 | @Override
35 | public String toString() {
36 | return "FileExtensionFilter{" +
37 | "extension='" + extension + '\'' +
38 | '}';
39 | }
40 |
41 | @Override
42 | public boolean accept(File file) {
43 | return Objects.equal(extension, Files.getExtension(file.getName()));
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/support/FileMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.support;
17 |
18 | import java.io.File;
19 | import java.io.IOException;
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | import org.springframework.util.AntPathMatcher;
24 |
25 | import io.fabric8.utils.Files;
26 |
27 | /**
28 | */
29 | public class FileMatcher {
30 | private final List includes;
31 | private final List excludes;
32 | private AntPathMatcher pathMatcher = new AntPathMatcher(File.pathSeparator);
33 |
34 | public FileMatcher(List includes, List excludes) {
35 | this.includes = includes;
36 | this.excludes = excludes;
37 | }
38 |
39 | public static FileMatcher createFileMatcher(List includes, List excludes) {
40 | return new FileMatcher(includes, excludes);
41 | }
42 |
43 | public List matchFiles(File dir) throws IOException {
44 | List answer = new ArrayList<>();
45 | addMatchFiles(answer, dir, dir);
46 | return answer;
47 | }
48 |
49 | private void addMatchFiles(List answer, File rootDir, File file) throws IOException {
50 | if (file.isDirectory()) {
51 | File[] children = file.listFiles();
52 | if (children != null) {
53 | for (File child : children) {
54 | addMatchFiles(answer, rootDir, child);
55 | }
56 | }
57 | } else {
58 | String path = Files.getRelativePath(rootDir, file);
59 | path = Strings.trimAllPrefix(path, File.separator);
60 | if (matchesPatterns(path, includes) && !matchesPatterns(path, excludes)) {
61 | answer.add(file);
62 | }
63 | }
64 | }
65 |
66 | protected boolean matchesPatterns(String path, Iterable patterns) {
67 | boolean matchesInclude = false;
68 | for (String include : patterns) {
69 | if (pathMatcher.match(include, path)) {
70 | matchesInclude = true;
71 | }
72 | }
73 | return matchesInclude;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/support/FilterHelpers.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.support;
17 |
18 | import io.fabric8.utils.Filter;
19 |
20 | import java.util.Arrays;
21 |
22 | /**
23 | */
24 | public class FilterHelpers {
25 | public static Filter and(final Filter... filters) {
26 | return new Filter() {
27 | @Override
28 | public boolean matches(T t) {
29 | for (Filter filter : filters) {
30 | if (!filter.matches(t)) {
31 | return false;
32 | }
33 | }
34 | return true;
35 | }
36 |
37 | @Override
38 | public String toString() {
39 | return "AndFilter" + Arrays.asList(filters);
40 | }
41 | };
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/support/JsonNodes.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.support;
17 |
18 | import com.fasterxml.jackson.databind.JsonNode;
19 |
20 | /**
21 | * Helper assertions for dealing with JSON or YAML markup
22 | */
23 | public class JsonNodes {
24 |
25 | public static JsonNode path(JsonNode tree, String... paths) {
26 | JsonNode node = tree;
27 | for (String path : paths) {
28 | if (node == null || !node.isObject()) {
29 | return null;
30 | }
31 | node = node.get(path);
32 | }
33 | return node;
34 | }
35 |
36 | /**
37 | * Returns the text value of the given field on an object or null if its not a value or the value is not a string
38 | */
39 | public static String textValue(JsonNode node, String field) {
40 | JsonNode value = node.get(field);
41 | if (value != null && value.isTextual()) {
42 | return value.textValue();
43 | }
44 | return null;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/support/Markdown.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.support;
17 |
18 | /**
19 | */
20 | public class Markdown {
21 | public static final String UPDATEBOT = "updatebot";
22 | public static final String UPDATEBOT_ICON = "[UpdateBot](https://github.com/jenkins-x/updatebot)";
23 | public static final String GENERATED_BY = "generated by " + UPDATEBOT_ICON;
24 | }
25 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/support/NpmJsonPrettyPrinter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.support;
17 |
18 | import com.fasterxml.jackson.core.JsonGenerator;
19 | import com.fasterxml.jackson.core.util.DefaultIndenter;
20 | import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
21 |
22 | import java.io.IOException;
23 |
24 | /**
25 | * A pretty printer for npm layout syntax
26 | */
27 | public final class NpmJsonPrettyPrinter extends DefaultPrettyPrinter {
28 | public NpmJsonPrettyPrinter() {
29 | this._objectFieldValueSeparatorWithSpaces = ": ";
30 |
31 | Indenter indenter = new DefaultIndenter(" ", System.lineSeparator());
32 | this.indentObjectsWith(indenter);
33 | this.indentArraysWith(indenter);
34 | }
35 |
36 | @Override
37 | public DefaultPrettyPrinter createInstance() {
38 | return new NpmJsonPrettyPrinter();
39 | }
40 |
41 | @Override
42 | public void writeEndObject(JsonGenerator g, int nrOfEntries) throws IOException {
43 | if (!this._objectIndenter.isInline()) {
44 | --this._nesting;
45 | }
46 |
47 | if (nrOfEntries > 0) {
48 | this._objectIndenter.writeIndentation(g, this._nesting);
49 | } else {
50 | // lets disable the space in empty objects
51 | //g.writeRaw(' ');
52 | }
53 |
54 | g.writeRaw('}');
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/support/ReflectionHelper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.support;
17 |
18 | import io.fabric8.utils.Filter;
19 | import org.slf4j.Logger;
20 | import org.slf4j.LoggerFactory;
21 |
22 | import java.lang.annotation.Annotation;
23 | import java.lang.reflect.Field;
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | /**
28 | */
29 | public class ReflectionHelper {
30 | private static final transient Logger LOG = LoggerFactory.getLogger(ReflectionHelper.class);
31 |
32 | /**
33 | * Returns all the fields annotated with the given annotation in the given class or any super classes
34 | */
35 | public static List findFieldsAnnotatedWith(Class> type, final Class extends Annotation> annotationClass) {
36 | return findFieldsMatching(type, new Filter() {
37 | @Override
38 | public boolean matches(Field field) {
39 | Annotation annotation = field.getAnnotation(annotationClass);
40 | return annotation != null;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return "HasAnnotation(" + annotationClass.getName() + ")";
46 | }
47 | });
48 | }
49 |
50 | /**
51 | * Returns all the fields matching the given filter in the given class or any super classes
52 | */
53 | public static List findFieldsMatching(Class> type, Filter filter) {
54 | List answer = new ArrayList<>();
55 | appendFieldsAnnotatatedWith(answer, type, filter);
56 | return answer;
57 | }
58 |
59 | protected static void appendFieldsAnnotatatedWith(List list, Class> type, Filter filter) {
60 | Field[] fields = type.getDeclaredFields();
61 | if (fields != null) {
62 | for (Field field : fields) {
63 | if (filter.matches(field)) {
64 | list.add(field);
65 | }
66 | }
67 | }
68 |
69 | if (type.getSuperclass() != null) {
70 | appendFieldsAnnotatatedWith(list, type.getSuperclass(), filter);
71 | }
72 | }
73 |
74 | public static Object getFieldValue(Field field, Object instance) {
75 | try {
76 | field.setAccessible(true);
77 | return field.get(instance);
78 | } catch (IllegalAccessException e) {
79 | LOG.warn("Could not access " + field + " on " + instance + ". " + e, e);
80 | return null;
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/support/Systems.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.support;
17 |
18 | import org.slf4j.Logger;
19 | import org.slf4j.LoggerFactory;
20 |
21 | /**
22 | */
23 | public class Systems {
24 | private static final transient Logger LOG = LoggerFactory.getLogger(Systems.class);
25 |
26 | public static String getConfigValue(String envVar) {
27 | return getConfigValue(envVar, null);
28 | }
29 |
30 | /**
31 | * Returns the value of the given environment variable as a system property or environment variable or returns the default value
32 | */
33 | public static String getConfigValue(String envVar, String defaultValue) {
34 | String systemProperty = envVar.toLowerCase().replace('_', '.');
35 | String answer = System.getProperty(systemProperty);
36 | if (Strings.notEmpty(answer)) {
37 | return answer;
38 | }
39 | try {
40 | answer = System.getenv(envVar);
41 | } catch (Exception e) {
42 | LOG.warn("Failed to look up environment variable $" + envVar + ". " + e, e);
43 | }
44 | if (Strings.notEmpty(answer)) {
45 | return answer;
46 | } else {
47 | return defaultValue;
48 | }
49 | }
50 |
51 |
52 | public static long getConfigLongValue(String envVar, long defaultValue) {
53 | String value = getConfigValue(envVar, "").trim();
54 | if (value.isEmpty()) {
55 | return defaultValue;
56 | }
57 | try {
58 | return Long.parseLong(value);
59 | } catch (NumberFormatException e) {
60 | LOG.warn("Failed to parse environment variable: " + envVar + " long value: " + value + ": " + e, e);
61 | return defaultValue;
62 | }
63 | }
64 |
65 |
66 |
67 |
68 | /**
69 | * Returns true if the env var or system property is "true"
70 | */
71 | public static boolean isConfigFlag(String envVar) {
72 | String value = getConfigValue(envVar);
73 | return value != null && value.equalsIgnoreCase("true");
74 | }
75 |
76 | /**
77 | * Returns value of the env var or system property if set, otherwise the specified default value
78 | * Different from a flag as a flag is always false if not present
79 | */
80 | public static boolean isConfigBoolean(String envVar, boolean defaultValue) {
81 | String value = getConfigValue(envVar);
82 | if( value != null ){
83 | return Boolean.parseBoolean(envVar);
84 | }
85 | return defaultValue;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/java/io/jenkins/updatebot/support/UserPassword.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package io.jenkins.updatebot.support;
18 |
19 | /**
20 | */
21 | public class UserPassword {
22 | private final String user;
23 | private final String password;
24 |
25 | public UserPassword(String user, String password) {
26 | this.user = user;
27 | this.password = password;
28 | }
29 |
30 | @Override
31 | public String toString() {
32 | return "UserPassword{" +
33 | "user='" + user + '\'' +
34 | ", password='" + password + '\'' +
35 | '}';
36 | }
37 |
38 | public String getUser() {
39 | return user;
40 | }
41 |
42 | public String getPassword() {
43 | return password;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/resources/io/jenkins/updatebot/support/versions.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2005-2015 Red Hat, Inc.
3 | #
4 | # Red Hat licenses this file to you under the Apache License, version
5 | # 2.0 (the "License"); you may not use this file except in compliance
6 | # with the License. You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | # implied. See the License for the specific language governing
14 | # permissions and limitations under the License.
15 | #
16 | io.jenkins.updatebot/updatebot-core=${updatebot.version}
17 | io.fabric8/fabric8-maven-plugin=${fabric8.maven.plugin.version}
18 | io.fabric8/kubernetes-api=${fabric8.version}
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/updatebot-core/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2005-2016 Red Hat, Inc.
3 | #
4 | # Red Hat licenses this file to you under the Apache License, version
5 | # 2.0 (the "License"); you may not use this file except in compliance
6 | # with the License. You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | # implied. See the License for the specific language governing
14 | # permissions and limitations under the License.
15 | #
16 | log4j.rootLogger=INFO, stdout
17 | #The logging properties used during tests..
18 | # CONSOLE appender not used by default
19 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
20 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
21 | log4j.appender.stdout.layout.ConversionPattern=%-5p %-30.30c{1} - %m%n
22 | log4j.appender.stdout.threshold=DEBUG
23 |
24 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/fabric8/updatebot/BrewPushSourceDependenciesTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.fabric8.updatebot;
17 |
18 |
19 | import io.jenkins.updatebot.Configuration;
20 | import io.jenkins.updatebot.commands.PushVersionChanges;
21 | import io.jenkins.updatebot.github.GitHubHelpers;
22 | import io.jenkins.updatebot.kind.Kind;
23 | import io.jenkins.updatebot.repository.LocalRepository;
24 | import io.fabric8.updatebot.test.Tests;
25 | import org.junit.Before;
26 | import org.junit.Test;
27 | import org.slf4j.Logger;
28 | import org.slf4j.LoggerFactory;
29 |
30 | import java.io.File;
31 | import java.io.IOException;
32 | import java.util.List;
33 |
34 | /**
35 | */
36 | public class BrewPushSourceDependenciesTest {
37 | private static final transient Logger LOG = LoggerFactory.getLogger(BrewPushSourceDependenciesTest.class);
38 |
39 | protected PushVersionChanges command;
40 | protected List localRepositories;
41 | protected Configuration configuration = new Configuration();
42 |
43 | @Before
44 | public void init() throws IOException {
45 | command = new PushVersionChanges(Kind.BREW, "jx", "1.0.13");
46 |
47 | String configFile = new File(Tests.getBasedir(), "src/test/resources/brew/source/updatebot.yml").getPath();
48 | String workDirPath = Tests.getCleanWorkDir(getClass());
49 |
50 | configuration.setConfigFile(configFile);
51 | configuration.setWorkDir(workDirPath);
52 |
53 | if (System.getProperty("updatebot.disable.pull", "false").equals("true")) {
54 | LOG.info("Disabling pull to speed up tests");
55 | configuration.setPullDisabled(true);
56 | }
57 | if (Tests.canTestWithGithubAPI(configuration)) {
58 |
59 | localRepositories = command.cloneOrPullRepositories(configuration);
60 |
61 | // lets close all open PRs
62 | GitHubHelpers.closeOpenUpdateBotIssuesAndPullRequests(configuration.getGithubPullRequestLabel(), localRepositories);
63 | GitHubHelpers.deleteUpdateBotBranches(localRepositories);
64 | }
65 | }
66 |
67 | @Test
68 | public void testUpdater() throws Exception {
69 | if (Tests.canTestWithGithubAPI(configuration)) {
70 | command.run(configuration);
71 | }
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/fabric8/updatebot/CommandParseTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.fabric8.updatebot;
17 |
18 | import io.jenkins.updatebot.CommandNames;
19 | import io.jenkins.updatebot.commands.PushVersionChanges;
20 | import io.fabric8.updatebot.test.CommandAssertions;
21 | import org.junit.Test;
22 |
23 | import static io.jenkins.updatebot.kind.Kind.NPM;
24 | import static io.fabric8.updatebot.test.CommandAssertions.assertParseCommand;
25 |
26 | /**
27 | */
28 | public class CommandParseTest {
29 |
30 | @Test
31 | public void testParseSimpleCommand() throws Exception {
32 | String dependency = "cheese";
33 | String version = "1.2.3";
34 | PushVersionChanges command = assertParseCommand(PushVersionChanges.class, CommandNames.PUSH_VERSION, "--kind", "npm", dependency, version);
35 | CommandAssertions.assertPushVersionContext(command, NPM, dependency, version);
36 | }
37 |
38 | @Test
39 | public void testParseDependencyWithAt() throws Exception {
40 | String dependency = "@angular/core";
41 | String version = "4.3.2";
42 | PushVersionChanges command = assertParseCommand(PushVersionChanges.class, CommandNames.PUSH_VERSION, "--kind", "npm", dependency, version);
43 | CommandAssertions.assertPushVersionContext(command, NPM, dependency, version);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/fabric8/updatebot/EnableFabric8Test.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.fabric8.updatebot;
17 |
18 |
19 | import io.jenkins.updatebot.Configuration;
20 | import io.jenkins.updatebot.commands.EnableFabric8;
21 | import io.jenkins.updatebot.github.GitHubHelpers;
22 | import io.jenkins.updatebot.repository.LocalRepository;
23 | import io.fabric8.updatebot.test.Tests;
24 | import org.junit.Before;
25 | import org.junit.Test;
26 | import org.slf4j.Logger;
27 | import org.slf4j.LoggerFactory;
28 |
29 | import java.io.File;
30 | import java.io.IOException;
31 | import java.util.List;
32 |
33 | /**
34 | */
35 | public class EnableFabric8Test {
36 | private static final transient Logger LOG = LoggerFactory.getLogger(EnableFabric8Test.class);
37 |
38 | protected EnableFabric8 enableFabric8 = new EnableFabric8();
39 | protected List localRepositories;
40 | protected Configuration configuration = new Configuration();
41 |
42 | @Before
43 | public void init() throws IOException {
44 | String workDirPath = Tests.getCleanWorkDir(getClass());
45 |
46 | configuration.setWorkDir(workDirPath);
47 | configuration.setSourceDir(new File(workDirPath));
48 |
49 | }
50 |
51 | @Test
52 | public void testEnableFabric8OnProjectWithFMP() throws Exception {
53 | enableFabric8.setOrganisationAndRepository("jstrachan-testing/spring-boot-webmvc");
54 | assertEnableFabric8();
55 | }
56 |
57 | @Test
58 | public void testEnableFabric8OnProjectWithoutFMP() throws Exception {
59 | enableFabric8.setOrganisationAndRepository("jstrachan-testing/spring-boot-webmvc-no-fmp");
60 | assertEnableFabric8();
61 | }
62 |
63 | protected void assertEnableFabric8() throws IOException {
64 | if (Tests.canTestWithGithubAPI(configuration)) {
65 | enableFabric8.run(configuration);
66 |
67 |
68 | // lets now close down the pending PRs
69 | localRepositories = enableFabric8.getLocalRepositories(configuration);
70 | GitHubHelpers.closeOpenUpdateBotIssuesAndPullRequests(configuration.getGithubPullRequestLabel(), localRepositories);
71 | GitHubHelpers.deleteUpdateBotBranches(localRepositories);
72 | }
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/fabric8/updatebot/LoggingTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.fabric8.updatebot;
17 |
18 | /**
19 | */
20 | public class LoggingTest {
21 | }
22 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/fabric8/updatebot/NpmUpdateBotTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.fabric8.updatebot;
17 |
18 |
19 | import io.jenkins.updatebot.Configuration;
20 | import io.jenkins.updatebot.commands.PushVersionChanges;
21 | import io.jenkins.updatebot.kind.Kind;
22 | import io.fabric8.updatebot.test.Tests;
23 | import org.junit.Before;
24 | import org.junit.Test;
25 |
26 | import java.io.File;
27 |
28 | /**
29 | */
30 | public class NpmUpdateBotTest {
31 | protected PushVersionChanges updateBot = new PushVersionChanges();
32 | private Configuration configuration = new Configuration();
33 |
34 | @Before
35 | public void init() {
36 | File testClasses = new File(Tests.getBasedir(), "src/test/resources/npm/updatebot.yml");
37 | configuration.setConfigFile(testClasses.getPath());
38 | configuration.setDryRun(true);
39 |
40 | // lets update a single version
41 | updateBot.setKind(Kind.NPM);
42 | updateBot.values("@angular/core", "4.3.7");
43 | }
44 |
45 | @Test
46 | public void testUpdater() throws Exception {
47 | updateBot.run(configuration);
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/fabric8/updatebot/PromoteTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.fabric8.updatebot;
17 |
18 |
19 | import io.jenkins.updatebot.Configuration;
20 | import io.jenkins.updatebot.commands.Promote;
21 | import io.jenkins.updatebot.repository.LocalRepository;
22 | import io.fabric8.updatebot.test.Tests;
23 | import org.junit.Before;
24 | import org.junit.Test;
25 | import org.slf4j.Logger;
26 | import org.slf4j.LoggerFactory;
27 |
28 | import java.io.File;
29 | import java.io.IOException;
30 | import java.util.List;
31 |
32 | /**
33 | */
34 | public class PromoteTest {
35 | private static final transient Logger LOG = LoggerFactory.getLogger(PromoteTest.class);
36 |
37 | protected Promote command = new Promote();
38 | protected List localRepositories;
39 | protected Configuration configuration = new Configuration();
40 |
41 | @Before
42 | public void init() throws IOException {
43 | String workDirPath = Tests.getCleanWorkDir(getClass());
44 | String configFile = new File(Tests.getBasedir(), "src/test/resources/helm/updatebot.yml").getPath();
45 |
46 | configuration.setConfigFile(configFile);
47 | configuration.setWorkDir(workDirPath);
48 | configuration.setSourceDir(new File(workDirPath));
49 |
50 | }
51 |
52 | @Test
53 | public void testEnableFabric8OnProjectWithoutFMP() throws Exception {
54 | command.setChart("pipelines");
55 | command.setVersion("0.0.2");
56 | assertPromote();
57 | }
58 |
59 | protected void assertPromote() throws IOException {
60 | if (Tests.canTestWithGithubAPI(configuration)) {
61 | command.run(configuration);
62 |
63 |
64 | /*
65 | // lets now close down the pending PRs
66 | localRepositories = command.getLocalRepositories(configuration);
67 | GitHubHelpers.closeOpenUpdateBotIssuesAndPullRequests(configuration.getGithubPullRequestLabel(), localRepositories);
68 | GitHubHelpers.deleteUpdateBotBranches(localRepositories);
69 | */
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/fabric8/updatebot/PushSourceDependenciesTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.fabric8.updatebot;
17 |
18 |
19 | import io.jenkins.updatebot.Configuration;
20 | import io.jenkins.updatebot.commands.PushSourceChanges;
21 | import io.jenkins.updatebot.github.GitHubHelpers;
22 | import io.jenkins.updatebot.repository.LocalRepository;
23 | import io.fabric8.updatebot.test.Tests;
24 | import org.junit.Before;
25 | import org.junit.Test;
26 | import org.slf4j.Logger;
27 | import org.slf4j.LoggerFactory;
28 |
29 | import java.io.File;
30 | import java.io.IOException;
31 | import java.util.List;
32 |
33 | import static org.assertj.core.api.Assertions.assertThat;
34 |
35 | /**
36 | */
37 | public class PushSourceDependenciesTest {
38 | private static final transient Logger LOG = LoggerFactory.getLogger(PushSourceDependenciesTest.class);
39 |
40 | protected PushSourceChanges pushSourceChanges = new PushSourceChanges();
41 | protected List localRepositories;
42 | protected Configuration configuration = new Configuration();
43 | protected String sourceRepoName = "ngx-base";
44 |
45 | @Before
46 | public void init() throws IOException {
47 | String configFile = new File(Tests.getBasedir(), "src/test/resources/npm/source/updatebot.yml").getPath();
48 | String workDirPath = Tests.getCleanWorkDir(getClass());
49 |
50 | configuration.setConfigFile(configFile);
51 | configuration.setWorkDir(workDirPath);
52 |
53 | localRepositories = pushSourceChanges.cloneOrPullRepositories(configuration);
54 |
55 | LocalRepository sourceRepo = LocalRepository.findRepository(localRepositories, sourceRepoName);
56 | assertThat(sourceRepo).describedAs("Could not find repository with name: " + sourceRepoName).isNotNull();
57 |
58 | // lets find the cloned repo...
59 | configuration.setSourceDir(sourceRepo.getDir());
60 |
61 | // lets close all open PRs
62 | GitHubHelpers.closeOpenUpdateBotIssuesAndPullRequests(configuration.getGithubPullRequestLabel(), localRepositories);
63 | GitHubHelpers.deleteUpdateBotBranches(localRepositories);
64 | }
65 |
66 | @Test
67 | public void testUpdater() throws Exception {
68 | if (Tests.canTestWithGithubAPI(configuration)) {
69 | pushSourceChanges.run(configuration);
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/fabric8/updatebot/filter/FilterMavenTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.fabric8.updatebot.filter;
17 |
18 | import io.jenkins.updatebot.model.Dependencies;
19 | import io.jenkins.updatebot.model.GitRepositoryConfig;
20 | import io.jenkins.updatebot.model.MavenArtifactKey;
21 | import io.jenkins.updatebot.model.MavenDependencies;
22 | import io.jenkins.updatebot.model.MavenDependencyFilter;
23 | import io.jenkins.updatebot.model.RepositoryConfig;
24 | import io.fabric8.updatebot.test.Tests;
25 | import io.fabric8.utils.Filter;
26 | import org.junit.Test;
27 |
28 | import java.io.File;
29 | import java.util.List;
30 |
31 | import static org.assertj.core.api.Assertions.assertThat;
32 |
33 | /**
34 | */
35 | public class FilterMavenTest {
36 |
37 | @Test
38 | public void testIncludes() throws Exception {
39 | File config = Tests.testFile(Tests.getBasedir(), "src/test/resources/maven/filter/updatebot.yml");
40 |
41 |
42 | RepositoryConfig repositoryConfig = Tests.assertLoadProjects(config);
43 |
44 | String cloneUrl = "https://github.com/jstrachan-testing/updatebot.git";
45 | GitRepositoryConfig updateBotDetails = repositoryConfig.getRepositoryDetails(cloneUrl);
46 | assertThat(updateBotDetails).describedAs("Should have found project details from cloneUrl " + cloneUrl).isNotNull();
47 |
48 | GitRepositoryConfig repository = Tests.assertGithubRepositoryFindByName(repositoryConfig, "updatebot");
49 |
50 | Dependencies push = repository.getPush();
51 | assertThat(push).describedAs("push configuration for " + repository).isNotNull();
52 |
53 | MavenDependencies maven = push.getMaven();
54 | assertThat(maven).describedAs("maven push configuration for " + repository).isNotNull();
55 |
56 | List mavenDependencies = maven.getDependencies();
57 | assertThat(mavenDependencies).describedAs("maven dependencies push configuration for " + repository).isNotNull();
58 |
59 |
60 | assertFilterDependency(true, mavenDependencies, "org.springframework:something", "org.apache.maven:whatnot", "org.apache:cheese");
61 | assertFilterDependency(false, mavenDependencies, "cheese:edam", "org.springframework.orm:cheese");
62 | }
63 |
64 | private void assertFilterDependency(boolean expected, List dependencies, String... values) {
65 | Filter filter = MavenDependencyFilter.createFilter(dependencies);
66 | for (String value : values) {
67 | MavenArtifactKey dependency = MavenArtifactKey.fromString(value);
68 | boolean actual = filter.matches(dependency);
69 | assertThat(actual).
70 | describedAs("Dependency " + dependency + " with Filter " + filter + " from " + dependencies).
71 | isEqualTo(expected);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/fabric8/updatebot/filter/FilterOrganisationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.fabric8.updatebot.filter;
17 |
18 | import io.jenkins.updatebot.model.GithubOrganisation;
19 | import io.fabric8.utils.Filter;
20 | import org.junit.Test;
21 |
22 | import static org.assertj.core.api.Assertions.assertThat;
23 |
24 | /**
25 | */
26 | public class FilterOrganisationTest {
27 | GithubOrganisation organisation = new GithubOrganisation();
28 |
29 | @Test
30 | public void testIncludesAndExcludes() throws Exception {
31 | organisation.include("foo-*", "bar");
32 | organisation.exclude("cheese", "foo-x*");
33 |
34 | assertFilterOrganisation(true, organisation, "foo-", "foo-bar");
35 | assertFilterOrganisation(false, organisation, "cheese", "foo-x");
36 | }
37 |
38 | @Test
39 | public void testIncludeOnly() throws Exception {
40 | organisation.include("spring-boot-camel*");
41 |
42 | assertFilterOrganisation(true, organisation, "spring-boot-camel", "spring-boot-camel-xml");
43 | assertFilterOrganisation(false, organisation, "spring-boot-amq", "vertx");
44 | }
45 |
46 | private void assertFilterOrganisation(boolean expected, GithubOrganisation organisation, String... values) {
47 | Filter filter = organisation.createFilter();
48 | for (String value : values) {
49 | boolean actual = filter.matches(value);
50 | assertThat(actual).
51 | describedAs("Filter " + filter + " from includes " + organisation.getIncludes() + " excludes: " + organisation.getExcludes()).
52 | isEqualTo(expected);
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/fabric8/updatebot/test/CommandAssertions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.fabric8.updatebot.test;
17 |
18 | import io.jenkins.updatebot.Configuration;
19 | import io.jenkins.updatebot.UpdateBot;
20 | import io.jenkins.updatebot.commands.CommandSupport;
21 | import io.jenkins.updatebot.commands.CompositeCommand;
22 | import io.jenkins.updatebot.commands.PushVersionChanges;
23 | import io.jenkins.updatebot.kind.Kind;
24 |
25 | import java.util.Arrays;
26 | import java.util.List;
27 |
28 | import static org.assertj.core.api.Assertions.assertThat;
29 |
30 | /**
31 | */
32 | public class CommandAssertions {
33 |
34 | /**
35 | * Asserts we can parse the given comand arguments to a command of the given class
36 | *
37 | * @return the parsed command
38 | */
39 | public static T assertParseCommand(Class clazz, String... args) {
40 | CommandSupport command = UpdateBot.parseCommand(args, new Configuration(), false);
41 | assertThat(command).isInstanceOf(clazz);
42 | return clazz.cast(command);
43 | }
44 |
45 | /**
46 | * Asserts that the child at the given index is a {@link PushVersionChanges} command
47 | *
48 | * @return the command
49 | */
50 | public static PushVersionChanges assertChildIsPushVersionChanges(CompositeCommand commands, int index) {
51 | return assertCommandIsA(commands, index, PushVersionChanges.class);
52 | }
53 |
54 | public static T assertCommandIsA(CompositeCommand commands, int index, Class clazz) {
55 | List children = commands.getCommands();
56 | assertThat(children.size()).describedAs("command count").isGreaterThan(index);
57 | CommandSupport command = children.get(index);
58 | assertThat(command).isInstanceOf(clazz);
59 | return clazz.cast(command);
60 | }
61 |
62 | public static void assertPushVersionContext(PushVersionChanges context, Kind kind, String... arguments) {
63 | assertThat(context.getKind()).describedAs("kind").isEqualTo(kind);
64 | List argumentList = Arrays.asList(arguments);
65 | assertThat(context.getValues()).describedAs("values").isEqualTo(argumentList);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/fabric8/updatebot/test/GithubAssertions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.fabric8.updatebot.test;
17 |
18 | import io.jenkins.updatebot.github.GitHubHelpers;
19 | import io.jenkins.updatebot.github.Issues;
20 | import io.jenkins.updatebot.github.PullRequests;
21 | import org.kohsuke.github.GHIssue;
22 | import org.kohsuke.github.GHPullRequest;
23 | import org.kohsuke.github.GHRepository;
24 |
25 | import java.io.IOException;
26 | import java.util.List;
27 |
28 | import static org.assertj.core.api.Assertions.assertThat;
29 |
30 | /**
31 | */
32 | public class GithubAssertions {
33 | public static List assertOpenPullRequestCount(GHRepository repository, String label, int exepectedPullRequestCount) throws IOException {
34 | List openPullRequests = PullRequests.getOpenPullRequests(repository, label);
35 | assertThat(openPullRequests).describedAs("open github PR with label " + label + ": " + openPullRequests).hasSize(exepectedPullRequestCount);
36 | return openPullRequests;
37 | }
38 |
39 | public static List assertOpenIssueCount(GHRepository repository, String label, int expectedIssueCount) throws IOException {
40 | List openIssues = Issues.getOpenIssues(repository, label);
41 | assertThat(openIssues).describedAs("open github issues with label " + label + ": " + openIssues).hasSize(expectedIssueCount);
42 | return openIssues;
43 | }
44 |
45 | /**
46 | * Waits for the mergable state to be available on the given pull request (which can take some time due to caching)
47 | */
48 | public static void assertWaitForPullRequestMergable(GHPullRequest pullRequest, boolean expectedMergable) throws IOException {
49 | Boolean mergable = GitHubHelpers.waitForPullRequestToHaveMergable(pullRequest, 1000L, 30000L);
50 | assertThat(mergable).describedAs("Should have found a mergable for PullRequest " + pullRequest.getHtmlUrl()).isNotNull().isEqualTo(expectedMergable);
51 |
52 | assertThat(GitHubHelpers.isMergeable(pullRequest)).describedAs("should not be mergable!").isEqualTo(expectedMergable);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/fabric8/updatebot/test/MarkupAssertions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.fabric8.updatebot.test;
17 |
18 | import com.fasterxml.jackson.databind.JsonNode;
19 | import com.fasterxml.jackson.databind.node.ObjectNode;
20 |
21 | import java.util.Arrays;
22 |
23 | import static org.assertj.core.api.Assertions.assertThat;
24 |
25 | /**
26 | * Helper assertions for dealing with JSON or YAML markup
27 | */
28 | public class MarkupAssertions {
29 | public static String assertTextValue(JsonNode tree, String... paths) {
30 | JsonNode node = assertPath(tree, paths);
31 | String pathText = Arrays.asList(paths).toString();
32 |
33 | assertThat(node).describedAs("Could not find value for path " + pathText).isNotNull();
34 | assertThat(node.isTextual()).describedAs("Value of path " + pathText + " is not textual but is " + node).isTrue();
35 |
36 | return node.asText();
37 | }
38 |
39 | public static ObjectNode assertSetValue(JsonNode tree, String value, String... paths) {
40 | assertThat(paths.length).describedAs("Should have at least one path expression!").isGreaterThan(0);
41 |
42 | int objectPathLength = paths.length - 1;
43 | ObjectNode objectNode;
44 | if (paths.length > 1) {
45 | String[] objectPath = new String[objectPathLength];
46 | System.arraycopy(paths, 0, objectPath, 0, objectPathLength);
47 | objectNode = assertObjectPath(tree, objectPath);
48 | } else {
49 | objectNode = assertObjectNode(tree);
50 | }
51 | objectNode.put(paths[objectPathLength], value);
52 | return objectNode;
53 | }
54 |
55 | public static ObjectNode assertObjectNode(JsonNode node) {
56 | assertThat(node).describedAs("ObjectNode expected").isInstanceOf(ObjectNode.class);
57 | return (ObjectNode) node;
58 | }
59 |
60 | public static ObjectNode assertObjectPath(JsonNode tree, String... paths) {
61 | JsonNode node = assertPath(tree, paths);
62 | return assertObjectNode(node);
63 | }
64 |
65 | public static JsonNode assertPath(JsonNode tree, String... paths) {
66 | JsonNode node = tree;
67 | for (String path : paths) {
68 | assertThat(node.isObject()).
69 | describedAs("cannot access property " + path + " as the node is not an object " + node).
70 | isTrue();
71 |
72 | JsonNode value = node.get(path);
73 | assertThat(value).
74 | describedAs("property " + path + " should exist on " + node).
75 | isNotNull();
76 | node = value;
77 | }
78 | return node;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/jenkins/updatebot/git/GitCloneUrlParseTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package io.jenkins.updatebot.git;
18 |
19 | import org.junit.Test;
20 |
21 | import static org.assertj.core.api.Assertions.assertThat;
22 |
23 | /**
24 | */
25 | public class GitCloneUrlParseTest {
26 | @Test
27 | public void testParseGitHostOrganisation() throws Exception {
28 | assertParseGitRepositoryInfo("git://host.xz/org/repo", "host.xz", "org", "repo");
29 | assertParseGitRepositoryInfo("git://host.xz/org/repo.git", "host.xz", "org", "repo");
30 | assertParseGitRepositoryInfo("git://host.xz/org/repo.git/", "host.xz", "org", "repo");
31 | assertParseGitRepositoryInfo("git://github.com/jstrachan/npm-pipeline-test-project.git", "github.com", "jstrachan", "npm-pipeline-test-project");
32 | assertParseGitRepositoryInfo("https://github.com/fabric8io/foo.git", "github.com", "fabric8io", "foo");
33 | assertParseGitRepositoryInfo("https://github.com/fabric8io/foo", "github.com", "fabric8io", "foo");
34 | assertParseGitRepositoryInfo("git@github.com:jstrachan/npm-pipeline-test-project.git", "github.com", "jstrachan", "npm-pipeline-test-project");
35 | assertParseGitRepositoryInfo("git@github.com:bar/foo.git", "github.com", "bar", "foo");
36 | assertParseGitRepositoryInfo("git@github.com:bar/foo", "github.com", "bar", "foo");
37 | }
38 |
39 | private void assertParseGitRepositoryInfo(String uri, String host, String organsation, String name) {
40 | GitRepositoryInfo actual = GitHelper.parseGitRepositoryInfo(uri);
41 | assertThat(actual).describedAs("Should have found GitRepositoryInfo").isNotNull();
42 | assertThat(actual.getHost()).describedAs("host").isEqualTo(host);
43 | assertThat(actual.getOrganisation()).describedAs("organsation").isEqualTo(organsation);
44 | assertThat(actual.getName()).describedAs("name").isEqualTo(name);
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/jenkins/updatebot/git/RemoteUsernamePasswordTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.git;
17 |
18 | import org.junit.Test;
19 | import org.slf4j.Logger;
20 | import org.slf4j.LoggerFactory;
21 |
22 | import static org.assertj.core.api.Assertions.assertThat;
23 |
24 | public class RemoteUsernamePasswordTest {
25 | private static final transient Logger LOG = LoggerFactory.getLogger(RemoteUsernamePasswordTest.class);
26 |
27 | public static void assertRemoveGitUserNamePassword(String input, String expected) {
28 | String actual = GitHelper.removeUsernamePassword(input);
29 | LOG.debug("Transformed " + input + " => " + actual);
30 | assertThat(actual).describedAs("Removed username password from " + input).isEqualTo(expected);
31 | }
32 |
33 | @Test
34 | public void testRemoteUserPassword() throws Exception {
35 | assertRemoveGitUserNamePassword("cheese", "cheese");
36 | assertRemoveGitUserNamePassword("https://github.com/foo/bar.git", "https://github.com/foo/bar.git");
37 | assertRemoveGitUserNamePassword("https://someuser:somepassword@github.com/fabric8-updatebot/updatebot.git", "https://github.com/fabric8-updatebot/updatebot.git");
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/jenkins/updatebot/kind/docker/ReplaceDockerfileStatementTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package io.jenkins.updatebot.kind.docker;
18 |
19 | import org.junit.Test;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | import static org.assertj.core.api.Assertions.assertThat;
25 |
26 | /**
27 | */
28 | public class ReplaceDockerfileStatementTest {
29 | protected static String assertReplace(String line, String name, String value, boolean expectedAnswer, String expectedLine) {
30 | List lines = new ArrayList<>();
31 | lines.add(line);
32 | boolean answer = DockerUpdater.replaceDockerfileStatement(lines, name, value);
33 | assertThat(answer).isEqualTo(expectedAnswer);
34 | String actualLine = lines.get(0);
35 | if (answer) {
36 | assertThat(actualLine).isEqualTo(expectedLine);
37 | }
38 | return actualLine;
39 | }
40 |
41 | @Test
42 | public void testReplaceDockerStatement() throws Exception {
43 | assertReplace("FROM jenkinsxio/jx:0.0.1", "jenkinsxio/jx", "1.2.3", true, "FROM jenkinsxio/jx:1.2.3");
44 | assertReplace("FROM jenkinsxio/jx:0.0.2", "jenkinsxio/jx", "1.2.3", true, "FROM jenkinsxio/jx:1.2.3");
45 | assertReplace("ENV JX_VERSION 0.0.1", "JX_VERSION", "1.2.3", true, "ENV JX_VERSION 1.2.3");
46 | assertReplace("ENV JX_VERSION 0.0.2", "JX_VERSION", "1.2.3", true, "ENV JX_VERSION 1.2.3");
47 | assertReplace("ARG JX_VERSION=0.0.1", "JX_VERSION", "1.2.3", true, "ARG JX_VERSION=1.2.3");
48 | assertReplace("ARG JX_VERSION=0.0.2", "JX_VERSION", "1.2.3", true, "ARG JX_VERSION=1.2.3");
49 | }
50 |
51 | @Test
52 | public void testDosNotChangeOtherStatements() throws Exception {
53 | assertReplace("FROM wine/cheese:whatnot", "jenkinsxio/jx", "1.2.3", false, "FROM wine/cheese:whatnot");
54 | assertReplace("ENV CHEESE_N_WINE_VERSION 0.0.1", "JX_VERSION", "1.2.3", false, "ENV JX_VERSION 1.2.3");
55 | assertReplace("ARG CHEESE_N_WINE_VERSION=0.0.1", "JX_VERSION", "1.2.3", false, "ARG JX_VERSION=1.2.3");
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/jenkins/updatebot/kind/helm/HelmUpdaterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.kind.helm;
17 |
18 | import io.jenkins.updatebot.Configuration;
19 | import io.jenkins.updatebot.commands.CommandContext;
20 | import io.jenkins.updatebot.kind.Kind;
21 | import io.jenkins.updatebot.kind.helm.model.ChartDependency;
22 | import io.jenkins.updatebot.kind.helm.model.Requirements;
23 | import io.jenkins.updatebot.model.DependencyVersionChange;
24 | import io.jenkins.updatebot.repository.LocalRepository;
25 | import io.jenkins.updatebot.support.MarkupHelper;
26 | import io.fabric8.updatebot.test.Tests;
27 | import org.junit.Before;
28 | import org.junit.Test;
29 |
30 | import java.io.File;
31 | import java.io.IOException;
32 | import java.util.ArrayList;
33 | import java.util.List;
34 |
35 | import static org.assertj.core.api.Assertions.assertThat;
36 |
37 | /**
38 | */
39 | public class HelmUpdaterTest {
40 | protected HelmUpdater updater = new HelmUpdater();
41 | protected CommandContext parentContext;
42 | protected File testDir;
43 | protected File requirementsYaml;
44 | protected Configuration configuration = new Configuration();
45 |
46 | @Before
47 | public void init() throws Exception {
48 | testDir = Tests.copyPackageSources(getClass());
49 | parentContext = new CommandContext(LocalRepository.fromDirectory(configuration, testDir), configuration);
50 | requirementsYaml = Tests.testFile(this.testDir, HelmFiles.REQUIREMENTS_YAML);
51 | }
52 |
53 | @Test
54 | public void testUpdateDependency() throws Exception {
55 | assertUpdateHelm(requirementsYaml, "subchart2", "0.2.1");
56 | }
57 |
58 |
59 | public void assertUpdateHelm(File requirementsYaml, String name, String version) throws IOException {
60 | assertThat(this.requirementsYaml).exists().isFile();
61 |
62 | List changes = new ArrayList<>();
63 | changes.add(new DependencyVersionChange(Kind.HELM, name, version));
64 | updater.pushVersions(parentContext, changes);
65 |
66 | Requirements requirements = MarkupHelper.loadYaml(requirementsYaml, Requirements.class);
67 | ChartDependency dependency = requirements.dependency(name);
68 | assertThat(dependency).describedAs("Should find a dependency for name " + name).isNotNull();
69 | String updatedVersion = dependency.getVersion();
70 | assertThat(updatedVersion).describedAs("Dependency " + name + " version").isEqualTo(version);
71 |
72 | System.out.println("Updated file " + requirementsYaml + " " + name + " to version " + updatedVersion);
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/jenkins/updatebot/kind/jenkinsx/ReplaceJenkinsXfileStatementTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package io.jenkins.updatebot.kind.jenkinsx;
18 |
19 | import org.junit.Test;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | import static org.assertj.core.api.Assertions.assertThat;
25 |
26 | /**
27 | */
28 | public class ReplaceJenkinsXfileStatementTest {
29 | protected static String assertReplace(String line, String name, String value, boolean expectedAnswer, String expectedLine) {
30 | List lines = new ArrayList<>();
31 | lines.add(line);
32 | boolean answer = JenkinsXUpdater.replaceJenkinsXfileStatement(lines, name, value);
33 | assertThat(answer).isEqualTo(expectedAnswer);
34 | String actualLine = lines.get(0);
35 | if (answer) {
36 | assertThat(actualLine).isEqualTo(expectedLine);
37 | }
38 | return actualLine;
39 | }
40 |
41 | @Test
42 | public void testReplaceJenkinsXStatement() throws Exception {
43 | assertReplace("image: jenkinsxio/jx:0.0.1", "jenkinsxio/jx", "1.2.3", true, "image: jenkinsxio/jx:1.2.3");
44 | assertReplace("image: jenkinsxio/jx:0.0.2", "jenkinsxio/jx", "1.2.3", true, "image: jenkinsxio/jx:1.2.3");
45 | }
46 |
47 | @Test
48 | public void testDosNotChangeOtherStatements() throws Exception {
49 | assertReplace("image: wine/cheese:whatnot", "jenkinsxio/jx", "1.2.3", false, "image: wine/cheese:whatnot");
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/jenkins/updatebot/kind/make/ReplaceMakefilesStatementTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package io.jenkins.updatebot.kind.make;
18 |
19 | import org.junit.Test;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | import static org.assertj.core.api.Assertions.assertThat;
25 |
26 | /**
27 | */
28 | public class ReplaceMakefilesStatementTest {
29 | protected static String assertReplace(String line, String name, String value, boolean expectedAnswer, String expectedLine) {
30 | List lines = new ArrayList<>();
31 | lines.add(line);
32 | boolean answer = MakeUpdater.replaceMakefileStatement(lines, name, value);
33 | assertThat(answer).isEqualTo(expectedAnswer);
34 | String actualLine = lines.get(0);
35 | if (answer) {
36 | assertThat(actualLine).isEqualTo(expectedLine);
37 | }
38 | return actualLine;
39 | }
40 |
41 | @Test
42 | public void testReplaceMakeStatement() throws Exception {
43 | assertReplace("CHART_VERSION:=0.0.1", "CHART_VERSION", "1.2.3", true, "CHART_VERSION:=1.2.3");
44 | assertReplace("CHART_VERSION := 0.0.2", "CHART_VERSION", "1.2.4", true, "CHART_VERSION := 1.2.4");
45 | }
46 |
47 | @Test
48 | public void testDosNotChangeOtherStatements() throws Exception {
49 | assertReplace("cheese := whatnot", "CHART_VERSION", "1.2.3", false, "cheese := whatnot");
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/jenkins/updatebot/kind/npm/PackageJsonUpdaterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.kind.npm;
17 |
18 | import com.fasterxml.jackson.databind.JsonNode;
19 | import io.jenkins.updatebot.Configuration;
20 | import io.jenkins.updatebot.commands.CommandContext;
21 | import io.jenkins.updatebot.commands.PushVersionChangesContext;
22 | import io.jenkins.updatebot.kind.Kind;
23 | import io.jenkins.updatebot.repository.LocalRepository;
24 | import io.jenkins.updatebot.support.MarkupHelper;
25 | import io.fabric8.updatebot.test.Tests;
26 | import org.junit.Before;
27 | import org.junit.Test;
28 |
29 | import java.io.File;
30 | import java.io.IOException;
31 |
32 | import static io.fabric8.updatebot.test.MarkupAssertions.assertTextValue;
33 | import static org.assertj.core.api.Assertions.assertThat;
34 |
35 | /**
36 | */
37 | public class PackageJsonUpdaterTest {
38 | protected PackageJsonUpdater updater = new PackageJsonUpdater();
39 | protected CommandContext parentContext;
40 | protected File testDir;
41 | protected File packageJson;
42 | protected Configuration configuration = new Configuration();
43 |
44 | @Before
45 | public void init() throws Exception {
46 | testDir = Tests.copyPackageSources(getClass());
47 | parentContext = new CommandContext(LocalRepository.fromDirectory(configuration, testDir), configuration);
48 | packageJson = Tests.testFile(this.testDir, "package.json");
49 | }
50 |
51 | @Test
52 | public void testUpdateDependency() throws Exception {
53 | assertUpdatePackageJson(packageJson, "dependencies", "@angular/core", "4.3.7");
54 | }
55 |
56 | @Test
57 | public void testUpdateDevDependency() throws Exception {
58 | assertUpdatePackageJson(packageJson, "devDependencies", "@angular/compiler", "4.3.7");
59 | }
60 |
61 | public void assertUpdatePackageJson(File packageJson, String dependencyKey, String name, String version) throws IOException {
62 | PushVersionChangesContext context = parentContext.updateVersion(Kind.NPM, name, version);
63 | assertThat(updater.isApplicable(context)).
64 | describedAs("File should be applicable " + packageJson).
65 | isTrue();
66 | updater.pushVersions(context);
67 |
68 | PushVersionChangesContext.Change change = context.change(name);
69 | assertThat(change).describedAs("expected change for name " + name).isNotNull();
70 | assertThat(change.getNewValue()).isEqualTo(version);
71 |
72 | JsonNode tree = MarkupHelper.loadJson(packageJson);
73 | String updatedVersion = assertTextValue(tree, dependencyKey, name);
74 | assertThat(updatedVersion).
75 | describedAs("updated version of " + name).
76 | isEqualTo(version);
77 | System.out.println("Updated file " + packageJson + " " + dependencyKey + " " + name + " to version " + updatedVersion);
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/jenkins/updatebot/kind/plugins/PluginsUpdaterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.kind.plugins;
17 |
18 | import io.jenkins.updatebot.Configuration;
19 | import io.jenkins.updatebot.commands.CommandContext;
20 | import io.jenkins.updatebot.kind.Kind;
21 | import io.jenkins.updatebot.model.DependencyVersionChange;
22 | import io.jenkins.updatebot.repository.LocalRepository;
23 | import io.fabric8.updatebot.test.Tests;
24 | import io.fabric8.utils.IOHelpers;
25 | import org.junit.Before;
26 | import org.junit.Test;
27 |
28 | import java.io.File;
29 | import java.io.IOException;
30 | import java.util.ArrayList;
31 | import java.util.List;
32 |
33 | import static org.assertj.core.api.Assertions.assertThat;
34 |
35 | /**
36 | */
37 | public class PluginsUpdaterTest {
38 | protected PluginsUpdater updater = new PluginsUpdater();
39 | protected CommandContext parentContext;
40 | protected File testDir;
41 | protected File pluginsFile;
42 | protected Configuration configuration = new Configuration();
43 |
44 | @Before
45 | public void init() throws Exception {
46 | testDir = Tests.copyPackageSources(getClass());
47 | LocalRepository repository = LocalRepository.fromDirectory(configuration, testDir);
48 | parentContext = new CommandContext(repository, configuration);
49 | pluginsFile = Tests.testFile(this.testDir, "plugins.txt");
50 | }
51 |
52 | @Test
53 | public void testUpdateDependency() throws Exception {
54 | assertUpdatePackageJson(pluginsFile, "dependencies", "branch-api", "3.0.0");
55 | }
56 |
57 | public void assertUpdatePackageJson(File packageJson, String dependencyKey, String artifactId, String version) throws IOException {
58 | List changes = new ArrayList<>();
59 | changes.add(new DependencyVersionChange(Kind.MAVEN, PluginsUpdater.PLUGIN_DEPENDENCY_PREFIX + artifactId, version));
60 | updater.pushVersions(parentContext, changes);
61 |
62 |
63 | // lets assert that the file contains the correct line
64 | String expectedLine = artifactId + PluginsUpdater.PLUGINS_SEPARATOR + version;
65 |
66 |
67 | List lines = IOHelpers.readLines(pluginsFile);
68 | assertThat(lines).describedAs("Should have updated the plugin " + artifactId + " to " + version).contains(expectedLine);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/jenkins/updatebot/model/EnvironmentsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | import io.jenkins.updatebot.Configuration;
19 | import io.fabric8.updatebot.test.Tests;
20 | import org.junit.Test;
21 |
22 | import java.io.File;
23 | import java.util.List;
24 |
25 | import static org.assertj.core.api.Assertions.assertThat;
26 |
27 | /**
28 | */
29 | public class EnvironmentsTest {
30 | protected Configuration configuration = new Configuration();
31 | protected String sourceRepoName = "kubernetes-client";
32 |
33 | @Test
34 | public void testParseEnvironments() throws Exception {
35 | String configFile = new File(Tests.getBasedir(), "src/test/resources/helm/updatebot.yml").getPath();
36 | String workDirPath = Tests.getCleanWorkDir(getClass());
37 |
38 | configuration.setConfigFile(configFile);
39 | configuration.setWorkDir(workDirPath);
40 |
41 |
42 | RepositoryConfig repositoryConfig = configuration.loadRepositoryConfig();
43 | assertThat(repositoryConfig).describedAs("repositoryConfig").isNotNull();
44 | List environments = repositoryConfig.getEnvironments();
45 | assertThat(environments).describedAs("repositoryConfig.environments").hasSize(2);
46 | Environment env1 = environments.get(0);
47 | Environment env2 = environments.get(1);
48 | assertThat(env1).describedAs("repositoryConfig.environments[0]").isNotNull();
49 | assertThat(env1.getId()).describedAs("repositoryConfig.environments[0].id").isEqualTo("stage");
50 | assertThat(env1.getName()).describedAs("repositoryConfig.environments[0].name").isEqualTo("Staging");
51 | assertThat(env1.getGithub()).describedAs("repositoryConfig.environments[0].github").isEqualTo("jstrachan/test-env-stage");
52 | assertThat(env2.getId()).describedAs("repositoryConfig.environments[1].id").isEqualTo("prod");
53 | assertThat(env2.getName()).describedAs("repositoryConfig.environments[1].name").isEqualTo("Production");
54 | assertThat(env2.getGithub()).describedAs("repositoryConfig.environments[1].github").isEqualTo("jstrachan/test-env-prod");
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/java/io/jenkins/updatebot/model/LoadGithubOrgConfigTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.jenkins.updatebot.model;
17 |
18 | import io.jenkins.updatebot.Configuration;
19 | import org.junit.Test;
20 | import org.slf4j.Logger;
21 | import org.slf4j.LoggerFactory;
22 |
23 | import java.io.IOException;
24 |
25 | import static org.assertj.core.api.Assertions.assertThat;
26 |
27 | /**
28 | */
29 | public class LoadGithubOrgConfigTest {
30 | private static final transient Logger LOG = LoggerFactory.getLogger(LoadGithubOrgConfigTest.class);
31 |
32 | Configuration configuration = new Configuration();
33 |
34 | @Test
35 | public void testLoadConfigFromGithubOrganisation() throws Exception {
36 | String gitUrl = "git@github.com:jstrachan-testing/doesNotExist.git";
37 | RepositoryConfig config = loadConfigFromGithubOrg(gitUrl);
38 | assertThat(config).
39 | describedAs("Should have found an UpdateBot YAML at the jstrachan-testing-updatebot-config repo from git url " + gitUrl).isNotNull();
40 | }
41 |
42 | protected RepositoryConfig loadConfigFromGithubOrg(String gitUrl) throws IOException {
43 | RepositoryConfig config = RepositoryConfigs.loadGithubOrganisationConfig(configuration, gitUrl);
44 | LOG.info("git url " + gitUrl + " found " + config);
45 | return config;
46 | }
47 |
48 |
49 | @Test
50 | public void testCannotLoadConfigurationFromOrgansisationWithoutUpdateBotRepo() throws Exception {
51 | String gitUrl = "git@github.com:jstrachan/cheese.git";
52 | RepositoryConfig config = loadConfigFromGithubOrg(gitUrl);
53 | assertThat(config).
54 | describedAs("Should not have found an UpdateBot YAML at the jstrachan-updatebot-config repo from git url " + gitUrl).isNull();
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/brew/source/updatebot.yml:
--------------------------------------------------------------------------------
1 | github:
2 | organisations:
3 | - name: jstrachan
4 | repositories:
5 | - name: homebrew-jx
6 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/helm/updatebot.yml:
--------------------------------------------------------------------------------
1 | environments:
2 | - id: stage
3 | name: Staging
4 | github: jstrachan/test-env-stage
5 | - id: prod
6 | name: Production
7 | github: jstrachan/test-env-prod
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/io/jenkins/updatebot/kind/helm/Chart.yaml:
--------------------------------------------------------------------------------
1 | name: cheese
2 | version: 1.0.1
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/io/jenkins/updatebot/kind/helm/requirements.yaml:
--------------------------------------------------------------------------------
1 | dependencies:
2 | - name: subchart1
3 | repository: http://localhost:10191
4 | version: 0.1.0
5 | condition: subchart1.enabled, global.subchart1.enabled
6 | tags:
7 | - front-end
8 | - subchart1
9 |
10 | - name: subchart2
11 | repository: http://localhost:10191
12 | version: 0.1.0
13 | condition: subchart2.enabled,global.subchart2.enabled
14 | tags:
15 | - back-end
16 | - subchart1
17 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/io/jenkins/updatebot/kind/maven/pom-with-parent.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
21 |
22 | 4.0.0
23 |
24 |
25 | io.jenkins.updatebot
26 | test-parent
27 | 0.1.0
28 |
29 |
30 | child-pom
31 |
32 | Child example pom
33 | Just a simple child project waiting to be updated, when the parent is updated
34 |
35 |
36 |
37 | io.jenkins.updatebot
38 | test-parent
39 | 0.1.0
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/io/jenkins/updatebot/kind/plugins/.updatebot.yml:
--------------------------------------------------------------------------------
1 | local:
2 | push:
3 | plugins:
4 | includes:
5 | - plugins.txt
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/io/jenkins/updatebot/kind/plugins/plugins.txt:
--------------------------------------------------------------------------------
1 | ace-editor:1.1
2 | async-http-client:1.7.8
3 | ant:1.5
4 | antisamy-markup-formatter:1.5
5 | authentication-tokens:1.3
6 | blueocean-autofavorite:1.0.0
7 | blueocean-commons:1.1.6
8 | blueocean-config:1.1.6
9 | blueocean-dashboard:1.1.6
10 | blueocean-display-url:2.0
11 | blueocean-events:1.1.6
12 | blueocean-git-pipeline:1.1.6
13 | blueocean-github-pipeline:1.1.6
14 | blueocean-i18n:1.1.6
15 | blueocean-jwt:1.1.6
16 | blueocean-personalization:1.1.6
17 | blueocean-pipeline-api-impl:1.1.6
18 | blueocean-pipeline-editor:0.2.0
19 | blueocean-pipeline-scm-api:1.1.6
20 | blueocean-rest-impl:1.1.6
21 | blueocean-rest:1.1.6
22 | blueocean-web:1.1.6
23 | blueocean:1.1.6
24 | bouncycastle-api:2.16.1
25 | branch-api:2.0.11
26 | build-timeout:1.18
27 | cloudbees-folder:6.1.2
28 | credentials-binding:1.13
29 | credentials:2.1.14
30 | display-url-api:2.0
31 | docker-commons:1.8
32 | docker-workflow:1.12
33 | dockerhub-notification:2.2.0
34 | durable-task:1.14
35 | email-ext:2.58
36 | embeddable-build-status:1.9
37 | external-monitor-job:1.7
38 | favorite:2.3.0
39 | ghprb:1.39.0
40 | git-client:2.5.0
41 | git-server:1.7
42 | git:3.5.1
43 | github-api:1.86
44 | github-branch-source:2.2.3
45 | github-issues:1.2.2
46 | github-oauth:0.27
47 | github-organization-folder:1.6
48 | github-pr-coverage-status:1.8.1
49 | github-pullrequest:0.1.0-rc24
50 | github:1.28.0
51 | gitlab-merge-request-jenkins:2.0.0
52 | gitlab-oauth:1.0.9
53 | gitlab-plugin:1.4.6
54 | google-login:1.3
55 | gradle:1.27.1
56 | gravatar:2.1
57 | handlebars:1.1.1
58 | #hubot-steps:1.1.0
59 | icon-shim:2.0.3
60 | jackson2-api:2.7.3
61 | jquery-detached:1.2.1
62 | junit:1.21
63 | kerberos-sso:1.3
64 | kubernetes:0.11
65 | ldap:1.16
66 | mailer:1.20
67 | mapdb-api:1.0.9.0
68 | mask-passwords:2.10.1
69 | matrix-auth:1.7
70 | matrix-project:1.11
71 | mercurial:1.61
72 | metrics:3.1.2.10
73 | momentjs:1.1.1
74 | multiple-scms:0.6
75 | nodejs:1.2.4
76 | oauth-credentials:0.3
77 | oic-auth:1.0
78 | openid:2.2
79 | openid4java:0.9.8.0
80 | openshift-client:0.9.6
81 | openshift-login:0.12
82 | openshift-pipeline:1.0.47
83 | openshift-sync:0.1.23
84 | pam-auth:1.3
85 | pipeline-build-step:2.5.1
86 | pipeline-github-lib:1.0
87 | pipeline-githubnotify-step:1.0.2
88 | pipeline-graph-analysis:1.4
89 | pipeline-input-step:2.8
90 | pipeline-milestone-step:1.3.1
91 | pipeline-model-api:1.1.9
92 | pipeline-model-declarative-agent:1.1.1
93 | pipeline-model-definition:1.1.9
94 | pipeline-model-extensions:1.1.9
95 | pipeline-rest-api:2.8
96 | pipeline-stage-step:2.2
97 | pipeline-stage-tags-metadata:1.1.9
98 | pipeline-stage-view:2.8
99 | pipeline-utility-steps:1.3.0
100 | plain-credentials:1.4
101 | pubsub-light:1.10
102 | resource-disposer:0.6
103 | scm-api:2.2.0
104 | script-security:1.31
105 | sse-gateway:1.15
106 | ssh-agent:1.15
107 | ssh-credentials:1.13
108 | ssh-slaves:1.20
109 | structs:1.10
110 | subversion:2.9
111 | timestamper:1.8.8
112 | token-macro:2.1
113 | url-auth-sso:1.0
114 | variant:1.1
115 | windows-slaves:1.3.1
116 | workflow-aggregator:2.5
117 | workflow-api:2.20
118 | workflow-basic-steps:2.6
119 | workflow-cps-global-lib:2.8
120 | workflow-cps:2.39
121 | workflow-durable-task-step:2.13
122 | workflow-job:2.14.1
123 | workflow-multibranch:2.16
124 | workflow-remote-loader:1.4
125 | workflow-scm-step:2.6
126 | workflow-step-api:2.12
127 | workflow-support:2.14
128 | ws-cleanup:0.33
129 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/maven/branch/updatebot-develop.yml:
--------------------------------------------------------------------------------
1 | github:
2 | organisations:
3 | - name: jstrachan-testing
4 | repositories:
5 | - name: updatebot
6 | branch: develop
7 | push:
8 | maven:
9 | dependencies:
10 | - groupInclude: org.apache*
11 | - groupInclude: org.springframework
12 | - artifactInclude: foo-bar
13 |
14 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/maven/branch/updatebot-master.yml:
--------------------------------------------------------------------------------
1 | github:
2 | organisations:
3 | - name: jstrachan-testing
4 | repositories:
5 | - name: updatebot
6 | push:
7 | maven:
8 | dependencies:
9 | - groupInclude: org.apache*
10 | - groupInclude: org.springframework
11 | - artifactInclude: foo-bar
12 |
13 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/maven/filter/updatebot.yml:
--------------------------------------------------------------------------------
1 | github:
2 | organisations:
3 | - name: jstrachan-testing
4 | repositories:
5 | - name: updatebot
6 | push:
7 | maven:
8 | dependencies:
9 | - groupInclude: org.apache*
10 | - groupInclude: org.springframework
11 | - artifactInclude: foo-bar
12 |
13 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/maven/source/updatebot.yml:
--------------------------------------------------------------------------------
1 | github:
2 | organisations:
3 | - name: jstrachan-testing
4 | repositories:
5 | - name: kubernetes-client
6 | - name: fabric8
7 | - name: fabric8-maven-plugin
8 | useSinglePullRequest: true
9 |
10 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/maven/source/updatebot2.yml:
--------------------------------------------------------------------------------
1 | github:
2 | organisations:
3 | - name: jstrachan
4 | repositories:
5 | - name: updatebot
6 | - name: updatebot-plugin
7 |
8 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/maven/updatebot.yml:
--------------------------------------------------------------------------------
1 | git:
2 | - name: fabric8-quickstarts/spring-boot-webmvc
3 | cloneUrl: git@github.com:fabric8-quickstarts/spring-boot-webmvc.git
4 | github:
5 | organisations:
6 | - name: fabric8-quickstarts
7 | includes:
8 | - spring-boot-camel-xml*
9 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/npm/join/updatebot.yml:
--------------------------------------------------------------------------------
1 | github:
2 | organisations:
3 | - name: jstrachan-testing
4 | repositories:
5 | - name: ngx-base
6 | - name: ngx-widgets
7 | - name: ngx-fabric8-wit
8 | - name: ngx-login-client
9 | - name: fabric8-planner
10 |
11 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/npm/push/updatebot.yml:
--------------------------------------------------------------------------------
1 | github:
2 | organisations:
3 | - name: jstrachan
4 | includes:
5 | - npm-pipeline-test-project
6 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/npm/source/updatebot.yml:
--------------------------------------------------------------------------------
1 | github:
2 | organisations:
3 | - name: jstrachan-testing
4 | repositories:
5 | - name: ngx-base
6 | push:
7 | npm:
8 | dependencies:
9 | includes:
10 | - "*"
11 | devDependencies:
12 | includes:
13 | - "*"
14 | - name: ngx-login-client
15 |
16 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/npm/updatebot.yml:
--------------------------------------------------------------------------------
1 | github:
2 | organisations:
3 | - name: fabric8-ui
4 | includes:
5 | - ngx*
6 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/plugins/source/updatebot.yml:
--------------------------------------------------------------------------------
1 | github:
2 | organisations:
3 | - name: jstrachan
4 | repositories:
5 | - name: jenkins-x-image
6 |
--------------------------------------------------------------------------------
/updatebot-core/src/test/resources/regex/.updatebot.yml:
--------------------------------------------------------------------------------
1 | github:
2 | organisations:
3 | - name: jstrachan
4 | repositories:
5 | - name: test-updatebot-jx-docs
6 |
--------------------------------------------------------------------------------
/updatebot-logging/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
21 | 4.0.0
22 |
23 | io.jenkins.updatebot
24 | parent
25 | 1.1-SNAPSHOT
26 |
27 |
28 | updatebot-logging
29 | jar
30 | updatebot :: logging
31 | 1.1-SNAPSHOT
32 |
33 |
34 |
35 |
36 | org.slf4j
37 | slf4j-simple
38 | ${slf4j-api.version}
39 |
40 |
41 |
42 |
43 |
44 | org.assertj
45 | assertj-core
46 | test
47 |
48 |
49 | junit
50 | junit
51 | test
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/updatebot-logging/src/main/java/org/slf4j/impl/PrintStreamHolder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.slf4j.impl;
18 |
19 | import java.io.PrintStream;
20 |
21 | /**
22 | */
23 | public class PrintStreamHolder {
24 | private static ThreadLocal threadLocal = new ThreadLocal<>();
25 | private static PrintStream defaultPrintStream = System.out;
26 |
27 | public static PrintStream getPrintStream() {
28 | PrintStream printStream = threadLocal.get();
29 | if (printStream == null) {
30 | System.out.println("PrintStreamHolder: No PrintStream on thread " + Thread.currentThread() + " so using default");
31 | printStream = defaultPrintStream;
32 | }
33 | return printStream;
34 | }
35 |
36 | public static void setPrintStream(PrintStream out) {
37 | if (out != null) {
38 | threadLocal.set(out);
39 | defaultPrintStream = out;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/updatebot-logging/src/main/java/org/slf4j/impl/UpdateBotLogConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package org.slf4j.impl;
17 |
18 | import java.io.PrintStream;
19 |
20 | /**
21 | * Replaces the simple logging configuration with a custom stream
22 | */
23 | public class UpdateBotLogConfiguration extends SimpleLoggerConfiguration {
24 | public UpdateBotLogConfiguration(PrintStream out) {
25 | PrintStreamHolder.setPrintStream(out);
26 | }
27 |
28 | public void init() {
29 | // lets set the initialised flag so we don't get replaced later on
30 | SimpleLogger.lazyInit();
31 | SimpleLogger.CONFIG_PARAMS = this;
32 | super.init();
33 | this.outputChoice = new OutputChoice(OutputChoice.OutputChoiceType.CACHED_SYS_ERR) {
34 | @Override
35 | PrintStream getTargetPrintStream() {
36 | return PrintStreamHolder.getPrintStream();
37 |
38 | }
39 | };
40 | this.showThreadName = false;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/updatebot-maven-plugin/src/main/java/io/fabric8/updatebot/maven/EnsurePluginVersionMojo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.fabric8.updatebot.maven;
17 |
18 | import io.jenkins.updatebot.kind.maven.PomUpdateStatus;
19 | import io.jenkins.updatebot.model.MavenArtifactKey;
20 | import org.apache.maven.model.Plugin;
21 | import org.apache.maven.plugin.AbstractMojo;
22 | import org.apache.maven.plugin.MojoExecutionException;
23 | import org.apache.maven.plugin.MojoFailureException;
24 | import org.apache.maven.plugin.logging.Log;
25 | import org.apache.maven.plugins.annotations.Mojo;
26 | import org.apache.maven.plugins.annotations.Parameter;
27 | import org.apache.maven.plugins.annotations.ResolutionScope;
28 | import org.apache.maven.project.MavenProject;
29 |
30 | import java.io.File;
31 | import java.io.IOException;
32 | import java.util.Map;
33 |
34 | /**
35 | * Ensures the given maven plugin version is of the given minimum version, modifying it if required
36 | */
37 | @Mojo(name = "plugin", aggregator = true, requiresProject = true,
38 | requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
39 | public class EnsurePluginVersionMojo extends AbstractMojo {
40 |
41 | @Parameter(defaultValue = "${project}", readonly = true)
42 | protected MavenProject project;
43 |
44 | @Parameter(property = "group", defaultValue = MavenArtifactKey.DEFAULT_MAVEN_PLUGIN_GROUP)
45 | protected String group;
46 |
47 | @Parameter(property = "artifact", required = true)
48 | protected String artifact;
49 |
50 | @Parameter(property = "version", required = true)
51 | protected String version;
52 |
53 | @Parameter(property = "pomFile", defaultValue = "${basedir}/pom.xml")
54 | protected File pomFile;
55 |
56 |
57 | @Override
58 | public void execute() throws MojoExecutionException, MojoFailureException {
59 | Log log = getLog();
60 | if (project == null) {
61 | throw new MojoExecutionException("No Project available!");
62 | }
63 | Map map = project.getBuild().getPluginsAsMap();
64 | String key = group + ":" + artifact;
65 | Plugin plugin = map.get(key);
66 | PomUpdateStatus status;
67 | try {
68 | status = PomUpdateStatus.createPomUpdateStatus(pomFile);
69 | } catch (IOException e) {
70 | throw new MojoExecutionException("Failed to parse pom.xml: " + e, e);
71 | }
72 | status.updatePluginVersion(key, version, true);
73 | if (status.isUpdated()) {
74 | try {
75 | status.saveIfChanged();
76 |
77 | log.info("Modified pom setting plugin " + key + " to version " + version);
78 | } catch (IOException e) {
79 | throw new MojoExecutionException("Failed to save pom.xml: " + e, e);
80 | }
81 | } else {
82 | log.info("No need to modify the pom.xml as the plugin " + key + " is on version: " + plugin.getVersion());
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/updatebot-maven-plugin/src/main/java/io/fabric8/updatebot/maven/health/AbstractHealthCheckEnricher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.fabric8.updatebot.maven.health;
17 |
18 | import org.apache.maven.project.MavenProject;
19 |
20 | /**
21 | */
22 | public abstract class AbstractHealthCheckEnricher {
23 | private final MavenProject project;
24 |
25 | protected AbstractHealthCheckEnricher(MavenProject project) {
26 | this.project = project;
27 | }
28 |
29 | public MavenProject getProject() {
30 | return project;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/updatebot-maven-plugin/src/main/java/io/fabric8/updatebot/maven/support/MavenHelper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version
5 | * 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 | * implied. See the License for the specific language governing
14 | * permissions and limitations under the License.
15 | */
16 | package io.fabric8.updatebot.maven.support;
17 |
18 | import io.jenkins.updatebot.model.MavenArtifactKey;
19 | import org.apache.maven.model.Dependency;
20 | import org.apache.maven.project.MavenProject;
21 |
22 | /**
23 | */
24 | public class MavenHelper {
25 | public static MavenArtifactKey toMavenDependency(Dependency dependency) {
26 | return new MavenArtifactKey(dependency.getGroupId(), dependency.getArtifactId());
27 | }
28 |
29 | public static MavenArtifactKey toMavenDependency(MavenProject parent) {
30 | return new MavenArtifactKey(parent.getGroupId(), parent.getArtifactId());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/updatebot-maven-plugin/src/test/resources/testcases/testcase-deploy-plugin-exists/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | io.jenkins.updatebot.testcases
6 | testcase-deploy-plugin-exists
7 | 1.0.0-SNAPSHOT
8 |
9 |
10 |
11 | maven-deploy-plugin
12 | 2.8.2
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/updatebot/src/main/resources/run.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | exec java -jar $0 "$@"
4 |
--------------------------------------------------------------------------------