X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-maven-plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang2sources%2Fplugin%2FUtil.java;fp=yang%2Fyang-maven-plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang2sources%2Fplugin%2FUtil.java;h=0000000000000000000000000000000000000000;hb=8f0b0b5dd235e30ec60c691c1bb8ba2177b752f3;hp=07cf2e2ccdace69cd010296e4ecc1965ff67aedf;hpb=f6b25b093b63feb1820970b9a9f270f166b5f8a1;p=yangtools.git diff --git a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/Util.java b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/Util.java deleted file mode 100644 index 07cf2e2ccd..0000000000 --- a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/Util.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.yang2sources.plugin; - -import static org.opendaylight.yangtools.yang2sources.plugin.YangToSourcesProcessor.LOG_PREFIX; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; -import org.apache.maven.artifact.resolver.ArtifactResolutionResult; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Plugin; -import org.apache.maven.project.MavenProject; -import org.apache.maven.repository.RepositorySystem; -import org.opendaylight.yangtools.yang.model.api.ModuleLike; -import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier; -import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -final class Util { - - /** - * It isn't desirable to create instances of this class. - */ - private Util() { - } - - private static final Logger LOG = LoggerFactory.getLogger(Util.class); - - static List getClassPath(final MavenProject project) { - final List dependencies = new ArrayList<>(); - for (Artifact element : project.getArtifacts()) { - File asFile = element.getFile(); - if (isJar(asFile) || asFile.isDirectory()) { - dependencies.add(asFile); - } - } - return dependencies; - } - - /** - * Read current project dependencies and check if it don't grab incorrect - * artifacts versions which could be in conflict with plugin dependencies. - * - * @param project - * current project - * @param repoSystem - * repository system - * @param localRepo - * local repository - * @param remoteRepos - * remote repositories - */ - static void checkClasspath(final MavenProject project, final RepositorySystem repoSystem, - final ArtifactRepository localRepo, final List remoteRepos) { - Plugin plugin = project.getPlugin(YangToSourcesMojo.PLUGIN_NAME); - if (plugin == null) { - LOG.warn("{} {} not found, dependencies version check skipped", LOG_PREFIX, YangToSourcesMojo.PLUGIN_NAME); - } else { - Map> pluginDependencies = new HashMap<>(); - getPluginTransitiveDependencies(plugin, pluginDependencies, repoSystem, localRepo, remoteRepos); - - Set projectDependencies = project.getDependencyArtifacts(); - for (Map.Entry> entry : pluginDependencies.entrySet()) { - checkArtifact(entry.getKey(), projectDependencies); - for (Artifact dependency : entry.getValue()) { - checkArtifact(dependency, projectDependencies); - } - } - } - } - - /** - * Read transitive dependencies of given plugin and store them in map. - * - * @param plugin - * plugin to read - * @param map - * map, where founded transitive dependencies will be stored - * @param repoSystem - * repository system - * @param localRepository - * local repository - * @param remoteRepos - * list of remote repositories - */ - private static void getPluginTransitiveDependencies(final Plugin plugin, - final Map> map, final RepositorySystem repoSystem, - final ArtifactRepository localRepository, final List remoteRepos) { - - List pluginDependencies = plugin.getDependencies(); - for (Dependency dep : pluginDependencies) { - Artifact artifact = repoSystem.createDependencyArtifact(dep); - - ArtifactResolutionRequest request = new ArtifactResolutionRequest(); - request.setArtifact(artifact); - request.setResolveTransitively(true); - request.setLocalRepository(localRepository); - request.setRemoteRepositories(remoteRepos); - - ArtifactResolutionResult result = repoSystem.resolve(request); - Set pluginDependencyDependencies = result.getArtifacts(); - map.put(artifact, pluginDependencyDependencies); - } - } - - /** - * Check artifact against collection of dependencies. If collection contains - * artifact with same groupId and artifactId, but different version, logs a - * warning. - * - * @param artifact - * artifact to check - * @param dependencies - * collection of dependencies - */ - private static void checkArtifact(final Artifact artifact, final Collection dependencies) { - for (org.apache.maven.artifact.Artifact d : dependencies) { - if (artifact.getGroupId().equals(d.getGroupId()) && artifact.getArtifactId().equals(d.getArtifactId())) { - if (!artifact.getVersion().equals(d.getVersion())) { - LOG.warn("{} Dependency resolution conflict:", LOG_PREFIX); - LOG.warn("{} '{}' dependency [{}] has different version than one declared in current project [{}]" - + ". It is recommended to fix this problem because it may cause compilation errors.", - LOG_PREFIX, YangToSourcesMojo.PLUGIN_NAME, artifact, d); - } - } - } - } - - private static boolean isJar(final File element) { - return element.isFile() && element.getName().endsWith(".jar"); - } - - static SourceIdentifier moduleToIdentifier(final ModuleLike module) { - return RevisionSourceIdentifier.create(module.getName(), module.getRevision()); - } -}