io.fabric8.utils.Objects Java Examples

The following examples show how to use io.fabric8.utils.Objects. 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: ArchetypeBuilder.java    From ipaas-quickstarts with Apache License 2.0 6 votes vote down vote up
/**
 * Iterates through all projects in the given github organisation and generates an archetype for it
 */
public void generateArchetypesFromGithubOrganisation(String githubOrg, File outputDir, List<String> dirs) throws IOException {
    GitHub github = GitHub.connectAnonymously();
    GHOrganization organization = github.getOrganization(githubOrg);
    Objects.notNull(organization, "No github organisation found for: " + githubOrg);
    Map<String, GHRepository> repositories = organization.getRepositories();
    Set<Map.Entry<String, GHRepository>> entries = repositories.entrySet();

    File cloneParentDir = new File(outputDir, "../git-clones");
    if (cloneParentDir.exists()) {
        Files.recursiveDelete(cloneParentDir);
    }
    for (Map.Entry<String, GHRepository> entry : entries) {
        String repoName = entry.getKey();
        GHRepository repo = entry.getValue();
        String url = repo.getGitTransportUrl();

        generateArchetypeFromGitRepo(outputDir, dirs, cloneParentDir, repoName, url, null);
    }
}
 
Example #3
Source File: NewIntegrationTestBuildCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    String buildConfigName = buildName.getValue();
    Objects.assertNotNull(buildConfigName, "buildName");
    Map<String, String> labels = BuildConfigs.createBuildLabels(buildConfigName);
    String gitUrlText = getOrFindGitUrl(context, gitUri.getValue());
    String imageText = image.getValue();
    List<EnvVar> envVars = createEnvVars(buildConfigName, gitUrlText, mavenCommand.getValue());
    BuildConfig buildConfig = BuildConfigs.createIntegrationTestBuildConfig(buildConfigName, labels, gitUrlText, imageText, envVars);

    LOG.info("Generated BuildConfig: " + toJson(buildConfig));

    ImageStream imageRepository = BuildConfigs.imageRepository(buildConfigName, labels);

    Controller controller = createController();
    controller.applyImageStream(imageRepository, "generated ImageStream: " + toJson(imageRepository));
    controller.applyBuildConfig(buildConfig, "generated BuildConfig: " + toJson(buildConfig));
    return Results.success("Added BuildConfig: " + Builds.getName(buildConfig) + " to OpenShift at master: " + getKubernetes().getMasterUrl());
}
 
Example #4
Source File: CamelXmlHelper.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
protected static Node findCamelNodeForPath(Node node, String path) {
    NodeList childNodes = node.getChildNodes();
    if (childNodes != null) {
        Map<String, Integer> nodeCounts = new HashMap<>();
        for (int i = 0, size = childNodes.getLength(); i < size; i++) {
            Node child = childNodes.item(i);
            if (child instanceof Element) {
                String actual = getIdOrIndex(child, nodeCounts);
                if (Objects.equal(actual, path)) {
                    return child;
                }
            }
        }
    }
    return null;
}
 
Example #5
Source File: PomUpdateStatus.java    From updatebot with Apache License 2.0 6 votes vote down vote up
public void updateVersions(List<DependencyVersionChange> changes, Map<String, String> propertyChanges) {
    for (DependencyVersionChange change : changes) {
        String scope = change.getScope();
        boolean lazyAdd = shouldLazyAdd(change);
        if (Objects.equal(MavenScopes.PLUGIN, scope)) {
            if (PomHelper.updatePluginVersion(doc, change, propertyChanges, lazyAdd)) {
                updated = true;
            }
        } else {
            if (PomHelper.updateDependencyVersion(doc, change, propertyChanges)) {
                updated = true;
            }
            // TODO check for BOM / Parent change too!
        }
    }
}
 
Example #6
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 #7
Source File: NodeDtos.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public static NodeDto findNodeByKey(Iterable<? extends NodeDto> nodes, String key) {
    if (nodes != null) {
        for (NodeDto node : nodes) {
            if (Objects.equal(node.getKey(), key)) {
                return node;
            }
            NodeDto answer = findNodeByKey(node.getChildren(), key);
            if (answer != null) {
                return answer;
            }
        }
    }
    return null;
}
 
Example #8
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 #9
Source File: MavenHelpers.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the list has the given dependency
 */
public static boolean hasDependency(List<org.apache.maven.model.Dependency> dependencies, String groupId, String artifactId) {
    if (dependencies != null) {
        for (org.apache.maven.model.Dependency dependency : dependencies) {
            if (Objects.equal(groupId, dependency.getGroupId()) && Objects.equal(artifactId, dependency.getArtifactId())) {
                return true;
            }
        }
    }
    return false;
}
 
Example #10
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 #11
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 #12
Source File: NewBuildCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    String buildConfigName = buildName.getValue();
    Objects.assertNotNull(buildConfigName, "buildName");
    Map<String, String> labels = BuildConfigs.createBuildLabels(buildConfigName);
    String ouputImageName = imageName.getValue();
    String gitUrlText = getOrFindGitUrl(context, gitUri.getValue());
    String imageText = outputImage.getValue();
    Model mavenModel = getMavenModel(context);
    if (Strings.isNullOrBlank(imageText) && mavenModel != null) {
        imageText = mavenModel.getProperties().getProperty("docker.image");
    }

    String webhookSecretText = webHookSecret.getValue();
    if (Strings.isNullOrBlank(webhookSecretText)) {
        // TODO generate a really good secret!
        webhookSecretText = "secret101";
    }
    BuildConfig buildConfig = BuildConfigs.createBuildConfig(buildConfigName, labels, gitUrlText, ouputImageName, imageText, webhookSecretText);

    System.out.println("Generated BuildConfig: " + toJson(buildConfig));

    ImageStream imageRepository = BuildConfigs.imageRepository(buildConfigName, labels);

    Controller controller = createController();
    controller.applyImageStream(imageRepository, "generated ImageStream: " + toJson(imageRepository));
    controller.applyBuildConfig(buildConfig, "generated BuildConfig: " + toJson(buildConfig));
    return Results.success("Added BuildConfig: " + Builds.getName(buildConfig) + " to OpenShift at master: " + getKubernetes().getMasterUrl());
}
 
Example #13
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 #14
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 #15
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 #16
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 #17
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, Object... values) {
    for (Object value : values) {
        if (value != null) {
            String text = value.toString();
            if (Objects.equal(text, actual)) {
                return true;
            }
        }
    }
    return false;
}
 
Example #18
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 #19
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 #20
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 #21
Source File: Agent.java    From funktion-connectors with Apache License 2.0 5 votes vote down vote up
public SubscribeResponse subscribe(SubscribeRequest request) throws InternalException {
    String namespace = request.getNamespace();
    Objects.notNull(namespace, "namespace");

    ConfigMap configMap = createSubscriptionResource(request, namespace);
    kubernetesClient.configMaps().inNamespace(namespace).create(configMap);
    return new SubscribeResponse(namespace, KubernetesHelper.getName(configMap));
}
 
Example #22
Source File: RepositoryConfig.java    From updatebot with Apache License 2.0 5 votes vote down vote up
public GitRepositoryConfig getRepositoryDetails(String cloneUrl) {
    GitRepositoryConfig answer = github.getRepositoryDetails(cloneUrl);
    if (answer == null) {
        for (GitRepository gitRepository : git) {
            if (Objects.equal(cloneUrl, gitRepository.getCloneUrl())) {
                answer = gitRepository.getRepositoryDetails();
                if (answer != null) {
                    return answer;
                }
            }
        }
    }
    return answer;
}
 
Example #23
Source File: LocalRepository.java    From updatebot with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the repository for the given repo
 */
public static LocalRepository findRepository(List<LocalRepository> localRepositories, GitRepository gitRepository) {
    if (localRepositories != null) {
        for (LocalRepository repository : localRepositories) {
            GitRepository repo = repository.getRepo();
            if (repo != null) {
                if (Objects.equal(repo.getCloneUrl(), gitRepository.getCloneUrl())) {
                    return repository;
                }
            }
        }
    }
    return null;
}
 
Example #24
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 #25
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 #26
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 #27
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 #28
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 #29
Source File: FileExtensionFilter.java    From updatebot with Apache License 2.0 4 votes vote down vote up
@Override
public boolean accept(File file) {
    return Objects.equal(extension, Files.getExtension(file.getName()));
}
 
Example #30
Source File: GitRepository.java    From updatebot with Apache License 2.0 4 votes vote down vote up
public boolean hasCloneUrl(String url) {
    return Objects.equal(this.cloneUrl, url);
}