ResolvedArtifactLibrary(ResolvedArtifact artifact, LibraryScope scope) { super(artifact.getModuleVersion().getId().getGroup(), artifact.getFile(), scope); this.artifact = artifact; }
@Override public Set<ArtifactSpec> resolveAll(final Set<ArtifactSpec> specs) throws Exception { if (specs.isEmpty()) { return specs; } final Set<ArtifactSpec> resolvedSpecs = new HashSet<>(); doResolve(specs).forEach(dep -> dep.getAllModuleArtifacts() .forEach(artifact -> resolvedSpecs .add(new ArtifactSpec(dep.getConfiguration(), dep.getModuleGroup(), artifact.getName(), dep.getModuleVersion(), artifact.getExtension(), artifact.getClassifier(), artifact.getFile())))); return resolvedSpecs.stream() .filter(a -> !"system".equals(a.scope)) .collect(Collectors.toSet()); }
private String coordinates(ResolvedArtifact artifact, boolean withVersion) { // group:artifact:extension:classifier:version String classifier = artifact.getClassifier(); String extension = artifact.getType(); ModuleVersionIdentifier artifactId = artifact.getModuleVersion().getId(); return artifactId.getGroup() + ":" + artifactId.getName() + (StringUtils.hasText(extension) && (!"jar".equals(extension) || StringUtils.hasText(classifier)) ? ":" + extension : "") + (StringUtils.hasText(classifier) ? ":" + classifier : "") + (withVersion ? ":" + artifactId.getVersion() : ""); }
private String key(ResolvedArtifact dependency, Properties props) { String key = dependency.getModuleVersion().getId().getName(); if (!StringUtils.isEmpty(dependency.getClassifier())) { key = key + "." + dependency.getClassifier(); } int counter = 1; while (props.get("dependencies." + key) != null) { key = key + "." + counter++; } return key; }
Optional<ProjectElement<ResolvedArtifact>> resolutionInfo = Projects.findResolvedArtifact( getProject().getAllprojects(), c -> c.getName().equals(JavaConfigPlugin.ANNOTATIONS_CONFIGURATION), a -> Objects.equals(a.getName(), annotationsProjectName) && Strings.isNullOrEmpty(a.getClassifier()) && Objects.equals(a.getType(), "jar")); annotationPath = resolutionInfo.map(i -> i.getElement().getFile());
@Override public ArtifactSpec resolve(final ArtifactSpec spec) { if (spec.file != null) { return spec; } final Iterator<ResolvedDependency> iterator = doResolve(new HashSet<>(Collections.singletonList(spec))).iterator(); if (iterator.hasNext()) { spec.file = iterator.next() .getModuleArtifacts() .iterator().next() .getFile(); return spec; } return null; }
if (EXT_LIB_ARCHIVE.equals(artifact.getExtension())) { if (DEBUG_DEPENDENCY) { printIndent(indent, "TYPE: AAR"); @SuppressWarnings("unchecked") LibInfo libInfo = new LibInfo( artifact.getFile(), explodedDir, (List<LibraryDependency>) (List<?>) nestedLibraries, nestedJars, name, artifact.getClassifier(), gradlePath, } else if (EXT_JAR.equals(artifact.getExtension())) { if (DEBUG_DEPENDENCY) { printIndent(indent, "TYPE: JAR"); artifact.getFile(), new MavenCoordinatesImpl(artifact), gradlePath, } else if (EXT_ANDROID_PACKAGE.equals(artifact.getExtension())) { String name = computeArtifactName(moduleVersion, artifact); "Dependency %s on project %s resolves to an APK archive " + "which is not supported as a compilation dependency. File: %s", name, project.getName(), artifact.getFile()))); } else if ("apklib".equals(artifact.getExtension())) {
File file = new File(path); Optional<ProjectElement<ResolvedArtifact>> artifact = Projects.findResolvedArtifact( getProject().getAllprojects(), p -> true, a -> a.getFile().equals(file)); getLogger().debug("Resolved classpath to artifact '{}'", a.getElement().getId()); a.getElement().getName() + "-annotations"); });
private ResolvedArtifact prepareArtifact( String name, String group, String filePath, String version) { ModuleVersionIdentifier moduleId = mock(ModuleVersionIdentifier.class); when(moduleId.getGroup()).thenReturn(group); when(moduleId.getVersion()).thenReturn(version); ResolvedModuleVersion moduleVersion = mock(ResolvedModuleVersion.class); when(moduleVersion.getId()).thenReturn(moduleId); File artifactFile = mock(File.class); when(artifactFile.getAbsolutePath()).thenReturn(filePath); ResolvedArtifact artifact = mock(ResolvedArtifact.class); when(artifact.getName()).thenReturn(name); when(artifact.getFile()).thenReturn(artifactFile); when(artifact.getModuleVersion()).thenReturn(moduleVersion); return artifact; } }
public String getGroup() { return mArtifact.getModuleVersion().getId().getGroup(); }
/** * Create Eclipse annotations tasks * * @param tasks Task container * @param configurations Container to access configurations * @param buildDir Build directory */ @Mutate public void createEclipseAnnotationsTasks(ModelMap<Task> tasks, ConfigurationContainer configurations, @Path("buildDir") File buildDir) { tasks.create("eclipseAnnotations", EclipseAnnotationsTask.class, t -> { t.setDescription("Generates external nullability annotations for dependencies."); t.setGroup("IDE"); ConventionMapping parameters = t.getConventionMapping(); parameters.map("jars", () -> { Set<File> jars = configurations.stream() .filter(c -> c.isCanBeResolved() && !c.getName().equals(JavaConfigPlugin.ANNOTATIONS_CONFIGURATION)) .map(c -> c.getResolvedConfiguration().getLenientConfiguration()) .flatMap(c -> c.getArtifacts().stream() .filter(a -> !(a.getId() .getComponentIdentifier() instanceof ProjectComponentIdentifier) && a.getType().equals("jar")) .map(a -> a.getFile())) .collect(Collectors.toSet()); return jars; }); }); }
static Set<PackageManifest> gatherManifests(Set<ResolvedDependency> deps) { Set<PackageManifest> manifests = Sets.newHashSet(); for (ResolvedDependency dep : deps) { File manifest = null; File unitypackage = null; for (ResolvedArtifact art : dep.getModuleArtifacts()) { if (art.getExtension().equals("manifest")) { manifest = art.getFile(); } else if (art.getExtension().equals("unitypackage")) { unitypackage = art.getFile(); } } if (null != manifest && null != unitypackage) { PackageManifest p = PackageManifest.load(manifest); p.setUnityPackage(unitypackage); manifests.add(p); } else { logger.error("Malformed package", manifest, unitypackage); } } return manifests; }
ModuleVersionIdentifier module = artifact.getModuleVersion().getId(); String group = "deobf." + module.getGroup(); idMap.put(artifact.getId().getComponentIdentifier(), module); deobf.setInJar(artifact.getFile()); deobf.setOutJar(getFile(DIR_DEOBF_DEPS, group, module.getName(), module.getVersion(), null)); deobf.setFieldCsv(delayedFile(CSV_FIELD));
private void walk(final boolean top, ResolvedDependency dep) { Set<ResolvedArtifact> artifacts = dep.getModuleArtifacts(); for (ResolvedArtifact each : artifacts) { String[] parts = dep.getName().split(":"); String groupId = parts[0]; String artifactId = parts[1]; String version = parts[2]; this.tool.dependency("compile", groupId, artifactId, version, each.getExtension(), each.getClassifier(), each.getFile(), top); } dep.getChildren().forEach(d -> walk(false, d)); } }
public MavenCoordinatesImpl(@NonNull ResolvedArtifact resolvedArtifact) { this( resolvedArtifact.getModuleVersion().getId().getGroup(), resolvedArtifact.getModuleVersion().getId().getName(), resolvedArtifact.getModuleVersion().getId().getVersion(), resolvedArtifact.getExtension(), resolvedArtifact.getClassifier()); }
@Override public InputStream getInputStream() throws Exception { // create a temporary configuration to resolve the file Configuration conf = project.getConfigurations().detachedConfiguration( project.getDependencies().create(dependencyNotation)); ResolvedArtifact artifactId = conf.getResolvedConfiguration().getResolvedArtifacts().iterator().next(); logger.info("Selected recommendation source " + artifactId.getId() + ", you requested " + dependencyNotation); return new FileInputStream(artifactId.getFile()); } };
/** * Resolve all dependencies of all configurations of this project and it's subprojects. * * @return All resolved dependencies. */ protected List<DependencyIdentifier> resolveDependencies() { return getProject().getAllprojects().stream() // all projects .flatMap(project -> project.getConfigurations().stream()) // get all configurations .filter(Configuration::isCanBeResolved) // only if the configuration can be resolved .flatMap(configuration -> configuration.getResolvedConfiguration().getResolvedArtifacts().stream()) // get all artifacts .filter(resolvedArtifact -> !(resolvedArtifact.getId().getComponentIdentifier() instanceof DefaultProjectComponentIdentifier)) .map(resolvedArtifact -> resolvedArtifact.getModuleVersion().getId()) // map to ModuleVersionIdentifier .map(DependencyIdentifier::new) // .distinct() // .filter(this::filterIgnoredDependencies) // .sorted(new DependencyIdentifierComparator()) // .collect(Collectors.toList()); }
@NonNull private static String computeArtifactName( @NonNull ModuleVersionIdentifier moduleVersion, @NonNull ResolvedArtifact artifact) { StringBuilder nameBuilder = new StringBuilder(); nameBuilder.append(moduleVersion.getGroup()) .append(':') .append(moduleVersion.getName()) .append(':') .append(moduleVersion.getVersion()); if (artifact.getClassifier() != null && !artifact.getClassifier().isEmpty()) { nameBuilder.append(':').append(artifact.getClassifier()); } return nameBuilder.toString(); }
public static ResolvedArtifact getArtifactWithName(final String name, final Set<ResolvedArtifact> artifacts) { for (ResolvedArtifact artifact : artifacts) { if (artifact.getName().equals(name)) { return artifact; } } throw new IllegalStateException("Could not find a dependency with name " + name); }
public AndroidArchiveLibrary(Project project, ResolvedArtifact artifact) { if (!"aar".equals(artifact.getType())) { throw new IllegalArgumentException("artifact must be aar type!"); } mProject = project; mArtifact = artifact; }