Пример #1
0
 /**
  * Resolve artifact
  *
  * @param settings the settings
  * @param dependency the canonical form of the dependency
  * @param scope the scope, one of "compile", "runtime", "provided", "test", "system", "import"
  * @param excludes canonical names of the dependencies to be excluded
  * @return the resolved Maven artifacts
  */
 public MavenResolvedArtifact[] resolveArtifact(
     String dependency, String scope, String[] excludes) {
   final String mavenSettingsFile = settings.get("apps.settings", DEFAULT_SETTINGS);
   final boolean useMavenCentral = settings.getAsBoolean("apps.usemavencentral", Boolean.TRUE);
   final String[] defaultExcludes = settings.getAsArray("apps.excludes", DEFAULT_EXCLUDE);
   final MavenDependencyExclusion[] exclusions =
       new MavenDependencyExclusion
           [defaultExcludes.length + (excludes != null ? excludes.length : 0)];
   for (int i = 0; i < defaultExcludes.length; i++) {
     exclusions[i] = MavenDependencies.createExclusion(defaultExcludes[i]);
   }
   if (excludes != null) {
     for (int i = 0; i < excludes.length; i++) {
       exclusions[defaultExcludes.length + i] = MavenDependencies.createExclusion(excludes[i]);
     }
   }
   ScopeType scopeType = scope != null ? ScopeType.fromScopeType(scope) : ScopeType.RUNTIME;
   // optional = false
   MavenDependency dep =
       MavenDependencies.createDependency(dependency, scopeType, false, exclusions);
   return Maven.configureResolver()
       .fromFile(mavenSettingsFile)
       .addDependencies(dep)
       .resolve()
       .withMavenCentralRepo(useMavenCentral)
       .using(new AcceptScopesStrategy(scopeType))
       .asResolvedArtifact();
 }
Пример #2
0
 /**
  * Helper method for refreshing all declared artifact apps
  *
  * @return a map of artifact apps that are present after refreshing
  */
 private Map<String, ArtifactApp> refreshArtifactApps() {
   final String mavenSettingsFile = settings.get("apps.settings", DEFAULT_SETTINGS);
   final boolean useMavenCentral = settings.getAsBoolean("apps.usemavencentral", Boolean.TRUE);
   final Map<String, Settings> appSettings = settings.getGroups("apps.dependencies");
   final String[] defaultExcludes = settings.getAsArray("apps.excludes", DEFAULT_EXCLUDE);
   Set<MavenDependency> defaultDeps = Sets.newHashSet();
   for (Map.Entry<String, Settings> entry : appSettings.entrySet()) {
     String name = entry.getKey(); // not used yet
     boolean enabled = entry.getValue().getAsBoolean("enabled", Boolean.TRUE);
     if (enabled) {
       String dependency = entry.getValue().get("dependency");
       String[] excludes = entry.getValue().getAsArray("exclude");
       MavenDependencyExclusion[] exclusions =
           new MavenDependencyExclusion[defaultExcludes.length + excludes.length];
       for (int i = 0; i < defaultExcludes.length; i++) {
         exclusions[i] = MavenDependencies.createExclusion(defaultExcludes[i]);
       }
       for (int i = 0; i < excludes.length; i++) {
         exclusions[defaultExcludes.length + i] = MavenDependencies.createExclusion(excludes[i]);
       }
       ScopeType scopeType = ScopeType.RUNTIME;
       defaultDeps.add(
           MavenDependencies.createDependency(dependency, scopeType, false, exclusions));
     }
   }
   MavenResolvedArtifact[] artifacts =
       defaultDeps.isEmpty()
           ? null
           : Maven.configureResolver()
               .fromFile(mavenSettingsFile)
               .addDependencies(defaultDeps)
               .resolve()
               .withMavenCentralRepo(useMavenCentral)
               .withTransitivity()
               .asResolvedArtifact();
   return loadArtifacts(artifacts);
 }
Пример #3
0
 private Set<App> whatRequires(String dependency, Set<String> visited) {
   final String mavenSettingsFile = settings.get("apps.settings", DEFAULT_SETTINGS);
   final boolean useMavenCentral = settings.getAsBoolean("apps.usemavencentral", Boolean.TRUE);
   final String[] defaultExcludes = settings.getAsArray("apps.excludes", DEFAULT_EXCLUDE);
   Set<App> foundDeps = Sets.newHashSet();
   for (App app : artifactApps.values()) {
     MavenDependencyExclusion[] exclusions = new MavenDependencyExclusion[defaultExcludes.length];
     for (int i = 0; i < defaultExcludes.length; i++) {
       exclusions[i] = MavenDependencies.createExclusion(defaultExcludes[i]);
     }
     MavenDependency dep =
         MavenDependencies.createDependency(
             app.getCanonicalForm(), ScopeType.RUNTIME, false, exclusions);
     MavenResolvedArtifact[] artifacts =
         Maven.configureResolver()
             .fromFile(mavenSettingsFile)
             .addDependencies(dep)
             .resolve()
             .withMavenCentralRepo(useMavenCentral)
             .withTransitivity()
             .asResolvedArtifact();
     if (artifacts != null && artifacts.length > 0) {
       visited.add(artifacts[0].getCoordinate().toCanonicalForm());
       for (MavenResolvedArtifact artifact : artifacts) {
         String artifactName = artifact.getCoordinate().toCanonicalForm();
         if (artifactName.startsWith(dependency)) {
           foundDeps.add(app);
         } else if (!visited.contains(artifactName)) {
           visited.add(artifactName);
           foundDeps.addAll(whatRequires(artifactName, visited));
         }
       }
     }
   }
   return foundDeps;
 }
Пример #4
0
 private Set<DependencyInfo> dependencyTree(
     String dependency, Set<DependencyInfo> visited, int level) {
   final String mavenSettingsFile = settings.get("apps.settings", DEFAULT_SETTINGS);
   final boolean useMavenCentral = settings.getAsBoolean("apps.usemavencentral", Boolean.TRUE);
   final String[] defaultExcludes = settings.getAsArray("apps.excludes", DEFAULT_EXCLUDE);
   MavenDependencyExclusion[] exclusions = new MavenDependencyExclusion[defaultExcludes.length];
   for (int i = 0; i < defaultExcludes.length; i++) {
     exclusions[i] = MavenDependencies.createExclusion(defaultExcludes[i]);
   }
   MavenDependency dep =
       MavenDependencies.createDependency(dependency, ScopeType.RUNTIME, false, exclusions);
   MavenResolvedArtifact[] artifacts =
       Maven.configureResolver()
           .fromFile(mavenSettingsFile)
           .addDependencies(dep)
           .resolve()
           .withMavenCentralRepo(useMavenCentral)
           .withTransitivity()
           .asResolvedArtifact();
   Set<DependencyInfo> foundDeps = Sets.newLinkedHashSet();
   if (artifacts != null && artifacts.length > 0) {
     DependencyInfo info = new DependencyInfo(artifacts[0], level);
     visited.add(info);
     foundDeps.add(info);
     for (MavenResolvedArtifact artifact : artifacts) {
       String artifactName = artifact.getCoordinate().toCanonicalForm();
       info = new DependencyInfo(artifact, level + 1);
       if (!visited.contains(info)) {
         visited.add(info);
         foundDeps.add(info);
         foundDeps.addAll(dependencyTree(artifactName, visited, level + 1));
       }
     }
   }
   return foundDeps;
 }
Пример #5
0
 /**
  * Remove artifact(s).
  *
  * @param settings
  * @param dependency
  */
 public void removeArtifacts(String dependency) {
   String mavenSettingsFile = settings.get("apps.settings", DEFAULT_SETTINGS);
   MavenDependency dep = MavenDependencies.createDependency(dependency, ScopeType.RUNTIME, false);
   File[] artifactFiles =
       Maven.configureResolver()
           .fromFile(mavenSettingsFile)
           .offline()
           .addDependency(dep)
           .resolve()
           .withoutTransitivity()
           .asFile();
   if (artifactFiles != null) {
     for (File artifactFile : artifactFiles) {
       // parent is the version file, a directory
       logger.warn("deleting {}", artifactFile.getParent());
       deleteDirectory(artifactFile.getParentFile());
     }
   }
 }