コード例 #1
0
  @Override
  protected List<File> getDependencies() {
    ArrayList<File> dependencies = new ArrayList<File>();

    @SuppressWarnings("unchecked")
    final Iterator<Artifact> it = project.getArtifacts().iterator();
    while (it.hasNext()) {
      final Artifact declared = it.next();
      this.log.debug("Checking artifact " + declared);
      if (this.isJavaArtifact(declared)) {
        if (Artifact.SCOPE_COMPILE.equals(declared.getScope())
            || Artifact.SCOPE_RUNTIME.equals(declared.getScope())
            || Artifact.SCOPE_PROVIDED.equals(declared.getScope())
            || Artifact.SCOPE_SYSTEM.equals(declared.getScope())) {
          this.log.debug("Resolving artifact " + declared);
          if (declared.getFile() != null) {
            dependencies.add(declared.getFile());
          } else {
            this.log.debug("Unable to resolve artifact " + declared);
          }
        } else {
          this.log.debug(
              "Artifact "
                  + declared
                  + " has not scope compile or runtime, but "
                  + declared.getScope());
        }
      } else {
        this.log.debug(
            "Artifact " + declared + " is not a java artifact, type is " + declared.getType());
      }
    }

    return dependencies;
  }
コード例 #2
0
  private Set<Artifact> getNativeDependenciesArtifacts() {
    Set<Artifact> filteredArtifacts = new HashSet<Artifact>();
    @SuppressWarnings("unchecked")
    final Set<Artifact> allArtifacts = project.getDependencyArtifacts();

    for (Artifact artifact : allArtifacts) {
      if ("so".equals(artifact.getType())
          && (Artifact.SCOPE_COMPILE.equals(artifact.getScope())
              || Artifact.SCOPE_RUNTIME.equals(artifact.getScope()))) {
        filteredArtifacts.add(artifact);
      }
    }

    return filteredArtifacts;
  }
コード例 #3
0
  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;
  }
コード例 #4
0
  protected List<IMavenProjectFacade> getWorkspaceDependencies(
      IProject project, MavenProject mavenProject) {
    Set<IProject> projects = new HashSet<IProject>();
    List<IMavenProjectFacade> dependencies = new ArrayList<IMavenProjectFacade>();
    Set<Artifact> artifacts = mavenProject.getArtifacts();
    for (Artifact artifact : artifacts) {
      IMavenProjectFacade dependency =
          projectManager.getMavenProject(
              artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());

      if ((Artifact.SCOPE_COMPILE.equals(artifact.getScope())
              || Artifact.SCOPE_RUNTIME.equals(
                  artifact.getScope())) // MNGECLIPSE-1578 Runtime dependencies should be deployed
          && dependency != null
          && !dependency.getProject().equals(project)
          && dependency.getFullPath(artifact.getFile()) != null
          && projects.add(dependency.getProject())) {
        dependencies.add(dependency);
      }
    }
    return dependencies;
  }
コード例 #5
0
  public void configureClasspath(
      IProject project,
      MavenProject mavenProject,
      IClasspathDescriptor classpath,
      IProgressMonitor monitor)
      throws CoreException {

    // Improve skinny war support by generating the manifest classpath
    // similar to mvn eclipse:eclipse
    // http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html
    WarPluginConfiguration config = new WarPluginConfiguration(mavenProject, project);
    IPackagingConfiguration opts =
        new PackagingConfiguration(config.getPackagingIncludes(), config.getPackagingExcludes());

    /*
     * Need to take care of three separate cases
     *
     * 1. remove any project dependencies (they are represented as J2EE module dependencies)
     * 2. add non-dependency attribute for entries originated by artifacts with
     *    runtime, system, test scopes or optional dependencies (not sure about the last one)
     * 3. make sure all dependency JAR files have unique file names, i.e. artifactId/version collisions
     */

    Set<String> dups = new LinkedHashSet<String>();
    Set<String> names = new HashSet<String>();
    FileNameMapping fileNameMapping = config.getFileNameMapping();
    String targetDir = mavenProject.getBuild().getDirectory();

    // first pass removes projects, adds non-dependency attribute and collects colliding filenames
    Iterator<IClasspathEntryDescriptor> iter = classpath.getEntryDescriptors().iterator();
    while (iter.hasNext()) {
      IClasspathEntryDescriptor descriptor = iter.next();
      IClasspathEntry entry = descriptor.toClasspathEntry();
      String scope = descriptor.getScope();
      Artifact artifact =
          ArtifactHelper.getArtifact(mavenProject.getArtifacts(), descriptor.getArtifactKey());

      ArtifactHelper.fixArtifactHandler(artifact.getArtifactHandler());

      String deployedName = fileNameMapping.mapFileName(artifact);

      boolean isDeployed =
          (Artifact.SCOPE_COMPILE.equals(scope) || Artifact.SCOPE_RUNTIME.equals(scope))
              && !descriptor.isOptionalDependency()
              && opts.isPackaged("WEB-INF/lib/" + deployedName)
              && !isWorkspaceProject(artifact);

      // add non-dependency attribute if this classpathentry is not meant to be deployed
      // or if it's a workspace project (projects already have a reference created in configure())
      if (!isDeployed) {
        descriptor.setClasspathAttribute(
            NONDEPENDENCY_ATTRIBUTE.getName(), NONDEPENDENCY_ATTRIBUTE.getValue());
      }

      // If custom fileName is used, then copy the artifact and rename the artifact under the build
      // dir
      String fileName = entry.getPath().lastSegment();
      if (!deployedName.equals(fileName)) {
        IPath newPath = renameArtifact(targetDir, entry.getPath(), deployedName);
        if (newPath != null) {
          descriptor.setPath(newPath);
        }
      }

      if (!names.add(deployedName)) {
        dups.add(deployedName);
      }
    }

    // second pass disambiguates colliding entry file names
    iter = classpath.getEntryDescriptors().iterator();
    while (iter.hasNext()) {
      IClasspathEntryDescriptor descriptor = iter.next();
      IClasspathEntry entry = descriptor.toClasspathEntry();

      if (dups.contains(entry.getPath().lastSegment())) {
        String newName = descriptor.getGroupId() + "-" + entry.getPath().lastSegment();
        IPath newPath = renameArtifact(targetDir, entry.getPath(), newName);
        if (newPath != null) {
          descriptor.setPath(newPath);
        }
      }
    }
  }
コード例 #6
0
  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;
  }
コード例 #7
0
  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;
  }