Search in sources :

Example 71 with LinkedHashSet

use of java.util.LinkedHashSet in project ACS by ACS-Community.

the class DOMJavaClassIntrospector method getElementFields.

public static String[] getElementFields(Object node) {
    Set<String> subnodes = new LinkedHashSet<String>();
    final Class nodeType = node.getClass();
    Class type = nodeType;
    while (type != null) {
        Field[] fields = type.getDeclaredFields();
        for (Field field : fields) {
            boolean isPrimitive = isPrimitive(field.getType());
            if (!isPrimitive && getAccessorMethod(nodeType, field.getName()) != null) {
                // do not add null elements check
                if (getChild(field.getName(), node) != null)
                    subnodes.add(field.getName());
            }
        }
        type = type.getSuperclass();
    }
    Object subnodesMap = getChild(SUBNODES_MAP_NAME, node);
    if (subnodesMap instanceof InternalElementsMap) {
        Set keySet = ((Map) subnodesMap).keySet();
        for (Object key : keySet) subnodes.add(key.toString());
    }
    subnodesMap = getChild(SUBNODES_MAP_NAME_ALTERNATIVE, node);
    if (subnodesMap instanceof InternalElementsMap) {
        Set keySet = ((Map) subnodesMap).keySet();
        for (Object key : keySet) subnodes.add(key.toString());
    }
    return subnodes.toArray(new String[subnodes.size()]);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Field(java.lang.reflect.Field) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 72 with LinkedHashSet

use of java.util.LinkedHashSet in project camel by apache.

the class AbstractCamelCatalog method validateEndpointProperties.

public EndpointValidationResult validateEndpointProperties(String uri, boolean ignoreLenientProperties, boolean consumerOnly, boolean producerOnly) {
    EndpointValidationResult result = new EndpointValidationResult(uri);
    Map<String, String> properties;
    List<Map<String, String>> rows;
    boolean lenientProperties;
    String scheme;
    try {
        String json = null;
        // parse the uri
        URI u = normalizeUri(uri);
        scheme = u.getScheme();
        if (scheme != null) {
            json = jsonSchemaResolver.getComponentJSonSchema(scheme);
        }
        if (json == null) {
            // if the uri starts with a placeholder then we are also incapable of parsing it as we wasn't able to resolve the component name
            if (uri.startsWith("{{")) {
                result.addIncapable(uri);
            } else if (scheme != null) {
                result.addUnknownComponent(scheme);
            } else {
                result.addUnknownComponent(uri);
            }
            return result;
        }
        rows = JSonSchemaHelper.parseJsonSchema("component", json, false);
        // is the component capable of both consumer and producer?
        boolean canConsumeAndProduce = false;
        if (!isComponentConsumerOnly(rows) && !isComponentProducerOnly(rows)) {
            canConsumeAndProduce = true;
        }
        if (canConsumeAndProduce && consumerOnly) {
            // lenient properties is not support in consumer only mode if the component can do both of them
            lenientProperties = false;
        } else {
            // only enable lenient properties if we should not ignore
            lenientProperties = !ignoreLenientProperties && isComponentLenientProperties(rows);
        }
        rows = JSonSchemaHelper.parseJsonSchema("properties", json, true);
        properties = endpointProperties(uri);
    } catch (URISyntaxException e) {
        if (uri.startsWith("{{")) {
            // if the uri starts with a placeholder then we are also incapable of parsing it as we wasn't able to resolve the component name
            result.addIncapable(uri);
        } else {
            result.addSyntaxError(e.getMessage());
        }
        return result;
    }
    // data format to the list of rows
    if ("dataformat".equals(scheme)) {
        String dfName = properties.get("name");
        if (dfName != null) {
            String dfJson = jsonSchemaResolver.getDataFormatJSonSchema(dfName);
            List<Map<String, String>> dfRows = JSonSchemaHelper.parseJsonSchema("properties", dfJson, true);
            if (dfRows != null && !dfRows.isEmpty()) {
                rows.addAll(dfRows);
            }
        }
    }
    for (Map.Entry<String, String> property : properties.entrySet()) {
        String value = property.getValue();
        String originalName = property.getKey();
        String name = property.getKey();
        // the name may be using an optional prefix, so lets strip that because the options
        // in the schema are listed without the prefix
        name = stripOptionalPrefixFromName(rows, name);
        // the name may be using a prefix, so lets see if we can find the real property name
        String propertyName = getPropertyNameFromNameWithPrefix(rows, name);
        if (propertyName != null) {
            name = propertyName;
        }
        String prefix = getPropertyPrefix(rows, name);
        String kind = getPropertyKind(rows, name);
        boolean namePlaceholder = name.startsWith("{{") && name.endsWith("}}");
        boolean valuePlaceholder = value.startsWith("{{") || value.startsWith("${") || value.startsWith("$simple{");
        boolean lookup = value.startsWith("#") && value.length() > 1;
        // we cannot evaluate multi values as strict as the others, as we don't know their expected types
        boolean mulitValue = prefix != null && originalName.startsWith(prefix) && isPropertyMultiValue(rows, name);
        Map<String, String> row = getRow(rows, name);
        if (row == null) {
            // and the name is not a property placeholder for one or more values
            if (!namePlaceholder && !"stub".equals(scheme)) {
                if (lenientProperties) {
                    // as if we are lenient then the option is a dynamic extra option which we cannot validate
                    result.addLenient(name);
                } else {
                    // its unknown
                    result.addUnknown(name);
                    if (suggestionStrategy != null) {
                        String[] suggestions = suggestionStrategy.suggestEndpointOptions(getNames(rows), name);
                        if (suggestions != null) {
                            result.addUnknownSuggestions(name, suggestions);
                        }
                    }
                }
            }
        } else {
            if ("parameter".equals(kind)) {
                // consumer only or producer only mode for parameters
                if (consumerOnly) {
                    boolean producer = isPropertyProducerOnly(rows, name);
                    if (producer) {
                        // the option is only for producer so you cannot use it in consumer mode
                        result.addNotConsumerOnly(name);
                    }
                } else if (producerOnly) {
                    boolean consumer = isPropertyConsumerOnly(rows, name);
                    if (consumer) {
                        // the option is only for consumer so you cannot use it in producer mode
                        result.addNotProducerOnly(name);
                    }
                }
            }
            // default value
            String defaultValue = getPropertyDefaultValue(rows, name);
            if (defaultValue != null) {
                result.addDefaultValue(name, defaultValue);
            }
            // is required but the value is empty
            boolean required = isPropertyRequired(rows, name);
            if (required && isEmpty(value)) {
                result.addRequired(name);
            }
            // is enum but the value is not within the enum range
            // but we can only check if the value is not a placeholder
            String enums = getPropertyEnum(rows, name);
            if (!mulitValue && !valuePlaceholder && !lookup && enums != null) {
                String[] choices = enums.split(",");
                boolean found = false;
                for (String s : choices) {
                    if (value.equalsIgnoreCase(s)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    result.addInvalidEnum(name, value);
                    result.addInvalidEnumChoices(name, choices);
                    if (suggestionStrategy != null) {
                        Set<String> names = new LinkedHashSet<>();
                        names.addAll(Arrays.asList(choices));
                        String[] suggestions = suggestionStrategy.suggestEndpointOptions(names, value);
                        if (suggestions != null) {
                            result.addInvalidEnumSuggestions(name, suggestions);
                        }
                    }
                }
            }
            // is reference lookup of bean (not applicable for @UriPath, enums, or multi-valued)
            if (!mulitValue && enums == null && !"path".equals(kind) && isPropertyObject(rows, name)) {
                // must start with # and be at least 2 characters
                if (!value.startsWith("#") || value.length() <= 1) {
                    result.addInvalidReference(name, value);
                }
            }
            // is boolean
            if (!mulitValue && !valuePlaceholder && !lookup && isPropertyBoolean(rows, name)) {
                // value must be a boolean
                boolean bool = "true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value);
                if (!bool) {
                    result.addInvalidBoolean(name, value);
                }
            }
            // is integer
            if (!mulitValue && !valuePlaceholder && !lookup && isPropertyInteger(rows, name)) {
                // value must be an integer
                boolean valid = validateInteger(value);
                if (!valid) {
                    result.addInvalidInteger(name, value);
                }
            }
            // is number
            if (!mulitValue && !valuePlaceholder && !lookup && isPropertyNumber(rows, name)) {
                // value must be an number
                boolean valid = false;
                try {
                    valid = !Double.valueOf(value).isNaN() || !Float.valueOf(value).isNaN();
                } catch (Exception e) {
                // ignore
                }
                if (!valid) {
                    result.addInvalidNumber(name, value);
                }
            }
        }
    }
    // now check if all required values are there, and that a default value does not exists
    for (Map<String, String> row : rows) {
        String name = row.get("name");
        boolean required = isPropertyRequired(rows, name);
        if (required) {
            String value = properties.get(name);
            if (isEmpty(value)) {
                value = getPropertyDefaultValue(rows, name);
            }
            if (isEmpty(value)) {
                result.addRequired(name);
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) URISupport.createQueryString(org.apache.camel.catalog.URISupport.createQueryString) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 73 with LinkedHashSet

use of java.util.LinkedHashSet in project camel by apache.

the class AbstractCamelCatalog method validateProperties.

public EndpointValidationResult validateProperties(String scheme, Map<String, String> properties) {
    EndpointValidationResult result = new EndpointValidationResult(scheme);
    String json = jsonSchemaResolver.getComponentJSonSchema(scheme);
    List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("properties", json, true);
    List<Map<String, String>> componentProps = JSonSchemaHelper.parseJsonSchema("componentProperties", json, true);
    // endpoint options have higher priority so remove those from component
    // that may clash
    componentProps.stream().filter(c -> rows.stream().noneMatch(e -> Objects.equals(e.get("name"), c.get("name")))).forEach(rows::add);
    boolean lenient = Boolean.getBoolean(properties.getOrDefault("lenient", "false"));
    // data format to the list of rows
    if ("dataformat".equals(scheme)) {
        String dfName = properties.get("name");
        if (dfName != null) {
            String dfJson = jsonSchemaResolver.getDataFormatJSonSchema(dfName);
            List<Map<String, String>> dfRows = JSonSchemaHelper.parseJsonSchema("properties", dfJson, true);
            if (dfRows != null && !dfRows.isEmpty()) {
                rows.addAll(dfRows);
            }
        }
    }
    for (Map.Entry<String, String> property : properties.entrySet()) {
        String value = property.getValue();
        String originalName = property.getKey();
        String name = property.getKey();
        // the name may be using an optional prefix, so lets strip that because the options
        // in the schema are listed without the prefix
        name = stripOptionalPrefixFromName(rows, name);
        // the name may be using a prefix, so lets see if we can find the real property name
        String propertyName = getPropertyNameFromNameWithPrefix(rows, name);
        if (propertyName != null) {
            name = propertyName;
        }
        String prefix = getPropertyPrefix(rows, name);
        String kind = getPropertyKind(rows, name);
        boolean namePlaceholder = name.startsWith("{{") && name.endsWith("}}");
        boolean valuePlaceholder = value.startsWith("{{") || value.startsWith("${") || value.startsWith("$simple{");
        boolean lookup = value.startsWith("#") && value.length() > 1;
        // we cannot evaluate multi values as strict as the others, as we don't know their expected types
        boolean multiValue = prefix != null && originalName.startsWith(prefix) && isPropertyMultiValue(rows, name);
        Map<String, String> row = getRow(rows, name);
        if (row == null) {
            // and the name is not a property placeholder for one or more values
            if (!namePlaceholder && !"stub".equals(scheme)) {
                if (lenient) {
                    // as if we are lenient then the option is a dynamic extra option which we cannot validate
                    result.addLenient(name);
                } else {
                    // its unknown
                    result.addUnknown(name);
                    if (suggestionStrategy != null) {
                        String[] suggestions = suggestionStrategy.suggestEndpointOptions(getNames(rows), name);
                        if (suggestions != null) {
                            result.addUnknownSuggestions(name, suggestions);
                        }
                    }
                }
            }
        } else {
            /* TODO: we may need to add something in the properties to know if they are related to a producer or consumer
                if ("parameter".equals(kind)) {
                    // consumer only or producer only mode for parameters
                    if (consumerOnly) {
                        boolean producer = isPropertyProducerOnly(rows, name);
                        if (producer) {
                            // the option is only for producer so you cannot use it in consumer mode
                            result.addNotConsumerOnly(name);
                        }
                    } else if (producerOnly) {
                        boolean consumer = isPropertyConsumerOnly(rows, name);
                        if (consumer) {
                            // the option is only for consumer so you cannot use it in producer mode
                            result.addNotProducerOnly(name);
                        }
                    }
                }
                */
            // default value
            String defaultValue = getPropertyDefaultValue(rows, name);
            if (defaultValue != null) {
                result.addDefaultValue(name, defaultValue);
            }
            // is required but the value is empty
            boolean required = isPropertyRequired(rows, name);
            if (required && isEmpty(value)) {
                result.addRequired(name);
            }
            // is enum but the value is not within the enum range
            // but we can only check if the value is not a placeholder
            String enums = getPropertyEnum(rows, name);
            if (!multiValue && !valuePlaceholder && !lookup && enums != null) {
                String[] choices = enums.split(",");
                boolean found = false;
                for (String s : choices) {
                    if (value.equalsIgnoreCase(s)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    result.addInvalidEnum(name, value);
                    result.addInvalidEnumChoices(name, choices);
                    if (suggestionStrategy != null) {
                        Set<String> names = new LinkedHashSet<>();
                        names.addAll(Arrays.asList(choices));
                        String[] suggestions = suggestionStrategy.suggestEndpointOptions(names, value);
                        if (suggestions != null) {
                            result.addInvalidEnumSuggestions(name, suggestions);
                        }
                    }
                }
            }
            // is reference lookup of bean (not applicable for @UriPath, enums, or multi-valued)
            if (!multiValue && enums == null && !"path".equals(kind) && isPropertyObject(rows, name)) {
                // must start with # and be at least 2 characters
                if (!value.startsWith("#") || value.length() <= 1) {
                    result.addInvalidReference(name, value);
                }
            }
            // is boolean
            if (!multiValue && !valuePlaceholder && !lookup && isPropertyBoolean(rows, name)) {
                // value must be a boolean
                boolean bool = "true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value);
                if (!bool) {
                    result.addInvalidBoolean(name, value);
                }
            }
            // is integer
            if (!multiValue && !valuePlaceholder && !lookup && isPropertyInteger(rows, name)) {
                // value must be an integer
                boolean valid = validateInteger(value);
                if (!valid) {
                    result.addInvalidInteger(name, value);
                }
            }
            // is number
            if (!multiValue && !valuePlaceholder && !lookup && isPropertyNumber(rows, name)) {
                // value must be an number
                boolean valid = false;
                try {
                    valid = !Double.valueOf(value).isNaN() || !Float.valueOf(value).isNaN();
                } catch (Exception e) {
                // ignore
                }
                if (!valid) {
                    result.addInvalidNumber(name, value);
                }
            }
        }
    }
    // now check if all required values are there, and that a default value does not exists
    for (Map<String, String> row : rows) {
        String name = row.get("name");
        boolean required = isPropertyRequired(rows, name);
        if (required) {
            String value = properties.get(name);
            if (isEmpty(value)) {
                value = getPropertyDefaultValue(rows, name);
            }
            if (isEmpty(value)) {
                result.addRequired(name);
            }
        }
    }
    return result;
}
Also used : Arrays(java.util.Arrays) JSonSchemaHelper.stripOptionalPrefixFromName(org.apache.camel.catalog.JSonSchemaHelper.stripOptionalPrefixFromName) URISyntaxException(java.net.URISyntaxException) JSonSchemaHelper.getPropertyEnum(org.apache.camel.catalog.JSonSchemaHelper.getPropertyEnum) HashMap(java.util.HashMap) JSonSchemaHelper.getPropertyKind(org.apache.camel.catalog.JSonSchemaHelper.getPropertyKind) JSonSchemaHelper.getPropertyNameFromNameWithPrefix(org.apache.camel.catalog.JSonSchemaHelper.getPropertyNameFromNameWithPrefix) URISupport.stripQuery(org.apache.camel.catalog.URISupport.stripQuery) JSonSchemaHelper.isPropertyBoolean(org.apache.camel.catalog.JSonSchemaHelper.isPropertyBoolean) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Matcher(java.util.regex.Matcher) JSonSchemaHelper.isPropertyRequired(org.apache.camel.catalog.JSonSchemaHelper.isPropertyRequired) Map(java.util.Map) JSonSchemaHelper.isPropertyInteger(org.apache.camel.catalog.JSonSchemaHelper.isPropertyInteger) JSonSchemaHelper.isPropertyNumber(org.apache.camel.catalog.JSonSchemaHelper.isPropertyNumber) URI(java.net.URI) URISupport.normalizeUri(org.apache.camel.catalog.URISupport.normalizeUri) LinkedList(java.util.LinkedList) Method(java.lang.reflect.Method) LinkedHashSet(java.util.LinkedHashSet) JSonSchemaHelper.isPropertyProducerOnly(org.apache.camel.catalog.JSonSchemaHelper.isPropertyProducerOnly) JSonSchemaHelper.isComponentLenientProperties(org.apache.camel.catalog.JSonSchemaHelper.isComponentLenientProperties) JSonSchemaHelper.getPropertyPrefix(org.apache.camel.catalog.JSonSchemaHelper.getPropertyPrefix) Iterator(java.util.Iterator) JSonSchemaHelper.isPropertyMultiValue(org.apache.camel.catalog.JSonSchemaHelper.isPropertyMultiValue) URISupport.isEmpty(org.apache.camel.catalog.URISupport.isEmpty) JSonSchemaHelper.getNames(org.apache.camel.catalog.JSonSchemaHelper.getNames) JSonSchemaHelper.isPropertyConsumerOnly(org.apache.camel.catalog.JSonSchemaHelper.isPropertyConsumerOnly) JSonSchemaHelper.getPropertyDefaultValue(org.apache.camel.catalog.JSonSchemaHelper.getPropertyDefaultValue) Set(java.util.Set) Collectors(java.util.stream.Collectors) CatalogHelper.after(org.apache.camel.catalog.CatalogHelper.after) JSonSchemaHelper.isComponentConsumerOnly(org.apache.camel.catalog.JSonSchemaHelper.isComponentConsumerOnly) URISupport.createQueryString(org.apache.camel.catalog.URISupport.createQueryString) InvocationTargetException(java.lang.reflect.InvocationTargetException) Objects(java.util.Objects) List(java.util.List) TreeMap(java.util.TreeMap) JSonSchemaHelper.isComponentProducerOnly(org.apache.camel.catalog.JSonSchemaHelper.isComponentProducerOnly) JSonSchemaHelper.getRow(org.apache.camel.catalog.JSonSchemaHelper.getRow) Pattern(java.util.regex.Pattern) JSonSchemaHelper.isPropertyObject(org.apache.camel.catalog.JSonSchemaHelper.isPropertyObject) LinkedHashSet(java.util.LinkedHashSet) URISupport.createQueryString(org.apache.camel.catalog.URISupport.createQueryString) URISyntaxException(java.net.URISyntaxException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 74 with LinkedHashSet

use of java.util.LinkedHashSet in project intellij-community by JetBrains.

the class RootVisitorHost method visitOrderEntryRoots.

private static boolean visitOrderEntryRoots(RootVisitor visitor, OrderEntry entry) {
    Set<VirtualFile> allRoots = new LinkedHashSet<>();
    Collections.addAll(allRoots, entry.getFiles(OrderRootType.SOURCES));
    Collections.addAll(allRoots, entry.getFiles(OrderRootType.CLASSES));
    Module module = entry instanceof ModuleOrderEntry ? ((ModuleOrderEntry) entry).getModule() : null;
    Sdk sdk = entry instanceof JdkOrderEntry ? ((JdkOrderEntry) entry).getJdk() : null;
    for (VirtualFile root : allRoots) {
        if (!visitor.visitRoot(root, module, sdk, false)) {
            return false;
        }
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 75 with LinkedHashSet

use of java.util.LinkedHashSet in project intellij-community by JetBrains.

the class CustomMaven3ArtifactResolver method resolve.

// ------------------------------------------------------------------------
//
// ------------------------------------------------------------------------
public ArtifactResolutionResult resolve(ArtifactResolutionRequest request) {
    Artifact rootArtifact = request.getArtifact();
    Set<Artifact> artifacts = request.getArtifactDependencies();
    Map<String, Artifact> managedVersions = request.getManagedVersionMap();
    List<ResolutionListener> listeners = request.getListeners();
    ArtifactFilter collectionFilter = request.getCollectionFilter();
    ArtifactFilter resolutionFilter = request.getResolutionFilter();
    RepositorySystemSession session = getSession(request.getLocalRepository());
    //TODO: hack because metadata isn't generated in m2e correctly and i want to run the maven i have in the workspace
    if (source == null) {
        try {
            source = container.lookup(ArtifactMetadataSource.class);
        } catch (ComponentLookupException e) {
        // won't happen
        }
    }
    if (listeners == null) {
        listeners = new ArrayList<ResolutionListener>();
        if (logger.isDebugEnabled()) {
            listeners.add(new DebugResolutionListener(logger));
        }
        listeners.add(new WarningResolutionListener(logger));
    }
    ArtifactResolutionResult result = new ArtifactResolutionResult();
    if (request.isResolveRoot()) /* && rootArtifact.getFile() == null */
    {
        try {
            resolve(rootArtifact, request.getRemoteRepositories(), session);
        } catch (ArtifactResolutionException e) {
            result.addErrorArtifactException(e);
            return result;
        } catch (ArtifactNotFoundException e) {
            result.addMissingArtifact(request.getArtifact());
            return result;
        }
    }
    ArtifactResolutionRequest collectionRequest = request;
    if (request.isResolveTransitively()) {
        MetadataResolutionRequest metadataRequest = new DefaultMetadataResolutionRequest(request);
        metadataRequest.setArtifact(rootArtifact);
        metadataRequest.setResolveManagedVersions(managedVersions == null);
        try {
            ResolutionGroup resolutionGroup = source.retrieve(metadataRequest);
            if (managedVersions == null) {
                managedVersions = resolutionGroup.getManagedVersions();
            }
            Set<Artifact> directArtifacts = resolutionGroup.getArtifacts();
            if (artifacts == null || artifacts.isEmpty()) {
                artifacts = directArtifacts;
            } else {
                List<Artifact> allArtifacts = new ArrayList<Artifact>();
                allArtifacts.addAll(artifacts);
                allArtifacts.addAll(directArtifacts);
                Map<String, Artifact> mergedArtifacts = new LinkedHashMap<String, Artifact>();
                for (Artifact artifact : allArtifacts) {
                    String conflictId = artifact.getDependencyConflictId();
                    if (!mergedArtifacts.containsKey(conflictId)) {
                        mergedArtifacts.put(conflictId, artifact);
                    }
                }
                artifacts = new LinkedHashSet<Artifact>(mergedArtifacts.values());
            }
            collectionRequest = new ArtifactResolutionRequest(request);
            collectionRequest.setServers(request.getServers());
            collectionRequest.setMirrors(request.getMirrors());
            collectionRequest.setProxies(request.getProxies());
            collectionRequest.setRemoteRepositories(resolutionGroup.getResolutionRepositories());
        } catch (ArtifactMetadataRetrievalException e) {
            ArtifactResolutionException are = new ArtifactResolutionException("Unable to get dependency information for " + rootArtifact.getId() + ": " + e.getMessage(), rootArtifact, metadataRequest.getRemoteRepositories(), e);
            result.addMetadataResolutionException(are);
            return result;
        }
    }
    if (artifacts == null || artifacts.isEmpty()) {
        if (request.isResolveRoot()) {
            result.addArtifact(rootArtifact);
        }
        return result;
    }
    // After the collection we will have the artifact object in the result but they will not be resolved yet.
    result = artifactCollector.collect(artifacts, rootArtifact, managedVersions, collectionRequest, source, collectionFilter, listeners, null);
    if (result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() || result.hasCircularDependencyExceptions()) {
        return result;
    }
    if (result.getArtifactResolutionNodes() != null) {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        CountDownLatch latch = new CountDownLatch(result.getArtifactResolutionNodes().size());
        for (ResolutionNode node : result.getArtifactResolutionNodes()) {
            Artifact artifact = node.getArtifact();
            if (resolutionFilter == null || resolutionFilter.include(artifact)) {
                executor.execute(new ResolveTask(classLoader, latch, artifact, session, node.getRemoteRepositories(), result));
            } else {
                latch.countDown();
            }
        }
        try {
            latch.await();
        } catch (InterruptedException e) {
            result.addErrorArtifactException(new ArtifactResolutionException("Resolution interrupted", rootArtifact, e));
        }
    }
    // have been resolved.
    if (request.isResolveRoot()) {
        // Add the root artifact (as the first artifact to retain logical order of class path!)
        Set<Artifact> allArtifacts = new LinkedHashSet<Artifact>();
        allArtifacts.add(rootArtifact);
        allArtifacts.addAll(result.getArtifacts());
        result.setArtifacts(allArtifacts);
    }
    return result;
}
Also used : DefaultMetadataResolutionRequest(org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest) MetadataResolutionRequest(org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest) LinkedHashSet(java.util.LinkedHashSet) ArtifactMetadataRetrievalException(org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException) ArrayList(java.util.ArrayList) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) LinkedHashMap(java.util.LinkedHashMap) DefaultMetadataResolutionRequest(org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ResolutionGroup(org.apache.maven.artifact.metadata.ResolutionGroup) CountDownLatch(java.util.concurrent.CountDownLatch) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ArtifactMetadataSource(org.apache.maven.artifact.metadata.ArtifactMetadataSource)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)3111 ArrayList (java.util.ArrayList)632 Set (java.util.Set)410 HashSet (java.util.HashSet)334 HashMap (java.util.HashMap)312 Map (java.util.Map)284 List (java.util.List)269 File (java.io.File)266 LinkedHashMap (java.util.LinkedHashMap)257 IOException (java.io.IOException)240 Test (org.junit.Test)239 LinkedList (java.util.LinkedList)139 Collection (java.util.Collection)103 URL (java.net.URL)83 ProcessResult (org.asqatasun.entity.audit.ProcessResult)76 Iterator (java.util.Iterator)73 SourceCodeRemark (org.asqatasun.entity.audit.SourceCodeRemark)73 TreeMap (java.util.TreeMap)70 TreeSet (java.util.TreeSet)70 Collectors (java.util.stream.Collectors)69