@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; }
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; }
static Set<PackageManifest> gatherManifests(Set<ResolvedDependency> deps) { Set<PackageManifest> manifests = Sets.newHashSet(); for (ResolvedDependency dep : deps) { File manifest = null; File unityZip = null; for (ResolvedArtifact art : dep.getModuleArtifacts()) { if (art.getExtension().equals("manifest")) { manifest = art.getFile(); } else if (art.getExtension().equals("zip")) { unityZip = art.getFile(); } } if (null != manifest && null != unityZip) { PackageManifest p = PackageManifest.load(manifest); p.setUnityPackage(unityZip); manifests.add(p); } else { logger.error("Malformed package", manifest, unityZip); } } return manifests; }
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; }
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 void collectArchives(final List<JApiCmpWorkerAction.Archive> archives, ResolvedDependency resolvedDependency) { String version = resolvedDependency.getModule().getId().getVersion(); archives.add(new JApiCmpWorkerAction.Archive(resolvedDependency.getAllModuleArtifacts().iterator().next().getFile(), version)); for (ResolvedDependency dependency : resolvedDependency.getChildren()) { collectArchives(archives, dependency); } }
@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()); } };
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)); } }
private void addConfigurationArtifacts(String[] configurations, Set<URL> urls) throws IOException { for (String configuration : configurations) { getLogger().debug("Adding configuration to classpath: " + configuration); ResolvedConfiguration resolvedConfiguration = getProject().getConfigurations().getByName(configuration).getResolvedConfiguration(); for (ResolvedArtifact artifact : resolvedConfiguration.getResolvedArtifacts()) { URL artifactUrl = artifact.getFile().toURI().toURL(); getLogger().debug("Adding artifact to classpath: " + artifactUrl); urls.add(artifactUrl); } } }
for (ResolvedArtifact artifact : artifacts) { ModuleVersionIdentifier id = artifact.getModuleVersion().getId(); File file = artifact.getFile(); idToFileMap.put(id, file);
for (ResolvedArtifact artifact : artifacts) { ModuleVersionIdentifier id = artifact.getModuleVersion().getId(); File file = artifact.getFile(); idToFileMap.put(id, file);
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; } }
&& Objects.equals(a.getType(), "jar")); annotationPath = resolutionInfo.map(i -> i.getElement().getFile());
private List<Pom> createPoms(Set<ResolvedArtifact> resolvedArtifacts, List<PomReference> pomReferences, PropertySource properties) { Map<String, PomReference> referencesById = new HashMap<String, PomReference>(); for (PomReference pomReference: pomReferences) { referencesById.put(createKey(pomReference.getCoordinates().getGroupId(), pomReference.getCoordinates().getArtifactId()), pomReference); } List<Pom> resolvedPoms = new ArrayList<Pom>(); for (ResolvedArtifact resolvedArtifact: resolvedArtifacts) { ModuleVersionIdentifier id = resolvedArtifact.getModuleVersion().getId(); PomReference reference = referencesById.get(createKey(id.getGroup(), id.getName())); CompositePropertySource allProperties = new CompositePropertySource(reference.getProperties(), properties); resolvedPoms.add(createPom(resolvedArtifact.getFile(), allProperties)); } return resolvedPoms; }
private void addConfigurationArtifacts(String[] configurations, Set<URL> urls) throws IOException { getLogger().debug("running: addConfigurationArtifacts()"); for (String configuration : configurations) { getLogger().debug("Adding configuration to classpath: " + configuration); ResolvedConfiguration resolvedConfiguration = getProject().getConfigurations().getByName(configuration).getResolvedConfiguration(); for (ResolvedArtifact artifact : resolvedConfiguration.getResolvedArtifacts()) { URL artifactUrl = artifact.getFile().toURI().toURL(); getLogger().debug("Adding artifact to classpath: " + artifactUrl); urls.add(artifactUrl); } } }
/** * 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; }); }); }
/** * 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; }); }); }
@TaskAction @SuppressWarnings("unused") public void checkSignatures() throws IOException { final AnimalSnifferToGradleLoggingBridge loggingBridge = new AnimalSnifferToGradleLoggingBridge( getLogger() ); for ( SourceSet sourceSet : config.getSourceSets() ) { for ( ResolvedArtifact resolvedArtifact : signatures.getResolvedConfiguration().getResolvedArtifacts() ) { final File signatureFile = resolvedArtifact.getFile(); getLogger().lifecycle( "Starting AnimalSniffer checks [" + signatureFile.getName() + "] against SourceSet [" + sourceSet.getName() + "]" ); final SignatureChecker signatureChecker = new SignatureChecker( new FileInputStream( signatureFile ), buildIgnores( sourceSet, loggingBridge ), loggingBridge ); signatureChecker.setCheckJars( false ); signatureChecker.setSourcePath( new ArrayList<>( sourceSet.getJava().getSrcDirs() ) ); signatureChecker.process( sourceSet.getJava().getOutputDir() ); if ( signatureChecker.isSignatureBroken() ) { throw new GradleException( "Signature errors found for SourceSet " + sourceSet.getName() + " against " + signatureFile.getAbsolutePath() + ". " + "Verify errors and ignore them with the proper annotation if needed." ); } } } }
private DefaultGosuCompileSpec createSpec() { DefaultGosuCompileSpec spec = new DefaultGosuCompileSpecFactory(_compileOptions).create(); Project project = getProject(); spec.setSource(getSource()); //project.files([ "src/main/gosu" ]) spec.setSourceRoots(getSourceRoots()); spec.setDestinationDir(getDestinationDir()); spec.setClasspath(getClasspath()); //Force gosu-core into the classpath. Normally it's a runtime dependency but compilation requires it. Set<ResolvedArtifact> projectDeps = project.getConfigurations().getByName("runtime").getResolvedConfiguration().getResolvedArtifacts(); File gosuCore = GosuPlugin.getArtifactWithName("gosu-core", projectDeps).getFile(); spec.setGosuClasspath( Collections.singletonList( gosuCore ) ); if(LOGGER.isDebugEnabled()) { LOGGER.debug("Gosu Compiler Spec classpath is:"); for(File file : spec.getClasspath()) { LOGGER.debug(file.getAbsolutePath()); } LOGGER.debug("Gosu Compile Spec gosuClasspath is:"); for(File file : spec.getGosuClasspath()) { LOGGER.debug(file.getAbsolutePath()); } } return spec; }