public ArtifactCoordinates mscCoordinates() { return new ArtifactCoordinates(this.groupId, this.artifactId, this.version, this.classifier == null ? "" : this.classifier); }
public String relativeArtifactPath(char separator, String timestampVersion) { String artifactId1 = getArtifactId(); String version1 = getVersion(); StringBuilder builder = new StringBuilder(getGroupId().replace('.', separator)); builder.append(separator).append(artifactId1).append(separator); String pathVersion; final Matcher versionMatcher = snapshotPattern.matcher(version1); if (versionMatcher.find()) { // it's really a snapshot pathVersion = version1.substring(0, versionMatcher.start()) + "-SNAPSHOT"; } else { pathVersion = version1; } builder.append(pathVersion).append(separator).append(artifactId1).append('-').append(timestampVersion); return builder.toString(); }
@Override public File resolveArtifact(ArtifactCoordinates coordinates, String packaging) throws IOException { String artifactRelativePath = "m2repo/" + relativeArtifactPath('/', coordinates.getGroupId(), coordinates.getArtifactId(), coordinates.getVersion()); String classifier = ""; if (coordinates.getClassifier() != null && !coordinates.getClassifier().trim().isEmpty()) { classifier = "-" + coordinates.getClassifier(); } String jarPath = artifactRelativePath + classifier + "." + packaging; InputStream stream = UberJarMavenResolver.class.getClassLoader().getResourceAsStream(jarPath); if (stream != null) { return copyTempJar(coordinates.getArtifactId() + "-" + coordinates.getVersion(), stream, packaging); } return null; } }
/** * Build the artifact path including the classifier. * * @param artifactCoordinates * @return */ String toGradleArtifactPath(ArtifactCoordinates artifactCoordinates) { // e.g.: org/jboss/ws/cxf/jbossws-cxf-resources/5.1.5.Final/jbossws-cxf-resources-5.1.5.Final String pathWithMissingClassifier = artifactCoordinates.relativeArtifactPath('/'); StringBuilder sb = new StringBuilder(pathWithMissingClassifier); if (artifactCoordinates.getClassifier() != null && artifactCoordinates.getClassifier().length() > 0) { // org/jboss/ws/cxf/jbossws-cxf-resources/5.1.5.Final/jbossws-cxf-resources-5.1.5.Final-wildfly1000 sb .append("-") .append(artifactCoordinates.getClassifier()); } return sb.toString(); }
/** * Build file name for artifact. * * @param artifactCoordinates * @param packaging * @return */ String toGradleArtifactFileName(ArtifactCoordinates artifactCoordinates, String packaging) { StringBuilder sbFileFilter = new StringBuilder(); sbFileFilter .append(artifactCoordinates.getArtifactId()) .append("-") .append(artifactCoordinates.getVersion()); if (artifactCoordinates.getClassifier() != null && artifactCoordinates.getClassifier().length() > 0) { sbFileFilter .append("-") .append(artifactCoordinates.getClassifier()); } sbFileFilter .append(".") .append(packaging); return sbFileFilter.toString(); }
String artifactRelativePath = coordinates.relativeArtifactPath(File.separatorChar); String artifactRelativeHttpPath = coordinates.relativeArtifactPath('/'); String artifactRelativeMetadataHttpPath = coordinates.relativeMetadataPath('/'); final MavenSettings settings = MavenSettings.getSettings(); final Path localRepository = settings.getLocalRepository(); if (coordinates.isSnapshot()) { try { String remoteMetadataPath = remoteRepository + artifactRelativeMetadataHttpPath; timestampedArtifactRelativePath = coordinates.relativeArtifactPath('/', downloadTimestampVersion(coordinates + ":" + packaging, remoteMetadataPath)); String remotePomPath = remoteRepository + timestampedArtifactRelativePath + ".pom"; downloadFile(coordinates + ":" + packaging, remotePomPath, pomFile); final String coordinatesClassifier = coordinates.getClassifier(); String classifier = coordinatesClassifier.isEmpty() ? "" : "-" + coordinatesClassifier; String artifactPath = artifactRelativePath + classifier + "." + packaging; if (coordinates.isSnapshot()) { String timestampedArtifactRelativePath; for (String remoteRepository : remoteRepos) { try { String remoteMetadataPath = remoteRepository + artifactRelativeMetadataHttpPath; timestampedArtifactRelativePath = coordinates.relativeArtifactPath('/', downloadTimestampVersion(coordinates + ":" + packaging, remoteMetadataPath)); String remotePomPath = remoteRepository + timestampedArtifactRelativePath + ".pom"; String remoteArtifactPath = remoteRepository + timestampedArtifactRelativePath + classifier + "." + packaging;
final ArtifactCoordinates coordinates; try { coordinates = ArtifactCoordinates.fromString(name); final File file = mavenResolver.resolveJarArtifact(coordinates); resourceLoader = factory.createResourceLoader("", file.getPath(), name); final String version = coordinates.getVersion(); try { return Version.parse(version);
String artifactRelativeMetadataHttpPath = artifactCoordinates.relativeMetadataPath('/'); for (String remoteRepos : remoteRepositories) { String artifactAbsoluteHttpPath = remoteRepos + artifactRelativeHttpPath + "."; if (artifactCoordinates.isSnapshot()) { String remoteMetadataPath = remoteRepos + artifactRelativeMetadataHttpPath; try { String timestamp = MavenArtifactUtil.downloadTimestampVersion(artifactCoordinates + ":" + packaging, remoteMetadataPath); String timestampedArtifactRelativePath = artifactCoordinates.relativeArtifactPath('/', timestamp); String artifactTimestampedAbsoluteHttpPath = remoteRepos + timestampedArtifactRelativePath + "."; File targetTimestampedArtifactPomDirectory = artifactDirectory.resolve(computeGradleUUID(artifactCoordinates + ":" + timestamp + ":pom")).toFile();
public boolean isSnapshot() { if (isSnapshot == null) { String version1 = getVersion(); final Matcher versionMatcher = snapshotPattern.matcher(version1); if (versionMatcher.find()) { isSnapshot = Boolean.TRUE; } else { isSnapshot = version1.contains("-SNAPSHOT"); } } return isSnapshot; }
/** * A utility method to create a Maven artifact resource loader for the given artifact name. * * @param mavenResolver the Maven resolver to use (must not be {@code null}) * @param name the artifact name * @return the resource loader * @throws IOException if the artifact could not be resolved */ public static ResourceLoader createMavenArtifactLoader(final MavenResolver mavenResolver, final String name) throws IOException { return createMavenArtifactLoader(mavenResolver, ArtifactCoordinates.fromString(name), name); }
/** * Determine whether this coordinates object equals the target object. * * @param obj the target object * @return {@code true} if the object is equal to this one, {@code false} otherwise */ public boolean equals(final Object obj) { return this == obj || obj instanceof ArtifactCoordinates && equals((ArtifactCoordinates) obj); }
/** * Create a relative repository path for the given artifact coordinates with a {@code '/'} separator. * * @return the path string */ public String relativeArtifactPath() { return relativeArtifactPath('/'); }
String artifactRelativePath = coordinates.relativeArtifactPath(File.separatorChar); String artifactRelativeHttpPath = coordinates.relativeArtifactPath('/'); final MavenSettings settings = MavenSettings.getSettings(); final Path localRepository = settings.getLocalRepository(); final String coordinatesClassifier = coordinates.getClassifier(); String classifier = coordinatesClassifier.isEmpty() ? "" : "-" + coordinatesClassifier; String artifactPath = artifactRelativePath + classifier + "." + packaging;
/** * A utility method to create a Maven artifact resource loader for the given artifact name. * * @param mavenResolver the Maven resolver to use (must not be {@code null}) * @param name the artifact name * @return the resource loader * @throws IOException if the artifact could not be resolved */ public static ResourceLoader createMavenArtifactLoader(final MavenResolver mavenResolver, final String name) throws IOException { return createMavenArtifactLoader(mavenResolver, ArtifactCoordinates.fromString(name), name); }
/** * Determine whether this coordinates object equals the target object. * * @param obj the target object * @return {@code true} if the object is equal to this one, {@code false} otherwise */ public boolean equals(final Object obj) { return this == obj || obj instanceof ArtifactCoordinates && equals((ArtifactCoordinates) obj); }
/** * Create a relative repository path for the given artifact coordinates with a {@code '/'} separator. * * @return the path string */ public String relativeArtifactPath() { return relativeArtifactPath('/'); }
public ArtifactCoordinates mscCoordinates() { return new ArtifactCoordinates(this.groupId, this.artifactId, this.version, this.classifier == null ? "" : this.classifier); }
public String relativeMetadataPath(char separator) { String artifactId1 = getArtifactId(); String version1 = getVersion(); StringBuilder builder = new StringBuilder(getGroupId().replace('.', separator)); builder.append(separator).append(artifactId1).append(separator); String pathVersion; final Matcher versionMatcher = snapshotPattern.matcher(version1); if (versionMatcher.find()) { // it's really a snapshot pathVersion = version1.substring(0, versionMatcher.start()) + "-SNAPSHOT"; } else { pathVersion = version1; } builder.append(pathVersion).append(separator).append("maven-metadata.xml"); return builder.toString(); }
@Override public File resolveArtifact(ArtifactCoordinates coordinates, String packaging) throws IOException { File resolved = this.resolutionCache.get(coordinates); if (resolved == null) { String artifactRelativePath = "m2repo/" + relativeArtifactPath('/', coordinates.getGroupId(), coordinates.getArtifactId(), coordinates.getVersion()); String classifier = ""; if (coordinates.getClassifier() != null && !coordinates.getClassifier().trim().isEmpty()) { classifier = HYPHEN + coordinates.getClassifier(); } String jarPath = artifactRelativePath + classifier + DOT + packaging; InputStream stream = UberJarMavenResolver.class.getClassLoader().getResourceAsStream(jarPath); if (stream != null) { try { resolved = copyTempJar(coordinates.getArtifactId() + HYPHEN + coordinates.getVersion(), stream, packaging); this.resolutionCache.put(coordinates, resolved); } finally { stream.close(); } } } return resolved; }
private static void createMavenNativeArtifactLoader(final MavenResolver mavenResolver, final String name, final XmlPullParser reader, final ModuleSpec.Builder specBuilder) throws IOException, XmlPullParserException { File fp = mavenResolver.resolveJarArtifact(ArtifactCoordinates.fromString(name)); if (fp == null) throw new XmlPullParserException(String.format("Failed to resolve native artifact '%s'", name), reader, null); File lib = new File(fp.getParentFile(), "lib"); if (!lib.exists()) { if (!fp.getParentFile().canWrite()) throw new XmlPullParserException(String.format("Native artifact '%s' cannot be unpacked", name), reader, null); unzip(fp, fp.getParentFile()); } specBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(new NativeLibraryResourceLoader(lib), PathFilters.rejectAll())); }