/**
   * Get the set of artifacts that are provided by Synapse at runtime.
   *
   * @return
   * @throws MojoExecutionException
   */
  private Set<Artifact> getSynapseRuntimeArtifacts() throws MojoExecutionException {
    Log log = getLog();
    log.debug("Looking for synapse-core artifact in XAR project dependencies ...");
    Artifact synapseCore = null;
    for (Iterator<?> it = project.getDependencyArtifacts().iterator(); it.hasNext(); ) {
      Artifact artifact = (Artifact) it.next();
      if (artifact.getGroupId().equals("org.apache.synapse")
          && artifact.getArtifactId().equals("synapse-core")) {
        synapseCore = artifact;
        break;
      }
    }
    if (synapseCore == null) {
      throw new MojoExecutionException("Could not locate dependency on synapse-core");
    }

    log.debug("Loading project data for " + synapseCore + " ...");
    MavenProject synapseCoreProject;
    try {
      synapseCoreProject =
          projectBuilder.buildFromRepository(
              synapseCore, remoteArtifactRepositories, localRepository);
    } catch (ProjectBuildingException e) {
      throw new MojoExecutionException(
          "Unable to retrieve project information for " + synapseCore, e);
    }
    Set<Artifact> synapseRuntimeDeps;
    try {
      synapseRuntimeDeps =
          synapseCoreProject.createArtifacts(
              artifactFactory, Artifact.SCOPE_RUNTIME, new TypeArtifactFilter("jar"));
    } catch (InvalidDependencyVersionException e) {
      throw new MojoExecutionException("Unable to get project dependencies for " + synapseCore, e);
    }
    log.debug("Direct runtime dependencies for " + synapseCore + " :");
    logArtifacts(synapseRuntimeDeps);

    log.debug("Resolving transitive dependencies for " + synapseCore + " ...");
    try {
      synapseRuntimeDeps =
          artifactCollector
              .collect(
                  synapseRuntimeDeps,
                  synapseCoreProject.getArtifact(),
                  synapseCoreProject.getManagedVersionMap(),
                  localRepository,
                  remoteArtifactRepositories,
                  artifactMetadataSource,
                  null,
                  Collections.singletonList(new DebugResolutionListener(logger)))
              .getArtifacts();
    } catch (ArtifactResolutionException e) {
      throw new MojoExecutionException(
          "Unable to resolve transitive dependencies for " + synapseCore);
    }
    log.debug("All runtime dependencies for " + synapseCore + " :");
    logArtifacts(synapseRuntimeDeps);

    return synapseRuntimeDeps;
  }
 private Artifact findGrailsDependency(MavenProject project) {
   Set dependencyArtifacts = project.getDependencyArtifacts();
   for (Object o : dependencyArtifacts) {
     Artifact artifact = (Artifact) o;
     if (artifact.getArtifactId().equals("grails-dependencies")) {
       return artifact;
     }
   }
   return null;
 }
 /**
  * @throws MojoExecutionException
  * @throws MojoFailureException
  */
 protected void deployDependencies() throws MojoExecutionException, MojoFailureException {
   Set<Artifact> directDependentArtifacts = project.getDependencyArtifacts();
   if (directDependentArtifacts != null) {
     for (Artifact artifact : directDependentArtifacts) {
       String type = artifact.getType();
       if (type.equals(APK)) {
         getLog()
             .debug(
                 "Detected apk dependency " + artifact + ". Will resolve and deploy to device...");
         final File targetApkFile = resolveArtifactToFile(artifact);
         getLog().debug("Deploying " + targetApkFile + " to device...");
         deployApk(targetApkFile);
       }
     }
   }
 }
  public Set<Artifact> getNativeDependenciesArtifacts(File unpackDirectory, boolean sharedLibraries)
      throws MojoExecutionException {
    final Set<Artifact> filteredArtifacts = new LinkedHashSet<Artifact>();

    // Add all dependent artifacts declared in the pom file
    @SuppressWarnings("unchecked")
    final Set<Artifact> allArtifacts = project.getDependencyArtifacts();

    // Add all attached artifacts as well - this could come from the NDK mojo for example
    boolean result = allArtifacts.addAll(project.getAttachedArtifacts());

    for (Artifact artifact : allArtifacts) {
      // A null value in the scope indicates that the artifact has been attached
      // as part of a previous build step (NDK mojo)
      if (isNativeLibrary(sharedLibraries, artifact.getType()) && artifact.getScope() == null) {
        // Including attached artifact
        log.debug(
            "Including attached artifact: "
                + artifact.getArtifactId()
                + "("
                + artifact.getGroupId()
                + ")");
        filteredArtifacts.add(artifact);
      } else if (isNativeLibrary(sharedLibraries, artifact.getType())
          && (Artifact.SCOPE_COMPILE.equals(artifact.getScope())
              || Artifact.SCOPE_RUNTIME.equals(artifact.getScope()))) {
        filteredArtifacts.add(artifact);
      } else if (APKLIB.equals(artifact.getType())) {
        // Check if the artifact contains a libs folder - if so, include it in the list
        File libsFolder =
            new File(
                AbstractAndroidMojo.getLibraryUnpackDirectory(unpackDirectory, artifact) + "/libs");
        if (libsFolder.exists()) {
          filteredArtifacts.add(artifact);
        }
      }
    }

    Set<Artifact> transientArtifacts =
        processTransientDependencies(project.getDependencies(), sharedLibraries);

    filteredArtifacts.addAll(transientArtifacts);

    return filteredArtifacts;
  }
Exemple #5
0
  private static Artifact findCamelCoreArtifact(MavenProject project) {
    // maybe this project is camel-core itself
    Artifact artifact = project.getArtifact();
    if (artifact.getGroupId().equals("org.apache.camel")
        && artifact.getArtifactId().equals("camel-core")) {
      return artifact;
    }

    // or its a component which has a dependency to camel-core
    Iterator it = project.getDependencyArtifacts().iterator();
    while (it.hasNext()) {
      artifact = (Artifact) it.next();
      if (artifact.getGroupId().equals("org.apache.camel")
          && artifact.getArtifactId().equals("camel-core")) {
        return artifact;
      }
    }
    return null;
  }
Exemple #6
0
  protected void addMvn2CompatResults(
      MavenProject project,
      List<Exception> exceptions,
      List<ResolutionListener> listeners,
      ArtifactRepository localRepository,
      Collection<MavenExecutionResult> executionResults) {
    ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest();
    resolutionRequest.setArtifactDependencies(project.getDependencyArtifacts());
    resolutionRequest.setArtifact(project.getArtifact());
    resolutionRequest.setManagedVersionMap(project.getManagedVersionMap());
    resolutionRequest.setLocalRepository(localRepository);
    resolutionRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
    resolutionRequest.setListeners(listeners);

    resolutionRequest.setResolveRoot(false);
    resolutionRequest.setResolveTransitively(true);

    ArtifactResolver resolver = getComponent(ArtifactResolver.class);
    ArtifactResolutionResult result = resolver.resolve(resolutionRequest);

    project.setArtifacts(result.getArtifacts());
    executionResults.add(new MavenExecutionResult(project, exceptions));
  }
  public void execute() throws MojoExecutionException, MojoFailureException {
    for (Artifact artifact : (Set<Artifact>) project.getDependencyArtifacts()) {
      String type = artifact.getType();
      if ("android:po".equals(type)) {
        String classifier = artifact.getClassifier();
        if (classifier == null) {
          throw new MojoExecutionException("android:po artifacts must have a classifier");
        }
        boolean isClassifier = defaultResources.contains(classifier);
        File valuesDir =
            (isClassifier)
                ? new File(resourceDirectory, "values")
                : new File(resourceDirectory, "values-" + classifier);
        if (!valuesDir.exists()) {
          valuesDir.mkdirs();
        }

        List<Resource> resources = project.getBuild().getResources();
        String resourceDir = (resources.isEmpty()) ? "res" : resources.get(0).getDirectory();

        ZipFile zip = null;
        try {
          zip = new ZipFile(artifact.getFile());
          Enumeration<? extends ZipEntry> en = zip.entries();
          while (en.hasMoreElements()) {
            ZipEntry entry = en.nextElement();
            if (entry.getName().endsWith(".po")) {
              writeWithCorrectEncoding(
                  artifact.getFile(), entry.getName(), valuesDir, resourceDir, isClassifier);
            }
          }
        } catch (IOException e) {
          throw new MojoExecutionException("", e);
        }
      }
    }
  }
  /** Iterate through dependencies, find those specified in the whitelist */
  private Set<Artifact> findThriftDependencies(Set<String> whitelist) throws IOException {
    Set<Artifact> thriftDependencies = new HashSet<Artifact>();

    Set<Artifact> deps = new HashSet<Artifact>();
    deps.addAll(project.getArtifacts());
    deps.addAll(project.getDependencyArtifacts());

    Map<String, Artifact> depsMap = new HashMap<String, Artifact>();
    for (Artifact dep : deps) {
      depsMap.put(dep.getId(), dep);
    }

    for (Artifact artifact : deps) {
      // This artifact is on the whitelist directly.
      if (whitelist.contains(artifact.getArtifactId())) {
        thriftDependencies.add(artifact);

        // Check if this artifact is being pulled in by an idl jar that's been whitelisted
      } else {
        List<String> depTrail = artifact.getDependencyTrail();
        // depTrail can be null sometimes, which seems like a maven bug
        if (depTrail != null) {
          for (String name : depTrail) {
            Artifact dep = depsMap.get(name);
            if (dep != null
                && "idl".equals(dep.getClassifier())
                && whitelist.contains(dep.getArtifactId())) {
              thriftDependencies.add(artifact);
              break;
            }
          }
        }
      }
    }
    return thriftDependencies;
  }
  @SuppressWarnings("unchecked")
  public void execute() throws MojoExecutionException {
    ArtifactVersion currentVersion = ri.getApplicationVersion();
    ArtifactVersion maxUsageVersion = new DefaultArtifactVersion("2.2.0");

    if (maxUsageVersion.compareTo(currentVersion) < 0) {
      getLog()
          .debug(
              "This version of Maven does not require injection of custom ArtifactHandlers using this code. Skipping.");
      return;
    }

    Map<String, ?> handlerDescriptors =
        session.getContainer().getComponentDescriptorMap(ArtifactHandler.ROLE);
    if (handlerDescriptors != null) {
      getLog().debug("Registering all unregistered ArtifactHandlers...");

      if (artifactHandlerManager instanceof DefaultArtifactHandlerManager) {
        Set<String> existingHints =
            ((DefaultArtifactHandlerManager) artifactHandlerManager).getHandlerTypes();
        if (existingHints != null) {
          for (String hint : existingHints) {
            handlerDescriptors.remove(hint);
          }
        }
      }

      if (handlerDescriptors.isEmpty()) {
        getLog().debug("All ArtifactHandlers are registered. Continuing...");
      } else {
        Map<String, ArtifactHandler> unregisteredHandlers =
            new HashMap<String, ArtifactHandler>(handlerDescriptors.size());

        for (String hint : handlerDescriptors.keySet()) {
          try {
            unregisteredHandlers.put(
                hint, (ArtifactHandler) session.lookup(ArtifactHandler.ROLE, hint));
            getLog().info("Adding ArtifactHandler for: " + hint);
          } catch (ComponentLookupException e) {
            getLog()
                .warn(
                    "Failed to lookup ArtifactHandler with hint: "
                        + hint
                        + ". Reason: "
                        + e.getMessage(),
                    e);
          }
        }

        artifactHandlerManager.addHandlers(unregisteredHandlers);
      }
    }

    getLog()
        .debug("...done.\nSetting ArtifactHandler on project-artifact: " + project.getId() + "...");

    Set<Artifact> artifacts = new HashSet<Artifact>();
    artifacts.add(project.getArtifact());

    Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
    if (dependencyArtifacts != null && !dependencyArtifacts.isEmpty()) {
      artifacts.addAll(dependencyArtifacts);
    }

    for (Artifact artifact : artifacts) {
      String type = artifact.getType();
      ArtifactHandler handler = artifactHandlerManager.getArtifactHandler(type);

      getLog()
          .debug(
              "Artifact: "
                  + artifact.getId()
                  + "\nType: "
                  + type
                  + "\nArtifactHandler extension: "
                  + handler.getExtension());

      artifact.setArtifactHandler(handler);
    }

    getLog().debug("...done.");
  }
 /**
  * @return a {@code Set} of direct project dependencies. Never {@code null}. This excludes
  *     artifacts of the {@code EXCLUDED_DEPENDENCY_SCOPES} scopes.
  */
 protected Set<Artifact> getRelevantDependencyArtifacts() {
   final Set<Artifact> allArtifacts = (Set<Artifact>) project.getDependencyArtifacts();
   final Set<Artifact> results = filterOutIrrelevantArtifacts(allArtifacts);
   return results;
 }
 /**
  * @return a {@code Set} of direct project dependencies. Never {@code null}. This excludes
  *     artifacts of the {@code EXCLUDED_DEPENDENCY_SCOPES} scopes.
  */
 protected Set<Artifact> getDirectDependencyArtifacts() {
   final Set<Artifact> allArtifacts = project.getDependencyArtifacts();
   return getArtifactResolverHelper().getFilteredArtifacts(allArtifacts);
 }
  public Set<Artifact> getNativeDependenciesArtifacts(
      AbstractAndroidMojo mojo, File unpackDirectory, boolean sharedLibraries)
      throws MojoExecutionException {
    log.debug(
        "Finding native dependencies. UnpackFolder="
            + unpackDirectory
            + " shared="
            + sharedLibraries);
    final Set<Artifact> filteredArtifacts = new LinkedHashSet<Artifact>();
    final Set<Artifact> allArtifacts = new LinkedHashSet<Artifact>();

    // Add all dependent artifacts declared in the pom file
    // Note: The result of project.getDependencyArtifacts() can be an UnmodifiableSet so we
    //       have created our own above and add to that.
    allArtifacts.addAll(project.getDependencyArtifacts());

    // Add all attached artifacts as well - this could come from the NDK mojo for example
    allArtifacts.addAll(project.getAttachedArtifacts());

    // Add all transitive artifacts as well
    // this allows armeabi classifier -> apklib -> apklib -> apk chaining to only include armeabi in
    // APK
    allArtifacts.addAll(project.getArtifacts());

    for (Artifact artifact : allArtifacts) {
      log.debug("Checking artifact : " + artifact);
      // A null value in the scope indicates that the artifact has been attached
      // as part of a previous build step (NDK mojo)
      if (isNativeLibrary(sharedLibraries, artifact.getType()) && artifact.getScope() == null) {
        // Including attached artifact
        log.debug("Including attached artifact: " + artifact + ". Artifact scope is not set.");
        filteredArtifacts.add(artifact);
      } else {
        if (isNativeLibrary(sharedLibraries, artifact.getType())
            && (Artifact.SCOPE_COMPILE.equals(artifact.getScope())
                || Artifact.SCOPE_RUNTIME.equals(artifact.getScope()))) {
          log.debug(
              "Including attached artifact: "
                  + artifact
                  + ". Artifact scope is Compile or Runtime.");
          filteredArtifacts.add(artifact);
        } else {
          final String type = artifact.getType();

          if (APKLIB.equals(type)) {
            // Check if the artifact contains a libs folder - if so, include it in the list
            File libsFolder = null;
            if (mojo != null) {
              libsFolder = mojo.getUnpackedLibNativesFolder(artifact);
            } else {
              // This is used from NativeHelperTest since we have no AbstractAndroidMojo there
              libsFolder =
                  new File(
                      AbstractAndroidMojo.getLibraryUnpackDirectory(unpackDirectory, artifact),
                      "libs");
            }

            if (!libsFolder.exists()) {
              log.debug("Skipping " + libsFolder.getAbsolutePath() + " for native artifacts");
              continue;
            }

            if (!libsFolder.isDirectory()) {
              continue;
            }

            log.debug("Checking " + libsFolder.getAbsolutePath() + " for native artifacts");
            // make sure we ignore libs folders that only contain JARs
            // The regular expression filters out all file paths ending with '.jar' or '.JAR',
            // so all native libs remain
            if (libsFolder.list(new PatternFilenameFilter("^.*(?<!(?i)\\.jar)$")).length > 0) {
              log.debug("Including attached artifact: " + artifact + ". Artifact is APKLIB.");
              filteredArtifacts.add(artifact);
            }
          } else if (!"jar".equals(type)) {
            log.debug("Not checking " + type + " for native artifacts");
          }
        }
      }
    }

    Set<Artifact> transitiveArtifacts =
        processTransitiveDependencies(project.getDependencies(), sharedLibraries);

    filteredArtifacts.addAll(transitiveArtifacts);

    return filteredArtifacts;
  }
  public Set<Artifact> getNativeDependenciesArtifacts(File unpackDirectory, boolean sharedLibraries)
      throws MojoExecutionException {
    final Set<Artifact> filteredArtifacts = new LinkedHashSet<Artifact>();
    final Set<Artifact> allArtifacts = new LinkedHashSet<Artifact>();

    // Add all dependent artifacts declared in the pom file
    // Note: The result of project.getDependencyArtifacts() can be an UnmodifiableSet so we
    //       have created our own above and add to that.
    allArtifacts.addAll(project.getDependencyArtifacts());

    // Add all attached artifacts as well - this could come from the NDK mojo for example
    allArtifacts.addAll(project.getAttachedArtifacts());

    for (Artifact artifact : allArtifacts) {
      // A null value in the scope indicates that the artifact has been attached
      // as part of a previous build step (NDK mojo)
      if (isNativeLibrary(sharedLibraries, artifact.getType()) && artifact.getScope() == null) {
        // Including attached artifact
        log.debug(
            "Including attached artifact: "
                + artifact.getArtifactId()
                + "("
                + artifact.getGroupId()
                + "). Artifact scope is not set.");
        filteredArtifacts.add(artifact);
      } else {
        if (isNativeLibrary(sharedLibraries, artifact.getType())
            && (Artifact.SCOPE_COMPILE.equals(artifact.getScope())
                || Artifact.SCOPE_RUNTIME.equals(artifact.getScope()))) {
          log.debug(
              "Including attached artifact: "
                  + artifact.getArtifactId()
                  + "("
                  + artifact.getGroupId()
                  + "). Artifact scope is Compile or Runtime.");
          filteredArtifacts.add(artifact);
        } else {
          if (APKLIB.equals(artifact.getType())) {
            // Check if the artifact contains a libs folder - if so, include it in the list
            File libsFolder =
                new File(
                    AbstractAndroidMojo.getLibraryUnpackDirectory(unpackDirectory, artifact),
                    "libs");
            // make sure we ignore libs folders that only contain JARs
            // The regular expression filters out all file paths ending with '.jar' or '.JAR',
            // so all native libs remain
            if (libsFolder.exists()
                && libsFolder.list(new PatternFilenameFilter("^.*(?<!(?i)\\.jar)$")).length > 0) {
              log.debug(
                  "Including attached artifact: "
                      + artifact.getArtifactId()
                      + "("
                      + artifact.getGroupId()
                      + "). Artifact is APKLIB.");
              filteredArtifacts.add(artifact);
            }
          }
        }
      }
    }

    Set<Artifact> transientArtifacts =
        processTransientDependencies(project.getDependencies(), sharedLibraries);

    filteredArtifacts.addAll(transientArtifacts);

    return filteredArtifacts;
  }