Java Code Examples for io.fabric8.utils.Objects#equal()

The following examples show how to use io.fabric8.utils.Objects#equal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MavenHelpers.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public static MavenPlugin findPlugin(Project project, String groupId, String artifactId) {
    if (project != null) {
        MavenPluginFacet pluginFacet = project.getFacet(MavenPluginFacet.class);
        if (pluginFacet != null) {
            List<MavenPlugin> plugins = pluginFacet.listConfiguredPlugins();
            if (plugins != null) {
                for (MavenPlugin plugin : plugins) {
                    Coordinate coordinate = plugin.getCoordinate();
                    if (coordinate != null) {
                        if (Objects.equal(groupId, coordinate.getGroupId()) &&
                                Objects.equal(artifactId, coordinate.getArtifactId())) {
                            return plugin;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 2
Source File: CamelXmlHelper.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public static Node findCamelNodeInDocument(Document root, String key) {
    Node selectedNode = null;
    if (root != null && Strings.isNotBlank(key)) {
        String[] paths = key.split("/");
        NodeList camels = getCamelContextElements(root);
        if (camels != null) {
            Map<String, Integer> rootNodeCounts = new HashMap<>();
            for (int i = 0, size = camels.getLength(); i < size; i++) {
                Node node = camels.item(i);
                boolean first = true;
                for (String path : paths) {
                    if (first) {
                        first = false;
                        String actual = getIdOrIndex(node, rootNodeCounts);
                        if (!Objects.equal(actual, path)) {
                            node = null;
                        }
                    } else {
                        node = findCamelNodeForPath(node, path);
                    }
                    if (node == null) {
                        break;
                    }
                }
                if (node != null) {
                    return node;
                }
            }
        }
    }
    return selectedNode;
}
 
Example 3
Source File: PomHelperTest.java    From updatebot with Apache License 2.0 5 votes vote down vote up
protected static void assertChangesValid(File file, Document doc, List<DependencyVersionChange> changes) {
    for (DependencyVersionChange change : changes) {
        if (Objects.equal(MavenScopes.PLUGIN, change.getScope())) {
            assertPluginVersionChanged(file, doc, change);
        } else {
            assertDependencyVersionChanged(file, doc, change);
        }
    }
}
 
Example 4
Source File: DependencyInfo.java    From updatebot with Apache License 2.0 5 votes vote down vote up
private String conflictedDependencyText() {
    List<String> messages = new ArrayList<>();
    for (Map.Entry<String, List<DependencyLink>> entry : versions.entrySet()) {
        String key = entry.getKey();
        if (!Objects.equal(version, key)) {
            List<DependencyLink> dependencies = entry.getValue();
            String dependencyNames = dependencies.stream().map(link -> link.getParent().toString()).collect(Collectors.joining(", "));
            messages.add(dependencyNames + " => " + key);
        }
    }
    return String.join(", ", messages);
}
 
Example 5
Source File: PackageJsonUpdater.java    From updatebot with Apache License 2.0 5 votes vote down vote up
protected boolean doPushVersionChange(String dependencyKey, ObjectNode dependencies, PushVersionChangesContext context) {
    String name = context.getName();
    String value = context.getValue();
    JsonNode dependency = dependencies.get(name);
    if (dependency != null && dependency.isTextual()) {
        String old = dependency.textValue();
        if (!Objects.equal(old, value)) {
            dependencies.put(name, value);
            context.updatedVersion(dependencyKey, name, value, old);
            return true;
        }
    }
    return false;
}
 
Example 6
Source File: MavenHelpers.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the maven plugin for the given artifact id or returns null if it cannot be found
 */
public static Plugin findPlugin(List<Plugin> plugins, String artifactId) {
    if (plugins != null) {
        for (Plugin plugin : plugins) {
            String groupId = plugin.getGroupId();
            if (Strings.isNullOrBlank(groupId) || Objects.equal(groupId, mavenPluginsGroupId)) {
                if (Objects.equal(artifactId, plugin.getArtifactId())) {
                    return plugin;
                }
            }
        }
    }
    return null;
}
 
Example 7
Source File: DecentXmlHelper.java    From updatebot with Apache License 2.0 5 votes vote down vote up
public static List<Element> findElementsWithName(Element rootElement, String elementName) {
    List<Element> answer = new ArrayList<>();
    List<Element> children = rootElement.getChildren();
    for (Element child : children) {
        if (Objects.equal(elementName, child.getName())) {
            answer.add(child);
        } else {
            answer.addAll(findElementsWithName(child, elementName));
        }
    }
    return answer;
}
 
Example 8
Source File: Strings.java    From updatebot with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the actual value matches any of the String representations of the given values.
 * <p>
 * So can match against String or URL objects etc
 */
public static boolean equalAnyValue(String actual, Iterable<?> values) {
    for (Object value : values) {
        if (value != null) {
            String text = value.toString();
            if (Objects.equal(text, actual)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 9
Source File: MavenHelpers.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the profile for the given id or null if it could not be found
 */
public static Profile findProfile(Model mavenModel, String profileId) {
    List<Profile> profiles = mavenModel.getProfiles();
    if (profiles != null) {
        for (Profile profile : profiles) {
            if (Objects.equal(profile.getId(), profileId)) {
                return profile;
            }
        }
    }
    return null;
}
 
Example 10
Source File: MavenHelpers.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the given maven property value if value is not null and returns true if the pom has been changed
 *
 * @return true if the value changed and was non null or updated was true
 */
public static boolean updatePomProperty(Properties properties, String name, Object value, boolean updated) {
    if (value != null) {
        Object oldValue = properties.get(name);
        if (!Objects.equal(oldValue, value)) {
            getLOG().debug("Updating pom.xml property: " + name + " to " + value);
            properties.put(name, value);
            return true;
        }
    }
    return updated;

}
 
Example 11
Source File: GitHubProjects.java    From updatebot with Apache License 2.0 5 votes vote down vote up
public GithubOrganisation findOrganisation(String name) {
    if (organisations != null) {
        for (GithubOrganisation organisation : organisations) {
            if (Objects.equal(name, organisation.getName())) {
                return organisation;
            }
        }
    }
    return null;
}
 
Example 12
Source File: UpdatePullRequests.java    From updatebot with Apache License 2.0 5 votes vote down vote up
private String updateBotCommentCommand(CommandContext context, GHIssueComment comment) throws IOException {
    GHUser user = comment.getUser();
    if (user != null) {
        if (Objects.equal(context.getConfiguration().getGithubUsername(), user.getLogin())) {
            String body = comment.getBody();
            if (body != null) {
                body = body.trim();
                if (body.startsWith(PullRequests.COMMAND_COMMENT_PREFIX)) {
                    return body;
                }
            }
        }
    }
    return null;
}
 
Example 13
Source File: GithubOrganisation.java    From updatebot with Apache License 2.0 5 votes vote down vote up
public GitRepositoryConfig findRepository(String name) {
    for (GitRepositoryConfig repository : repositories) {
        if (Objects.equal(name, repository.getName())) {
            return repository;
        }
    }
    return null;
}
 
Example 14
Source File: LocalRepository.java    From updatebot with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the repository for the given name or null if it could not be found
 */
public static LocalRepository findRepository(List<LocalRepository> localRepositories, String name) {
    if (localRepositories != null) {
        for (LocalRepository repository : localRepositories) {
            GitRepository repo = repository.getRepo();
            if (repo != null) {
                if (Objects.equal(name, repo.getName())) {
                    return repository;
                }
            }
        }
    }
    return null;
}
 
Example 15
Source File: Issues.java    From updatebot with Apache License 2.0 5 votes vote down vote up
public static String updateBotIssuePendingChangesComment(CommandContext context, GHIssueComment comment) throws IOException {
    GHUser user = comment.getUser();
    if (user != null) {
        if (Objects.equal(context.getConfiguration().getGithubUsername(), user.getLogin())) {
            String body = comment.getBody();
            if (body != null) {
                body = body.trim();
                if (body.startsWith(PENDING_CHANGE_COMMENT_PREFIX)) {
                    return body;
                }
            }
        }
    }
    return null;
}
 
Example 16
Source File: GitHubHelpers.java    From updatebot with Apache License 2.0 5 votes vote down vote up
public static boolean hasLabel(Collection<GHLabel> labels, String label) {
    if (labels != null) {
        for (GHLabel ghLabel : labels) {
            if (Objects.equal(label, ghLabel.getName())) {
                return true;
            }
        }
    }
    return false;
}
 
Example 17
Source File: DependencyVersionChange.java    From updatebot with Apache License 2.0 4 votes vote down vote up
/**
 * Returns true if this change matches the given artifact key
 */
public boolean matches(MavenArtifactKey artifactKey) {
    return Objects.equal(this.dependency, artifactKey.toString());
}
 
Example 18
Source File: DependencyVersionChange.java    From updatebot with Apache License 2.0 4 votes vote down vote up
/**
 * Returns true if the given change is for the same kind and dependency
 */
public boolean matches(DependencyVersionChange that) {
    return Objects.equal(this.kind, that.kind) && Objects.equal(this.dependency, that.dependency);
}
 
Example 19
Source File: ArchetypeBuilder.java    From ipaas-quickstarts with Apache License 2.0 4 votes vote down vote up
protected File generatePomIfRequired(File archetypeDir, String originalName, String originalDescription) throws IOException {
    File archetypeProjectPom = new File(archetypeDir, "pom.xml");
    // now generate Archetype's pom
    if (!archetypeProjectPom.exists()) {
        StringWriter sw = new StringWriter();
        IOHelpers.copy(new InputStreamReader(getClass().getResourceAsStream("default-archetype-pom.xml")), sw);
        Document pomDocument = archetypeUtils.parseXml(new InputSource(new StringReader(sw.toString())));

        List<String> emptyList = Collections.emptyList();

        // lets replace the parent pom's version
        String projectVersion = System.getProperty("project.version");
        if (Strings.isNotBlank(projectVersion)) {
            Element parent = DomHelper.firstChild(pomDocument.getDocumentElement(), "parent");
            if (parent != null) {
                Element version = DomHelper.firstChild(parent, "version");
                if (version != null) {
                    if (!Objects.equal(version.getTextContent(), projectVersion)) {
                        version.setTextContent(projectVersion);
                    }
                }
            }
        }


        // artifactId = original artifactId with "-archetype"
        Element artifactId = replaceOrAddElement(pomDocument, pomDocument.getDocumentElement(), "artifactId", emptyList);
        artifactId.setTextContent(archetypeDir.getName());

        // name = "Fabric8 :: Qickstarts :: xxx" -> "Fabric8 :: Archetypes :: xxx"
        Element name = replaceOrAddElement(pomDocument, pomDocument.getDocumentElement(), "name", emptyList);
        if (originalName.contains(" :: ")) {
            String[] originalNameTab = originalName.split(" :: ");
            if (originalNameTab.length > 2) {
                StringBuilder sb = new StringBuilder();
                sb.append("Fabric8 :: Archetypes");
                for (int idx = 2; idx < originalNameTab.length; idx++) {
                    sb.append(" :: ").append(originalNameTab[idx]);
                }
                name.setTextContent(sb.toString());
            } else {
                name.setTextContent("Fabric8 :: Archetypes :: " + originalNameTab[1]);
            }
        } else {
            name.setTextContent("Fabric8 :: Archetypes :: " + originalName);
        }

        // description = "Creates a new " + originalDescription
        Element description = replaceOrAddElement(pomDocument, pomDocument.getDocumentElement(), "description", emptyList);
        description.setTextContent("Creates a new " + originalDescription);

        archetypeUtils.writeXmlDocument(pomDocument, archetypeProjectPom);
    }
    return archetypeProjectPom;
}
 
Example 20
Source File: StatusInfo.java    From updatebot with Apache License 2.0 4 votes vote down vote up
/**
 * Returns true if this and that object have the same underlying status
 */
public boolean equalStatus(StatusInfo that) {
    return Objects.equal(this.status, that.status) &&
            Objects.equal(this.issueState, that.issueState) &&
            Objects.equal(this.pullRequestState, that.pullRequestState);
}